Introduce notion of using HTTP status text to pass status message to the end user

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@62287 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-09-12 01:50:08 +00:00
parent b7b59bd916
commit 117f1171e7
2 changed files with 27 additions and 6 deletions

View File

@ -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')

View File

@ -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");
}
}
}
});
/**