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;
}
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) {
(new Promise(function (resolve, reject) {
resolve();

View file

@ -1854,23 +1854,7 @@ define([
requestPlugins: function(pluginsPath) { // request plugins
if (!pluginsPath) 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 value = _getPluginJson(pluginsPath);
if (value)
this.updatePlugins(value, false);
this.updatePlugins( Common.Utils.getConfigJson(pluginsPath), false );
},
updatePlugins: function(plugins, uiCustomize) { // plugins from config
@ -1879,29 +1863,15 @@ define([
var pluginsData = (uiCustomize) ? plugins.UIpluginsData : plugins.pluginsData;
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 = [],
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);
item = baseUrl + item; // for compatibility with previous version of server, where plugins.url is used.
var value = Common.Utils.getConfigJson(item);
if (value) {
value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
value.oldVersion = (baseUrl !== "");
@ -1922,18 +1892,11 @@ 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 ( (isEdit || itemVar.isViewer) &&
_.contains(itemVar.EditorsSupport, 'word') )
{
var icons = itemVar.icons;
if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used.
icons = [];
@ -1941,27 +1904,23 @@ define([
icons.push(icon.substring(icon.lastIndexOf("\/")+1));
});
}
item.isUICustomizer ? arrUI.push(item.baseUrl + itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description,
index: variationsArr.length,
url : (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/")+1) ) : itemVar.url,
icons : icons,
isViewer: itemVar.isViewer,
EditorsSupport: itemVar.EditorsSupport,
isVisual: itemVar.isVisual,
isCustomWindow: itemVar.isCustomWindow,
isModal: itemVar.isModal,
isInsideMode: itemVar.isInsideMode,
initDataType: itemVar.initDataType,
initData: itemVar.initData,
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged
}));
if (item.isUICustomizer ) {
arrUI.push(item.baseUrl + itemVar.url)
} else {
var model = new Common.Models.PluginVariation(itemVar);
model.set({
index: variationsArr.length,
url: (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/") + 1) ) : itemVar.url,
icons: icons
});
variationsArr.push(model);
}
}
});
if (variationsArr.length>0 && !item.isUICustomizer)
arr.push(new Common.Models.Plugin({
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;
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.length > 0);
}
} else if (!uiCustomize){
this.appOptions.canPlugins = false;

View file

@ -242,7 +242,7 @@ define([
this.panelHistory = panel.render('#left-panel-history');
} else
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
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 );
},
@ -1671,49 +1635,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 !== "");
@ -1739,13 +1669,9 @@ define([
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 isSupported = itemVar.EditorsSupport.includes('slide');
if ( isSupported && (isEdit || itemVar.isViewer) ){
var icons = itemVar.icons;
if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used.
icons = [];
@ -1753,25 +1679,20 @@ define([
icons.push(icon.substring(icon.lastIndexOf("\/")+1));
});
}
item.isUICustomizer ? arrUI.push(item.baseUrl + itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description,
index: variationsArr.length,
url : (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/")+1) ) : itemVar.url,
icons : icons,
isViewer: itemVar.isViewer,
EditorsSupport: itemVar.EditorsSupport,
isVisual: itemVar.isVisual,
isCustomWindow: itemVar.isCustomWindow,
isModal: itemVar.isModal,
isInsideMode: itemVar.isInsideMode,
initDataType: itemVar.initDataType,
initData: itemVar.initData,
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged
}));
if ( item.isUICustomizer ) {
arrUI.push(item.baseUrl + itemVar.url);
} else {
var model = new Common.Models.PluginVariation(itemVar);
model.set({
index: variationsArr.length,
url: (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/") + 1) ) : itemVar.url,
icons: icons
});
variationsArr.push(model);
}
}
});
if (variationsArr.length>0 && !item.isUICustomizer)

View file

@ -1811,43 +1811,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
@ -1856,49 +1820,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 !== "");
@ -1924,13 +1854,9 @@ define([
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)) {
if ((isEdit || itemVar.isViewer) &&
itemVar.EditorsSupport.includes('cell') )
{
var icons = itemVar.icons;
if (item.oldVersion) { // for compatibility with previouse version of server, where plugins.url is used.
icons = [];
@ -1938,25 +1864,20 @@ define([
icons.push(icon.substring(icon.lastIndexOf("\/")+1));
});
}
item.isUICustomizer ? arrUI.push(item.baseUrl + itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description,
index: variationsArr.length,
url : (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/")+1) ) : itemVar.url,
icons : icons,
isViewer: itemVar.isViewer,
EditorsSupport: itemVar.EditorsSupport,
isVisual: itemVar.isVisual,
isCustomWindow: itemVar.isCustomWindow,
isModal: itemVar.isModal,
isInsideMode: itemVar.isInsideMode,
initDataType: itemVar.initDataType,
initData: itemVar.initData,
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged
}));
if ( item.isUICustomizer ) {
arrUI.push(item.baseUrl + itemVar.url);
} else {
var model = new Common.Models.PluginVariation(itemVar);
model.set({
index: variationsArr.length,
url: (item.oldVersion) ? (itemVar.url.substring(itemVar.url.lastIndexOf("\/") + 1)) : itemVar.url,
icons: icons
});
variationsArr.push(model);
}
}
});
if (variationsArr.length>0 && !item.isUICustomizer)