Added support for container id within clipboard actions
authorAlexander Ebert <ebert@woltlab.com>
Tue, 15 May 2012 18:57:10 +0000 (20:57 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 15 May 2012 18:57:10 +0000 (20:57 +0200)
Closes #546

wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/action/ClipboardAction.class.php
wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php
wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php
wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php

index 397115b117aa2e36b94576fb79d88d836a8288f8..e307ccc4eb8bd4df2ef05553ea09a1c6a9604c34 100644 (file)
@@ -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');
+               }
        },
        
        /**
index 8fd94be194d76749d439aecfa505573cd4eae952..5f547cfc571d34f6405209c48dbb1a4da7b65bf0 100644 (file)
@@ -24,6 +24,12 @@ class ClipboardAction extends AbstractSecureAction {
         */
        protected $action = '';
        
+       /**
+        * container data
+        * @var array
+        */
+       protected $containerData = array();
+       
        /**
         * list of object ids
         * @var array<integer>
@@ -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<array>
         */
        protected function getEditorItems() {
-               $data = ClipboardHandler::getInstance()->getEditorItems($this->pageClassName);
+               $data = ClipboardHandler::getInstance()->getEditorItems($this->pageClassName, $this->containerData);
                
                if ($data === null) {
                        return array();
index 601785603f06130401829ba93c60655e262205fe..99beee71eac4ea43efa243b0f33a1d5b170c290a 100644 (file)
@@ -218,9 +218,10 @@ class ClipboardHandler extends SingletonFactory {
         * Returns items for clipboard editor.
         * 
         * @param       string          $page
+        * @param       array           $containerData
         * @return      array<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;
                                }
index 8ef8b1f63d4bba6b8791597b19a0384c71a3ac79..d1b38a96bffb90dd00cd1b36c54b347ccb98331c 100644 (file)
@@ -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.
index c09d4db771f0c31528a9498a8da54f2e6ab11fda..0fa1b39761d6a7bb8e3b9b0a25fefa2dc0f56856 100644 (file)
@@ -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