From 1ac4d0502247c42fccc971abe480681c8cc31392 Mon Sep 17 00:00:00 2001 From: sunpietro Date: Thu, 23 Feb 2017 11:34:51 +0100 Subject: [PATCH] EZS-1393: Fixed select location js error making it impossible to change the location (#25) --- ...-createcontent-universaldiscoveryplugin.js | 28 +++++++++++++++++++ ...content-universaldiscoveryserviceplugin.js | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/bundle/Resources/public/js/views/plugins/cof-createcontent-universaldiscoveryplugin.js b/bundle/Resources/public/js/views/plugins/cof-createcontent-universaldiscoveryplugin.js index 41f5b9d..d59fa4b 100644 --- a/bundle/Resources/public/js/views/plugins/cof-createcontent-universaldiscoveryplugin.js +++ b/bundle/Resources/public/js/views/plugins/cof-createcontent-universaldiscoveryplugin.js @@ -31,6 +31,8 @@ YUI.add('cof-createcontent-universaldiscoveryplugin', function (Y) { host.get('methods').push(this.get('tabCreateView')); + host.before('activeChange', this._checkBrowseMethodPresence, host); + host.on('*:saveDiscoveryState', this._saveDiscoveryWidgetState, this); host.on('*:restoreDiscoveryWidget', this._restoreDiscoveryWidgetState, this); host.on('*:contentLoaded', this._closeDiscoveryWidget, this); @@ -49,6 +51,32 @@ YUI.add('cof-createcontent-universaldiscoveryplugin', function (Y) { event.target.set('savedDiscoveryState', this.get('host').getAttrs()); }, + /** + * Checks if `browse` method is present in the methods definitions. + * If not, then sets the visible method to `finder` + * + * @method _checkBrowseMethodPresence + * @protected + * @param event {Object} event facade + */ + _checkBrowseMethodPresence: function (event) { + var browseMethod, + methodToSet; + + if (!event.newVal || !this.get('forceVisibleMethod')) { + return; + } + + browseMethod = this.get('methods').filter(function (method) { + return method.get('identifier') === 'browse'; + })[0]; + + methodToSet = browseMethod ? 'browse' : 'finder'; + + this.set('visibleMethod', methodToSet); + this.set('forceVisibleMethod', false); + }, + /** * Restores state of Discovery Widget. * diff --git a/bundle/Resources/public/js/views/plugins/cof-createcontent-universaldiscoveryserviceplugin.js b/bundle/Resources/public/js/views/plugins/cof-createcontent-universaldiscoveryserviceplugin.js index 7a3d2a3..410718a 100644 --- a/bundle/Resources/public/js/views/plugins/cof-createcontent-universaldiscoveryserviceplugin.js +++ b/bundle/Resources/public/js/views/plugins/cof-createcontent-universaldiscoveryserviceplugin.js @@ -64,7 +64,7 @@ YUI.add('cof-createcontent-universaldiscoveryserviceplugin', function (Y) { multiple: false, contentDiscoveredHandler: Y.bind(this._setSelectedLocation, this, target), isSelectable: function () {return true;}, - visibleMethod: 'browse', + forceVisibleMethod: true, hideTabCreate: true }, });