Commit 7dfcc927 authored by Julia Radzhabova's avatar Julia Radzhabova

Interface customization using plugins. Need to append...

Interface customization using plugins. Need to append config->editorConfig->pluigns->UIpluginsData field with list of customizer plugins.
parent 970d1368
......@@ -602,6 +602,48 @@ Common.Utils.applyCustomization = function(config, elmap) {
}
};
Common.Utils.applyCustomizationPlugins = function(plugins) {
if (!plugins || plugins.length<1) return;
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 _getPluginCode = function(url) {
if (!url) return '';
try {
var xhrObj = _createXMLHTTPObject();
if (xhrObj && url) {
xhrObj.open('GET', url, false);
xhrObj.send('');
if (xhrObj.status == 200)
eval(xhrObj.responseText);
}
}
catch (e) {}
return null;
};
plugins.forEach(function(url){
if (url) _getPluginCode(url);
});
};
Common.Utils.fillUserInfo = function(info, lang, defname) {
var _user = info || {};
!_user.id && (_user.id = ('uid-' + Date.now()));
......
......@@ -147,6 +147,7 @@ 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));
......@@ -857,7 +858,7 @@ define([
application.getController('Common.Controllers.ExternalMergeEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization});
pluginsController.setApi(me.api);
me.updatePlugins(me.plugins);
me.updatePlugins(me.plugins, false);
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
documentHolderController.setApi(me.api);
......@@ -900,9 +901,14 @@ define([
toolbarController.onApiCoAuthoringDisconnect();
me.api.UpdateInterfaceState();
me.fillTextArt(me.api.asc_getTextArtPreviews());
if (me.appOptions.canBrandingExt)
Common.NotificationCenter.trigger('document:ready', 'main');
}
}, 50);
}
} else if (me.appOptions.canBrandingExt)
Common.NotificationCenter.trigger('document:ready', 'main');
if (this.appOptions.canAnalytics && false)
Common.component.Analytics.initialize('UA-12442749-13', 'Document Editor');
......@@ -1008,7 +1014,9 @@ define([
params.asc_getTrial() && headerView.setDeveloperMode(true);
this.appOptions.canRename && headerView.setCanRename(true);
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object');
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();
......@@ -1443,13 +1451,15 @@ define([
},
hidePreloader: function() {
if (!!this.appOptions.customization && !this.appOptions.customization.done) {
this.appOptions.customization.done = true;
if (!this.appOptions.isDesktopApp)
if (!this._state.customizationDone) {
this._state.customizationDone = true;
if (this.appOptions.customization && !this.appOptions.isDesktopApp)
this.appOptions.customization.about = true;
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
if (this.appOptions.canBrandingExt)
if (this.appOptions.canBrandingExt) {
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
Common.Utils.applyCustomizationPlugins(this.UICustomizePlugins);
}
}
Common.NotificationCenter.trigger('layout:changed', 'main');
......@@ -1782,8 +1792,11 @@ define([
if (url) this.iframePrint.src = url;
},
updatePlugins: function(plugins) { // plugins from config
if (!plugins || !plugins.pluginsData || plugins.pluginsData.length<1) return;
updatePlugins: function(plugins, uiCustomize) { // plugins from config
if (!plugins) return;
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
if (!pluginsData || pluginsData.length<1) return;
var _createXMLHTTPObject = function() {
var xmlhttp;
......@@ -1821,7 +1834,7 @@ define([
var arr = [],
baseUrl = plugins.url;
plugins.pluginsData.forEach(function(item){
pluginsData.forEach(function(item){
var url = item;
if (!/(^https?:\/\/)/i.test(url) && !/(^www.)/i.test(item))
url = baseUrl + item;
......@@ -1834,14 +1847,14 @@ define([
autoStartGuid: plugins.autoStartGuid,
url: plugins.url,
pluginsData: arr
});
}, !!uiCustomize);
},
updatePluginsList: function(plugins) {
updatePluginsList: function(plugins, uiCustomize) {
var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins'),
isEdit = this.appOptions.isEdit;
if (pluginStore && plugins) {
var arr = [];
if (plugins) {
var arr = [], arrUI = [];
plugins.pluginsData.forEach(function(item){
var variations = item.variations,
variationsArr = [];
......@@ -1852,7 +1865,9 @@ define([
isSupported = true; break;
}
}
if (isSupported && (isEdit || itemVar.isViewer))
if (isSupported && (isEdit || itemVar.isViewer)) {
var isRelativeUrl = !(/(^https?:\/\/)/i.test(itemVar.url) || /(^www.)/i.test(itemVar.url));
item.isUICustomizer ? arrUI.push((isRelativeUrl) ? ((item.baseUrl ? item.baseUrl : plugins.url) + itemVar.url) : itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description,
index: variationsArr.length,
......@@ -1869,10 +1884,11 @@ define([
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged,
isRelativeUrl: !(/(^https?:\/\/)/i.test(itemVar.url) || /(^www.)/i.test(itemVar.url))
isRelativeUrl: isRelativeUrl
}));
}
});
if (variationsArr.length>0)
if (variationsArr.length>0 && !item.isUICustomizer)
arr.push(new Common.Models.Plugin({
name : item.name,
guid: item.guid,
......@@ -1882,11 +1898,15 @@ define([
}));
});
pluginStore.reset(arr);
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
this.UICustomizePlugins = arrUI;
this.appOptions.pluginsPath = (plugins.url);
this.appOptions.canPlugins = (arr.length>0);
} else {
if (!uiCustomize) {
if (pluginStore) pluginStore.reset(arr);
this.appOptions.pluginsPath = (plugins.url);
this.appOptions.canPlugins = (arr.length>0);
}
} else if (!uiCustomize){
this.appOptions.pluginsPath = '';
this.appOptions.canPlugins = false;
}
......@@ -1895,7 +1915,7 @@ define([
if (plugins.autoStartGuid)
this.api.asc_pluginRun(plugins.autoStartGuid, 0, '');
}
this.getApplication().getController('LeftMenu').enablePlugins();
if (!uiCustomize) this.getApplication().getController('LeftMenu').enablePlugins();
},
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.',
......
......@@ -142,6 +142,7 @@ 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));
......@@ -636,7 +637,7 @@ define([
application.getController('Common.Controllers.ExternalDiagramEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization});
pluginsController.setApi(me.api);
me.updatePlugins(me.plugins);
me.updatePlugins(me.plugins, false);
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
documentHolderController.setApi(me.api);
......@@ -681,9 +682,14 @@ define([
if (me.needToUpdateVersion)
toolbarController.onApiCoAuthoringDisconnect();
me.api.UpdateInterfaceState();
if (me.appOptions.canBrandingExt)
Common.NotificationCenter.trigger('document:ready', 'main');
}
}, 50);
}
} else if (me.appOptions.canBrandingExt)
Common.NotificationCenter.trigger('document:ready', 'main');
if (this.appOptions.canAnalytics && false)
Common.component.Analytics.initialize('UA-12442749-13', 'Presentation Editor');
......@@ -773,7 +779,9 @@ define([
params.asc_getTrial() && headerView.setDeveloperMode(true);
this.appOptions.canRename && headerView.setCanRename(true);
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object');
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();
......@@ -1196,13 +1204,15 @@ define([
},
hidePreloader: function() {
if (!!this.appOptions.customization && !this.appOptions.customization.done) {
this.appOptions.customization.done = true;
if (!this.appOptions.isDesktopApp)
if (!this._state.customizationDone) {
this._state.customizationDone = true;
if (this.appOptions.customization && !this.appOptions.isDesktopApp)
this.appOptions.customization.about = true;
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
if (this.appOptions.canBrandingExt)
if (this.appOptions.canBrandingExt) {
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
Common.Utils.applyCustomizationPlugins(this.UICustomizePlugins);
}
}
Common.NotificationCenter.trigger('layout:changed', 'main');
......@@ -1563,8 +1573,11 @@ define([
}
},
updatePlugins: function(plugins) { // plugins from config
if (!plugins || !plugins.pluginsData || plugins.pluginsData.length<1) return;
updatePlugins: function(plugins, uiCustomize) { // plugins from config
if (!plugins) return;
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
if (!pluginsData || pluginsData.length<1) return;
var _createXMLHTTPObject = function() {
var xmlhttp;
......@@ -1602,7 +1615,7 @@ define([
var arr = [],
baseUrl = plugins.url;
plugins.pluginsData.forEach(function(item){
pluginsData.forEach(function(item){
var url = item;
if (!/(^https?:\/\/)/i.test(url) && !/(^www.)/i.test(item))
url = baseUrl + item;
......@@ -1615,14 +1628,14 @@ define([
autoStartGuid: plugins.autoStartGuid,
url: plugins.url,
pluginsData: arr
});
}, !!uiCustomize);
},
updatePluginsList: function(plugins) {
updatePluginsList: function(plugins, uiCustomize) {
var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins'),
isEdit = this.appOptions.isEdit;
if (pluginStore && plugins) {
var arr = [];
if (plugins) {
var arr = [], arrUI = [];
plugins.pluginsData.forEach(function(item){
var variations = item.variations,
variationsArr = [];
......@@ -1633,7 +1646,9 @@ define([
isSupported = true; break;
}
}
if (isSupported && (isEdit || itemVar.isViewer))
if (isSupported && (isEdit || itemVar.isViewer)){
var isRelativeUrl = !(/(^https?:\/\/)/i.test(itemVar.url) || /(^www.)/i.test(itemVar.url));
item.isUICustomizer ? arrUI.push((isRelativeUrl) ? ((item.baseUrl ? item.baseUrl : plugins.url) + itemVar.url) : itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description,
index: variationsArr.length,
......@@ -1650,10 +1665,11 @@ define([
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged,
isRelativeUrl: !(/(^https?:\/\/)/i.test(itemVar.url) || /(^www.)/i.test(itemVar.url))
isRelativeUrl: isRelativeUrl
}));
}
});
if (variationsArr.length>0)
if (variationsArr.length>0 && !item.isUICustomizer)
arr.push(new Common.Models.Plugin({
name : item.name,
guid: item.guid,
......@@ -1663,11 +1679,15 @@ define([
}));
});
pluginStore.reset(arr);
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
this.UICustomizePlugins = arrUI;
this.appOptions.pluginsPath = (plugins.url);
this.appOptions.canPlugins = (arr.length>0);
} else {
if (!uiCustomize) {
if (pluginStore) pluginStore.reset(arr);
this.appOptions.pluginsPath = (plugins.url);
this.appOptions.canPlugins = (arr.length>0);
}
} else if (!uiCustomize){
this.appOptions.pluginsPath = '';
this.appOptions.canPlugins = false;
}
......@@ -1676,7 +1696,7 @@ define([
if (plugins.autoStartGuid)
this.api.asc_pluginRun(plugins.autoStartGuid, 0, '');
}
this.getApplication().getController('LeftMenu').enablePlugins();
if (!uiCustomize) this.getApplication().getController('LeftMenu').enablePlugins();
},
// Translation
......
......@@ -147,6 +147,7 @@ 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));
......@@ -614,7 +615,7 @@ define([
if (!me.appOptions.isEditMailMerge && !me.appOptions.isEditDiagram) {
pluginsController.setApi(me.api);
me.updatePlugins(me.plugins);
me.updatePlugins(me.plugins, false);
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
}
......@@ -684,9 +685,13 @@ define([
}
if (me.needToUpdateVersion)
toolbarController.onApiCoAuthoringDisconnect();
if (me.appOptions.canBrandingExt)
Common.NotificationCenter.trigger('document:ready', 'main');
}
}, 50);
}
} else if (me.appOptions.canBrandingExt)
Common.NotificationCenter.trigger('document:ready', 'main');
if (me.appOptions.canAnalytics && false)
Common.component.Analytics.initialize('UA-12442749-13', 'Spreadsheet Editor');
......@@ -782,7 +787,9 @@ define([
if (this.appOptions.canBranding)
this.headerView.setBranding(this.editorConfig.customization);
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object');
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
if (this.appOptions.canBrandingExt)
this.updatePlugins(this.plugins, true);
params.asc_getTrial() && this.headerView.setDeveloperMode(true);
this.appOptions.canRename && this.headerView.setCanRename(true);
......@@ -1325,13 +1332,15 @@ define([
},
hidePreloader: function() {
if (!!this.appOptions.customization && !this.appOptions.customization.done) {
this.appOptions.customization.done = true;
if (!this.appOptions.isDesktopApp)
if (!this._state.customizationDone) {
this._state.customizationDone = true;
if (this.appOptions.customization && !this.appOptions.isDesktopApp)
this.appOptions.customization.about = true;
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements);
if (this.appOptions.canBrandingExt)
if (this.appOptions.canBrandingExt) {
Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements);
Common.Utils.applyCustomizationPlugins(this.UICustomizePlugins);
}
}
this.stackLongActions.pop({id: InitApplication, type: Asc.c_oAscAsyncActionType.BlockInteraction});
......@@ -1773,8 +1782,11 @@ define([
if (url) this.iframePrint.src = url;
},
updatePlugins: function(plugins) { // plugins from config
if (!plugins || !plugins.pluginsData || plugins.pluginsData.length<1) return;
updatePlugins: function(plugins, uiCustomize) { // plugins from config
if (!plugins) return;
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
if (!pluginsData || pluginsData.length<1) return;
var _createXMLHTTPObject = function() {
var xmlhttp;
......@@ -1812,7 +1824,7 @@ define([
var arr = [],
baseUrl = plugins.url;
plugins.pluginsData.forEach(function(item){
pluginsData.forEach(function(item){
var url = item;
if (!/(^https?:\/\/)/i.test(url) && !/(^www.)/i.test(item))
url = baseUrl + item;
......@@ -1825,14 +1837,14 @@ define([
autoStartGuid: plugins.autoStartGuid,
url: plugins.url,
pluginsData: arr
});
}, !!uiCustomize);
},
updatePluginsList: function(plugins) {
updatePluginsList: function(plugins, uiCustomize) {
var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins'),
isEdit = this.appOptions.isEdit;
if (pluginStore && plugins) {
var arr = [];
if (plugins) {
var arr = [], arrUI = [];
plugins.pluginsData.forEach(function(item){
var variations = item.variations,
variationsArr = [];
......@@ -1843,7 +1855,9 @@ define([
isSupported = true; break;
}
}
if (isSupported && (isEdit || itemVar.isViewer))
if (isSupported && (isEdit || itemVar.isViewer)) {
var isRelativeUrl = !(/(^https?:\/\/)/i.test(itemVar.url) || /(^www.)/i.test(itemVar.url));
item.isUICustomizer ? arrUI.push((isRelativeUrl) ? ((item.baseUrl ? item.baseUrl : plugins.url) + itemVar.url) : itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description,
index: variationsArr.length,
......@@ -1860,10 +1874,11 @@ define([
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged,
isRelativeUrl: !(/(^https?:\/\/)/i.test(itemVar.url) || /(^www.)/i.test(itemVar.url))
isRelativeUrl: isRelativeUrl
}));
}
});
if (variationsArr.length>0)
if (variationsArr.length>0 && !item.isUICustomizer)
arr.push(new Common.Models.Plugin({
name : item.name,
guid: item.guid,
......@@ -1873,11 +1888,15 @@ define([
}));
});
pluginStore.reset(arr);
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
this.UICustomizePlugins = arrUI;
this.appOptions.pluginsPath = (plugins.url);
this.appOptions.canPlugins = (arr.length>0);
} else {
if (!uiCustomize) {
if (pluginStore) pluginStore.reset(arr);
this.appOptions.pluginsPath = (plugins.url);
this.appOptions.canPlugins = (arr.length>0);
}
} else if (!uiCustomize){
this.appOptions.pluginsPath = '';
this.appOptions.canPlugins = false;
}
......@@ -1886,7 +1905,7 @@ define([
if (plugins.autoStartGuid)
this.api.asc_pluginRun(plugins.autoStartGuid, 0, '');
}
this.getApplication().getController('LeftMenu').enablePlugins();
if (!uiCustomize) this.getApplication().getController('LeftMenu').enablePlugins();
},
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.',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment