refactoring

This commit is contained in:
Maxim Kadushkin 2017-09-04 17:20:46 +03:00
parent 1ea8cea665
commit cd5721977d
5 changed files with 84 additions and 270 deletions

View file

@ -702,6 +702,22 @@ Common.Utils.createXhr = function () {
return xmlhttp; 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;
}
Common.Utils.asyncCall = function (callback, scope, args) { Common.Utils.asyncCall = function (callback, scope, args) {
(new Promise(function (resolve, reject) { (new Promise(function (resolve, reject) {
resolve(); resolve();

View file

@ -1854,23 +1854,7 @@ define([
requestPlugins: function(pluginsPath) { // request plugins requestPlugins: function(pluginsPath) { // request plugins
if (!pluginsPath) return; if (!pluginsPath) return;
var _getPluginJson = function(plugin) { this.updatePlugins( Common.Utils.getConfigJson(pluginsPath), false );
if ( plugin ) {
try {
var xhrObj = Common.Utils.createXhr();
if (xhrObj && plugin) {
xhrObj.open('GET', plugin, false);
xhrObj.send('');
return JSON.parse(xhrObj.responseText);
}
} catch (e) {}
}
return null;
};
var value = _getPluginJson(pluginsPath);
if (value)
this.updatePlugins(value, false);
}, },
updatePlugins: function(plugins, uiCustomize) { // plugins from config updatePlugins: function(plugins, uiCustomize) { // plugins from config
@ -1879,29 +1863,15 @@ define([
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData; var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
if (!pluginsData || pluginsData.length<1) return; if (!pluginsData || pluginsData.length<1) return;
var _getPluginJson = function(plugin) {
if ( plugin ) {
try {
var xhrObj = Common.Utils.createXhr();
if (xhrObj && plugin) {
xhrObj.open('GET', plugin, false);
xhrObj.send('');
return JSON.parse(xhrObj.responseText);
}
} catch (e) {}
}
return null;
};
var arr = [], var arr = [],
baseUrl = _.isEmpty(plugins.url) ? "" : plugins.url; baseUrl = _.isEmpty(plugins.url) ? "" : plugins.url;
if (baseUrl !== "") 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){ pluginsData.forEach(function(item){
item = baseUrl + item; // for compatibility with previouse version of server, where plugins.url is used. item = baseUrl + item; // for compatibility with previous version of server, where plugins.url is used.
var value = _getPluginJson(item); var value = Common.Utils.getConfigJson(item);
if (value) { if (value) {
value.baseUrl = item.substring(0, item.lastIndexOf("config.json")); value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
value.oldVersion = (baseUrl !== ""); value.oldVersion = (baseUrl !== "");
@ -1922,18 +1892,11 @@ define([
if (plugins) { if (plugins) {
var arr = [], arrUI = []; var arr = [], arrUI = [];
plugins.pluginsData.forEach(function(item){ plugins.pluginsData.forEach(function(item){
if (uiCustomize!==undefined && (pluginStore.findWhere({baseUrl : item.baseUrl}) || pluginStore.findWhere({guid : item.guid}))) return; var variationsArr = [];
item.variations.forEach(function(itemVar){
var variations = item.variations, if ( (isEdit || itemVar.isViewer) &&
variationsArr = []; _.contains(itemVar.EditorsSupport, 'word') )
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 icons = itemVar.icons; var icons = itemVar.icons;
if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used. if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used.
icons = []; icons = [];
@ -1941,27 +1904,23 @@ define([
icons.push(icon.substring(icon.lastIndexOf("\/")+1)); icons.push(icon.substring(icon.lastIndexOf("\/")+1));
}); });
} }
item.isUICustomizer ? arrUI.push(item.baseUrl + itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({ if (item.isUICustomizer ) {
description: itemVar.description, arrUI.push(item.baseUrl + itemVar.url)
index: variationsArr.length, } else {
url : (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/")+1) ) : itemVar.url, var model = new Common.Models.PluginVariation(itemVar);
icons : icons,
isViewer: itemVar.isViewer, model.set({
EditorsSupport: itemVar.EditorsSupport, index: variationsArr.length,
isVisual: itemVar.isVisual, url: (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/") + 1) ) : itemVar.url,
isCustomWindow: itemVar.isCustomWindow, icons: icons
isModal: itemVar.isModal, });
isInsideMode: itemVar.isInsideMode,
initDataType: itemVar.initDataType, variationsArr.push(model);
initData: itemVar.initData, }
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged
}));
} }
}); });
if (variationsArr.length>0 && !item.isUICustomizer) if (variationsArr.length>0 && !item.isUICustomizer)
arr.push(new Common.Models.Plugin({ arr.push(new Common.Models.Plugin({
name : item.name, name : item.name,
@ -1972,15 +1931,12 @@ define([
})); }));
}); });
if (uiCustomize!==false) // from ui customizer in editor config or desktop event if ( uiCustomize!==false ) // from ui customizer in editor config or desktop event
this.UICustomizePlugins = arrUI; this.UICustomizePlugins = arrUI;
if (uiCustomize === undefined) { // for desktop if ( !uiCustomize ) {
if (pluginStore) pluginStore.reset(arr); if (pluginStore) pluginStore.reset(arr);
this.appOptions.canPlugins = (pluginStore.length>0); this.appOptions.canPlugins = (pluginStore.length > 0);
} else if (!uiCustomize) {
if (pluginStore) pluginStore.add(arr);
this.appOptions.canPlugins = (pluginStore.length>0);
} }
} else if (!uiCustomize){ } else if (!uiCustomize){
this.appOptions.canPlugins = false; this.appOptions.canPlugins = false;

View file

@ -242,7 +242,7 @@ define([
this.panelHistory = panel.render('#left-panel-history'); this.panelHistory = panel.render('#left-panel-history');
} else } else
if (name == 'plugins' && !this.panelPlugins) { if (name == 'plugins' && !this.panelPlugins) {
this.panelPlugins = panel.render('#left-panel-plugins'); this.panelPlugins = panel.render(/*'#left-panel-plugins'*/);
} }
}, },

View file

@ -1625,43 +1625,7 @@ define([
requestPlugins: function(pluginsPath) { // request plugins requestPlugins: function(pluginsPath) { // request plugins
if (!pluginsPath) return; if (!pluginsPath) return;
var _createXMLHTTPObject = function() { this.updatePlugins( Common.Utils.getConfigJson(pluginsPath), false );
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);
}, },
@ -1671,49 +1635,15 @@ define([
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData; var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
if (!pluginsData || pluginsData.length<1) return; 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 = [], var arr = [],
baseUrl = _.isEmpty(plugins.url) ? "" : plugins.url; baseUrl = _.isEmpty(plugins.url) ? "" : plugins.url;
if (baseUrl !== "") 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){ pluginsData.forEach(function(item){
item = baseUrl + item; // for compatibility with previouse version of server, where plugins.url is used. 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) { if (value) {
value.baseUrl = item.substring(0, item.lastIndexOf("config.json")); value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
value.oldVersion = (baseUrl !== ""); value.oldVersion = (baseUrl !== "");
@ -1739,13 +1669,9 @@ define([
var variations = item.variations, var variations = item.variations,
variationsArr = []; variationsArr = [];
variations.forEach(function(itemVar){ variations.forEach(function(itemVar){
var isSupported = false; var isSupported = itemVar.EditorsSupport.includes('slide');
for (var i=0; i<itemVar.EditorsSupport.length; i++){
if (itemVar.EditorsSupport[i]=='slide') { if ( isSupported && (isEdit || itemVar.isViewer) ){
isSupported = true; break;
}
}
if (isSupported && (isEdit || itemVar.isViewer)){
var icons = itemVar.icons; var icons = itemVar.icons;
if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used. if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used.
icons = []; icons = [];
@ -1753,25 +1679,20 @@ define([
icons.push(icon.substring(icon.lastIndexOf("\/")+1)); icons.push(icon.substring(icon.lastIndexOf("\/")+1));
}); });
} }
item.isUICustomizer ? arrUI.push(item.baseUrl + itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({ if ( item.isUICustomizer ) {
description: itemVar.description, arrUI.push(item.baseUrl + itemVar.url);
index: variationsArr.length, } else {
url : (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/")+1) ) : itemVar.url, var model = new Common.Models.PluginVariation(itemVar);
icons : icons,
isViewer: itemVar.isViewer, model.set({
EditorsSupport: itemVar.EditorsSupport, index: variationsArr.length,
isVisual: itemVar.isVisual, url: (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/") + 1) ) : itemVar.url,
isCustomWindow: itemVar.isCustomWindow, icons: icons
isModal: itemVar.isModal, });
isInsideMode: itemVar.isInsideMode,
initDataType: itemVar.initDataType, variationsArr.push(model);
initData: itemVar.initData, }
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged
}));
} }
}); });
if (variationsArr.length>0 && !item.isUICustomizer) if (variationsArr.length>0 && !item.isUICustomizer)

View file

@ -1811,43 +1811,7 @@ define([
requestPlugins: function(pluginsPath) { // request plugins requestPlugins: function(pluginsPath) { // request plugins
if (!pluginsPath) return; if (!pluginsPath) return;
var _createXMLHTTPObject = function() { this.updatePlugins( Common.Utils.getConfigJson(pluginsPath), false );
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);
}, },
updatePlugins: function(plugins, uiCustomize) { // plugins from config updatePlugins: function(plugins, uiCustomize) { // plugins from config
@ -1856,49 +1820,15 @@ define([
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData; var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
if (!pluginsData || pluginsData.length<1) return; 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 = [], var arr = [],
baseUrl = _.isEmpty(plugins.url) ? "" : plugins.url; baseUrl = _.isEmpty(plugins.url) ? "" : plugins.url;
if (baseUrl !== "") 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){ pluginsData.forEach(function(item){
item = baseUrl + item; // for compatibility with previouse version of server, where plugins.url is used. 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) { if (value) {
value.baseUrl = item.substring(0, item.lastIndexOf("config.json")); value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
value.oldVersion = (baseUrl !== ""); value.oldVersion = (baseUrl !== "");
@ -1924,13 +1854,9 @@ define([
var variations = item.variations, var variations = item.variations,
variationsArr = []; variationsArr = [];
variations.forEach(function(itemVar){ variations.forEach(function(itemVar){
var isSupported = false; if ((isEdit || itemVar.isViewer) &&
for (var i=0; i<itemVar.EditorsSupport.length; i++){ itemVar.EditorsSupport.includes('cell') )
if (itemVar.EditorsSupport[i]=='cell') { {
isSupported = true; break;
}
}
if (isSupported && (isEdit || itemVar.isViewer)) {
var icons = itemVar.icons; var icons = itemVar.icons;
if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used. if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used.
icons = []; icons = [];
@ -1938,25 +1864,20 @@ define([
icons.push(icon.substring(icon.lastIndexOf("\/")+1)); icons.push(icon.substring(icon.lastIndexOf("\/")+1));
}); });
} }
item.isUICustomizer ? arrUI.push(item.baseUrl + itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({ if ( item.isUICustomizer ) {
description: itemVar.description, arrUI.push(item.baseUrl + itemVar.url);
index: variationsArr.length, } else {
url : (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/")+1) ) : itemVar.url, var model = new Common.Models.PluginVariation(itemVar);
icons : icons,
isViewer: itemVar.isViewer, model.set({
EditorsSupport: itemVar.EditorsSupport, index: variationsArr.length,
isVisual: itemVar.isVisual, url: (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/") + 1)) : itemVar.url,
isCustomWindow: itemVar.isCustomWindow, icons: icons
isModal: itemVar.isModal, });
isInsideMode: itemVar.isInsideMode,
initDataType: itemVar.initDataType, variationsArr.push(model);
initData: itemVar.initData, }
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged
}));
} }
}); });
if (variationsArr.length>0 && !item.isUICustomizer) if (variationsArr.length>0 && !item.isUICustomizer)