mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
ENHANCEMENT Defaulting to action_save button in ajaxSubmit() javascript logic in CMS form
ENHANCEMENT Making ajax options overrideable in ajaxSubmit() javascript logic in CMS form git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92684 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
54a7beb5e7
commit
5f8a164d21
@ -31,10 +31,13 @@
|
||||
|
||||
/**
|
||||
* @param {DOMElement} button The pressed button (optional)
|
||||
* @param {Function} callback Called in complete() handler of jQuery.ajax()
|
||||
*/
|
||||
ajaxSubmit: function(button) {
|
||||
ajaxSubmit: function(button, callback, ajaxOptions) {
|
||||
// look for save button
|
||||
if(!button) button = this.find('.Actions :submit[name=action_save]');
|
||||
// default to first button if none given - simulates browser behaviour
|
||||
if(!button) button = this.find(':submit:first');
|
||||
if(!button) button = this.find('.Actions :submit:first');
|
||||
|
||||
var self = this;
|
||||
|
||||
@ -60,18 +63,20 @@
|
||||
var formData = this.serializeArray();
|
||||
// add button action
|
||||
formData.push({name: $(button).attr('name'), value:'1'});
|
||||
|
||||
$.ajax({
|
||||
$.ajax($.extend({
|
||||
url: this.attr('action'),
|
||||
data: formData,
|
||||
type: 'POST',
|
||||
complete: function(xmlhttp, status) {
|
||||
$(button).removeClass('loading');
|
||||
|
||||
if(callback) callback(xmlhttp, status);
|
||||
|
||||
// pass along original form data to enable old/new comparisons
|
||||
self._loadResponse(xmlhttp.responseText, status, xmlhttp, formData);
|
||||
},
|
||||
dataType: 'html'
|
||||
});
|
||||
}, ajaxOptions));
|
||||
|
||||
return false;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user