Customization plugins refactoring

This commit is contained in:
Julia Radzhabova 2019-05-23 17:25:44 +03:00
parent bf8dafb914
commit 2e16e770e8
4 changed files with 44 additions and 56 deletions

View file

@ -467,13 +467,20 @@ define([
}, },
applyUICustomization: function () { applyUICustomization: function () {
if ( this.customPluginsComplete && this.configPlugins.UIplugins ) { var me = this;
this.configPlugins.UIplugins.forEach(function (c) { return new Promise(function(resolve, reject) {
var timer_sl = setInterval(function() {
if ( me.customPluginsComplete ) {
clearInterval(timer_sl);
try {
me.configPlugins.UIplugins && me.configPlugins.UIplugins.forEach(function (c) {
if ( c.code ) eval(c.code); if ( c.code ) eval(c.code);
}); });
return true; } catch (e) {}
resolve();
} }
return false; }, 10);
});
}, },
parsePlugins: function(pluginsdata, uiCustomize) { parsePlugins: function(pluginsdata, uiCustomize) {
@ -646,8 +653,9 @@ define([
}, },
getAppCustomPlugins: function (plugins) { getAppCustomPlugins: function (plugins) {
var me = this,
funcComplete = function() {me.customPluginsComplete = true;};
if ( plugins.config ) { if ( plugins.config ) {
var me = this;
this.getPlugins(plugins.config.UIpluginsData) this.getPlugins(plugins.config.UIpluginsData)
.then(function(loaded) .then(function(loaded)
{ {
@ -662,20 +670,10 @@ define([
item.code = text; item.code = text;
return text; return text;
}); });
}).then(function () }).then(funcComplete, funcComplete);
{ }, funcComplete);
me.customPluginsComplete = true;
}).catch(function(err)
{
me.customPluginsComplete = true;
});
}).catch(function(err)
{
me.customPluginsComplete = true;
});
} else } else
this.customPluginsComplete = true; funcComplete();
} }
}, Common.Controllers.Plugins || {})); }, Common.Controllers.Plugins || {}));
}); });

View file

@ -1678,7 +1678,7 @@ define([
}, },
hidePreloader: function() { hidePreloader: function() {
var UICustomizationComplete = true; var promise;
if (!this._state.customizationDone) { if (!this._state.customizationDone) {
this._state.customizationDone = true; this._state.customizationDone = true;
if (this.appOptions.customization) { if (this.appOptions.customization) {
@ -1690,21 +1690,17 @@ 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);
UICustomizationComplete = this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization(); promise = this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization();
} }
} }
Common.NotificationCenter.trigger('layout:changed', 'main'); Common.NotificationCenter.trigger('layout:changed', 'main');
var me = this; (promise || (new Promise(function(resolve, reject) {
var timer_sl = setInterval(function() { resolve();
(!UICustomizationComplete) && (UICustomizationComplete = me.getApplication().getController('Common.Controllers.Plugins').applyUICustomization()); }))).then(function() {
if (UICustomizationComplete) {
clearInterval(timer_sl);
$('#loading-mask').hide().remove(); $('#loading-mask').hide().remove();
Common.Controllers.Desktop.process('preloader:hide'); Common.Controllers.Desktop.process('preloader:hide');
} });
}, 10);
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url) {

View file

@ -1388,7 +1388,7 @@ define([
}, },
hidePreloader: function() { hidePreloader: function() {
var UICustomizationComplete = true; var promise;
if (!this._state.customizationDone) { if (!this._state.customizationDone) {
this._state.customizationDone = true; this._state.customizationDone = true;
if (this.appOptions.customization) { if (this.appOptions.customization) {
@ -1400,21 +1400,17 @@ 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);
UICustomizationComplete = this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization(); promise = this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization();
} }
} }
Common.NotificationCenter.trigger('layout:changed', 'main'); Common.NotificationCenter.trigger('layout:changed', 'main');
var me = this; (promise || (new Promise(function(resolve, reject) {
var timer_sl = setInterval(function() { resolve();
(!UICustomizationComplete) && (UICustomizationComplete = me.getApplication().getController('Common.Controllers.Plugins').applyUICustomization()); }))).then(function() {
if (UICustomizationComplete) {
clearInterval(timer_sl);
$('#loading-mask').hide().remove(); $('#loading-mask').hide().remove();
Common.Controllers.Desktop.process('preloader:hide'); Common.Controllers.Desktop.process('preloader:hide');
} });
}, 10);
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url) {

View file

@ -1524,7 +1524,7 @@ define([
}, },
hidePreloader: function() { hidePreloader: function() {
var UICustomizationComplete = true; var promise;
if (!this._state.customizationDone) { if (!this._state.customizationDone) {
this._state.customizationDone = true; this._state.customizationDone = true;
if (this.appOptions.customization) { if (this.appOptions.customization) {
@ -1536,21 +1536,19 @@ 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);
UICustomizationComplete = this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization(); promise = this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization();
} }
} }
this.stackLongActions.pop({id: InitApplication, type: Asc.c_oAscAsyncActionType.BlockInteraction}); this.stackLongActions.pop({id: InitApplication, type: Asc.c_oAscAsyncActionType.BlockInteraction});
Common.NotificationCenter.trigger('layout:changed', 'main'); Common.NotificationCenter.trigger('layout:changed', 'main');
var me = this;
var timer_sl = setInterval(function() { (promise || (new Promise(function(resolve, reject) {
(!UICustomizationComplete) && (UICustomizationComplete = me.getApplication().getController('Common.Controllers.Plugins').applyUICustomization()); resolve();
if (UICustomizationComplete) { }))).then(function() {
clearInterval(timer_sl);
$('#loading-mask').hide().remove(); $('#loading-mask').hide().remove();
Common.Controllers.Desktop.process('preloader:hide'); Common.Controllers.Desktop.process('preloader:hide');
} });
}, 10);
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url) {