diff --git a/apps/common/main/lib/util/utils.js b/apps/common/main/lib/util/utils.js index 50b1d6049..f87d958ac 100644 --- a/apps/common/main/lib/util/utils.js +++ b/apps/common/main/lib/util/utils.js @@ -781,6 +781,45 @@ Common.Utils.InternalSettings = new(function() { } }); +Common.Utils.lockControls = function(causes, lock, opts, defControls) { + !opts && (opts = {}); + + var controls = opts.array || defControls; + opts.merge && (controls = _.union(defControls,controls)); + + function doLock(cmp, cause) { + if ( cmp && _.contains(cmp.options.lock, cause) ) { + var index = cmp.keepState.indexOf(cause); + if (lock) { + if (index < 0) { + cmp.keepState.push(cause); + } + } else { + if (!(index < 0)) { + cmp.keepState.splice(index, 1); + } + } + } + } + + _.each(controls, function(item) { + if (item && _.isFunction(item.setDisabled)) { + !item.keepState && (item.keepState = []); + if (opts.clear && opts.clear.length > 0 && item.keepState.length > 0) { + item.keepState = _.difference(item.keepState, opts.clear); + } + + _.isArray(causes) ? _.each(causes, function(c) {doLock(item, c)}) : doLock(item, causes); + + if (!(item.keepState.length > 0)) { + item.isDisabled() && item.setDisabled(false); + } else { + !item.isDisabled() && item.setDisabled(true); + } + } + }); +}; + Common.Utils.InternalSettings.set('toolbar-height-tabs', 32); Common.Utils.InternalSettings.set('toolbar-height-tabs-top-title', 28); Common.Utils.InternalSettings.set('toolbar-height-controls', 67); diff --git a/apps/documenteditor/main/app/view/MailMergeSettings.js b/apps/documenteditor/main/app/view/MailMergeSettings.js index 2713692bc..85fc0adc7 100644 --- a/apps/documenteditor/main/app/view/MailMergeSettings.js +++ b/apps/documenteditor/main/app/view/MailMergeSettings.js @@ -783,7 +783,7 @@ define([ disableControls: function(disable) { if (this._initSettings) return; - + this.lockControls(DE.enumLockMM.lostConnect, disable, { array: _.union([this.btnEditData, this.btnInsField, this.chHighlight], (this.mode.mergeFolderUrl) ? [this.btnPortal] : []), merge: true @@ -833,42 +833,7 @@ define([ }, lockControls: function(causes, lock, opts) { - !opts && (opts = {}); - - var controls = opts.array || this.emptyDBControls; - opts.merge && (controls = _.union(this.emptyDBControls,controls)); - - function doLock(cmp, cause) { - if ( _.contains(cmp.options.lock, cause) ) { - var index = cmp.keepState.indexOf(cause); - if (lock) { - if (index < 0) { - cmp.keepState.push(cause); - } - } else { - if (!(index < 0)) { - cmp.keepState.splice(index, 1); - } - } - } - } - - _.each(controls, function(item) { - if (_.isFunction(item.setDisabled)) { - !item.keepState && (item.keepState = []); - if (opts.clear && opts.clear.length > 0 && item.keepState.length > 0) { - item.keepState = _.difference(item.keepState, opts.clear); - } - - _.isArray(causes) ? _.each(causes, function(c) {doLock(item, c)}) : doLock(item, causes); - - if (!(item.keepState.length > 0)) { - item.isDisabled() && item.setDisabled(false); - } else { - !item.isDisabled() && item.setDisabled(true); - } - } - }); + Common.Utils.lockControls(causes, lock, opts, this.emptyDBControls); }, textDataSource: 'Data Source', diff --git a/apps/presentationeditor/main/app/view/Toolbar.js b/apps/presentationeditor/main/app/view/Toolbar.js index 39becbb96..2fc3f765d 100644 --- a/apps/presentationeditor/main/app/view/Toolbar.js +++ b/apps/presentationeditor/main/app/view/Toolbar.js @@ -826,44 +826,7 @@ define([ }, lockToolbar: function (causes, lock, opts) { - !opts && (opts = {}); - - var controls = opts.array || this.lockControls; - opts.merge && (controls = _.union(this.lockControls, controls)); - - function doLock(cmp, cause) { - if (_.contains(cmp.options.lock, cause)) { - var index = cmp.keepState.indexOf(cause); - if (lock) { - if (index < 0) { - cmp.keepState.push(cause); - } - } else { - if (!(index < 0)) { - cmp.keepState.splice(index, 1); - } - } - } - } - - _.each(controls, function (item) { - if (_.isFunction(item.setDisabled)) { - !item.keepState && (item.keepState = []); - if (opts.clear && opts.clear.length > 0 && item.keepState.length > 0) { - item.keepState = _.difference(item.keepState, opts.clear); - } - - _.isArray(causes) ? _.each(causes, function (c) { - doLock(item, c) - }) : doLock(item, causes); - - if (!(item.keepState.length > 0)) { - item.isDisabled() && item.setDisabled(false); - } else { - !item.isDisabled() && item.setDisabled(true); - } - } - }); + Common.Utils.lockControls(causes, lock, opts, this.lockControls); }, render: function (mode) { diff --git a/apps/spreadsheeteditor/main/app/view/Toolbar.js b/apps/spreadsheeteditor/main/app/view/Toolbar.js index 7412b1e65..a167b3b26 100644 --- a/apps/spreadsheeteditor/main/app/view/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/view/Toolbar.js @@ -150,42 +150,7 @@ define([ }, lockToolbar: function(causes, lock, opts) { - !opts && (opts = {}); - - var controls = opts.array || this.lockControls; - opts.merge && (controls = _.union(this.lockControls,controls)); - - function doLock(cmp, cause) { - if ( cmp && _.contains(cmp.options.lock, cause) ) { - var index = cmp.keepState.indexOf(cause); - if (lock) { - if (index < 0) { - cmp.keepState.push(cause); - } - } else { - if (!(index < 0)) { - cmp.keepState.splice(index, 1); - } - } - } - } - - _.each(controls, function(item) { - if (item && _.isFunction(item.setDisabled)) { - !item.keepState && (item.keepState = []); - if (opts.clear && opts.clear.length > 0 && item.keepState.length > 0) { - item.keepState = _.difference(item.keepState, opts.clear); - } - - _.isArray(causes) ? _.each(causes, function(c) {doLock(item, c)}) : doLock(item, causes); - - if (!(item.keepState.length > 0)) { - item.isDisabled() && item.setDisabled(false); - } else { - !item.isDisabled() && item.setDisabled(true); - } - } - }); + Common.Utils.lockControls(causes, lock, opts, this.lockControls); }, applyLayout: function (config) {