Landing page is now automatically assigned
authorAlexander Ebert <ebert@woltlab.com>
Mon, 31 Dec 2012 17:03:00 +0000 (18:03 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 31 Dec 2012 17:03:00 +0000 (18:03 +0100)
Fixes #1059

wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/acp/templates/pageMenuItemAdd.tpl
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemAction.class.php
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php
wcfsetup/install/lang/de.xml

index d7ca3f9f8ed3d5eaed41540bb6a31c3f8e141335..311ad34575f05187892ab8f944f6741ca94dd082 100644 (file)
@@ -708,67 +708,6 @@ WCF.ACP.Package.Uninstallation = WCF.ACP.Package.Installation.extend({
        }
 });
 
-/**
- * Namespace for page menu.
- */
-WCF.ACP.PageMenu = { };
-
-/**
- * Allows menu items to be set as landing page.
- * 
- * @param      integer         menuItemID
- */
-WCF.ACP.PageMenu.SetAsLandingPage = Class.extend({
-       /**
-        * menu item id
-        * @var integer
-        */
-       _menuItemID: 0,
-       
-       /**
-        * Initializes the WCF.ACP.PageMenu.SetAsLandingPage class.
-        * 
-        * @param       integer         menuItemID
-        */
-       init: function(menuItemID) {
-               this._menuItemID = menuItemID;
-               
-               $('#setAsLandingPage').click($.proxy(this._click, this));
-       },
-       
-       /**
-        * Handles button clicks.
-        */
-       _click: function() {
-               var self = this;
-               WCF.System.Confirmation.show(WCF.Language.get('wcf.acp.pageMenu.isLandingPage.confirmMessage'), function(action) {
-                       if (action === 'confirm') {
-                               new WCF.Action.Proxy({
-                                       autoSend: true,
-                                       data: {
-                                               actionName: 'setAsLandingPage',
-                                               className: 'wcf\\data\\page\\menu\\item\\PageMenuItemAction',
-                                               objectIDs: [ self._menuItemID ]
-                                       },
-                                       success: $.proxy(self._success, self)
-                               });
-                       }
-               });
-       },
-       
-       /**
-        * Handles successful AJAX requests.
-        * 
-        * @param       object          data
-        * @param       string          textStatus
-        * @param       jQuery          jqXHR
-        */
-       _success: function(data, textStatus, jqXHR) {
-               var $notification = new WCF.System.Notification(WCF.Language.get('wcf.acp.pageMenu.isLandingPage.success'));
-               $notification.show(function() { window.location.reload(); });
-       }
-});
-
 /**
  * Handles option selection.
  */
index 6a4b1a56dc9bb6057d04753104774b62766fb2db..86f6cbf9d203d7857f8a30186242153b09658501 100644 (file)
                
                handleMenuPosition();
                handleIsInternalLink();
-               
-               {if $action == 'edit' && $menuItem->isValidLandingPage()}
-                       WCF.Language.addObject({
-                               'wcf.acp.pageMenu.isLandingPage.confirmMessage': '{lang}wcf.acp.pageMenu.isLandingPage.confirmMessage{/lang}',
-                               'wcf.acp.pageMenu.isLandingPage.success': '{lang}wcf.acp.pageMenu.isLandingPage.success{/lang}'
-                       });
-                       
-                       new WCF.ACP.PageMenu.SetAsLandingPage({@$menuItem->menuItemID});
-               {/if}
        });
        //]]>
 </script>
@@ -61,9 +52,6 @@
 <div class="contentNavigation">
        <nav>
                <ul>
-                       {if $action == 'edit' && $menuItem->isValidLandingPage()}
-                               <li id="setAsLandingPage"><a class="button"><img src="{@$__wcf->getPath()}icon/default.svg" /> <span>{lang}wcf.acp.pageMenu.setAsLandingPage{/lang}</span></a></li>
-                       {/if}
                        <li><a href="{link controller='PageMenuItemList'}{/link}" class="button"><img src="{@$__wcf->getPath()}icon/list.svg" alt="" /> <span>{lang}wcf.acp.pageMenu.list{/lang}</span></a></li>
                </ul>
        </nav>
