[DE] moved plugins functions from Main controller
This commit is contained in:
parent
0810196641
commit
8bff4f4b35
|
@ -45,6 +45,8 @@ define([
|
||||||
|
|
||||||
Common.Controllers.Plugins = Backbone.Controller.extend(_.extend({
|
Common.Controllers.Plugins = Backbone.Controller.extend(_.extend({
|
||||||
models: [],
|
models: [],
|
||||||
|
appOptions: {},
|
||||||
|
plugins: { autostart:[] },
|
||||||
collections: [
|
collections: [
|
||||||
'Common.Collections.Plugins'
|
'Common.Collections.Plugins'
|
||||||
],
|
],
|
||||||
|
@ -96,6 +98,32 @@ define([
|
||||||
|
|
||||||
this._moveOffset = {x:0, y:0};
|
this._moveOffset = {x:0, y:0};
|
||||||
this.autostart = null;
|
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 = DE ? 'word' : PE ? 'slide' : 'cell';
|
||||||
|
|
||||||
|
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) {
|
setApi: function(api) {
|
||||||
|
@ -106,14 +134,33 @@ define([
|
||||||
this.api.asc_registerCallback("asc_onPluginResize", _.bind(this.onPluginResize, this));
|
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_onPluginMouseUp", _.bind(this.onPluginMouseUp, this));
|
||||||
this.api.asc_registerCallback("asc_onPluginMouseMove", _.bind(this.onPluginMouseMove, 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;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
setMode: function(mode) {
|
setMode: function(mode) {
|
||||||
if (mode.canPlugins) {
|
console.log('set plugins mode');
|
||||||
this.updatePluginsList();
|
// if (mode.canPlugins) {
|
||||||
}
|
// this.refreshPluginsList();
|
||||||
|
// }
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -138,7 +185,7 @@ define([
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
updatePluginsList: function() {
|
refreshPluginsList: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
var storePlugins = this.getApplication().getCollection('Common.Collections.Plugins'),
|
var storePlugins = this.getApplication().getCollection('Common.Collections.Plugins'),
|
||||||
arr = [];
|
arr = [];
|
||||||
|
@ -147,6 +194,7 @@ define([
|
||||||
plugin.set_Name(item.get('name'));
|
plugin.set_Name(item.get('name'));
|
||||||
plugin.set_Guid(item.get('guid'));
|
plugin.set_Guid(item.get('guid'));
|
||||||
plugin.set_BaseUrl(item.get('baseUrl'));
|
plugin.set_BaseUrl(item.get('baseUrl'));
|
||||||
|
|
||||||
var variations = item.get('variations'),
|
var variations = item.get('variations'),
|
||||||
variationsArr = [];
|
variationsArr = [];
|
||||||
variations.forEach(function(itemVar){
|
variations.forEach(function(itemVar){
|
||||||
|
@ -168,8 +216,10 @@ define([
|
||||||
variation.set_Size(itemVar.get('size'));
|
variation.set_Size(itemVar.get('size'));
|
||||||
variation.set_InitOnSelectionChanged(itemVar.get('initOnSelectionChanged'));
|
variation.set_InitOnSelectionChanged(itemVar.get('initOnSelectionChanged'));
|
||||||
variation.set_Events(itemVar.get('events'));
|
variation.set_Events(itemVar.get('events'));
|
||||||
|
|
||||||
variationsArr.push(variation);
|
variationsArr.push(variation);
|
||||||
});
|
});
|
||||||
|
|
||||||
plugin.set_Variations(variationsArr);
|
plugin.set_Variations(variationsArr);
|
||||||
item.set('pluginObj', plugin);
|
item.set('pluginObj', plugin);
|
||||||
arr.push(plugin);
|
arr.push(plugin);
|
||||||
|
@ -193,6 +243,7 @@ define([
|
||||||
|
|
||||||
onResetPlugins: function (collection) {
|
onResetPlugins: function (collection) {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
me.appOptions.canPlugins = !collection.isEmpty();
|
||||||
if ( me.$toolbarPanelPlugins ) {
|
if ( me.$toolbarPanelPlugins ) {
|
||||||
me.$toolbarPanelPlugins.empty();
|
me.$toolbarPanelPlugins.empty();
|
||||||
|
|
||||||
|
@ -217,6 +268,8 @@ define([
|
||||||
rank = new_rank;
|
rank = new_rank;
|
||||||
});
|
});
|
||||||
_group.appendTo(me.$toolbarPanelPlugins);
|
_group.appendTo(me.$toolbarPanelPlugins);
|
||||||
|
} else {
|
||||||
|
console.error('toolbar panel isnot created');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -397,12 +450,173 @@ define([
|
||||||
},
|
},
|
||||||
|
|
||||||
runAutoStartPlugins: function(autostart) {
|
runAutoStartPlugins: function(autostart) {
|
||||||
|
autostart = this.plugins.autostart;
|
||||||
if (autostart && autostart.length > 0) {
|
if (autostart && autostart.length > 0) {
|
||||||
var guid = autostart.shift();
|
// var guid = autostart.shift();
|
||||||
this.autostart = autostart;
|
// this.autostart = autostart;
|
||||||
this.api.asc_pluginRun(guid, 0, '');
|
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(e => {
|
||||||
|
me.plugins.serverpluginsdata = false;
|
||||||
|
console.log('getServerPlugins error: ' + e.message);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getAppConfigPlugins: function (config) {
|
||||||
|
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(e => {
|
||||||
|
console.log('error: ' + e.message);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
}, Common.Controllers.Plugins || {}));
|
}, Common.Controllers.Plugins || {}));
|
||||||
});
|
});
|
||||||
|
|
|
@ -191,7 +191,6 @@ define([
|
||||||
this.editorConfig = {};
|
this.editorConfig = {};
|
||||||
this.appOptions = {};
|
this.appOptions = {};
|
||||||
this.plugins = undefined;
|
this.plugins = undefined;
|
||||||
this.UICustomizePlugins = [];
|
|
||||||
Common.Gateway.on('init', _.bind(this.loadConfig, this));
|
Common.Gateway.on('init', _.bind(this.loadConfig, this));
|
||||||
Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this));
|
Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this));
|
||||||
Common.Gateway.on('opendocument', _.bind(this.loadDocument, this));
|
Common.Gateway.on('opendocument', _.bind(this.loadDocument, this));
|
||||||
|
@ -925,9 +924,9 @@ define([
|
||||||
application.getController('Common.Controllers.ExternalMergeEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization});
|
application.getController('Common.Controllers.ExternalMergeEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization});
|
||||||
|
|
||||||
pluginsController.setApi(me.api);
|
pluginsController.setApi(me.api);
|
||||||
me.requestPlugins('../../../../plugins.json');
|
if ( (me.appOptions.canPlugins = pluginsController.appOptions.canPlugins) )
|
||||||
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
|
pluginsController.runAutoStartPlugins();
|
||||||
me.api.asc_registerCallback('asc_onPluginsReset', _.bind(me.resetPluginsList, me));
|
leftmenuController.enablePlugins();
|
||||||
|
|
||||||
documentHolderController.setApi(me.api);
|
documentHolderController.setApi(me.api);
|
||||||
documentHolderController.createDelayedElements();
|
documentHolderController.createDelayedElements();
|
||||||
|
@ -1165,10 +1164,7 @@ define([
|
||||||
}
|
}
|
||||||
|
|
||||||
this.appOptions.canRename && appHeader.setCanRename(true);
|
this.appOptions.canRename && appHeader.setCanRename(true);
|
||||||
|
|
||||||
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
|
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.applyModeCommonElements();
|
||||||
this.applyModeEditorElements();
|
this.applyModeEditorElements();
|
||||||
|
@ -1648,7 +1644,7 @@ define([
|
||||||
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
|
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
|
||||||
if (this.appOptions.canBrandingExt) {
|
if (this.appOptions.canBrandingExt) {
|
||||||
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
|
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
|
||||||
Common.Utils.applyCustomizationPlugins(this.UICustomizePlugins);
|
this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2054,162 +2050,6 @@ define([
|
||||||
if (url) this.iframePrint.src = url;
|
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 )*/;
|
|
||||||
|
|
||||||
var me = this;
|
|
||||||
Common.Utils.loadConfig(pluginsPath, function(json) {
|
|
||||||
if (json != 'error') {
|
|
||||||
request_plugins = me.updatePlugins(json);
|
|
||||||
me.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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**/
|
|
||||||
Promise.all(pluginsData.map(url => {
|
|
||||||
return fetch(url)
|
|
||||||
.then(response => response.json());
|
|
||||||
// .then(json => json);
|
|
||||||
})).then( values => {
|
|
||||||
console.log('plugins: ' + values);
|
|
||||||
}).catch(e => {
|
|
||||||
console.log('error: ' + e.message);
|
|
||||||
});
|
|
||||||
/**/
|
|
||||||
|
|
||||||
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.',
|
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.',
|
||||||
defaultTitleText: 'ONLYOFFICE Document Editor',
|
defaultTitleText: 'ONLYOFFICE Document Editor',
|
||||||
criticalErrorTitle: 'Error',
|
criticalErrorTitle: 'Error',
|
||||||
|
|
Loading…
Reference in a new issue