From 54ce37067cacf355b001777d44f879a88c7150de Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 16 Jul 2016 14:32:51 +0200 Subject: [PATCH] Only show media clipboard if media manager is open Clipboard now allows stacking multiple page class names if `Clipboard.setup()` is called multiple times. --- .../js/WoltLab/WCF/Controller/Clipboard.js | 68 +++++++++++++++---- .../js/WoltLab/WCF/Media/Manager/Base.js | 18 +++++ .../install/files/js/WoltLab/WCF/Ui/Dialog.js | 4 +- .../item/ClipboardItemAction.class.php | 5 +- .../clipboard/ClipboardHandler.class.php | 20 +++--- 5 files changed, 91 insertions(+), 24 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Controller/Clipboard.js b/wcfsetup/install/files/js/WoltLab/WCF/Controller/Clipboard.js index c0e8cbde9d..3713d23c6a 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Controller/Clipboard.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Controller/Clipboard.js @@ -34,6 +34,8 @@ define( var _callbackItem = null; var _callbackUnmarkAll = null; + var _addPageOverlayActiveClass = false; + /** * Clipboard API * @@ -46,19 +48,31 @@ define( * @param {object} options initialization options */ setup: function(options) { - _callbackCheckbox = this._mark.bind(this); - _callbackItem = this._executeAction.bind(this); - _callbackUnmarkAll = this._unmarkAll.bind(this); - _options = Core.extend({ - hasMarkedItems: false, - pageClassName: '', - pageObjectId: 0 - }, options); - - if (!_options.pageClassName) { + if (!options.pageClassName) { throw new Error("Expected a non-empty string for parameter 'pageClassName'."); } + if (_callbackCheckbox === null) { + _callbackCheckbox = this._mark.bind(this); + _callbackItem = this._executeAction.bind(this); + _callbackUnmarkAll = this._unmarkAll.bind(this); + + _options = Core.extend({ + hasMarkedItems: false, + pageClassNames: [options.pageClassName], + pageObjectId: 0 + }, options); + + delete _options.pageClassName; + } + else { + if (options.pageObjectId) { + throw new Error("Cannot load secondary clipboard with page object id set."); + } + + _options.pageClassNames.push(options.pageClassName); + } + this._initContainers(); if (_options.hasMarkedItems && _elements.length) { @@ -122,7 +136,7 @@ define( Ajax.api(this, { actionName: 'getMarkedItems', parameters: { - pageClassName: _options.pageClassName, + pageClassNames: _options.pageClassNames, pageObjectID: _options.pageObjectId } }); @@ -216,7 +230,7 @@ define( Ajax.api(this, { actionName: (isMarked ? 'mark' : 'unmark'), parameters: { - pageClassName: _options.pageClassName, + pageClassNames: _options.pageClassNames, pageObjectID: _options.pageObjectId, objectIDs: objectIds, objectType: type @@ -550,6 +564,36 @@ define( parent.classList[(markAll ? 'add' : 'remove')]('jsMarked'); } } + }, + + /** + * Hides the clipboard editor for the given object type. + * + * @param {string} objectType + */ + hideEditor: function(objectType) { + UiPageAction.remove('wcfClipboard-' + objectType); + + if (_addPageOverlayActiveClass) { + _addPageOverlayActiveClass = false; + + document.documentElement.classList.add('pageOverlayActive'); + } + }, + + /** + * Shows the clipboard editor for the given object type. + * + * @param {string} objectType + */ + showEditor: function(objectType) { + this._loadMarkedItems(); + + if (document.documentElement.classList.contains('pageOverlayActive')) { + document.documentElement.classList.remove('pageOverlayActive'); + + _addPageOverlayActiveClass = true; + } } }; }); diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Media/Manager/Base.js b/wcfsetup/install/files/js/WoltLab/WCF/Media/Manager/Base.js index 77a3dc1873..d9d013dcb5 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Media/Manager/Base.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Media/Manager/Base.js @@ -92,6 +92,14 @@ define( } }, + /** + * Is called if the media manager dialog is closed. + */ + _dialogClose: function() { + // only show media clipboard if editor is open + Clipboard.hideEditor('com.woltlab.wcf.media'); + }, + /** * Returns all data to setup the media manager dialog. * @@ -101,6 +109,8 @@ define( return { id: 'mediaManager', options: { + onClose: this._dialogClose.bind(this), + onShow: this._dialogShow.bind(this), title: this._options.dialogTitle }, source: { @@ -117,6 +127,14 @@ define( }; }, + /** + * Is called if the media manager dialog is shown. + */ + _dialogShow: function() { + // only show media clipboard if editor is open + Clipboard.showEditor('com.woltlab.wcf.media'); + }, + /** * Opens the media editor for a media file. * diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Dialog.js b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Dialog.js index f209cd3f80..e2e077592d 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Dialog.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Dialog.js @@ -189,6 +189,8 @@ define( * @return {object} dialog data */ openStatic: function(id, html, options, createOnly) { + document.documentElement.classList.add('pageOverlayActive'); + if (_dialogs.has(id)) { this._updateDialog(id, html); } @@ -220,8 +222,6 @@ define( this._createDialog(id, html, options); } - document.documentElement.classList.add('pageOverlayActive'); - return _dialogs.get(id); }, diff --git a/wcfsetup/install/files/lib/data/clipboard/item/ClipboardItemAction.class.php b/wcfsetup/install/files/lib/data/clipboard/item/ClipboardItemAction.class.php index 42c5e32209..565bcd83da 100644 --- a/wcfsetup/install/files/lib/data/clipboard/item/ClipboardItemAction.class.php +++ b/wcfsetup/install/files/lib/data/clipboard/item/ClipboardItemAction.class.php @@ -116,7 +116,8 @@ class ClipboardItemAction extends AbstractDatabaseObjectAction { * Validates generic parameters used for most clipboard actions. */ protected function validateDefaultParameters() { - $this->readString('pageClassName'); + $this->readStringArray('pageClassNames'); + $this->readInteger('pageObjectID', true); } @@ -140,7 +141,7 @@ class ClipboardItemAction extends AbstractDatabaseObjectAction { * @return mixed[] */ protected function getEditorItems() { - $data = ClipboardHandler::getInstance()->getEditorItems($this->parameters['pageClassName'], $this->parameters['pageObjectID']); + $data = ClipboardHandler::getInstance()->getEditorItems($this->parameters['pageClassNames'], $this->parameters['pageObjectID']); if ($data === null) { return []; diff --git a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php index 4d2f88a673..dea634ab49 100644 --- a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php @@ -292,16 +292,18 @@ class ClipboardHandler extends SingletonFactory { /** * Returns items for clipboard editor. * - * @param string $page - * @param integer $pageObjectID + * @param string|string[] $page + * @param integer $pageObjectID * @return mixed[][] * @throws SystemException */ public function getEditorItems($page, $pageObjectID) { - $this->pageObjectID = 0; + $pages = $page; + if (!is_array($pages)) { + $pages = [$page]; + } - // ignore unknown pages - if (!isset($this->pageCache[$page])) return null; + $this->pageObjectID = 0; // get objects $this->loadMarkedItems(); @@ -312,9 +314,11 @@ class ClipboardHandler extends SingletonFactory { // fetch action ids $this->loadActionCache(); $actionIDs = []; - foreach ($this->pageCache[$page] as $actionID) { - if (isset($this->actionCache[$actionID])) { - $actionIDs[] = $actionID; + foreach ($pages as $page) { + foreach ($this->pageCache[$page] as $actionID) { + if (isset($this->actionCache[$actionID])) { + $actionIDs[] = $actionID; + } } } $actionIDs = array_unique($actionIDs); -- 2.20.1