Improved clipboard for multiple action classes
authorAlexander Ebert <ebert@woltlab.com>
Fri, 3 May 2013 20:25:34 +0000 (22:25 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 3 May 2013 20:25:34 +0000 (22:25 +0200)
wcfsetup/install/files/acp/templates/header.tpl
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/action/ClipboardAction.class.php
wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php

index 72caf6461aafa9f916bc8d45c4454ddc70474990..0c6990ff4e83d80f66608ffeab5a051c7caeb226 100644 (file)
@@ -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}',
index 21724f65c843019e3909f916d8762a4801f28ded..a3aadabbea9ca5b7f5d9d85bd927814c96dd0d2a 100755 (executable)
@@ -1204,10 +1204,6 @@ WCF.Clipboard = {
                        for (var $itemIndex in $editor.items) {
                                var $item = $editor.items[$itemIndex];
                                
-                               if ($item.actionName === 'unmarkAll') {
-                                       $('<li class="dropdownDivider" />').appendTo($itemList);
-                               }
-                               
                                var $listItem = $('<li><span>' + $item.label + '</span></li>').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'
+                       $('<li class="dropdownDivider" />').appendTo($itemList);
+                       $('<li><span>' + WCF.Language.get('wcf.clipboard.item.unmarkAll') + '</span></li>').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();
index f31a7f6803e80b191c7cade255e292f79f204426..328c345cb997becd17ae9e3c6dc058fd33044f7a 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage action
@@ -24,6 +24,12 @@ class ClipboardAction extends AJAXInvokeAction {
         */
        protected $action = '';
        
+       /**
+        * list of allowed action methods
+        * @var array<string>
+        */
+       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;
index 16ddee55540702c4e2e064e91615b31cba89d7d3..18b38bb7c00b040d70e9f68236d2e9a32fa04470 100644 (file)
@@ -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;