From d68ec395a3c8c9f01a4453db4196c884c8f1f058 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 9 Jun 2011 15:47:59 +1200 Subject: [PATCH] API CHANGE Using $Link instead of $ApplicationTitle and $SectionTitle in LeftAndMain.ss. Adding new 'X-Title' HTTP header in order to support title changes for history.pushState --- admin/code/CMSMenu.php | 10 ++++++---- admin/code/LeftAndMain.php | 11 +++++++++++ admin/javascript/LeftAndMain.js | 4 ++++ admin/templates/LeftAndMain.ss | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/admin/code/CMSMenu.php b/admin/code/CMSMenu.php index e13e7eff1..becb5261d 100755 --- a/admin/code/CMSMenu.php +++ b/admin/code/CMSMenu.php @@ -208,10 +208,12 @@ class CMSMenu extends Object implements IteratorAggregate, i18nEntityProvider // checks on if($menuItem->controller) { $controllerObj = singleton($menuItem->controller); - // Necessary for canView() to have request data available, - // e.g. to check permissions against LeftAndMain->currentPage() - $controllerObj->setRequest(Controller::curr()->getRequest()); - if(!$controllerObj->canView($member)) continue; + if(Controller::has_curr()) { + // Necessary for canView() to have request data available, + // e.g. to check permissions against LeftAndMain->currentPage() + $controllerObj->setRequest(Controller::curr()->getRequest()); + if(!$controllerObj->canView($member)) continue; + } } $viewableMenuItems[$code] = $menuItem; diff --git a/admin/code/LeftAndMain.php b/admin/code/LeftAndMain.php index f0094cec3..bf02b25d9 100755 --- a/admin/code/LeftAndMain.php +++ b/admin/code/LeftAndMain.php @@ -342,8 +342,12 @@ class LeftAndMain extends Controller { } function handleRequest($request) { + $title = $this->Title(); + $response = parent::handleRequest($request); $response->addHeader('X-Controller', $this->class); + $response->addHeader('X-Title', $title); + return $response; } @@ -1175,6 +1179,13 @@ class LeftAndMain extends Controller { function getApplicationName() { return self::$application_name; } + + /** + * @return String + */ + function Title() { + return sprintf('%s | %s', $this->getApplicationName(), $this->SectionTitle()); + } /** * Return the title of the current section, as shown on the main menu diff --git a/admin/javascript/LeftAndMain.js b/admin/javascript/LeftAndMain.js index 5da775475..cf9e2334d 100755 --- a/admin/javascript/LeftAndMain.js +++ b/admin/javascript/LeftAndMain.js @@ -122,6 +122,10 @@ var xhr = $.ajax({ url: state.url, success: function(data, status, xhr) { + // Update title + var title = xhr.getResponseHeader('X-Title'); + if(title) document.title = title; + // Update panels contentEl.afterLoad(data, status, xhr); self.redraw(); diff --git a/admin/templates/LeftAndMain.ss b/admin/templates/LeftAndMain.ss index cdfbc5ba1..751a35906 100755 --- a/admin/templates/LeftAndMain.ss +++ b/admin/templates/LeftAndMain.ss @@ -4,7 +4,7 @@ <% base_tag %> -$ApplicationName | $SectionTitle +$Title