From 5f8a164d216377ba88b8c71e2bed7c02850aa87d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 21 Nov 2009 03:14:05 +0000 Subject: [PATCH] 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 --- javascript/LeftAndMain.EditForm.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/javascript/LeftAndMain.EditForm.js b/javascript/LeftAndMain.EditForm.js index ba216662..9b758ce7 100644 --- a/javascript/LeftAndMain.EditForm.js +++ b/javascript/LeftAndMain.EditForm.js @@ -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; },