From d5e04842ca72e20ae04394af35ac18b4d3087924 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 31 Dec 2012 18:03:00 +0100 Subject: [PATCH] Landing page is now automatically assigned Fixes #1059 --- wcfsetup/install/files/acp/js/WCF.ACP.js | 61 ------------------- .../files/acp/templates/pageMenuItemAdd.tpl | 12 ---- .../menu/item/PageMenuItemAction.class.php | 31 ++++++---- .../menu/item/PageMenuItemEditor.class.php | 18 +++++- wcfsetup/install/lang/de.xml | 2 - 5 files changed, 33 insertions(+), 91 deletions(-) diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index d7ca3f9f8e..311ad34575 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -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. */ diff --git a/wcfsetup/install/files/acp/templates/pageMenuItemAdd.tpl b/wcfsetup/install/files/acp/templates/pageMenuItemAdd.tpl index 6a4b1a56dc..86f6cbf9d2 100644 --- a/wcfsetup/install/files/acp/templates/pageMenuItemAdd.tpl +++ b/wcfsetup/install/files/acp/templates/pageMenuItemAdd.tpl @@ -31,15 +31,6 @@ 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} }); //]]> @@ -61,9 +52,6 @@
diff --git a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemAction.class.php b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemAction.class.php index 20cf883a9b..34b0aef31c 100644 --- a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemAction.class.php +++ b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemAction.class.php @@ -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(); + } } } diff --git a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php index 22aa0616d0..1603d37425 100644 --- a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php +++ b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php @@ -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(); } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 0085592b5e..c1f3c26646 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -432,8 +432,6 @@ - - -- 2.20.1