diff --git a/admin/javascript/LeftAndMain.AddForm.js b/admin/javascript/LeftAndMain.AddForm.js index 5f32a841a..57eef8278 100644 --- a/admin/javascript/LeftAndMain.AddForm.js +++ b/admin/javascript/LeftAndMain.AddForm.js @@ -91,7 +91,7 @@ data.push({name:button.attr('name'),value:button.val()}); // TODO Should be set by hiddenfield already - $('.cms-content').submitForm( + $('.cms-container').submitForm( this, button, function() { diff --git a/admin/javascript/LeftAndMain.Content.js b/admin/javascript/LeftAndMain.Content.js index 2f69663ad..819292a0d 100644 --- a/admin/javascript/LeftAndMain.Content.js +++ b/admin/javascript/LeftAndMain.Content.js @@ -27,168 +27,6 @@ this.add(this.find('.cms-tabset')).redrawTabs(); this.layout(); - }, - - /** - * Function: ajaxSubmit - * - * Parameters: - * {DOMElement} button - The pressed button (optional) - * {Function} callback - Called in complete() handler of jQuery.ajax() - * {Object} ajaxOptions - Object literal to merge into $.ajax() call - * {boolean} loadResponse - Render response through _loadResponse() (Default: true) - * - * Returns: - * (boolean) - */ - submitForm: function(form, button, callback, ajaxOptions, loadResponse) { - var self = this; - - // 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('.Actions :submit:first'); - - form.trigger('beforesave'); - this.trigger('submitform', {form: form, button: button}); - - // set button to "submitting" state - $(button).addClass('loading'); - - // validate if required - if(!form.validate()) { - // TODO Automatically switch to the tab/position of the first error - statusMessage("Validation failed.", "bad"); - - $(button).removeClass('loading'); - - return false; - } - - // save tab selections in order to reconstruct them later - var selectedTabs = []; - form.find('.cms-tabset').each(function(i, el) { - if($(el).attr('id')) selectedTabs.push({id:$(el).attr('id'), selected:$(el).tabs('option', 'selected')}); - }); - - // get all data from the form - var formData = form.serializeArray(); - // add button action - formData.push({name: $(button).attr('name'), value:'1'}); - // Artificial HTTP referer, IE doesn't submit them via ajax. - // Also rewrites anchors to their page counterparts, which is important - // as automatic browser ajax response redirects seem to discard the hash/fragment. - formData.push({name: 'BackURL', value:History.getPageUrl()}); - - // Standard Pjax behaviour is to replace the submitted form with new content. - // The returned view isn't always decided upon when the request - // is fired, so the server might decide to change it based on its own logic, - // sending back different `X-Pjax` headers and content - jQuery.ajax(jQuery.extend({ - headers: { - "X-Pjax" : "CurrentForm,Breadcrumbs" - }, - url: form.attr('action'), - data: formData, - type: 'POST', - complete: function(xmlhttp, status) { - $(button).removeClass('loading'); - - // TODO This should be using the plugin API - form.removeClass('changed'); - - if(callback) callback(xmlhttp, status); - - // pass along original form data to enable old/new comparisons - if(loadResponse !== false) { - self.submitForm_responseHandler(form, xmlhttp.responseText, status, xmlhttp, formData); - } - - // Re-init tabs (in case the form tag itself is a tabset) - if(self.hasClass('cms-tabset')) self.removeClass('cms-tabset').addClass('cms-tabset'); - - // re-select previously saved tabs - $.each(selectedTabs, function(i, selectedTab) { - form.find('#' + selectedTab.id).tabs('select', selectedTab.selected); - }); - - // Redraw the layout - $('.cms-container').redraw(); - }, - dataType: 'html' - }, ajaxOptions)); - - return false; - }, - - /** - * Function: _loadResponse - * - * Parameters: - * {String} data - Either HTML for straight insertion, or eval'ed JavaScript. - * If passed as HTML, it is assumed that everying inside the