Commit 704d0fc7 authored by Julia Radzhabova's avatar Julia Radzhabova

Load plugins from config or using request to server.

Add "autostart" parameter to plugins config: run first plugin from autostart plugins list.
parent 5c8d0a31
......@@ -683,6 +683,40 @@ Common.Utils.fillUserInfo = function(info, lang, defname) {
return _user;
};
Common.Utils.createXhr = 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;
};
Common.Utils.getConfigJson = function (url) {
if ( url ) {
try {
var xhrObj = Common.Utils.createXhr();
if ( xhrObj ) {
xhrObj.open('GET', url, false);
xhrObj.send('');
return JSON.parse(xhrObj.responseText);
}
} catch (e) {}
}
return null;
};
// Extend javascript String type
String.prototype.strongMatch = function(regExp){
if (regExp && regExp instanceof RegExp) {
......
......@@ -183,7 +183,7 @@ define([
},
closeNotVisualMode: function() {
this.viewPluginsList.cmpEl.find('.selected').removeClass('selected');
this.viewPluginsList && this.viewPluginsList.cmpEl.find('.selected').removeClass('selected');
},
_onLoad: function() {
......
......@@ -858,8 +858,10 @@ 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, false);
me.requestPlugins('../../../../plugins.json');
if (me.plugins && me.plugins.pluginsData && me.plugins.pluginsData.length>0)
me.updatePlugins(me.plugins, false);
else
me.requestPlugins('../../../../plugins.json');
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
documentHolderController.setApi(me.api);
......@@ -1871,43 +1873,7 @@ define([
requestPlugins: function(pluginsPath) { // request plugins
if (!pluginsPath) 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 _getPluginJson = function(plugin) {
if (!plugin) return '';
try {
var xhrObj = _createXMLHTTPObject();
if (xhrObj && plugin) {
xhrObj.open('GET', plugin, false);
xhrObj.send('');
var pluginJson = eval("(" + xhrObj.responseText + ")");
return pluginJson;
}
}
catch (e) {}
return null;
};
var value = _getPluginJson(pluginsPath);
if (value)
this.updatePlugins(value, false);
this.updatePlugins( Common.Utils.getConfigJson(pluginsPath), false );
},
updatePlugins: function(plugins, uiCustomize) { // plugins from config
......@@ -1916,49 +1882,15 @@ define([
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
if (!pluginsData || pluginsData.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 _getPluginJson = function(plugin) {
if (!plugin) return '';
try {
var xhrObj = _createXMLHTTPObject();
if (xhrObj && plugin) {
xhrObj.open('GET', plugin, false);
xhrObj.send('');
var pluginJson = eval("(" + xhrObj.responseText + ")");
return pluginJson;
}
}
catch (e) {}
return null;
};
var arr = [],
baseUrl = _.isEmpty(plugins.url) ? "" : plugins.url;
if (baseUrl !== "")
console.log("Obsolete: The url parameter is deprecated. Please check the documentation for new plugin connection configuration.");
console.warn("Obsolete: The url parameter is deprecated. Please check the documentation for new plugin connection configuration.");
pluginsData.forEach(function(item){
item = baseUrl + item; // for compatibility with previouse version of server, where plugins.url is used.
var value = _getPluginJson(item);
var value = Common.Utils.getConfigJson(item);
if (value) {
value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
value.oldVersion = (baseUrl !== "");
......@@ -1966,11 +1898,17 @@ define([
}
});
if (arr.length>0)
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.");
this.updatePluginsList({
autoStartGuid: plugins.autoStartGuid,
autostart: autostart,
pluginsData: arr
}, !!uiCustomize);
}
},
updatePluginsList: function(plugins, uiCustomize) {
......@@ -1979,18 +1917,9 @@ define([
if (plugins) {
var arr = [], arrUI = [];
plugins.pluginsData.forEach(function(item){
if (uiCustomize!==undefined && (pluginStore.findWhere({baseUrl : item.baseUrl}) || pluginStore.findWhere({guid : item.guid}))) return;
var variations = item.variations,
variationsArr = [];
variations.forEach(function(itemVar){
var isSupported = false;
for (var i=0; i<itemVar.EditorsSupport.length; i++){
if (itemVar.EditorsSupport[i]=='word') {
isSupported = true; break;
}
}
if (isSupported && (isEdit || itemVar.isViewer)) {
var variationsArr = [];
item.variations.forEach(function(itemVar){
if (_.contains(itemVar.EditorsSupport, 'word') && (isEdit || itemVar.isViewer)) {
var icons = itemVar.icons;
if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used.
icons = [];
......@@ -2032,20 +1961,17 @@ define([
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
this.UICustomizePlugins = arrUI;
if (uiCustomize === undefined) { // for desktop
if ( !uiCustomize ) {
if (pluginStore) pluginStore.reset(arr);
this.appOptions.canPlugins = (pluginStore.length>0);
} else if (!uiCustomize) {
if (pluginStore) pluginStore.add(arr);
this.appOptions.canPlugins = (pluginStore.length>0);
this.appOptions.canPlugins = !pluginStore.isEmpty();
}
} else if (!uiCustomize){
this.appOptions.canPlugins = false;
}
if (this.appOptions.canPlugins) {
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);
if (plugins.autoStartGuid)
this.api.asc_pluginRun(plugins.autoStartGuid, 0, '');
if (plugins.autostart && plugins.autostart.length>0)
this.api.asc_pluginRun(plugins.autostart[0], 0, '');
}
if (!uiCustomize) this.getApplication().getController('LeftMenu').enablePlugins();
},
......
......@@ -635,8 +635,10 @@ 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, false);
me.requestPlugins('../../../../plugins.json');
if (me.plugins && me.plugins.pluginsData && me.plugins.pluginsData.length>0)
me.updatePlugins(me.plugins, false);
else
me.requestPlugins('../../../../plugins.json');
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
documentHolderController.setApi(me.api);
......@@ -1653,95 +1655,24 @@ define([
requestPlugins: function(pluginsPath) { // request plugins
if (!pluginsPath) 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 _getPluginJson = function(plugin) {
if (!plugin) return '';
try {
var xhrObj = _createXMLHTTPObject();
if (xhrObj && plugin) {
xhrObj.open('GET', plugin, false);
xhrObj.send('');
var pluginJson = eval("(" + xhrObj.responseText + ")");
return pluginJson;
}
}
catch (e) {}
return null;
};
var value = _getPluginJson(pluginsPath);
if (value)
this.updatePlugins(value, false);
this.updatePlugins( Common.Utils.getConfigJson(pluginsPath), 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 _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 _getPluginJson = function(plugin) {
if (!plugin) return '';
try {
var xhrObj = _createXMLHTTPObject();
if (xhrObj && plugin) {
xhrObj.open('GET', plugin, false);
xhrObj.send('');
var pluginJson = eval("(" + xhrObj.responseText + ")");
return pluginJson;
}
}
catch (e) {}
return null;
};
var arr = [],
baseUrl = _.isEmpty(plugins.url) ? "" : plugins.url;
if (baseUrl !== "")
console.log("Obsolete: The url parameter is deprecated. Please check the documentation for new plugin connection configuration.");
console.warn("Obsolete: The url parameter is deprecated. Please check the documentation for new plugin connection configuration.");
pluginsData.forEach(function(item){
item = baseUrl + item; // for compatibility with previouse version of server, where plugins.url is used.
var value = _getPluginJson(item);
var value = Common.Utils.getConfigJson(item);
if (value) {
value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
value.oldVersion = (baseUrl !== "");
......@@ -1749,11 +1680,17 @@ define([
}
});
if (arr.length>0)
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.");
this.updatePluginsList({
autoStartGuid: plugins.autoStartGuid,
autostart: autostart,
pluginsData: arr
}, !!uiCustomize);
}
},
updatePluginsList: function(plugins, uiCustomize) {
......@@ -1762,18 +1699,9 @@ define([
if (plugins) {
var arr = [], arrUI = [];
plugins.pluginsData.forEach(function(item){
if (uiCustomize!==undefined && (pluginStore.findWhere({baseUrl : item.baseUrl}) || pluginStore.findWhere({guid : item.guid}))) return;
var variations = item.variations,
variationsArr = [];
variations.forEach(function(itemVar){
var isSupported = false;
for (var i=0; i<itemVar.EditorsSupport.length; i++){
if (itemVar.EditorsSupport[i]=='slide') {
isSupported = true; break;
}
}
if (isSupported && (isEdit || itemVar.isViewer)){
var variationsArr = [];
item.variations.forEach(function(itemVar){
if (_.contains(itemVar.EditorsSupport, 'word') && (isEdit || itemVar.isViewer)) {
var icons = itemVar.icons;
if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used.
icons = [];
......@@ -1815,20 +1743,17 @@ define([
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
this.UICustomizePlugins = arrUI;
if (uiCustomize === undefined) { // for desktop
if ( !uiCustomize ) {
if (pluginStore) pluginStore.reset(arr);
this.appOptions.canPlugins = (pluginStore.length>0);
} else if (!uiCustomize) {
if (pluginStore) pluginStore.add(arr);
this.appOptions.canPlugins = (pluginStore.length>0);
this.appOptions.canPlugins = !pluginStore.isEmpty();
}
} else if (!uiCustomize){
this.appOptions.canPlugins = false;
}
if (this.appOptions.canPlugins) {
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);
if (plugins.autoStartGuid)
this.api.asc_pluginRun(plugins.autoStartGuid, 0, '');
if (plugins.autostart && plugins.autostart.length>0)
this.api.asc_pluginRun(plugins.autostart[0], 0, '');
}
if (!uiCustomize) this.getApplication().getController('LeftMenu').enablePlugins();
},
......
......@@ -617,8 +617,10 @@ define([
if (!me.appOptions.isEditMailMerge && !me.appOptions.isEditDiagram) {
pluginsController.setApi(me.api);
me.updatePlugins(me.plugins, false);
me.requestPlugins('../../../../plugins.json');
if (me.plugins && me.plugins.pluginsData && me.plugins.pluginsData.length>0)
me.updatePlugins(me.plugins, false);
else
me.requestPlugins('../../../../plugins.json');
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
}
......@@ -1843,43 +1845,7 @@ define([
requestPlugins: function(pluginsPath) { // request plugins
if (!pluginsPath) 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 _getPluginJson = function(plugin) {
if (!plugin) return '';
try {
var xhrObj = _createXMLHTTPObject();
if (xhrObj && plugin) {
xhrObj.open('GET', plugin, false);
xhrObj.send('');
var pluginJson = eval("(" + xhrObj.responseText + ")");
return pluginJson;
}
}
catch (e) {}
return null;
};
var value = _getPluginJson(pluginsPath);
if (value)
this.updatePlugins(value, false);
this.updatePlugins( Common.Utils.getConfigJson(pluginsPath), false );
},
updatePlugins: function(plugins, uiCustomize) { // plugins from config
......@@ -1888,49 +1854,15 @@ define([
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
if (!pluginsData || pluginsData.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 _getPluginJson = function(plugin) {
if (!plugin) return '';
try {
var xhrObj = _createXMLHTTPObject();
if (xhrObj && plugin) {
xhrObj.open('GET', plugin, false);
xhrObj.send('');
var pluginJson = eval("(" + xhrObj.responseText + ")");
return pluginJson;
}
}
catch (e) {}
return null;
};
var arr = [],
baseUrl = _.isEmpty(plugins.url) ? "" : plugins.url;
if (baseUrl !== "")
console.log("Obsolete: The url parameter is deprecated. Please check the documentation for new plugin connection configuration.");
console.warn("Obsolete: The url parameter is deprecated. Please check the documentation for new plugin connection configuration.");
pluginsData.forEach(function(item){
item = baseUrl + item; // for compatibility with previouse version of server, where plugins.url is used.
var value = _getPluginJson(item);
var value = Common.Utils.getConfigJson(item);
if (value) {
value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
value.oldVersion = (baseUrl !== "");
......@@ -1938,11 +1870,17 @@ define([
}
});
if (arr.length>0)
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.");
this.updatePluginsList({
autoStartGuid: plugins.autoStartGuid,
autostart: autostart,
pluginsData: arr
}, !!uiCustomize);
}
},
updatePluginsList: function(plugins, uiCustomize) {
......@@ -1951,18 +1889,9 @@ define([
if (plugins) {
var arr = [], arrUI = [];
plugins.pluginsData.forEach(function(item){
if (uiCustomize!==undefined && (pluginStore.findWhere({baseUrl : item.baseUrl}) || pluginStore.findWhere({guid : item.guid}))) return;
var variations = item.variations,
variationsArr = [];
variations.forEach(function(itemVar){
var isSupported = false;
for (var i=0; i<itemVar.EditorsSupport.length; i++){
if (itemVar.EditorsSupport[i]=='cell') {
isSupported = true; break;
}
}
if (isSupported && (isEdit || itemVar.isViewer)) {
var variationsArr = [];
item.variations.forEach(function(itemVar){
if (_.contains(itemVar.EditorsSupport, 'word') && (isEdit || itemVar.isViewer)) {
var icons = itemVar.icons;
if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used.
icons = [];
......@@ -2004,20 +1933,17 @@ define([
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
this.UICustomizePlugins = arrUI;
if (uiCustomize === undefined) { // for desktop
if ( !uiCustomize ) {
if (pluginStore) pluginStore.reset(arr);
this.appOptions.canPlugins = (pluginStore.length>0);
} else if (!uiCustomize) {
if (pluginStore) pluginStore.add(arr);
this.appOptions.canPlugins = (pluginStore.length>0);
this.appOptions.canPlugins = !pluginStore.isEmpty();
}
} else if (!uiCustomize){
this.appOptions.canPlugins = false;
}
if (this.appOptions.canPlugins) {
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);
if (plugins.autoStartGuid)
this.api.asc_pluginRun(plugins.autoStartGuid, 0, '');
if (plugins.autostart && plugins.autostart.length>0)
this.api.asc_pluginRun(plugins.autostart[0], 0, '');
}
if (!uiCustomize) this.getApplication().getController('LeftMenu').enablePlugins();
},
......
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