Refactoring

This commit is contained in:
OVSharova 2021-09-15 03:40:16 +03:00
parent 78b4d54c4f
commit 0de7742cfa
40 changed files with 218 additions and 247 deletions

View file

@ -846,7 +846,7 @@
for (var i = scripts.length - 1; i >= 0; i--) {
match = scripts[i].src.match(/(.*)apps\/api\/documents\/api.js/i);
if (match) {
return match[1] + "test/apps/";
return match[1] + "test/";
}
}

View file

@ -1,159 +0,0 @@
/*
*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
if (Common === undefined) {
var Common = {};
}
Common.Locale = new(function() {
"use strict";
var l10n = null;
var loadcallback,
apply = false,
defLang = '{{DEFAULT_LANG}}',
currentLang = defLang;
var _applyLocalization = function(callback) {
try {
callback && (loadcallback = callback);
if (l10n) {
for (var prop in l10n) {
var p = prop.split('.');
if (p && p.length > 2) {
var obj = window;
for (var i = 0; i < p.length - 1; ++i) {
if (obj[p[i]] === undefined) {
obj[p[i]] = new Object();
}
obj = obj[p[i]];
}
if (obj) {
obj[p[p.length - 1]] = l10n[prop];
}
}
}
loadcallback && loadcallback();
} else
apply = true;
}
catch (e) {
}
};
var _get = function(prop, scope) {
var res = '';
if (l10n && scope && scope.name) {
res = l10n[scope.name + '.' + prop];
if ( !res && scope.default )
res = scope.default;
}
return res || (scope ? eval(scope.name).prototype[prop] : '');
};
var _getCurrentLanguage = function() {
return currentLang;
};
var _getLoadedLanguage = function() {
return loadedLang;
};
var _getUrlParameterByName = function(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
};
var _requireLang = function () {
var lang = (_getUrlParameterByName('lang') || defLang).split(/[\-_]/)[0];
currentLang = lang;
fetch('locale/' + lang + '.json')
.then(function(response) {
if (!response.ok) {
currentLang = defLang;
if (lang != defLang)
/* load default lang if fetch failed */
return fetch('locale/' + defLang + '.json');
throw new Error('server error');
}
return response.json();
}).then(function(response) {
if ( response.json ) {
if (!response.ok)
throw new Error('server error');
return response.json();
} else {
l10n = response;
/* to break promises chain */
throw new Error('loaded');
}
}).then(function(json) {
l10n = json || {};
apply && _applyLocalization();
}).catch(function(e) {
l10n = l10n || {};
apply && _applyLocalization();
if ( e.message == 'loaded' ) {
} else {
currentLang = null;
console.log('fetch error: ' + e);
}
});
};
if ( !window.fetch ) {
/* use fetch polifill if native method isn't supported */
var polyfills = ['../vendor/fetch/fetch.umd'];
if ( !window.Promise ) {
require(['../vendor/es6-promise/es6-promise.auto.min'],
function () {
require(polyfills, _requireLang);
});
} else require(polyfills, _requireLang);
} else _requireLang();
return {
apply: _applyLocalization,
get: _get,
getCurrentLanguage: _getCurrentLanguage
};
})();

View file

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

Before

Width:  |  Height:  |  Size: 323 B

After

Width:  |  Height:  |  Size: 323 B

View file

Before

Width:  |  Height:  |  Size: 323 B

After

Width:  |  Height:  |  Size: 323 B

View file

@ -1,25 +1,25 @@
// Core variables and mixins
@import "../../../../../../vendor/bootstrap/less/variables.less";
@import "../../../../../vendor/bootstrap/less/variables.less";
@icon-font-path: "../../../../../../vendor/bootstrap/dist/fonts/";
@import "../../../../../../vendor/bootstrap/less/mixins.less";
@import "../../../../../vendor/bootstrap/less/mixins.less";
// Reset
@import "../../../../../../vendor/bootstrap/less/normalize.less";
@import "../../../../../../vendor/bootstrap/less/print.less";
@import "../../../../../vendor/bootstrap/less/normalize.less";
@import "../../../../../vendor/bootstrap/less/print.less";
// Core CSS
@import "../../../../../../vendor/bootstrap/less/scaffolding.less";
@import "../../../../../../vendor/bootstrap/less/type.less";
@import "../../../../../vendor/bootstrap/less/scaffolding.less";
@import "../../../../../vendor/bootstrap/less/type.less";
//@import "code.less";
//@import "grid.less";
//@import "tables.less";
@import "../../../../../../vendor/bootstrap/less/forms.less";
@import "../../../../../../vendor/bootstrap/less/buttons.less";
@import "../../../../../vendor/bootstrap/less/forms.less";
@import "../../../../../vendor/bootstrap/less/buttons.less";
// Components
@import "../../../../../../vendor/bootstrap/less/component-animations.less";
@import "../../../../../vendor/bootstrap/less/component-animations.less";
//@import "../../../../../../vendor/bootstrap/less/glyphicons.less";
//@import "dropdowns.less";
//@import "button-groups.less";
@ -29,28 +29,28 @@
//@import "breadcrumbs.less";
//@import "pagination.less";
//@import "pager.less";
@import "../../../../../../vendor/bootstrap/less/labels.less";
@import "../../../../../vendor/bootstrap/less/labels.less";
//@import "badges.less";
//@import "jumbotron.less";
//@import "thumbnails.less";
@import "../../../../../../vendor/bootstrap/less/alerts.less";
@import "../../../../../vendor/bootstrap/less/alerts.less";
//@import "progress-bars.less";
//@import "media.less";
//@import "list-group.less";
//@import "panels.less";
//@import "wells.less";
@import "../../../../../../vendor/bootstrap/less/close.less";
@import "../../../../../vendor/bootstrap/less/close.less";
// Components w/ JavaScript
@import "../../../../../../vendor/bootstrap/less/modals.less";
@import "../../../../../../vendor/bootstrap/less/tooltip.less";
@import "../../../../../vendor/bootstrap/less/modals.less";
@import "../../../../../vendor/bootstrap/less/tooltip.less";
//@import "../../../../../../vendor/bootstrap/less/popovers.less";
@import "../../../../../../vendor/bootstrap/less/dropdowns.less";
@import "../../../../../vendor/bootstrap/less/dropdowns.less";
//@import "carousel.less";
// Utility classes
@import "../../../../../../vendor/bootstrap/less/utilities.less";
@import "../../../../../../vendor/bootstrap/less/responsive-utilities.less";
@import "../../../../../vendor/bootstrap/less/utilities.less";
@import "../../../../../vendor/bootstrap/less/responsive-utilities.less";
@import "loadmask.less";

View file

@ -20,7 +20,7 @@
<!-- debug begin -->
<script type="text/javascript">var less=less||{};less.env='development';</script>
<script src="../../../../vendor/less/dist/less.js" type="text/javascript"></script>
<script src="../../../vendor/less/dist/less.js" type="text/javascript"></script>
<!-- debug end -->
<script>
@ -63,59 +63,30 @@
var params = getUrlParams(),
lang = (params["lang"] || 'en').split(/[\-\_]/)[0];
logo = params["headerlogo"] ? encodeUrlParam(params["headerlogo"]) : null;
window.frameEditorId = params["frameEditorId"];
window.parentOrigin = params["parentOrigin"];
var elem = document.querySelector('.loading-logo');
if (elem && logo) {
elem.style.backgroundImage= 'none';
var img = document.querySelector('.loading-logo img');
img && img.setAttribute('src', logo);
img.style.opacity = 1;
}
</script>
<div id="editor_sdk" class="viewer" style="overflow: hidden;" tabindex="-1"></div>
<!-- <div class="modal fade error" id="id-critical-error-dialog" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 id="id-critical-error-title"></h4>
</div>
<div class="modal-body">
<p id="id-critical-error-message"></p>
</div>
<div class="modal-footer">
<button id="id-critical-error-close" class="btn btn-sm btn-primary" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</div>
</div>
<div class="hyperlink-tooltip" data-toggle="tooltip" title="" style="display:none;"></div>-->
<!--vendor-->
<script type="text/javascript" src="../../../../vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../../../vendor/jquery.browser/dist/jquery.browser.min.js"></script>
<script type="text/javascript" src="../../../../vendor/bootstrap/dist/js/bootstrap.js"></script>
<script type="text/javascript" src="../../../vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../../vendor/jquery.browser/dist/jquery.browser.min.js"></script>
<script type="text/javascript" src="../../../vendor/bootstrap/dist/js/bootstrap.js"></script>
<script type="text/javascript" src="../../../../vendor/sockjs/sockjs.min.js"></script>
<script type="text/javascript" src="../../../../vendor/xregexp/xregexp-all-min.js"></script>
<script type="text/javascript" src="../../../vendor/sockjs/sockjs.min.js"></script>
<script type="text/javascript" src="../../../vendor/xregexp/xregexp-all-min.js"></script>
<script src="../../../../vendor/requirejs/require.js"></script>
<script src="../../../vendor/requirejs/require.js"></script>
<script type="text/javascript" src="../../../../../sdkjs/develop/sdkjs/word/scripts.js"></script>
<script type="text/javascript" src="../../../../sdkjs/develop/sdkjs/word/scripts.js"></script>
<script>
window.sdk_scripts.forEach(function(item){
document.write('<script type="text/javascript" src="../' + item + '"><\/script>');
document.write('<script type="text/javascript" src="' + item + '"><\/script>');
});
</script>

