From 91cca0c64d1bcc345a1c546174b6ae6bc8793376 Mon Sep 17 00:00:00 2001 From: Mateusz Uzdowski Date: Wed, 16 Oct 2013 13:20:54 +1300 Subject: [PATCH] BUG Move the SubsiteList PJAX request to a dedicated Controller. Currently the request cannot be made if one doesn't have access to the SubsiteAdmin section, which often happens with subsite-specific admins. --- code/SubsiteAdmin.php | 13 ---------- code/SubsiteXHRController.php | 38 ++++++++++++++++++++++++++++++ javascript/LeftAndMain_Subsites.js | 6 ++--- 3 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 code/SubsiteXHRController.php diff --git a/code/SubsiteAdmin.php b/code/SubsiteAdmin.php index 7ed122ca..abea9a1b 100644 --- a/code/SubsiteAdmin.php +++ b/code/SubsiteAdmin.php @@ -30,17 +30,4 @@ public function getEditForm($id = null, $fields = null) { return $form; } - public function getResponseNegotiator() { - $negotiator = parent::getResponseNegotiator(); - $self = $this; - // Register a new callback - $negotiator->setCallback('SubsiteList', function() use(&$self) { - return $self->SubsiteList(); - }); - return $negotiator; - } - - public function SubsiteList() { - return $this->renderWith('SubsiteList'); - } } diff --git a/code/SubsiteXHRController.php b/code/SubsiteXHRController.php new file mode 100644 index 00000000..944bbd7e --- /dev/null +++ b/code/SubsiteXHRController.php @@ -0,0 +1,38 @@ +count()>0) return true; + + return false; + } + + public function getResponseNegotiator() { + $negotiator = parent::getResponseNegotiator(); + $self = $this; + + // Register a new callback + $negotiator->setCallback('SubsiteList', function() use(&$self) { + return $self->SubsiteList(); + }); + + return $negotiator; + } + + /** + * Provide the list of available subsites as a cms-section-agnostic PJAX handler. + */ + public function SubsiteList() { + return $this->renderWith('SubsiteList'); + } + +} diff --git a/javascript/LeftAndMain_Subsites.js b/javascript/LeftAndMain_Subsites.js index 59664407..8988eb60 100644 --- a/javascript/LeftAndMain_Subsites.js +++ b/javascript/LeftAndMain_Subsites.js @@ -58,7 +58,7 @@ */ $('.cms-container .cms-menu-list li a').entwine({ onclick: function(e) { - $('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList'); + $('.cms-container').subsiteFetchPjaxFragment('SubsiteXHRController', 'SubsiteList'); this._super(e); } }); @@ -68,7 +68,7 @@ */ $('.cms-container .SubsiteAdmin .cms-edit-form fieldset.ss-gridfield').entwine({ onreload: function(e) { - $('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList'); + $('.cms-container').subsiteFetchPjaxFragment('SubsiteXHRController', 'SubsiteList'); this._super(e); } }); @@ -81,7 +81,7 @@ */ $('.cms-container .cms-content-fields .subsite-model').entwine({ onadd: function(e) { - $('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList'); + $('.cms-container').subsiteFetchPjaxFragment('SubsiteXHRController', 'SubsiteList'); this._super(e); } });