Added style changer and made selection permanent
authorAlexander Ebert <ebert@woltlab.com>
Wed, 27 Jul 2016 11:44:21 +0000 (13:44 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 27 Jul 2016 11:44:26 +0000 (13:44 +0200)
com.woltlab.wcf/option.xml
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
com.woltlab.wcf/templates/pageFooter.tpl
constants.php
wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js
wcfsetup/install/files/js/WoltLab/WCF/Controller/Style/Changer.js
wcfsetup/install/files/lib/data/style/StyleAction.class.php
wcfsetup/install/files/lib/system/style/StyleHandler.class.php
wcfsetup/install/files/style/layout/box.scss

index f1d6162ddf9061ca7204035fc41631309be812e0..c12bf9810aef3bb32a0e7eec5b18659cdc78bbd0 100644 (file)
                                <optiontype>boolean</optiontype>
                                <defaultvalue>0</defaultvalue>
                        </option>
+                       <option name="show_style_changer">
+                               <categoryname>general.page</categoryname>
+                               <optiontype>boolean</optiontype>
+                               <defaultvalue>0</defaultvalue>
+                       </option>
                        <option name="footer_code">
                                <categoryname>general.page</categoryname>
                                <optiontype>textarea</optiontype>
index dbe61852bc1bc92943e39a5f5728c34678e0d6a9..30b36cbcfd317eb96d6330e1acd126865373d13a 100644 (file)
@@ -110,7 +110,7 @@ requirejs.config({
                                url: '{link controller="BackgroundQueuePerform"}{/link}',
                                force: {if $forceBackgroundQueuePerform|isset}true{else}false{/if}
                        },
-                       styleChanger: {if $__wcf->getStyleHandler()->countStyles() > 1}true{else}false{/if}
+                       styleChanger: {if $__wcf->getStyleHandler()->showStyleChanger()}true{else}false{/if}
                });
                
                User.init({@$__wcf->user->userID}, '{@$__wcf->user->username|encodeJS}');
index 13d61a9107b67a89902032100b03ae054a39aa99..77080693c670e26be11e1dd642e710619cce795f 100644 (file)
@@ -1,17 +1,25 @@
 <footer id="pageFooter" class="pageFooter">
-       {hascontent}
+       {assign var=__boxesFooter value=$__wcf->getBoxHandler()->getBoxes('footer')}
+       {assign var=__showStyleChanger value=$__wcf->getStyleHandler()->showStyleChanger()}
+       
+       {if $__boxesFooter|count || $__showStyleChanger}
                <div class="boxesFooter">
-                       <div class="layoutBoundary">
-                               <div class="boxContainer">
-                                       {content}
-                                               {foreach from=$__wcf->getBoxHandler()->getBoxes('footer') item=box}
+                       <div class="layoutBoundary{if $__showStyleChanger} clearfix{/if}">
+                               {if $__showStyleChanger}
+                                       <span class="styleChanger">
+                                               <a href="#" class="jsButtonStyleChanger">{lang}wcf.style.changeStyle{/lang}</a>
+                                       </span>
+                               {/if}
+                               {if $__boxesFooter|count}
+                                       <div class="boxContainer">
+                                               {foreach from=$__boxesFooter item=box}
                                                        {@$box->render()}
                                                {/foreach}
-                                       {/content}
-                               </div>
+                                       </div>
+                               {/if}
                        </div>
                </div>
-       {/hascontent}
+       {/if}
        
        {hascontent}
                <div id="pageFooterCopyright" class="pageFooterCopyright">
index 4b14b661b9d63f959c67022feb966b7594c82552..e3a79a04bac31901d5a8c8e7e4250dc3cb58dd26 100644 (file)
@@ -213,3 +213,4 @@ define('ARTICLE_RELATED_ARTICLES', 1);
 define('ARTICLE_RELATED_ARTICLES_MATCH_THRESHOLD', 1);
 define('SHOW_UPDATE_NOTICE_FRONTEND', 1);
 define('LANGUAGE_USE_INFORMAL_VARIANT', 0);
