Merge branch 'feature/async-xhr' into develop
This commit is contained in:
commit
69c9cc3dab
|
@ -35,28 +35,27 @@ if (Common === undefined) {
|
|||
}
|
||||
|
||||
Common.Locale = new(function() {
|
||||
"use strict";
|
||||
var l10n = {};
|
||||
|
||||
var _createXMLHTTPObject = function() {
|
||||
var xmlhttp;
|
||||
if (typeof XMLHttpRequest != 'undefined') {
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
} else {
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
catch (E) {
|
||||
xmlhttp = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return xmlhttp;
|
||||
};
|
||||
// var _createXMLHTTPObject = function() {
|
||||
// var xmlhttp;
|
||||
// try {
|
||||
// xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
|
||||
// }
|
||||
// catch (e) {
|
||||
// try {
|
||||
// xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
// }
|
||||
// catch (E) {
|
||||
// xmlhttp = false;
|
||||
// }
|
||||
// }
|
||||
// if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
|
||||
// xmlhttp = new XMLHttpRequest();
|
||||
// }
|
||||
// return xmlhttp;
|
||||
// };
|
||||
|
||||
var _applyLocalization = function() {
|
||||
try {
|
||||
|
@ -98,21 +97,105 @@ Common.Locale = new(function() {
|
|||
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||
};
|
||||
|
||||
// {
|
||||
// let lang = (_getUrlParameterByName('lang') || 'en').split(/[\-_]/)[0];
|
||||
// let httpGet = function(url) {
|
||||
// return new Promise(
|
||||
// function (resolve, reject) {
|
||||
// var request = new XMLHttpRequest();
|
||||
// request.onload = function() {
|
||||
// if ( this.readyState === 4 )
|
||||
// if ( this.status == 200 ) {
|
||||
// resolve(this.responseText);
|
||||
// } else {
|
||||
// resolve('failed');
|
||||
// }
|
||||
// else reject('error: ' + this.readyState);
|
||||
// };
|
||||
// request.onerror = function () {
|
||||
// reject(new Error(
|
||||
// 'XMLHttpRequest Error: '+this.statusText));
|
||||
// };
|
||||
// request.open('GET', url);
|
||||
// request.send(null);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// httpGet('locale/' + lang + '.json')
|
||||
// .then(function(result) {
|
||||
// // console.log('httpget result: ' + result);
|
||||
//
|
||||
// if ( result == 'failed' ) {
|
||||
// if ( lang != 'en' )
|
||||
// return httpGet('locale/en.json');
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// }).then(function(result) {
|
||||
// if (result == 'failed')
|
||||
// throw new Error('server error');
|
||||
// else {
|
||||
// let _l10n = JSON.parse(result);
|
||||
// // console.log('ok: ' + _l10n);
|
||||
// console.log('ok: ');
|
||||
// }
|
||||
// }).catch(function(e) {
|
||||
// console.log('httpget error: ' + e);
|
||||
// });
|
||||
// }
|
||||
|
||||
var _requireLang = function () {
|
||||
var lang = (_getUrlParameterByName('lang') || 'en').split(/[\-_]/)[0];
|
||||
fetch('locale/' + lang + '.json')
|
||||
.then(function(response) {
|
||||
if (!response.ok) {
|
||||
if (lang != 'en')
|
||||
/* load default lang if fetch failed */
|
||||
return fetch('locale/en.json');
|
||||
|
||||
throw new Error('server error');
|
||||
}
|
||||
return response.json();
|
||||
}).then(function(response) {
|
||||
if ( response.then )
|
||||
return response.json();
|
||||
else {
|
||||
l10n = response;
|
||||
/* to break promises chain */
|
||||
throw new Error('loaded');
|
||||
}
|
||||
}).then(function(json) {
|
||||
if ( !!json ) l10n = json;
|
||||
}).catch(function(e) {
|
||||
if ( e.message == 'loaded' ) {
|
||||
|
||||
} else
|
||||
console.log('fetch error: ' + e);
|
||||
});
|
||||
};
|
||||
|
||||
if ( !window.fetch ) {
|
||||
/* use fetch polifill if native method isn't supported */
|
||||
require(['../vendor/fetch/fetch.umd'], _requireLang);
|
||||
} else _requireLang();
|
||||
|
||||
try {
|
||||
var langParam = _getUrlParameterByName('lang');
|
||||
var xhrObj = _createXMLHTTPObject();
|
||||
if (xhrObj && langParam) {
|
||||
var lang = langParam.split(/[\-\_]/)[0];
|
||||
xhrObj.open('GET', 'locale/' + lang + '.json', false);
|
||||
xhrObj.send('');
|
||||
l10n = eval("(" + xhrObj.responseText + ")");
|
||||
}
|
||||
// var langParam = _getUrlParameterByName('lang');
|
||||
// var xhrObj = _createXMLHTTPObject();
|
||||
// if (xhrObj && langParam) {
|
||||
// var lang = langParam.split(/[\-\_]/)[0];
|
||||
// xhrObj.open('GET', 'locale/' + lang + '.json', false);
|
||||
// xhrObj.send('');
|
||||
// l10n = eval("(" + xhrObj.responseText + ")");
|
||||
// }
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
xhrObj.open('GET', 'locale/en.json', false);
|
||||
xhrObj.send('');
|
||||
l10n = eval("(" + xhrObj.responseText + ")");
|
||||
// xhrObj.open('GET', 'locale/en.json', false);
|
||||
// xhrObj.send('');
|
||||
// l10n = eval("(" + xhrObj.responseText + ")");
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ define([
|
|||
|
||||
Common.Controllers.Plugins = Backbone.Controller.extend(_.extend({
|
||||
models: [],
|
||||
appOptions: {},
|
||||
plugins: { autostart:[] },
|
||||
collections: [
|
||||
'Common.Collections.Plugins'
|
||||
],
|
||||
|
@ -96,6 +98,34 @@ define([
|
|||
|
||||
this._moveOffset = {x:0, y:0};
|
||||
this.autostart = null;
|
||||
|
||||
Common.Gateway.on('init', this.loadConfig.bind(this));
|
||||
Common.NotificationCenter.on('app:face', this.onAppShowed.bind(this));
|
||||
},
|
||||
|
||||
loadConfig: function(data) {
|
||||
var me = this;
|
||||
me.appOptions.lang = data.config.lang;
|
||||
me.appOptions.plugins = data.config.plugins;
|
||||
me.appOptions.editor = !!window.DE ? 'word' : !!window.PE ? 'slide' : 'cell';
|
||||
|
||||
if ( me.appOptions.plugins ) {
|
||||
me.plugins.autostart = me.appOptions.plugins.autostart;
|
||||
me.getAppConfigPlugins(me.appOptions.plugins);
|
||||
}
|
||||
|
||||
var server_plugins_url = '../../../../plugins.json';
|
||||
Common.Utils.loadConfig(server_plugins_url, function (obj) {
|
||||
if ( obj != 'error' ) {
|
||||
me.plugins.autostart = _.union(me.plugins.autostart, obj.autostart);
|
||||
me.getServerPlugins(obj);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onAppShowed: function (config) {
|
||||
this.appOptions.isEdit = config.isEdit;
|
||||
// this.appOptions.canPlugins = config.canPlugins;
|
||||
},
|
||||
|
||||
setApi: function(api) {
|
||||
|
@ -106,14 +136,29 @@ define([
|
|||
this.api.asc_registerCallback("asc_onPluginResize", _.bind(this.onPluginResize, this));
|
||||
this.api.asc_registerCallback("asc_onPluginMouseUp", _.bind(this.onPluginMouseUp, this));
|
||||
this.api.asc_registerCallback("asc_onPluginMouseMove", _.bind(this.onPluginMouseMove, this));
|
||||
this.api.asc_registerCallback('asc_onPluginsReset', _.bind(this.resetPluginsList, this));
|
||||
// this.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
|
||||
|
||||
/**
|
||||
* sometime plugins info from server can be received after
|
||||
* AppShowed event, so try to parse info there
|
||||
**/
|
||||
if ( this.plugins.serverpluginsdata == undefined ) {
|
||||
console.log('set api: plugins data from server is late')
|
||||
} else
|
||||
if ( this.plugins.serverpluginsdata === false ) {
|
||||
console.log('set api: error for plugins data from server');
|
||||
} else {
|
||||
this.parsePlugins(this.plugins.serverpluginsdata);
|
||||
}
|
||||
|
||||
if ( this.appOptions.canPlugins )
|
||||
this.refreshPluginsList();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setMode: function(mode) {
|
||||
if (mode.canPlugins) {
|
||||
this.updatePluginsList();
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@ -138,7 +183,7 @@ define([
|
|||
});
|
||||
},
|
||||
|
||||
updatePluginsList: function() {
|
||||
refreshPluginsList: function() {
|
||||
var me = this;
|
||||
var storePlugins = this.getApplication().getCollection('Common.Collections.Plugins'),
|
||||
arr = [];
|
||||
|
@ -147,6 +192,7 @@ define([
|
|||
plugin.set_Name(item.get('name'));
|
||||
plugin.set_Guid(item.get('guid'));
|
||||
plugin.set_BaseUrl(item.get('baseUrl'));
|
||||
|
||||
var variations = item.get('variations'),
|
||||
variationsArr = [];
|
||||
variations.forEach(function(itemVar){
|
||||
|
@ -168,8 +214,10 @@ define([
|
|||
variation.set_Size(itemVar.get('size'));
|
||||
variation.set_InitOnSelectionChanged(itemVar.get('initOnSelectionChanged'));
|
||||
variation.set_Events(itemVar.get('events'));
|
||||
|
||||
variationsArr.push(variation);
|
||||
});
|
||||
|
||||
plugin.set_Variations(variationsArr);
|
||||
item.set('pluginObj', plugin);
|
||||
arr.push(plugin);
|
||||
|
@ -193,6 +241,7 @@ define([
|
|||
|
||||
onResetPlugins: function (collection) {
|
||||
var me = this;
|
||||
me.appOptions.canPlugins = !collection.isEmpty();
|
||||
if ( me.$toolbarPanelPlugins ) {
|
||||
me.$toolbarPanelPlugins.empty();
|
||||
|
||||
|
@ -217,6 +266,8 @@ define([
|
|||
rank = new_rank;
|
||||
});
|
||||
_group.appendTo(me.$toolbarPanelPlugins);
|
||||
} else {
|
||||
console.error('toolbar panel isnot created');
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -397,12 +448,175 @@ define([
|
|||
},
|
||||
|
||||
runAutoStartPlugins: function(autostart) {
|
||||
if (autostart && autostart.length>0) {
|
||||
var guid = autostart.shift();
|
||||
this.autostart = autostart;
|
||||
this.api.asc_pluginRun(guid, 0, '');
|
||||
autostart = this.plugins.autostart;
|
||||
if (autostart && autostart.length > 0) {
|
||||
// var guid = autostart.shift();
|
||||
// this.autostart = autostart;
|
||||
this.api.asc_pluginRun(autostart.shift(), 0, '');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
resetPluginsList: function() {
|
||||
this.getApplication().getCollection('Common.Collections.Plugins').reset();
|
||||
},
|
||||
|
||||
applyUICustomization: function () {
|
||||
var me = this;
|
||||
if ( me.plugins.uicustom ) {
|
||||
me.plugins.uicustom.forEach(function (c) {
|
||||
if ( c.code ) eval(c.code);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
parsePlugins: function(pluginsdata, silent/*, uiCustomize*/) {
|
||||
var me = this;
|
||||
var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins'),
|
||||
isEdit = me.appOptions.isEdit,
|
||||
editor = me.appOptions.editor;
|
||||
if ( pluginsdata instanceof Array ) {
|
||||
var arr = [], arrUI = [],
|
||||
lang = me.appOptions.lang.split(/[\-_]/)[0];
|
||||
pluginsdata.forEach(function(item){
|
||||
if ( arr.some(function(i) {
|
||||
return (i.get('baseUrl') == item.baseUrl || i.get('guid') == item.guid);
|
||||
}
|
||||
) || pluginStore.findWhere({baseUrl: item.baseUrl}) || pluginStore.findWhere({guid: item.guid}))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var variationsArr = [],
|
||||
pluginVisible = false;
|
||||
item.variations.forEach(function(itemVar){
|
||||
var visible = (isEdit || itemVar.isViewer && (itemVar.isDisplayedInViewer!==false)) && _.contains(itemVar.EditorsSupport, editor) && !itemVar.isSystem;
|
||||
if ( visible ) pluginVisible = true;
|
||||
|
||||
if (item.isUICustomizer ) {
|
||||
visible && arrUI.push({
|
||||
url: item.baseUrl + itemVar.url
|
||||
});
|
||||
} else {
|
||||
var model = new Common.Models.PluginVariation(itemVar);
|
||||
var description = itemVar.description;
|
||||
if (typeof itemVar.descriptionLocale == 'object')
|
||||
description = itemVar.descriptionLocale[lang] || itemVar.descriptionLocale['en'] || description || '';
|
||||
|
||||
_.each(itemVar.buttons, function(b, index){
|
||||
if (typeof b.textLocale == 'object')
|
||||
b.text = b.textLocale[lang] || b.textLocale['en'] || b.text || '';
|
||||
b.visible = (isEdit || b.isViewer !== false);
|
||||
});
|
||||
|
||||
model.set({
|
||||
description: description,
|
||||
index: variationsArr.length,
|
||||
url: itemVar.url,
|
||||
icons: itemVar.icons,
|
||||
buttons: itemVar.buttons,
|
||||
visible: visible
|
||||
});
|
||||
|
||||
variationsArr.push(model);
|
||||
}
|
||||
});
|
||||
|
||||
if (variationsArr.length > 0 && !item.isUICustomizer) {
|
||||
var name = item.name;
|
||||
if (typeof item.nameLocale == 'object')
|
||||
name = item.nameLocale[lang] || item.nameLocale['en'] || name || '';
|
||||
|
||||
arr.push(new Common.Models.Plugin({
|
||||
name : name,
|
||||
guid: item.guid,
|
||||
baseUrl : item.baseUrl,
|
||||
variations: variationsArr,
|
||||
currentVariation: 0,
|
||||
visible: pluginVisible,
|
||||
groupName: (item.group) ? item.group.name : '',
|
||||
groupRank: (item.group) ? item.group.rank : 0
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
// if ( uiCustomize!==false ) // from ui customizer in editor config or desktop event
|
||||
// this.UICustomizePlugins = arrUI;
|
||||
if ( arrUI.length )
|
||||
me.plugins.uicustom = _.union(me.plugins.uicustom, arrUI);
|
||||
|
||||
// if ( !uiCustomize && pluginStore)
|
||||
{
|
||||
arr = pluginStore.models.concat(arr);
|
||||
arr.sort(function(a, b){
|
||||
var rank_a = a.get('groupRank'),
|
||||
rank_b = b.get('groupRank');
|
||||
if (rank_a < rank_b)
|
||||
return (rank_a==0) ? 1 : -1;
|
||||
if (rank_a > rank_b)
|
||||
return (rank_b==0) ? -1 : 1;
|
||||
return 0;
|
||||
});
|
||||
pluginStore.reset(arr, {silent: !!silent});
|
||||
// this.appOptions.canPlugins = !pluginStore.isEmpty();
|
||||
}
|
||||
}
|
||||
// else if (!uiCustomize){
|
||||
// this.appOptions.canPlugins = false;
|
||||
// }
|
||||
|
||||
// if (!uiCustomize)
|
||||
// this.getApplication().getController('LeftMenu').enablePlugins();
|
||||
|
||||
// if (this.appOptions.canPlugins) {
|
||||
// this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions).runAutoStartPlugins(plugins.autostart);
|
||||
// }
|
||||
},
|
||||
|
||||
getServerPlugins: function (config) {
|
||||
var me = this;
|
||||
Promise.all(config.pluginsData.map(function(url) {
|
||||
return fetch(url)
|
||||
.then(function(response) {
|
||||
if ( response.ok ) return response.json();
|
||||
else return 'error';
|
||||
}).then(function(json) {
|
||||
json.baseUrl = url.substring(0, url.lastIndexOf("config.json"));
|
||||
return json;
|
||||
});
|
||||
})).then(function(values) {
|
||||
me.plugins.serverpluginsdata = values;
|
||||
// console.log('server plugins data received');
|
||||
}).catch(function(e) {
|
||||
me.plugins.serverpluginsdata = false;
|
||||
console.log('getServerPlugins error: ' + e.message);
|
||||
});
|
||||
},
|
||||
|
||||
getAppConfigPlugins: function (config) {
|
||||
if ( config.UIpluginsData ) {
|
||||
var me = this;
|
||||
Promise.all(config.UIpluginsData.map(function(url) {
|
||||
return fetch(url)
|
||||
.then(function(response) {return response.json();})
|
||||
.then(function(json) {
|
||||
json.baseUrl = url.substring(0, url.lastIndexOf("config.json"));
|
||||
return json;
|
||||
});
|
||||
})).then(function(values) {
|
||||
me.parsePlugins(values, true);
|
||||
|
||||
if ( me.plugins.uicustom ) {
|
||||
me.plugins.uicustom.forEach(function (c) {
|
||||
fetch(c.url)
|
||||
.then(function (response) {return response.text();})
|
||||
.then(function (text) {c.code = text;});
|
||||
});
|
||||
}
|
||||
}).catch(function(e) {
|
||||
console.log('error: ' + e.message);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
}, Common.Controllers.Plugins || {}));
|
||||
});
|
||||
|
|
|
@ -726,21 +726,18 @@ Common.Utils.getConfigJson = function (url) {
|
|||
return null;
|
||||
};
|
||||
|
||||
Common.Utils.getConfigJson = function (url) {
|
||||
if ( url ) {
|
||||
try {
|
||||
var xhrObj = Common.Utils.createXhr();
|
||||
if ( xhrObj ) {
|
||||
xhrObj.open('GET', url, false);
|
||||
xhrObj.send('');
|
||||
Common.Utils.loadConfig = function(url, callback) {
|
||||
"use strict";
|
||||
|
||||
return JSON.parse(xhrObj.responseText);
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
fetch(url)
|
||||
.then(function(response){
|
||||
if ( response.ok )
|
||||
return response.json();
|
||||
else return 'error';
|
||||
}).then(function(json){
|
||||
callback(json);
|
||||
});
|
||||
};
|
||||
|
||||
Common.Utils.asyncCall = function (callback, scope, args) {
|
||||
(new Promise(function (resolve, reject) {
|
||||
|
|
|
@ -201,7 +201,6 @@ define([
|
|||
this.editorConfig = {};
|
||||
this.appOptions = {};
|
||||
this.plugins = undefined;
|
||||
this.UICustomizePlugins = [];
|
||||
Common.Gateway.on('init', _.bind(this.loadConfig, this));
|
||||
Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this));
|
||||
Common.Gateway.on('opendocument', _.bind(this.loadDocument, this));
|
||||
|
@ -954,9 +953,9 @@ define([
|
|||
application.getController('Common.Controllers.ExternalMergeEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization});
|
||||
|
||||
pluginsController.setApi(me.api);
|
||||
me.requestPlugins('../../../../plugins.json');
|
||||
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
|
||||
me.api.asc_registerCallback('asc_onPluginsReset', _.bind(me.resetPluginsList, me));
|
||||
if ( (me.appOptions.canPlugins = pluginsController.appOptions.canPlugins) )
|
||||
pluginsController.runAutoStartPlugins();
|
||||
leftmenuController.enablePlugins();
|
||||
|
||||
documentHolderController.setApi(me.api);
|
||||
documentHolderController.createDelayedElements();
|
||||
|
@ -1186,10 +1185,7 @@ define([
|
|||
}
|
||||
|
||||
this.appOptions.canRename && appHeader.setCanRename(true);
|
||||
|
||||
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
|
||||
if (this.appOptions.canBrandingExt)
|
||||
this.updatePlugins(this.plugins, true);
|
||||
|
||||
this.applyModeCommonElements();
|
||||
this.applyModeEditorElements();
|
||||
|
@ -1676,7 +1672,7 @@ define([
|
|||
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
|
||||
if (this.appOptions.canBrandingExt) {
|
||||
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
|
||||
Common.Utils.applyCustomizationPlugins(this.UICustomizePlugins);
|
||||
this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2081,144 +2077,6 @@ define([
|
|||
if (url) this.iframePrint.src = url;
|
||||
},
|
||||
|
||||
requestPlugins: function(pluginsPath) { // request plugins
|
||||
if (!pluginsPath) return;
|
||||
|
||||
var config_plugins = (this.plugins && this.plugins.pluginsData && this.plugins.pluginsData.length>0) ? this.updatePlugins(this.plugins, false) : null, // return plugins object
|
||||
request_plugins = this.updatePlugins( Common.Utils.getConfigJson(pluginsPath), false );
|
||||
|
||||
this.updatePluginsList({
|
||||
autostart: (config_plugins&&config_plugins.autostart ? config_plugins.autostart : []).concat(request_plugins&&request_plugins.autostart ? request_plugins.autostart : []),
|
||||
pluginsData: (config_plugins ? config_plugins.pluginsData : []).concat(request_plugins ? request_plugins.pluginsData : [])
|
||||
}, false);
|
||||
},
|
||||
|
||||
updatePlugins: function(plugins, uiCustomize) { // plugins from config
|
||||
if (!plugins) return;
|
||||
|
||||
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
|
||||
if (!pluginsData || pluginsData.length<1) return;
|
||||
|
||||
var arr = [];
|
||||
pluginsData.forEach(function(item){
|
||||
var value = Common.Utils.getConfigJson(item);
|
||||
if (value) {
|
||||
value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
|
||||
arr.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
if (arr.length>0) {
|
||||
var autostart = plugins.autostart || plugins.autoStartGuid;
|
||||
if (typeof (autostart) == 'string')
|
||||
autostart = [autostart];
|
||||
plugins.autoStartGuid && console.warn("Obsolete: The autoStartGuid parameter is deprecated. Please check the documentation for new plugin connection configuration.");
|
||||
|
||||
if (uiCustomize)
|
||||
this.updatePluginsList({
|
||||
autostart: autostart,
|
||||
pluginsData: arr
|
||||
}, !!uiCustomize);
|
||||
else return {
|
||||
autostart: autostart,
|
||||
pluginsData: arr
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
updatePluginsList: function(plugins, uiCustomize) {
|
||||
var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins'),
|
||||
isEdit = this.appOptions.isEdit;
|
||||
if (plugins) {
|
||||
var arr = [], arrUI = [],
|
||||
lang = this.appOptions.lang.split(/[\-\_]/)[0];
|
||||
plugins.pluginsData.forEach(function(item){
|
||||
if (_.find(arr, function(arritem) {
|
||||
return (arritem.get('baseUrl') == item.baseUrl || arritem.get('guid') == item.guid);
|
||||
}) || pluginStore.findWhere({baseUrl: item.baseUrl}) || pluginStore.findWhere({guid: item.guid}))
|
||||
return;
|
||||
|
||||
var variationsArr = [],
|
||||
pluginVisible = false;
|
||||
item.variations.forEach(function(itemVar){
|
||||
var visible = (isEdit || itemVar.isViewer && (itemVar.isDisplayedInViewer!==false)) && _.contains(itemVar.EditorsSupport, 'word') && !itemVar.isSystem;
|
||||
if ( visible ) pluginVisible = true;
|
||||
|
||||
if (item.isUICustomizer ) {
|
||||
visible && arrUI.push(item.baseUrl + itemVar.url);
|
||||
} else {
|
||||
var model = new Common.Models.PluginVariation(itemVar);
|
||||
var description = itemVar.description;
|
||||
if (typeof itemVar.descriptionLocale == 'object')
|
||||
description = itemVar.descriptionLocale[lang] || itemVar.descriptionLocale['en'] || description || '';
|
||||
|
||||
_.each(itemVar.buttons, function(b, index){
|
||||
if (typeof b.textLocale == 'object')
|
||||
b.text = b.textLocale[lang] || b.textLocale['en'] || b.text || '';
|
||||
b.visible = (isEdit || b.isViewer !== false);
|
||||
});
|
||||
|
||||
model.set({
|
||||
description: description,
|
||||
index: variationsArr.length,
|
||||
url: itemVar.url,
|
||||
icons: itemVar.icons,
|
||||
buttons: itemVar.buttons,
|
||||
visible: visible
|
||||
});
|
||||
|
||||
variationsArr.push(model);
|
||||
}
|
||||
});
|
||||
|
||||
if (variationsArr.length>0 && !item.isUICustomizer) {
|
||||
var name = item.name;
|
||||
if (typeof item.nameLocale == 'object')
|
||||
name = item.nameLocale[lang] || item.nameLocale['en'] || name || '';
|
||||
|
||||
arr.push(new Common.Models.Plugin({
|
||||
name : name,
|
||||
guid: item.guid,
|
||||
baseUrl : item.baseUrl,
|
||||
variations: variationsArr,
|
||||
currentVariation: 0,
|
||||
visible: pluginVisible,
|
||||
groupName: (item.group) ? item.group.name : '',
|
||||
groupRank: (item.group) ? item.group.rank : 0
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
if ( uiCustomize!==false ) // from ui customizer in editor config or desktop event
|
||||
this.UICustomizePlugins = arrUI;
|
||||
|
||||
if ( !uiCustomize && pluginStore) {
|
||||
arr = pluginStore.models.concat(arr);
|
||||
arr.sort(function(a, b){
|
||||
var rank_a = a.get('groupRank'),
|
||||
rank_b = b.get('groupRank');
|
||||
if (rank_a < rank_b)
|
||||
return (rank_a==0) ? 1 : -1;
|
||||
if (rank_a > rank_b)
|
||||
return (rank_b==0) ? -1 : 1;
|
||||
return 0;
|
||||
});
|
||||
pluginStore.reset(arr);
|
||||
this.appOptions.canPlugins = !pluginStore.isEmpty();
|
||||
}
|
||||
} else if (!uiCustomize){
|
||||
this.appOptions.canPlugins = false;
|
||||
}
|
||||
if (!uiCustomize) this.getApplication().getController('LeftMenu').enablePlugins();
|
||||
if (this.appOptions.canPlugins) {
|
||||
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions).runAutoStartPlugins(plugins.autostart);
|
||||
}
|
||||
},
|
||||
|
||||
resetPluginsList: function() {
|
||||
this.getApplication().getCollection('Common.Collections.Plugins').reset();
|
||||
},
|
||||
|
||||
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.',
|
||||
criticalErrorTitle: 'Error',
|
||||
notcriticalErrorTitle: 'Warning',
|
||||
|
|
|
@ -187,7 +187,6 @@ define([
|
|||
this.editorConfig = {};
|
||||
this.appOptions = {};
|
||||
this.plugins = undefined;
|
||||
this.UICustomizePlugins = [];
|
||||
Common.Gateway.on('init', _.bind(this.loadConfig, this));
|
||||
Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this));
|
||||
Common.Gateway.on('opendocument', _.bind(this.loadDocument, this));
|
||||
|
@ -705,9 +704,9 @@ define([
|
|||
application.getController('Common.Controllers.ExternalDiagramEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization});
|
||||
|
||||
pluginsController.setApi(me.api);
|
||||
me.requestPlugins('../../../../plugins.json');
|
||||
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
|
||||
me.api.asc_registerCallback('asc_onPluginsReset', _.bind(me.resetPluginsList, me));
|
||||
if ( (me.appOptions.canPlugins = pluginsController.appOptions.canPlugins) )
|
||||
pluginsController.runAutoStartPlugins();
|
||||
leftmenuController.enablePlugins();
|
||||
|
||||
documentHolderController.setApi(me.api);
|
||||
documentHolderController.createDelayedElements();
|
||||
|
@ -917,10 +916,7 @@ define([
|
|||
}
|
||||
|
||||
this.appOptions.canRename && appHeader.setCanRename(true);
|
||||
|
||||
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
|
||||
if (this.appOptions.canBrandingExt)
|
||||
this.updatePlugins(this.plugins, true);
|
||||
|
||||
this.applyModeCommonElements();
|
||||
this.applyModeEditorElements();
|
||||
|
@ -1401,7 +1397,7 @@ define([
|
|||
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
|
||||
if (this.appOptions.canBrandingExt) {
|
||||
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
|
||||
Common.Utils.applyCustomizationPlugins(this.UICustomizePlugins);
|
||||
this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1819,144 +1815,6 @@ define([
|
|||
}
|
||||
},
|
||||
|
||||
requestPlugins: function(pluginsPath) { // request plugins
|
||||
if (!pluginsPath) return;
|
||||
|
||||
var config_plugins = (this.plugins && this.plugins.pluginsData && this.plugins.pluginsData.length>0) ? this.updatePlugins(this.plugins, false) : null,
|
||||
request_plugins = this.updatePlugins( Common.Utils.getConfigJson(pluginsPath), false );
|
||||
|
||||
this.updatePluginsList({
|
||||
autostart: (config_plugins&&config_plugins.autostart ? config_plugins.autostart : []).concat(request_plugins&&request_plugins.autostart ? request_plugins.autostart : []),
|
||||
pluginsData: (config_plugins ? config_plugins.pluginsData : []).concat(request_plugins ? request_plugins.pluginsData : [])
|
||||
}, false);
|
||||
},
|
||||
|
||||
|
||||
updatePlugins: function(plugins, uiCustomize) { // plugins from config
|
||||
if (!plugins) return;
|
||||
|
||||
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
|
||||
if (!pluginsData || pluginsData.length<1) return;
|
||||
|
||||
var arr = [];
|
||||
pluginsData.forEach(function(item){
|
||||
var value = Common.Utils.getConfigJson(item);
|
||||
if (value) {
|
||||
value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
|
||||
arr.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
if (arr.length>0) {
|
||||
var autostart = plugins.autostart || plugins.autoStartGuid;
|
||||
if (typeof (autostart) == 'string')
|
||||
autostart = [autostart];
|
||||
plugins.autoStartGuid && console.warn("Obsolete: The autoStartGuid parameter is deprecated. Please check the documentation for new plugin connection configuration.");
|
||||
|
||||
if (uiCustomize)
|
||||
this.updatePluginsList({
|
||||
autostart: autostart,
|
||||
pluginsData: arr
|
||||
}, !!uiCustomize);
|
||||
else return {
|
||||
autostart: autostart,
|
||||
pluginsData: arr
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
updatePluginsList: function(plugins, uiCustomize) {
|
||||
var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins'),
|
||||
isEdit = this.appOptions.isEdit;
|
||||
if (plugins) {
|
||||
var arr = [], arrUI = [],
|
||||
lang = this.appOptions.lang.split(/[\-\_]/)[0];
|
||||
plugins.pluginsData.forEach(function(item){
|
||||
if (_.find(arr, function(arritem) {
|
||||
return (arritem.get('baseUrl') == item.baseUrl || arritem.get('guid') == item.guid);
|
||||
}) || pluginStore.findWhere({baseUrl: item.baseUrl}) || pluginStore.findWhere({guid: item.guid}))
|
||||
return;
|
||||
|
||||
var variationsArr = [],
|
||||
pluginVisible = false;
|
||||
item.variations.forEach(function(itemVar){
|
||||
var visible = (isEdit || itemVar.isViewer && (itemVar.isDisplayedInViewer!==false)) && _.contains(itemVar.EditorsSupport, 'slide') && !itemVar.isSystem;
|
||||
if ( visible ) pluginVisible = true;
|
||||
|
||||
if ( item.isUICustomizer ) {
|
||||
visible && arrUI.push(item.baseUrl + itemVar.url);
|
||||
} else {
|
||||
var model = new Common.Models.PluginVariation(itemVar);
|
||||
var description = itemVar.description;
|
||||
if (typeof itemVar.descriptionLocale == 'object')
|
||||
description = itemVar.descriptionLocale[lang] || itemVar.descriptionLocale['en'] || description || '';
|
||||
|
||||
_.each(itemVar.buttons, function(b, index){
|
||||
if (typeof b.textLocale == 'object')
|
||||
b.text = b.textLocale[lang] || b.textLocale['en'] || b.text || '';
|
||||
b.visible = (isEdit || b.isViewer !== false);
|
||||
});
|
||||
|
||||
model.set({
|
||||
description: description,
|
||||
index: variationsArr.length,
|
||||
url: itemVar.url,
|
||||
icons: itemVar.icons,
|
||||
buttons: itemVar.buttons,
|
||||
visible: visible
|
||||
});
|
||||
|
||||
variationsArr.push(model);
|
||||
}
|
||||
});
|
||||
if (variationsArr.length>0 && !item.isUICustomizer) {
|
||||
var name = item.name;
|
||||
if (typeof item.nameLocale == 'object')
|
||||
name = item.nameLocale[lang] || item.nameLocale['en'] || name || '';
|
||||
|
||||
arr.push(new Common.Models.Plugin({
|
||||
name : name,
|
||||
guid: item.guid,
|
||||
baseUrl : item.baseUrl,
|
||||
variations: variationsArr,
|
||||
currentVariation: 0,
|
||||
visible: pluginVisible,
|
||||
groupName: (item.group) ? item.group.name : '',
|
||||
groupRank: (item.group) ? item.group.rank : 0
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
|
||||
this.UICustomizePlugins = arrUI;
|
||||
|
||||
if ( !uiCustomize && pluginStore) {
|
||||
arr = pluginStore.models.concat(arr);
|
||||
arr.sort(function(a, b){
|
||||
var rank_a = a.get('groupRank'),
|
||||
rank_b = b.get('groupRank');
|
||||
if (rank_a < rank_b)
|
||||
return (rank_a==0) ? 1 : -1;
|
||||
if (rank_a > rank_b)
|
||||
return (rank_b==0) ? -1 : 1;
|
||||
return 0;
|
||||
});
|
||||
pluginStore.reset(arr);
|
||||
this.appOptions.canPlugins = !pluginStore.isEmpty();
|
||||
}
|
||||
} else if (!uiCustomize){
|
||||
this.appOptions.canPlugins = false;
|
||||
}
|
||||
if (!uiCustomize) this.getApplication().getController('LeftMenu').enablePlugins();
|
||||
if (this.appOptions.canPlugins) {
|
||||
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions).runAutoStartPlugins(plugins.autostart);
|
||||
}
|
||||
},
|
||||
|
||||
resetPluginsList: function() {
|
||||
this.getApplication().getCollection('Common.Collections.Plugins').reset();
|
||||
},
|
||||
|
||||
// Translation
|
||||
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.',
|
||||
criticalErrorTitle: 'Error',
|
||||
|
|
|
@ -1922,7 +1922,7 @@ define([
|
|||
documentHolderView = me.documentHolder,
|
||||
menu = documentHolderView.funcMenu,
|
||||
menuContainer = documentHolderView.cmpEl.find('#menu-formula-selection'),
|
||||
funcdesc = SSE.Views.FormulaLang.getDescription(Common.Utils.InternalSettings.get("sse-settings-func-locale"));
|
||||
funcdesc = me.getApplication().getController('FormulaDialog').getDescription(Common.Utils.InternalSettings.get("sse-settings-func-locale"));
|
||||
|
||||
for (var i = 0; i < menu.items.length; i++) {
|
||||
var tip = menu.items[i].cmpEl.data('bs.tooltip');
|
||||
|
@ -2048,7 +2048,7 @@ define([
|
|||
this.documentHolder.cmpEl.append(functip.parentEl);
|
||||
}
|
||||
|
||||
var funcdesc = SSE.Views.FormulaLang.getDescription(Common.Utils.InternalSettings.get("sse-settings-func-locale")),
|
||||
var funcdesc = this.getApplication().getController('FormulaDialog').getDescription(Common.Utils.InternalSettings.get("sse-settings-func-locale")),
|
||||
hint = ((funcdesc && funcdesc[name]) ? (this.api.asc_getFormulaLocaleName(name) + funcdesc[name].a) : '').replace(/[,;]/g, this.api.asc_getFunctionArgumentSeparator());
|
||||
|
||||
if (functip.ref && functip.ref.isVisible()) {
|
||||
|
|
|
@ -60,10 +60,19 @@ define([
|
|||
|
||||
initialize: function () {
|
||||
var me = this;
|
||||
me.langJson = {};
|
||||
me.langDescJson = {};
|
||||
|
||||
this.addListeners({
|
||||
'FileMenu': {
|
||||
'settings:apply': function() {
|
||||
me.needUpdateFormula = true;
|
||||
|
||||
var lang = Common.localStorage.getItem("sse-settings-func-locale");
|
||||
Common.Utils.InternalSettings.set("sse-settings-func-locale", lang);
|
||||
|
||||
me.formulasGroups.reset();
|
||||
me.reloadTranslations(lang);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -73,7 +82,8 @@ define([
|
|||
this.api = api;
|
||||
|
||||
if (this.formulasGroups && this.api) {
|
||||
this.loadingFormulas();
|
||||
this.reloadTranslations(
|
||||
Common.localStorage.getItem("sse-settings-func-locale") || this.appOptions.lang );
|
||||
|
||||
var me = this;
|
||||
|
||||
|
@ -82,7 +92,7 @@ define([
|
|||
toolclose : 'hide',
|
||||
formulasGroups : this.formulasGroups,
|
||||
handler : function (func) {
|
||||
if (func && me.api) {
|
||||
if (func) {
|
||||
me.api.asc_insertFormula(func, Asc.c_oAscPopUpSelectorType.Func);
|
||||
}
|
||||
}
|
||||
|
@ -90,9 +100,7 @@ define([
|
|||
|
||||
this.formulas.on({
|
||||
'hide': function () {
|
||||
if (me.api) {
|
||||
me.api.asc_enableKeyEvents(true);
|
||||
}
|
||||
me.api.asc_enableKeyEvents(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -101,19 +109,80 @@ define([
|
|||
},
|
||||
|
||||
setMode: function(mode) {
|
||||
this.mode = mode;
|
||||
return this;
|
||||
},
|
||||
|
||||
onLaunch: function () {
|
||||
this.formulasGroups = this.getApplication().getCollection('FormulaGroups');
|
||||
|
||||
Common.Gateway.on('init', this.loadConfig.bind(this));
|
||||
},
|
||||
|
||||
loadConfig: function(data) {
|
||||
this.appOptions = {};
|
||||
this.appOptions.lang = data.config.lang;
|
||||
},
|
||||
|
||||
reloadTranslations: function (lang) {
|
||||
var me = this;
|
||||
lang = (lang || 'en').split(/[\-_]/)[0].toLowerCase();
|
||||
|
||||
Common.Utils.InternalSettings.set("sse-settings-func-locale", lang);
|
||||
if (me.langJson[lang]) {
|
||||
me.api.asc_setLocalization(me.langJson[lang]);
|
||||
Common.NotificationCenter.trigger('formula:settings', this);
|
||||
} else if (lang == 'en') {
|
||||
me.api.asc_setLocalization(undefined);
|
||||
Common.NotificationCenter.trigger('formula:settings', this);
|
||||
} else {
|
||||
Common.Utils.loadConfig('resources/formula-lang/' + lang + '.json',
|
||||
function (config) {
|
||||
if ( config != 'error' ) {
|
||||
me.langJson[lang] = config;
|
||||
me.api.asc_setLocalization(config);
|
||||
Common.NotificationCenter.trigger('formula:settings', this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (me.langDescJson[lang])
|
||||
me.loadingFormulas(me.langDescJson[lang]);
|
||||
else {
|
||||
Common.Utils.loadConfig('resources/formula-lang/' + lang + '_desc.json',
|
||||
function (config) {
|
||||
if ( config != 'error' ) {
|
||||
me.langDescJson[lang] = config;
|
||||
me.loadingFormulas(config);
|
||||
} else {
|
||||
Common.Utils.loadConfig('resources/formula-lang/en_desc.json',
|
||||
function (config) {
|
||||
me.langDescJson[lang] = (config != 'error') ? config : null;
|
||||
me.loadingFormulas(me.langDescJson[lang]);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
getDescription: function(lang) {
|
||||
if (!lang) return '';
|
||||
lang = lang.toLowerCase() ;
|
||||
|
||||
if (this.langDescJson[lang])
|
||||
return this.langDescJson[lang];
|
||||
return null;
|
||||
},
|
||||
|
||||
showDialog: function () {
|
||||
if (this.formulas) {
|
||||
if (this.needUpdateFormula)
|
||||
this.updateFormulas();
|
||||
this.needUpdateFormula = false;
|
||||
if ( this.needUpdateFormula ) {
|
||||
this.needUpdateFormula = false;
|
||||
|
||||
if (this.formulas.$window) {
|
||||
this.formulas.fillFormulasGroups();
|
||||
this.formulas.fillFunctions('All');
|
||||
}
|
||||
}
|
||||
this.formulas.show();
|
||||
}
|
||||
},
|
||||
|
@ -123,7 +192,7 @@ define([
|
|||
}
|
||||
},
|
||||
|
||||
loadingFormulas: function () {
|
||||
loadingFormulas: function (descrarr) {
|
||||
var i = 0, j = 0,
|
||||
ascGroupName,
|
||||
ascFunctions,
|
||||
|
@ -138,8 +207,6 @@ define([
|
|||
separator = this.api.asc_getFunctionArgumentSeparator();
|
||||
|
||||
if (store) {
|
||||
var value = SSE.Views.FormulaLang.getDescription(Common.Utils.InternalSettings.get("sse-settings-func-locale"));
|
||||
|
||||
allFunctionsGroup = new SSE.Models.FormulaGroup ({
|
||||
name : 'All',
|
||||
index : index,
|
||||
|
@ -173,8 +240,8 @@ define([
|
|||
index : funcInd,
|
||||
group : ascGroupName,
|
||||
name : ascFunctions[j].asc_getLocaleName(),
|
||||
args : ((value && value[funcname]) ? value[funcname].a : '').replace(/[,;]/g, separator),
|
||||
desc : (value && value[funcname]) ? value[funcname].d : ''
|
||||
args : ((descrarr && descrarr[funcname]) ? descrarr[funcname].a : '').replace(/[,;]/g, separator),
|
||||
desc : (descrarr && descrarr[funcname]) ? descrarr[funcname].d : ''
|
||||
});
|
||||
|
||||
funcInd += 1;
|
||||
|
@ -191,15 +258,6 @@ define([
|
|||
_.sortBy(allFunctions, function (model) {return model.get('name'); }));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
updateFormulas: function () {
|
||||
this.formulasGroups.reset();
|
||||
this.loadingFormulas();
|
||||
if (this.formulas.$window) {
|
||||
this.formulas.fillFormulasGroups();
|
||||
this.formulas.fillFunctions('All');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -376,11 +376,6 @@ define([
|
|||
this.api.asc_setAutoSaveGap(value);
|
||||
}
|
||||
|
||||
value = Common.localStorage.getItem("sse-settings-func-locale");
|
||||
Common.Utils.InternalSettings.set("sse-settings-func-locale", value);
|
||||
if (value) value = SSE.Views.FormulaLang.get(value);
|
||||
if (value!==null) this.api.asc_setLocalization(value);
|
||||
|
||||
value = Common.localStorage.getItem("sse-settings-reg-settings");
|
||||
if (value!==null) this.api.asc_setLocale(parseInt(value));
|
||||
|
||||
|
|
|
@ -54,8 +54,7 @@ define([
|
|||
'spreadsheeteditor/main/app/collection/ShapeGroups',
|
||||
'spreadsheeteditor/main/app/collection/TableTemplates',
|
||||
'spreadsheeteditor/main/app/collection/EquationGroups',
|
||||
'spreadsheeteditor/main/app/controller/FormulaDialog',
|
||||
'spreadsheeteditor/main/app/view/FormulaLang'
|
||||
'spreadsheeteditor/main/app/controller/FormulaDialog'
|
||||
], function () {
|
||||
'use strict';
|
||||
|
||||
|
@ -182,7 +181,6 @@ define([
|
|||
// Initialize api gateway
|
||||
this.editorConfig = {};
|
||||
this.plugins = undefined;
|
||||
this.UICustomizePlugins = [];
|
||||
Common.Gateway.on('init', _.bind(this.loadConfig, this));
|
||||
Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this));
|
||||
Common.Gateway.on('opendocument', _.bind(this.loadDocument, this));
|
||||
|
@ -334,18 +332,6 @@ define([
|
|||
this.api.asc_setLocale((this.editorConfig.lang) ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(this.editorConfig.lang)) : 0x0409);
|
||||
}
|
||||
|
||||
value = Common.localStorage.getItem("sse-settings-func-locale");
|
||||
if (value===null) {
|
||||
var lang = ((this.editorConfig.lang) ? this.editorConfig.lang : 'en').split(/[\-\_]/)[0].toLowerCase();
|
||||
Common.Utils.InternalSettings.set("sse-settings-func-locale", lang);
|
||||
if (lang !== 'en')
|
||||
value = SSE.Views.FormulaLang.get(lang);
|
||||
} else {
|
||||
Common.Utils.InternalSettings.set("sse-settings-func-locale", value);
|
||||
value = SSE.Views.FormulaLang.get(value);
|
||||
}
|
||||
if (value) this.api.asc_setLocalization(value);
|
||||
|
||||
value = Common.localStorage.getBool("sse-settings-r1c1");
|
||||
Common.Utils.InternalSettings.set("sse-settings-r1c1", value);
|
||||
this.api.asc_setR1C1Mode(value);
|
||||
|
@ -696,9 +682,9 @@ define([
|
|||
|
||||
if (!me.appOptions.isEditMailMerge && !me.appOptions.isEditDiagram) {
|
||||
pluginsController.setApi(me.api);
|
||||
me.requestPlugins('../../../../plugins.json');
|
||||
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
|
||||
me.api.asc_registerCallback('asc_onPluginsReset', _.bind(me.resetPluginsList, me));
|
||||
if ( (me.appOptions.canPlugins = pluginsController.appOptions.canPlugins) )
|
||||
pluginsController.runAutoStartPlugins();
|
||||
leftmenuController.enablePlugins();
|
||||
}
|
||||
|
||||
leftMenuView.disableMenu('all',false);
|
||||
|
@ -955,8 +941,6 @@ define([
|
|||
|
||||
if (!this.appOptions.isEditDiagram && !this.appOptions.isEditMailMerge) {
|
||||
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
|
||||
if (this.appOptions.canBrandingExt)
|
||||
this.updatePlugins(this.plugins, true);
|
||||
}
|
||||
|
||||
this.applyModeCommonElements();
|
||||
|
@ -1546,7 +1530,7 @@ define([
|
|||
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
|
||||
if (this.appOptions.canBrandingExt) {
|
||||
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
|
||||
Common.Utils.applyCustomizationPlugins(this.UICustomizePlugins);
|
||||
this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2022,143 +2006,6 @@ define([
|
|||
if (url) this.iframePrint.src = url;
|
||||
},
|
||||
|
||||
requestPlugins: function(pluginsPath) { // request plugins
|
||||
if (!pluginsPath) return;
|
||||
|
||||
var config_plugins = (this.plugins && this.plugins.pluginsData && this.plugins.pluginsData.length>0) ? this.updatePlugins(this.plugins, false) : null, // return plugins object
|
||||
request_plugins = this.updatePlugins( Common.Utils.getConfigJson(pluginsPath), false );
|
||||
|
||||
this.updatePluginsList({
|
||||
autostart: (config_plugins&&config_plugins.autostart ? config_plugins.autostart : []).concat(request_plugins&&request_plugins.autostart ? request_plugins.autostart : []),
|
||||
pluginsData: (config_plugins ? config_plugins.pluginsData : []).concat(request_plugins ? request_plugins.pluginsData : [])
|
||||
}, false);
|
||||
},
|
||||
|
||||
updatePlugins: function(plugins, uiCustomize) { // plugins from config
|
||||
if (!plugins) return;
|
||||
|
||||
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
|
||||
if (!pluginsData || pluginsData.length<1) return;
|
||||
|
||||
var arr = [];
|
||||
pluginsData.forEach(function(item){
|
||||
var value = Common.Utils.getConfigJson(item);
|
||||
if (value) {
|
||||
value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
|
||||
arr.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
if (arr.length>0) {
|
||||
var autostart = plugins.autostart || plugins.autoStartGuid;
|
||||
if (typeof (autostart) == 'string')
|
||||
autostart = [autostart];
|
||||
plugins.autoStartGuid && console.warn("Obsolete: The autoStartGuid parameter is deprecated. Please check the documentation for new plugin connection configuration.");
|
||||
|
||||
if (uiCustomize)
|
||||
this.updatePluginsList({
|
||||
autostart: autostart,
|
||||
pluginsData: arr
|
||||
}, !!uiCustomize);
|
||||
else return {
|
||||
autostart: autostart,
|
||||
pluginsData: arr
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
updatePluginsList: function(plugins, uiCustomize) {
|
||||
var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins'),
|
||||
isEdit = this.appOptions.isEdit;
|
||||
if (plugins) {
|
||||
var arr = [], arrUI = [],
|
||||
lang = this.appOptions.lang.split(/[\-\_]/)[0];
|
||||
plugins.pluginsData.forEach(function(item){
|
||||
if (_.find(arr, function(arritem) {
|
||||
return (arritem.get('baseUrl') == item.baseUrl || arritem.get('guid') == item.guid);
|
||||
}) || pluginStore.findWhere({baseUrl: item.baseUrl}) || pluginStore.findWhere({guid: item.guid}))
|
||||
return;
|
||||
|
||||
var variationsArr = [],
|
||||
pluginVisible = false;
|
||||
item.variations.forEach(function(itemVar){
|
||||
var visible = (isEdit || itemVar.isViewer && (itemVar.isDisplayedInViewer!==false)) && _.contains(itemVar.EditorsSupport, 'cell') && !itemVar.isSystem;
|
||||
if ( visible ) pluginVisible = true;
|
||||
|
||||
if ( item.isUICustomizer ) {
|
||||
visible && arrUI.push(item.baseUrl + itemVar.url);
|
||||
} else {
|
||||
var model = new Common.Models.PluginVariation(itemVar);
|
||||
var description = itemVar.description;
|
||||
if (typeof itemVar.descriptionLocale == 'object')
|
||||
description = itemVar.descriptionLocale[lang] || itemVar.descriptionLocale['en'] || description || '';
|
||||
|
||||
_.each(itemVar.buttons, function(b, index){
|
||||
if (typeof b.textLocale == 'object')
|
||||
b.text = b.textLocale[lang] || b.textLocale['en'] || b.text || '';
|
||||
b.visible = (isEdit || b.isViewer !== false);
|
||||
});
|
||||
|
||||
model.set({
|
||||
description: description,
|
||||
index: variationsArr.length,
|
||||
url: itemVar.url,
|
||||
icons: itemVar.icons,
|
||||
buttons: itemVar.buttons,
|
||||
visible: visible
|
||||
});
|
||||
|
||||
variationsArr.push(model);
|
||||
}
|
||||
});
|
||||
if (variationsArr.length>0 && !item.isUICustomizer) {
|
||||
var name = item.name;
|
||||
if (typeof item.nameLocale == 'object')
|
||||
name = item.nameLocale[lang] || item.nameLocale['en'] || name || '';
|
||||
|
||||
arr.push(new Common.Models.Plugin({
|
||||
name : name,
|
||||
guid: item.guid,
|
||||
baseUrl : item.baseUrl,
|
||||
variations: variationsArr,
|
||||
currentVariation: 0,
|
||||
visible: pluginVisible,
|
||||
groupName: (item.group) ? item.group.name : '',
|
||||
groupRank: (item.group) ? item.group.rank : 0
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
|
||||
this.UICustomizePlugins = arrUI;
|
||||
|
||||
if ( !uiCustomize && pluginStore) {
|
||||
arr = pluginStore.models.concat(arr);
|
||||
arr.sort(function(a, b){
|
||||
var rank_a = a.get('groupRank'),
|
||||
rank_b = b.get('groupRank');
|
||||
if (rank_a < rank_b)
|
||||
return (rank_a==0) ? 1 : -1;
|
||||
if (rank_a > rank_b)
|
||||
return (rank_b==0) ? -1 : 1;
|
||||
return 0;
|
||||
});
|
||||
pluginStore.reset(arr);
|
||||
this.appOptions.canPlugins = !pluginStore.isEmpty();
|
||||
}
|
||||
} else if (!uiCustomize){
|
||||
this.appOptions.canPlugins = false;
|
||||
}
|
||||
if (!uiCustomize) this.getApplication().getController('LeftMenu').enablePlugins();
|
||||
if (this.appOptions.canPlugins) {
|
||||
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions).runAutoStartPlugins(plugins.autostart);
|
||||
}
|
||||
},
|
||||
|
||||
resetPluginsList: function() {
|
||||
this.getApplication().getCollection('Common.Collections.Plugins').reset();
|
||||
},
|
||||
|
||||
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.',
|
||||
criticalErrorTitle: 'Error',
|
||||
notcriticalErrorTitle: 'Warning',
|
||||
|
|
|
@ -78,9 +78,6 @@ define([
|
|||
'Statusbar': {
|
||||
'sheet:changed': _.bind(this.onApiSheetChanged, this)
|
||||
},
|
||||
'LeftMenu': {
|
||||
'settings:apply': _.bind(this.applyFormulaSettings, this)
|
||||
},
|
||||
'Common.Views.Header': {
|
||||
'toolbar:setcompact': this.onChangeViewMode.bind(this),
|
||||
'print': function (opts) {
|
||||
|
@ -123,6 +120,7 @@ define([
|
|||
}
|
||||
});
|
||||
Common.NotificationCenter.on('page:settings', _.bind(this.onApiSheetChanged, this));
|
||||
Common.NotificationCenter.on('formula:settings', _.bind(this.applyFormulaSettings, this));
|
||||
|
||||
this.editMode = true;
|
||||
this._isAddingShape = false;
|
||||
|
|
|
@ -1,123 +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
|
||||
*
|
||||
*/
|
||||
define([
|
||||
], function () {
|
||||
'use strict';
|
||||
|
||||
SSE.Views = SSE.Views || {};
|
||||
|
||||
SSE.Views.FormulaLang = new(function() {
|
||||
var langJson = {},
|
||||
langDescJson = {};
|
||||
|
||||
var _createXMLHTTPObject = function() {
|
||||
var xmlhttp;
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
catch (E) {
|
||||
xmlhttp = false;
|
||||
}
|
||||
}
|
||||
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
}
|
||||
return xmlhttp;
|
||||
};
|
||||
|
||||
var _get = function(lang) {
|
||||
if (!lang) return '';
|
||||
lang = lang.toLowerCase() ;
|
||||
|
||||
if (langJson[lang])
|
||||
return langJson[lang];
|
||||
else if (lang == 'en')
|
||||
return undefined;
|
||||
else {
|
||||
try {
|
||||
var xhrObj = _createXMLHTTPObject();
|
||||
if (xhrObj && lang) {
|
||||
xhrObj.open('GET', 'resources/formula-lang/' + lang + '.json', false);
|
||||
xhrObj.send('');
|
||||
langJson[lang] = eval("(" + xhrObj.responseText + ")");
|
||||
return langJson[lang];
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
var _getDescription = function(lang) {
|
||||
if (!lang) return '';
|
||||
lang = lang.toLowerCase() ;
|
||||
|
||||
if (langDescJson[lang])
|
||||
return langDescJson[lang];
|
||||
else {
|
||||
try {
|
||||
var xhrObj = _createXMLHTTPObject();
|
||||
if (xhrObj && lang) {
|
||||
xhrObj.open('GET', 'resources/formula-lang/' + lang + '_desc.json', false);
|
||||
xhrObj.send('');
|
||||
if (xhrObj.status==200 ||
|
||||
(xhrObj.status==0 && !!xhrObj.responseURL && xhrObj.responseURL.startsWith('file://')))
|
||||
langDescJson[lang] = eval("(" + xhrObj.responseText + ")");
|
||||
else {
|
||||
xhrObj.open('GET', 'resources/formula-lang/en_desc.json', false);
|
||||
xhrObj.send('');
|
||||
langDescJson[lang] = eval("(" + xhrObj.responseText + ")");
|
||||
}
|
||||
return langDescJson[lang];
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
return {
|
||||
get: _get,
|
||||
getDescription: _getDescription
|
||||
};
|
||||
})();
|
||||
});
|
Loading…
Reference in a new issue