diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index f99c1433..6aa52f1d 100644 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -626,10 +626,10 @@ class ModelAdmin_RecordController extends Controller { function edit($request) { if ($this->currentRecord) { if(Director::is_ajax()) { - return $this->EditForm()->forAjaxTemplate(); + return new HTTPResponse($this->EditForm()->forAjaxTemplate(), 200, "Page loaded"); } else { // This is really quite ugly; to fix will require a change in the way that customise() works. :-( - return$this->parentController->parentController->customise(array( + return $this->parentController->parentController->customise(array( 'Right' => $this->parentController->parentController->customise(array( 'EditForm' => $this->EditForm() ))->renderWith('ModelAdmin_right') diff --git a/javascript/ModelAdmin.js b/javascript/ModelAdmin.js index 46a54ad6..5eca3426 100644 --- a/javascript/ModelAdmin.js +++ b/javascript/ModelAdmin.js @@ -187,13 +187,11 @@ jQuery(document).ready(function() { * @todo Should this be turned into a method on the #Form_EditForm using effen or something? */ function showRecord(uri) { - jQuery.get(uri, function(result){ - jQuery('#right #ModelAdminPanel').html(result); + jQuery('#right #ModelAdminPanel').load(uri, standardStatusHandler(function(result) { jQuery('#SearchForm_holder').tabs(); - Behaviour.apply(); // refreshes ComplexTableField jQuery('#right ul.tabstrip').tabs(); - }); + })); } /** @@ -210,6 +208,29 @@ jQuery(document).ready(function() { }); return data; } + + /** + * Standard SilverStripe status handler for ajax responses + * It will generate a status message out of the response, and only call the callback for successful responses + * + * To use: + * Instead of passing your callback function as: + * function(response) { ... } + * + * Pass it as this: + * standardStatusHandler(function(response) { ... }) + */ + function standardStatusHandler(callback) { + return function(response, status, xhr) { + if(status == 'success') { + statusMessage(xhr.statusText, "good"); + callback(response, status, xhr); + } else { + statusMessage(xhr.statusText, "bad"); + } + } + } + }); /**