Supporting collapsible sidebar persistence
authorAlexander Ebert <ebert@woltlab.com>
Mon, 22 Oct 2012 14:05:41 +0000 (16:05 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 22 Oct 2012 14:05:41 +0000 (16:05 +0200)
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleSidebarHandler.class.php [new file with mode: 0644]

index 3e7cfbd141534ef3e911348e08a178eafb8841ba..c8f722735dff9583cd958ae29e80e82ecda196a8 100755 (executable)
@@ -3491,13 +3491,43 @@ WCF.Collapsible.SimpleRemote = WCF.Collapsible.Remote.extend({
        }
 });
 
+/**
+ * Provides collapsible sidebars with persistency support.
+ */
 WCF.Collapsible.Sidebar = Class.extend({
+       /**
+        * trigger button object
+        * @var jQuery
+        */
        _button: null,
+       
+       /**
+        * sidebar state
+        * @var boolean
+        */
        _isOpen: false,
+       
+       /**
+        * action proxy
+        * @var WCF.Action.Proxy
+        */
        _proxy: null,
+       
+       /**
+        * sidebar object
+        * @var jQuery
+        */
        _sidebar: null,
+       
+       /**
+        * sidebar identifier
+        * @var string
+        */
        _sidebarName: '',
        
+       /**
+        * Creates a new WCF.Collapsible.Sidebar object.
+        */
        init: function() {
                this._sidebar = $('.sidebar:eq(0)');
                if (!this._sidebar.length) {
@@ -3513,16 +3543,21 @@ WCF.Collapsible.Sidebar = Class.extend({
                this._button.click($.proxy(this._click, this));
                
                this._proxy = new WCF.Action.Proxy({
-                       url: 'index.php/CollapsibleSidebar/?t=' + SECURITY_TOKEN + SID_2ND
+                       url: 'index.php/AJAXInvoke/?t=' + SECURITY_TOKEN + SID_2ND
                });
                
                this._renderSidebar();
        },
        
+       /**
+        * Handles clicks on the trigger button.
+        */
        _click: function() {
                this._isOpen = (this._isOpen) ? false : true;
                
                this._proxy.setOption('data', {
+                       actionName: 'toggle',
+                       className: 'wcf\\system\\user\\collapsible\\content\\UserCollapsibleSidebarHandler',
                        isOpen: (this._isOpen ? 1 : 0),
                        sidebarName: this._sidebarName
                });
@@ -3531,6 +3566,9 @@ WCF.Collapsible.Sidebar = Class.extend({
                this._renderSidebar();
        },
        
+       /**
+        * Renders the sidebar state.
+        */
        _renderSidebar: function() {
                if (this._isOpen) {
                        this._sidebar.addClass('sidebarCollapsed');
diff --git a/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleSidebarHandler.class.php b/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleSidebarHandler.class.php
new file mode 100644 (file)
index 0000000..8534fb0
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+namespace wcf\system\user\collapsible\content;
+use wcf\system\exception\UserInputException;
+use wcf\system\IAJAXInvokeAction;
+use wcf\system\SingletonFactory;
+use wcf\util\StringUtil;
+
+/**
+ * Provides methods for handling collapsible sidebars.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.user.collapsible.content
+ * @category   Community Framework
+ */
+class UserCollapsibleSidebarHandler extends SingletonFactory implements IAJAXInvokeAction {
+       /**
+        * Toggles a sidebar.
+        */
+       public function toggle() {
+               $isOpen = (isset($_POST['isOpen'])) ? intval($_POST['isOpen']) : 1;
+               $objectID = (isset($_POST['sidebarName'])) ? StringUtil::trim($_POST['sidebarName']) : '';
+               if (empty($objectID)) {
+                       throw new UserInputException('sidebarName');
+               }
+               
+               $objectTypeID = UserCollapsibleContentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.collapsibleSidebar');
+               if ($isOpen) {
+                       UserCollapsibleContentHandler::getInstance()->markAsOpened($objectTypeID, $objectID);
+               }
+               else {
+                       UserCollapsibleContentHandler::getInstance()->markAsCollapsed($objectTypeID, $objectID);
+               }
+       }
+}