index 20cf883a9ba1303326ab17f58ec6de3abb2fcd94..34b0aef31cb95f1f942c06eeda1d369879b8bd7a 100644 (file)
@@ -45,31 +45,31 @@ class PageMenuItemAction extends AbstractDatabaseObjectAction implements ISortab
                
                $menuItem = parent::create();
                
-               if ($menuItem->isLandingPage) {
-                       $menuItemEditor = new PageMenuItemEditor($menuItem);
-                       $menuItemEditor->setAsLandingPage();
+               if ($menuItem->menuPosition == 'header') {
+                       PageMenuItemEditor::updateLandingPage();
                }
                
                return $menuItem;
        }
        
        /**
-        * Validates parameters to set a menu item as landing page.
+        * @see wcf\data\AbstractDatabaseObjectAction::delete()
         */
-       public function validateSetAsLandingPage() {
-               WCF::getSession()->checkPermissions(array('admin.display.canManagePageMenu'));
+       public function delete() {
+               $returnValues = parent::delete();
                
-               $this->menuItemEditor = $this->getSingleObject();
-               if (!$this->menuItemEditor->isValidLandingPage()) {
-                       throw new PermissionDeniedException();
-               }
+               PageMenuItemEditor::updateLandingPage();
+               
+               return $returnValues;
        }
        
        /**
-        * Sets a menu item as landing page.
+        * @see wcf\data\AbstractDatabaseObjectAction::update()
         */
-       public function setAsLandingPage() {
-               $this->menuItemEditor->setAsLandingPage();
+       public function update() {
+               parent::update();
+               
+               PageMenuItemEditor::updateLandingPage();
        }
        
        /**
@@ -136,5 +136,10 @@ class PageMenuItemAction extends AbstractDatabaseObjectAction implements ISortab
                        }
                }
                WCF::getDB()->commitTransaction();
+               
+               // update landing page
+               if ($this->parameters['menuPosition'] == 'header') {
+                       PageMenuItemEditor::updateLandingPage();
+               }
        }
 }
index 22aa0616d0a3151061335ce56c2f528579887478..1603d374258323185fe950e1ef70f888a26077c0 100644 (file)
@@ -65,15 +65,27 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached
        }
        
        /**
-        * Sets current page menu item as landing page.
+        * Sets first top header menu item as landing page.
         */
-       public function setAsLandingPage() {
+       public static function updateLandingPage() {
                $sql = "UPDATE  wcf".WCF_N."_page_menu_item
                        SET     isLandingPage = 0";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute();
                
-               $this->update(array('isLandingPage' => 1));
+               $sql = "UPDATE          wcf".WCF_N."_page_menu_item
+                       SET             isLandingPage = ?
+                       WHERE           menuPosition = ?
+                                       AND parentMenuItem = ?
+                                       AND menuItemController <> ?
+                       ORDER BY        showOrder ASC";
+               $statement = WCF::getDB()->prepareStatement($sql, 1);
+               $statement->execute(array(
+                       1,
+                       'header',
+                       '',
+                       ''
+               ));
                
                self::resetCache();
        }
index 0085592b5e6553d39417f83906dd998aa9635faf..c1f3c266463352013e58d1b1ed1f18483778b56c 100644 (file)
                <item name="wcf.acp.pageMenu.footer"><![CDATA[Fußzeile]]></item>
                <item name="wcf.acp.pageMenu.header"><![CDATA[Hauptmenü]]></item>
                <item name="wcf.acp.pageMenu.isDisabled"><![CDATA[Menüpunkt deaktivieren]]></item>
-               <item name="wcf.acp.pageMenu.isLandingPage.confirmMessage"><![CDATA[Möchten Sie den Menüpunkt „{$menuItem}“ als Startseite Ihrer Website festlegen?]]></item>
-               <item name="wcf.acp.pageMenu.isLandingPage.success"><![CDATA[„{$menuItem}“ ist nun als Startseite festgelegt]]></item>
                <item name="wcf.acp.pageMenu.link"><![CDATA[Link]]></item>
                <item name="wcf.acp.pageMenu.link.external"><![CDATA[Externer Link]]></item>
                <item name="wcf.acp.pageMenu.link.internal"><![CDATA[Interner Link]]></item>