Fixed toggling of page menu items
authorAlexander Ebert <ebert@woltlab.com>
Mon, 28 Jan 2013 18:14:49 +0000 (19:14 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 28 Jan 2013 18:14:49 +0000 (19:14 +0100)
Fixes #1110

wcfsetup/install/files/acp/templates/pageMenuItemList.tpl
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemAction.class.php

index 6a91b41c3e134cdf123b096743b89ed21ba594f1..3543d31f8571b765e939779d33ccb92684a8d8cd 100644 (file)
@@ -9,8 +9,8 @@
 <script type="text/javascript">
        //<![CDATA[
        $(function() {
-               new WCF.Action.Delete('wcf\\data\\page\\menu\\item\\PageMenuItemAction', '.sortableNode');
-               new WCF.Action.Toggle('wcf\\data\\page\\menu\\item\\PageMenuItemAction', '.sortableNode');
+               new WCF.Action.Delete('wcf\\data\\page\\menu\\item\\PageMenuItemAction', '.sortableNode', '> .sortableNodeLabel .jsDeleteButton');
+               new WCF.Action.Toggle('wcf\\data\\page\\menu\\item\\PageMenuItemAction', '.sortableNode', '> .sortableNodeLabel .jsToggleButton');
                
                {if $headerItems|count}
                        new WCF.Sortable.List('pageMenuItemHeaderList', 'wcf\\data\\page\\menu\\item\\PageMenuItemAction', undefined, { protectRoot: true }, false, { menuPosition: 'header' });
index 90aa526ab93c4f140202024d2cbac154e0b0bc96..b547e04be412eacb2a84b7f99fe50a5688f1d8a7 100755 (executable)
@@ -1684,8 +1684,15 @@ WCF.Action.SimpleProxy = Class.extend({
  * 
  * @param      string          className
  * @param      string          containerSelector
+ * @param      string          buttonSelector
  */
 WCF.Action.Delete = Class.extend({
+       /**
+        * delete button selector
+        * @var string
+        */
+       _buttonSelector: '',
+       
        /**
         * action class name
         * @var string
@@ -1709,10 +1716,13 @@ WCF.Action.Delete = Class.extend({
         * 
         * @param       string          className
         * @param       string          containerSelector
+        * @param       string          buttonSelector
         */
-       init: function(className, containerSelector) {
+       init: function(className, containerSelector, buttonSelector) {
                this._containerSelector = containerSelector;
                this._className = className;
+               this._buttonSelector = (buttonSelector) ? buttonSelector : '.jsDeleteButton';
+               
                this.proxy = new WCF.Action.Proxy({
                        success: $.proxy(this._success, this)
                });
@@ -1733,7 +1743,7 @@ WCF.Action.Delete = Class.extend({
                        
                        if (!WCF.inArray($containerID, self._containers)) {
                                self._containers.push($containerID);
-                               $container.find('.jsDeleteButton').click($.proxy(self._click, self));
+                               $container.find(this._buttonSelector).click($.proxy(self._click, self));
                        }
                });
        },
@@ -1818,9 +1828,15 @@ WCF.Action.Delete = Class.extend({
  * 
  * @param      string          className
  * @param      jQuery          containerList
- * @param      string          toggleButtonSelector
+ * @param      string          buttonSelector
  */
 WCF.Action.Toggle = Class.extend({
+       /**
+        * toogle button selector
+        * @var string
+        */
+       _buttonSelector: '.jsToggleButton',
+       
        /**
         * action class name
         * @var string
@@ -1839,25 +1855,17 @@ WCF.Action.Toggle = Class.extend({
         */
        _containers: [ ],
        
-       /**
-        * toogle button selector
-        * @var string
-        */
-       _toggleButtonSelector: '.jsToggleButton',
-       
        /**
         * Initializes 'toggle'-Proxy
         * 
         * @param       string          className
         * @param       string          containerSelector
-        * @param       string          toggleButtonSelector
+        * @param       string          buttonSelector
         */
-       init: function(className, containerSelector, toggleButtonSelector) {
+       init: function(className, containerSelector, buttonSelector) {
                this._containerSelector = containerSelector;
                this._className = className;
-               if (toggleButtonSelector) {
-                       this._toggleButtonSelector = toggleButtonSelector;
-               }
+               this._buttonSelector = (buttonSelector) ? buttonSelector : '.jsToggleButton';
                
                // initialize proxy
                var options = {
@@ -1880,7 +1888,7 @@ WCF.Action.Toggle = Class.extend({
                        
                        if (!WCF.inArray($containerID, this._containers)) {
                                this._containers.push($containerID);
-                               $container.find(this._toggleButtonSelector).click($.proxy(this._click, this));
+                               $container.find(this._buttonSelector).click($.proxy(this._click, this));
                        }
                }, this));
        },
@@ -1945,7 +1953,7 @@ WCF.Action.Toggle = Class.extend({
        triggerEffect: function(objectIDs) {
                for (var $index in this._containers) {
                        var $container = $('#' + this._containers[$index]);
-                       var $toggleButton = $container.find(this._toggleButtonSelector);
+                       var $toggleButton = $container.find(this._buttonSelector);
                        if (WCF.inArray($toggleButton.data('objectID'), objectIDs)) {
                                $container.wcfHighlight();
                                this._toggleButton($container, $toggleButton);
index 5ab631ed8a4b032ff2364d7d47f4ab133b71c542..b0298b0f1be5bff087e555dadc0b30c1b882cb23 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\page\menu\item;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\ISortableAction;
+use wcf\data\IToggleAction;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\PermissionDeniedException;
 use wcf\system\exception\UserInputException;
@@ -11,13 +12,13 @@ use wcf\system\WCF;
  * Executes page menu item-related actions.
  * 
  * @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 data.page.menu.item
  * @category   Community Framework
  */
-class PageMenuItemAction extends AbstractDatabaseObjectAction implements ISortableAction {
+class PageMenuItemAction extends AbstractDatabaseObjectAction implements ISortableAction, IToggleAction {
        /**
         * @see wcf\data\AbstractDatabaseObjectAction::$className
         */
@@ -141,4 +142,23 @@ class PageMenuItemAction extends AbstractDatabaseObjectAction implements ISortab
                        PageMenuItemEditor::updateLandingPage();
                }
        }
+       
+       /**
+        * @see wcf\data\IToggleAction::validateToggle()
+        */
+       public function validateToggle() {
+               $this->menuItemEditor = $this->getSingleObject();
+               if ($this->menuItemEditor->isLandingPage) {
+                       throw new PermissionDeniedException();
+               }
+       }
+       
+       /**
+        * @see wcf\data\IToggleAction::toggle()
+        */
+       public function toggle() {
+               $this->menuItemEditor->update(array(
+                       'isDisabled' => ($this->menuItemEditor->isDisabled ? 0 : 1)
+               ));
+       }
 }