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
This commit is contained in:
colymba 2012-07-19 15:48:17 +03:00
parent 0567bb0841
commit 8a4066bef9

View File

@ -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;