From d893cd14653cc825691447bd473fc5ecc4a3b58c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 15 May 2012 20:57:10 +0200 Subject: [PATCH] Added support for container id within clipboard actions Closes #546 --- wcfsetup/install/files/js/WCF.js | 28 +++++++++---------- .../lib/action/ClipboardAction.class.php | 9 +++++- .../clipboard/ClipboardHandler.class.php | 10 +++++-- .../action/IClipboardAction.class.php | 3 +- .../action/UserClipboardAction.class.php | 2 +- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 397115b117..e307ccc4eb 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -657,6 +657,12 @@ WCF.Clipboard = { */ _container: null, + /** + * container meta data + * @var object + */ + _containerData: { }, + /** * user has marked items * @var boolean @@ -722,6 +728,7 @@ WCF.Clipboard = { new WCF.Action.Proxy({ autoSend: true, data: { + containerData: this._containerData, pageClassName: this._page }, success: $.proxy(this._loadMarkedItemsSuccess, this), @@ -796,23 +803,14 @@ WCF.Clipboard = { */ _initContainer: function(container) { var $container = $(container); + var $containerID = $container.wcfIdentify(); - // fetch id or assign a random one if none found - var $id = $container.attr('id'); - if (!$id) { - $id = WCF.getRandomID(); - $container.attr('id', $id); - } - - // bind mark all checkboxes - $container.find('.jsClipboardMarkAll').each($.proxy(function(index, item) { - $(item).data('hasContainer', $id).click($.proxy(this._markAll, this)); - }, this)); + $container.find('.jsClipboardMarkAll').data('hasContainer', $containerID).click($.proxy(this._markAll, this)); + $container.find('input.jsClipboardItem').data('hasContainer', $containerID).click($.proxy(this._click, this)); - // bind item checkboxes - $container.find('input.jsClipboardItem').each($.proxy(function(index, item) { - $(item).data('hasContainer', $id).click($.proxy(this._click, this)); - }, this)); + if ($container.data('typeContainerID')) { + this._containerData[$container.data('type')] = $container.data('typeContainerID'); + } }, /** diff --git a/wcfsetup/install/files/lib/action/ClipboardAction.class.php b/wcfsetup/install/files/lib/action/ClipboardAction.class.php index 8fd94be194..5f547cfc57 100644 --- a/wcfsetup/install/files/lib/action/ClipboardAction.class.php +++ b/wcfsetup/install/files/lib/action/ClipboardAction.class.php @@ -24,6 +24,12 @@ class ClipboardAction extends AbstractSecureAction { */ protected $action = ''; + /** + * container data + * @var array + */ + protected $containerData = array(); + /** * list of object ids * @var array @@ -72,6 +78,7 @@ class ClipboardAction extends AbstractSecureAction { parent::readParameters(); if (isset($_POST['action'])) $this->action = StringUtil::trim($_POST['action']); + if (isset($_POST['containerData']) && is_array($_POST['containerData'])) $this->containerData = ArrayUtil::toIntegerArray($_POST['containerData']); if (isset($_POST['objectIDs']) && is_array($_POST['objectIDs'])) $this->objectIDs = ArrayUtil::toIntegerArray($_POST['objectIDs']); if (isset($_POST['pageClassName'])) $this->pageClassName = StringUtil::trim($_POST['pageClassName']); if (isset($_POST['type'])) $this->type = StringUtil::trim($_POST['type']); @@ -111,7 +118,7 @@ class ClipboardAction extends AbstractSecureAction { * @return array */ protected function getEditorItems() { - $data = ClipboardHandler::getInstance()->getEditorItems($this->pageClassName); + $data = ClipboardHandler::getInstance()->getEditorItems($this->pageClassName, $this->containerData); if ($data === null) { return array(); diff --git a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php index 601785603f..99beee71ea 100644 --- a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php @@ -218,9 +218,10 @@ class ClipboardHandler extends SingletonFactory { * Returns items for clipboard editor. * * @param string $page + * @param array $containerData * @return array */ - public function getEditorItems($page) { + public function getEditorItems($page, $containerData) { // ignore unknown pages if (!isset($this->pageCache[$page])) return null; @@ -270,8 +271,13 @@ class ClipboardHandler extends SingletonFactory { 'items' => array() ); + $typeData = array(); + if (isset($containerData[$typeName])) { + $typeData = $containerData[$typeName]; + } + foreach ($actionData['actions'] as $action) { - $data = $actionData['object']->execute($this->markedItems[$typeName], $action); + $data = $actionData['object']->execute($this->markedItems[$typeName], $action, $typeData); if ($data === null) { continue; } diff --git a/wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php b/wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php index 8ef8b1f63d..d1b38a96bf 100644 --- a/wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php @@ -24,9 +24,10 @@ interface IClipboardAction { * * @param array $objects * @param string $actionName + * @param array $typeData * @return wcf\system\clipboard\ClipboardEditorItem */ - public function execute(array $objects, $actionName); + public function execute(array $objects, $actionName, $typeData = array()); /** * Returns label for item editor. diff --git a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php index c09d4db771..0fa1b39761 100644 --- a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php @@ -28,7 +28,7 @@ class UserClipboardAction implements IClipboardAction { /** * @see wcf\system\clipboard\action\IClipboardAction::execute() */ - public function execute(array $objects, $actionName) { + public function execute(array $objects, $actionName, $typeData = array()) { $item = new ClipboardEditorItem(); // handle actions -- 2.20.1