From 8a4066bef9bfa1a599d0233237433c930bf315d2 Mon Sep 17 00:00:00 2001 From: colymba Date: Thu, 19 Jul 2012 15:48:17 +0300 Subject: [PATCH] FIX: X-Include-JS requirements load order UploadField.js was always loaded last, causing the new template not to load and crashing the whole thing. Simply calling the forTemplate() method earlier, makes all the Form's requirements (including UploadField.js) being loaded first --- code/GridFieldBulkImageUpload_Request.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/code/GridFieldBulkImageUpload_Request.php b/code/GridFieldBulkImageUpload_Request.php index 0bbdc85..8d1f9e4 100644 --- a/code/GridFieldBulkImageUpload_Request.php +++ b/code/GridFieldBulkImageUpload_Request.php @@ -224,13 +224,15 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { $form->Backlink = $one_level_up->Link; } - // add these custom requirement after the UploadField is called -> depends on tmpl.js loaded with UploadField (avoid crashing) - // seems to fix some styling issue as well? + // this actually fixes the JS Requirements issue. + // Calling forTemplate() before other requirements forces SS to add the Form's X-Include-JS before + $formHTML = $form->forTemplate(); + Requirements::javascript('GridFieldBulkImageUpload/javascript/GridFieldBulkImageUpload.js'); Requirements::css('GridFieldBulkImageUpload/css/GridFieldBulkImageUpload.css'); - Requirements::javascript('GridFieldBulkImageUpload/javascript/GridFieldBulkImageUpload_downloadtemplate.js'); + Requirements::javascript('GridFieldBulkImageUpload/javascript/GridFieldBulkImageUpload_downloadtemplate.js'); - $response = new SS_HTTPResponse($form->forTemplate()); + $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;