From 5cc24ad59638400948af13d8541c154688d5260f Mon Sep 17 00:00:00 2001 From: Tony Air Date: Mon, 6 May 2013 02:22:25 +0700 Subject: [PATCH] Non ajax loading This small fix let's user to refresh bulk uploading page. --- code/GridFieldBulkImageUpload_Request.php | 25 ++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/code/GridFieldBulkImageUpload_Request.php b/code/GridFieldBulkImageUpload_Request.php index e1722ce..e38897e 100644 --- a/code/GridFieldBulkImageUpload_Request.php +++ b/code/GridFieldBulkImageUpload_Request.php @@ -259,7 +259,30 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { $response = new SS_HTTPResponse($formHTML); $response->addHeader('Content-Type', 'text/plain'); $response->addHeader('X-Title', 'SilverStripe - Bulk '.$this->gridField->list->dataClass.' Image Upload'); - return $response; + if($request->isAjax()) { + return $response; + } else { + $controller = $this->getToplevelController(); + // If not requested by ajax, we need to render it within the controller context+template + return $controller->customise(array( + 'Content' => $response->getBody(), + )); + } + } + + /** + * Traverse up nested requests until we reach the first that's not a GridFieldDetailForm or GridFieldDetailForm_ItemRequest. + * The opposite of {@link Controller::curr()}, required because + * Controller::$controller_stack is not directly accessible. + * + * @return Controller + */ + protected function getToplevelController() { + $c = $this->controller; + while($c && ($c instanceof GridFieldDetailForm_ItemRequest || $c instanceof GridFieldDetailForm)) { + $c = $c->getController(); + } + return $c; } /**