View file

@ -40,7 +40,7 @@
</div>
<!-- debug begin -->
<script type="text/javascript">var less=less||{};less.env='development';</script>
<script src="../../../../vendor/less/dist/less.js" type="text/javascript"></script>
<script src="../../../vendor/less/dist/less.js" type="text/javascript"></script>
<!-- debug end -->
<script>
@ -144,20 +144,20 @@
<div class="hyperlink-tooltip" data-toggle="tooltip" title="Press Ctrl and click the link" style="display:none;"></div>-->
<!--vendor-->
<script type="text/javascript" src="../../../../vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../../../vendor/jquery.browser/dist/jquery.browser.min.js"></script>
<script type="text/javascript" src="../../../../vendor/bootstrap/dist/js/bootstrap.js"></script>
<script type="text/javascript" src="../../../../vendor/sockjs/sockjs.min.js"></script>
<script type="text/javascript" src="../../../../vendor/xregexp/xregexp-all-min.js"></script>
<script type="text/javascript" src="../../../vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../../vendor/jquery.browser/dist/jquery.browser.min.js"></script>
<script type="text/javascript" src="../../../vendor/bootstrap/dist/js/bootstrap.js"></script>
<script type="text/javascript" src="../../../vendor/sockjs/sockjs.min.js"></script>
<script type="text/javascript" src="../../../vendor/xregexp/xregexp-all-min.js"></script>
<script src="../../../../vendor/requirejs/require.js"></script>
<script src="../../../vendor/requirejs/require.js"></script>
<script>
require.config({
baseUrl: '../../'
});
</script>
<script type="text/javascript" src="../../../../../sdkjs/develop/sdkjs/slide/scripts.js"></script>
<script type="text/javascript" src="../../../../sdkjs/develop/sdkjs/slide/scripts.js"></script>
<script>
window.sdk_scripts.forEach(function(item){
document.write('<script type="text/javascript" src="' + item + '"><\/script>');
@ -165,7 +165,6 @@
</script>
<!--application-->
<script type="text/javascript" src="../../common/locale.js"></script>
<script type="text/javascript" src="../../common/Gateway.js"></script>
<script type="text/javascript" src="../../common/main/lib/util/LocalStorage.js"></script>
<script type="text/javascript" src="../../common/main/lib/util/utils.js"></script>

View file

@ -9,7 +9,7 @@
<!-- debug begin -->
<link rel="stylesheet" type="text/css" href="../../../../../sdkjs/cell/css/main.css"/>
<link rel="stylesheet" type="text/css" href="../../../../sdkjs/cell/css/main.css"/>
<link rel="stylesheet/less" type="text/css" href="resources/less/application.less" />
<link rel="stylesheet/less" type="text/css" href="resources/less/celleditor.less" />
<!-- debug end -->
@ -42,7 +42,7 @@
<!-- debug begin -->
<script type="text/javascript">var less=less||{};less.env='development';</script>
<script src="../../../../vendor/less/dist/less-2.7.1.js" type="text/javascript"></script>
<script src="../../../vendor/less/dist/less-2.7.1.js" type="text/javascript"></script>
<!-- debug end -->
<script>
@ -127,24 +127,24 @@
<div class="hyperlink-tooltip" data-toggle="tooltip" title="Press Ctrl and click the link" style="display:none;"></div>
<!--vendor-->
<script type="text/javascript" src="../../../../vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../../../vendor/jquery.browser/dist/jquery.browser.min.js"></script>
<script type="text/javascript" src="../../../../vendor/bootstrap/dist/js/bootstrap.js"></script>
<script type="text/javascript" src="../../../vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../../vendor/jquery.browser/dist/jquery.browser.min.js"></script>
<script type="text/javascript" src="../../../vendor/bootstrap/dist/js/bootstrap.js"></script>
<script type="text/javascript" src="../../../../vendor/sockjs/sockjs.min.js"></script>
<script type="text/javascript" src="../../../../vendor/underscore/underscore-min.js"></script>
<script type="text/javascript" src="../../../../vendor/xregexp/xregexp-all-min.js"></script>
<script type="text/javascript" src="../../../../vendor/jszip/jszip.min.js"></script>
<script type="text/javascript" src="../../../../vendor/jszip-utils/jszip-utils.min.js"></script>
<script type="text/javascript" src="../../../vendor/sockjs/sockjs.min.js"></script>
<script type="text/javascript" src="../../../vendor/underscore/underscore-min.js"></script>
<script type="text/javascript" src="../../../vendor/xregexp/xregexp-all-min.js"></script>
<script type="text/javascript" src="../../../vendor/jszip/jszip.min.js"></script>
<script type="text/javascript" src="../../../vendor/jszip-utils/jszip-utils.min.js"></script>
<script src="../../../../vendor/requirejs/require.js"></script>
<script src="../../../vendor/requirejs/require.js"></script>
<script>
require.config({
baseUrl: '../../'
});
</script>
<script type="text/javascript" src="../../../../../sdkjs/develop/sdkjs/cell/scripts.js"></script>
<script type="text/javascript" src="../../../../sdkjs/develop/sdkjs/cell/scripts.js"></script>
<script>
window.sdk_scripts.forEach(function(item){
document.write('<script type="text/javascript" src="' + item + '"><\/script>');
@ -152,14 +152,13 @@
</script>
<!--application-->
<script type="text/javascript" src="../../common/locale.js"></script>
<script type="text/javascript" src="../../common/Gateway.js"></script>
<script type="text/javascript" src="../../common/main/lib/util/LocalStorage.js"></script>
<script type="text/javascript" src="../../common/main/lib/util/utils.js"></script>
<script type="text/javascript" src="../../common/main/lib/view/LoadMask.js"></script>
<script type="text/javascript" src="../../common/main/lib/view/CellEditor.js"></script>
<script type="text/javascript" src="../../common/main/lib/controller/CellEditor.js"></script>
<script type="text/javascript" src="js/CellEditorView.js"></script>
<script type="text/javascript" src="js/CellEditorController.js"></script>
<script type="text/javascript" src="js/ApplicationView.js"></script>
<script type="text/javascript" src="js/ApplicationController.js"></script>
<script type="text/javascript" src="js/application.js"></script>

View file

@ -33,10 +33,8 @@
(function ($) {
$(function(){
Common.Locale.apply(function() {
SSE.ApplicationView.create();
SSE.ApplicationController.create();
});
})
})(window.jQuery);

15
test/unit-tests/common.js Normal file
View file

@ -0,0 +1,15 @@
/**
* common.js
*
* Created by Alexander Yuzhin on 5/7/14
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
*
*/
// Include and setup all the stuff for testing
define([
'chai'
],function(chai) {
window.expect = chai.expect;
window.assert = chai.assert;
});

View file

@ -3,12 +3,12 @@
<head>
<meta charset="utf-8">
<title>Unit Tests</title>
<link rel="stylesheet" href="../../../build/node_modules/mocha/mocha.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="../../../../web-apps%20—%20копия/build/node_modules/mocha/mocha.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<div id="mocha"></div>
<script src="../../../build/node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../vendor/requirejs/require.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../web-apps%20—%20копия/build/node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../web-apps%20—%20копия/vendor/requirejs/require.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
// Partial config file
@ -82,7 +82,7 @@
require([
'../test/common',
'./main/lib/util/utils.js',
'.//main/lib/component/Button.js'
'../../test/common/main/lib/component/Button.js'
], runMocha);
</script>
</body>

View file

@ -0,0 +1,115 @@
/**
* Button.js
*
* Unit test
*
* Created by Alexander Yuzhin on 6/20/14
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
*
*/
define([
'backbone',
'../../../../../../../web-apps — копия/apps/common/main/lib/component/Button.js',
'../../../../../apps/common/main/lib/component/Menu.js'
],function() {
var chai = require('chai'),
should = chai.should();
describe('Common.UI.Button', function(){
var button,
domPlaceholder = document.createElement('div');
it('Create simple button', function(){
$('body').append(domPlaceholder);
button = new Common.UI.Button({
id: 'id-btn-simple',
caption: 'test'
});
button.render($(domPlaceholder));
should.exist(button);
$('#id-btn-simple').should.have.length(1);
});
it('Button caption', function(){
button.caption.should.equal('test');
});
it('Button update caption', function(){
button.setCaption('update caption');
// object
button.caption.should.equal('update caption');
// dom
assert.equal(button.cmpEl.find('button:first').andSelf().filter('button').text(), 'update caption', 'dom caption');
});
it('Button toggle', function(){
button.toggle();
assert.equal(button.isActive(), true, 'should by active');
button.toggle();
assert.equal(button.isActive(), false, 'should NOT by active');
button.toggle(false);
assert.equal(button.isActive(), false, 'should NOT by active');
button.toggle(true);
assert.equal(button.isActive(), true, 'should by active');
button.toggle(false);
});
it('Button disable', function(){
assert.equal(button.isDisabled(), false, 'should NOT by disable');
button.setDisabled(true);
assert.equal(button.isDisabled(), true, 'should by disable');
button.setDisabled(false);
assert.equal(button.isDisabled(), false, 'should NOT by disable');
});
it('Remove simple button', function(){
button.remove();
$('#id-btn-simple').should.have.length(0);
button = null;
// domPlaceholder.remove();
});
it('Create split button', function(){
$('body').append(domPlaceholder);
button = new Common.UI.Button({
id : 'id-btn-split',
caption : 'split',
split : true,
menu : new Common.UI.Menu({
items: [
{
caption: 'print',
value: 'print'
}
]
})
});
button.render($(domPlaceholder));
should.exist(button);
$('#id-btn-split').should.have.length(1);
$('#id-btn-split button').should.have.length(2);
});
it('Remove split button', function(){
button.remove();
$('#id-btn-split').should.have.length(0);
button = null;
// domPlaceholder.remove();
});
});
});

View file

@ -0,0 +1,33 @@
/**
* utils.js
*
* Unit test
*
* Created by Alexander Yuzhin on 5/7/14
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
*
*/
define([
'../../../../../../../web-apps — копия/apps/common/main/lib/util/utils.js'
],function() {
describe('Common.Utils.String', function(){
it('Test format', function(){
assert.equal('successively: first, second', Common.Utils.String.format('successively: {0}, {1}', 'first', 'second'));
assert.equal('revers: second, first', Common.Utils.String.format('revers: {1}, {0}', 'first', 'second'));
});
it('Test htmlEncode', function(){
assert.equal('Curly, Larry &amp; Moe', Common.Utils.String.htmlEncode('Curly, Larry & Moe'));
});
it('Test htmlDecode', function(){
assert.equal('Curly, Larry & Moe', Common.Utils.String.htmlDecode('Curly, Larry &amp; Moe'));
});
it('Test ellipsis', function(){
assert.equal('Truncate a s...', Common.Utils.String.ellipsis('Truncate a string and add an ellipsis', 15));
assert.equal('Truncate a string and add...', Common.Utils.String.ellipsis('Truncate a string and add an ellipsis', 30, true));
});
});
});