+define('SHOW_STYLE_CHANGER', 0);
index 12f9851787b9a997ba0c8c12a93a19d0a79a7485..4604e0b4b3a0d73a4d64c178992a74aed80d2d6c 100644 (file)
@@ -33,7 +33,7 @@ define(
                        Bootstrap.setup();
                        
                        if (options.styleChanger) {
-                               //ControllerStyleChanger.setup();
+                               ControllerStyleChanger.setup();
                        }
                        
                        this._initUserPopover();
index 9baa25203c39d8dec7f2f521f62802abba374cab..89139728e11c2fe9a2ec1375518844d22349db62 100644 (file)
@@ -2,7 +2,7 @@
  * Dialog based style changer.
  * 
  * @author     Alexander Ebert
- * @copyright  2001-2015 WoltLab GmbH
+ * @copyright  2001-2016 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module     WoltLab/WCF/Controller/Style/Changer
  */
@@ -12,26 +12,15 @@ define(['Ajax', 'Language', 'Ui/Dialog'], function(Ajax, Language, UiDialog) {
        /**
         * @exports     WoltLab/WCF/Controller/Style/Changer
         */
-       var ControllerStyleChanger = {
+       return {
                /**
                 * Adds the style changer to the bottom navigation.
                 */
                setup: function() {
-                       var list = elBySel('#footerNavigation > ul.navigationItems');
-                       if (list === null) {
-                               return;
+                       var link = elBySel('.jsButtonStyleChanger');
+                       if (link) {
+                               link.addEventListener(WCF_CLICK_EVENT, this.showDialog.bind(this));
                        }
-                       
-                       var listItem = elCreate('li');
-                       listItem.classList.add('styleChanger');
-                       listItem.addEventListener(WCF_CLICK_EVENT, this.showDialog.bind(this));
-                       
-                       var link = elCreate('a');
-                       elAttr(link, 'href', '#');
-                       link.textContent = Language.get('wcf.style.changeStyle');
-                       listItem.appendChild(link);
-                       
-                       list.appendChild(listItem);
                },
                
                /**
@@ -88,6 +77,4 @@ define(['Ajax', 'Language', 'Ui/Dialog'], function(Ajax, Language, UiDialog) {
                        });
                }
        };
-       
-       return ControllerStyleChanger;
 });
index 7f067312f9d4395a28177fd6d0e108a4c10821a5..edcd3d1c4d2cd70473b884b3467f406104db8722 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\data\style;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IToggleAction;
 use wcf\data\IUploadAction;
+use wcf\data\user\UserAction;
 use wcf\system\cache\builder\StyleCacheBuilder;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\PermissionDeniedException;
@@ -623,6 +624,14 @@ class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction,
                StyleHandler::getInstance()->changeStyle($this->style->styleID);
                if (StyleHandler::getInstance()->getStyle()->styleID == $this->style->styleID) {
                        WCF::getSession()->setStyleID($this->style->styleID);
+                       
+                       if (WCF::getUser()->userID) {
+                               // set this as the permanent style
+                               $userAction = new UserAction([WCF::getUser()], 'update', ['data' => [
+                                       'styleID' => ($this->style->isDefault ? 0 : $this->style->styleID)
+                               ]]);
+                               $userAction->executeAction();
+                       }
                }
        }
        
index 908c19038989a49098943a96f5127ff122062e32..4df81f0b0e26d0c1e69510cc47068dc2027310bc 100644 (file)
@@ -200,4 +200,13 @@ class StyleHandler extends SingletonFactory {
                
                return null;
        }
+       
+       /**
+        * Returns true if there is more than one available style and the changer is to be displayed.
+        * 
+        * @return      boolean         true if style changer should be displayed
+        */
+       public function showStyleChanger() {
+               return ($this->countStyles() && SHOW_STYLE_CHANGER);
+       }
 }
index a28dae922ad5393889f4783eba83d216b094bbea..c0c1c22f5f382e54dc5c86fadefc46099847c601 100644 (file)
                        }
                }
        }
+       
+       .styleChanger {
+               @include screen-sm-down {
+                       display: none;
+               }
+               
+               @include screen-md-up {
+                       float: right;
+                       padding-left: 20px;
+               }
+       }
 }