From 77f8b178d676235a942a2e0728d71be2a8b6c070 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 3 May 2013 22:25:34 +0200 Subject: [PATCH] Improved clipboard for multiple action classes --- .../install/files/acp/templates/header.tpl | 1 + wcfsetup/install/files/js/WCF.js | 27 +++++++++++-- .../lib/action/ClipboardAction.class.php | 34 ++++++++++++----- .../clipboard/ClipboardHandler.class.php | 38 +++++++++++-------- 4 files changed, 70 insertions(+), 30 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/header.tpl b/wcfsetup/install/files/acp/templates/header.tpl index 72caf6461a..0c6990ff4e 100644 --- a/wcfsetup/install/files/acp/templates/header.tpl +++ b/wcfsetup/install/files/acp/templates/header.tpl @@ -45,6 +45,7 @@ '__daysShort': [ '{lang}wcf.date.day.sun{/lang}', '{lang}wcf.date.day.mon{/lang}', '{lang}wcf.date.day.tue{/lang}', '{lang}wcf.date.day.wed{/lang}', '{lang}wcf.date.day.thu{/lang}', '{lang}wcf.date.day.fri{/lang}', '{lang}wcf.date.day.sat{/lang}' ], '__months': [ '{lang}wcf.date.month.january{/lang}', '{lang}wcf.date.month.february{/lang}', '{lang}wcf.date.month.march{/lang}', '{lang}wcf.date.month.april{/lang}', '{lang}wcf.date.month.may{/lang}', '{lang}wcf.date.month.june{/lang}', '{lang}wcf.date.month.july{/lang}', '{lang}wcf.date.month.august{/lang}', '{lang}wcf.date.month.september{/lang}', '{lang}wcf.date.month.october{/lang}', '{lang}wcf.date.month.november{/lang}', '{lang}wcf.date.month.december{/lang}' ], '__monthsShort': [ '{lang}wcf.date.month.jan{/lang}', '{lang}wcf.date.month.feb{/lang}', '{lang}wcf.date.month.mar{/lang}', '{lang}wcf.date.month.apr{/lang}', '{lang}wcf.date.month.may{/lang}', '{lang}wcf.date.month.jun{/lang}', '{lang}wcf.date.month.jul{/lang}', '{lang}wcf.date.month.aug{/lang}', '{lang}wcf.date.month.sep{/lang}', '{lang}wcf.date.month.oct{/lang}', '{lang}wcf.date.month.nov{/lang}', '{lang}wcf.date.month.dec{/lang}' ], + 'wcf.clipboard.item.unmarkAll': '{lang}wcf.clipboard.item.unmarkAll{/lang}', 'wcf.date.relative.now': '{lang}wcf.date.relative.now{/lang}', 'wcf.date.relative.minutes': '{capture assign=relativeMinutes}{lang}wcf.date.relative.minutes{/lang}{/capture}{@$relativeMinutes|encodeJS}', 'wcf.date.relative.hours': '{capture assign=relativeHours}{lang}wcf.date.relative.hours{/lang}{/capture}{@$relativeHours|encodeJS}', diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 21724f65c8..a3aadabbea 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1204,10 +1204,6 @@ WCF.Clipboard = { for (var $itemIndex in $editor.items) { var $item = $editor.items[$itemIndex]; - if ($item.actionName === 'unmarkAll') { - $('
  • ' + $item.label + '
  • ').appendTo($itemList); $listItem.data('objectType', $typeName); $listItem.data('actionName', $item.actionName).data('parameters', $item.parameters); @@ -1217,6 +1213,29 @@ WCF.Clipboard = { $listItem.click($.proxy(this._executeAction, this)); } + // add 'unmark all' + $('
  • ' + WCF.Language.get('wcf.clipboard.item.unmarkAll') + '
  • ').appendTo($itemList).click($.proxy(function() { + this._proxy.setOption('data', { + action: 'unmarkAll', + type: $typeName + }); + this._proxy.setOption('success', $.proxy(function(data, textStatus, jqXHR) { + for (var $__containerID in this._containers) { + var $__container = $(this._containers[$__containerID]); + if ($__container.data('type') == $typeName) { + $__container.find('.jsClipboardMarkAll, .jsClipboardItem').removeAttr('checked'); + break; + } + } + + // call and restore success method + this._success(data, textStatus, jqXHR); + this._proxy.setOption('success', $.proxy(this._success, this)); + }, this)); + this._proxy.sendRequest(); + }, this)); + // block click event $container.click(function(event) { event.stopPropagation(); diff --git a/wcfsetup/install/files/lib/action/ClipboardAction.class.php b/wcfsetup/install/files/lib/action/ClipboardAction.class.php index f31a7f6803..328c345cb9 100644 --- a/wcfsetup/install/files/lib/action/ClipboardAction.class.php +++ b/wcfsetup/install/files/lib/action/ClipboardAction.class.php @@ -11,7 +11,7 @@ use wcf\util\StringUtil; * Handles clipboard items. * * @author Alexander Ebert - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage action @@ -24,6 +24,12 @@ class ClipboardAction extends AJAXInvokeAction { */ protected $action = ''; + /** + * list of allowed action methods + * @var array + */ + protected $allowedActions = array('mark', 'unmark', 'unmarkAll'); + /** * container data * @var array @@ -92,7 +98,12 @@ class ClipboardAction extends AJAXInvokeAction { $this->validate(); // execute action - ClipboardHandler::getInstance()->{$this->action}($this->objectIDs, $this->objectTypeID); + if ($this->action == 'unmarkAll') { + ClipboardHandler::getInstance()->unmarkAll($this->objectTypeID); + } + else { + ClipboardHandler::getInstance()->{$this->action}($this->objectIDs, $this->objectTypeID); + } } /** @@ -128,6 +139,7 @@ class ClipboardAction extends AJAXInvokeAction { } return array( + 'action' => $this->action, 'items' => $editorItems ); } @@ -136,16 +148,18 @@ class ClipboardAction extends AJAXInvokeAction { * Validates parameters. */ protected function validate() { - if (empty($this->objectIDs)) { - throw new UserInputException('objectIDs'); - } - - if (empty($this->pageClassName)) { - throw new UserInputException('pageClassName'); + if (!in_array($this->action, $this->allowedActions)) { + throw new UserInputException('action'); } - if ($this->action != 'mark' && $this->action != 'unmark') { - throw new UserInputException('action'); + if ($this->action != 'unmarkAll') { + if (empty($this->objectIDs)) { + throw new UserInputException('objectIDs'); + } + + if (empty($this->pageClassName)) { + throw new UserInputException('pageClassName'); + } } $this->objectTypeID = (!empty($this->type)) ? ClipboardHandler::getInstance()->getObjectTypeID($this->type) : null; diff --git a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php index 16ddee5554..18b38bb7c0 100644 --- a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php @@ -111,6 +111,22 @@ class ClipboardHandler extends SingletonFactory { $statement->execute($conditions->getParameters()); } + /** + * Unmarks all items of given type. + * + * @param integer $objectTypeID + */ + public function unmarkAll($objectTypeID) { + $sql = "DELETE FROM wcf".WCF_N."_clipboard_item + WHERE objectTypeID = ? + AND userID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + $objectTypeID, + WCF::getUser()->userID + )); + } + /** * Returns a type id by name. * @@ -323,10 +339,12 @@ class ClipboardHandler extends SingletonFactory { $objects = $actionData['object']->filterObjects($this->markedItems[$typeName], $typeData); if (empty($objects)) continue; - $editorData[$typeName] = array( - 'label' => $actionData['object']->getEditorLabel($objects), - 'items' => array() - ); + if (!isset($editorData[$typeName])) { + $editorData[$typeName] = array( + 'label' => $actionData['object']->getEditorLabel($objects), + 'items' => array() + ); + } foreach ($actionData['actions'] as $action) { $data = $actionData['object']->execute($objects, $action); @@ -336,18 +354,6 @@ class ClipboardHandler extends SingletonFactory { $editorData[$typeName]['items'][$action] = $data; } - - // append 'unmark all' item - if (!ClassUtil::isInstanceOf($actionData['object']->getClassName(), 'wcf\data\IClipboardAction')) { - throw new SystemException("'".$actionData['object']->getClassName()."' does not implement 'wcf\data\IClipboardAction'"); - } - - $unmarkAll = new ClipboardEditorItem(); - $unmarkAll->setName('unmarkAll'); - $unmarkAll->addParameter('actionName', 'unmarkAll'); - $unmarkAll->addParameter('className', $actionData['object']->getClassName()); - - $editorData[$typeName]['items'][] = $unmarkAll; } return $editorData; -- 2.20.1