From 2637969bcd99c2f07c5a0504498c5788864d5c37 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 12 Jun 2012 17:13:36 +0200 Subject: [PATCH] API CHANGE Renamed JS event from 'reloadeditform' on 'aftersubmitform', 'beforesave' to 'beforesubmitform'. Listening to bubbled event on container to avoid binding to forms which are removed before the event is triggered. --- admin/javascript/LeftAndMain.EditForm.js | 4 ++-- admin/javascript/LeftAndMain.Menu.js | 5 +---- admin/javascript/LeftAndMain.Preview.js | 9 ++------- admin/javascript/LeftAndMain.Tree.js | 12 +++++------- admin/javascript/LeftAndMain.js | 21 +++++++++------------ javascript/HtmlEditorField.js | 2 +- 6 files changed, 20 insertions(+), 33 deletions(-) diff --git a/admin/javascript/LeftAndMain.EditForm.js b/admin/javascript/LeftAndMain.EditForm.js index 2b87ce83f..850de067b 100644 --- a/admin/javascript/LeftAndMain.EditForm.js +++ b/admin/javascript/LeftAndMain.EditForm.js @@ -6,7 +6,7 @@ // Can't bind this through jQuery window.onbeforeunload = function(e) { var form = $('.cms-edit-form'); - form.trigger('beforesave'); + form.trigger('beforesubmitform'); if(form.is('.changed')) return ss.i18n._t('LeftAndMain.CONFIRMUNSAVEDSHORT'); }; @@ -142,7 +142,7 @@ * or the user wants to discard them. */ confirmUnsavedChanges: function() { - this.trigger('beforesave'); + this.trigger('beforesubmitform'); return (this.is('.changed')) ? confirm(ss.i18n._t('LeftAndMain.CONFIRMUNSAVED')) : true; }, diff --git a/admin/javascript/LeftAndMain.Menu.js b/admin/javascript/LeftAndMain.Menu.js index 5eb7fb30e..aa4d89d89 100644 --- a/admin/javascript/LeftAndMain.Menu.js +++ b/admin/javascript/LeftAndMain.Menu.js @@ -86,12 +86,9 @@ } self.updateItems(); }; - $('.cms-container').live('afterstatechange', function(e, data) { + $('.cms-container').live('afterstatechange aftersubmitform', function(e, data) { updateMenuFromResponse(data.xhr); }); - $('.cms-edit-form').live('reloadeditform', function(e, data) { - updateMenuFromResponse(data.xmlhttp); - }); // Sync collapsed state with parent panel this.parents('.cms-panel:first').bind('toggle', function(e) { diff --git a/admin/javascript/LeftAndMain.Preview.js b/admin/javascript/LeftAndMain.Preview.js index 56e1b68e7..e20ff770e 100644 --- a/admin/javascript/LeftAndMain.Preview.js +++ b/admin/javascript/LeftAndMain.Preview.js @@ -57,15 +57,10 @@ } else { self.block(); } - } - - // Listen to form loads. Limit to CMS forms for the moment - $('.cms-edit-form').bind('reloadeditform', function(e, ui) { - updateAfterXhr(); - }); + }; // Listen to history state changes - $('.cms-container').bind('afterstatechange', function(e) { + $('.cms-container').bind('afterstatechange aftersubmitform', function(e) { updateAfterXhr(); }); diff --git a/admin/javascript/LeftAndMain.Tree.js b/admin/javascript/LeftAndMain.Tree.js index 9c0134632..e0cc2e0cc 100644 --- a/admin/javascript/LeftAndMain.Tree.js +++ b/admin/javascript/LeftAndMain.Tree.js @@ -97,16 +97,12 @@ }); }); - $('.cms-container').bind('afterstatechange.tree', function(e, data) { - self.updateFromEditForm(e.origData); - }); - $('.cms-content').bind('reloadeditform.tree', function(e, data) { + $('.cms-container').bind('afterstatechange.tree aftersubmitform.tree', function(e, data) { self.updateFromEditForm(e.origData); }); }, onunmatch: function() { - $('.cms-container').unbind('afterstatechange.tree'); - $('.cms-content').unbind('reloadeditform.tree'); + $('.cms-container').unbind('afterstatechange.tree aftersubmitform.tree'); this._super(); }, @@ -208,7 +204,9 @@ /** * Assumes to be triggered by a form element with the following input fields: - * ID, ParentID, TreeTitle (or Title), ClassName + * ID, ParentID, TreeTitle (or Title), ClassName. + * + * @todo Serverside node refresh, see http://open.silverstripe.org/ticket/7450 */ updateFromEditForm: function(origData) { var self = this, diff --git a/admin/javascript/LeftAndMain.js b/admin/javascript/LeftAndMain.js index 4f14a6d88..3ac4ef9de 100644 --- a/admin/javascript/LeftAndMain.js +++ b/admin/javascript/LeftAndMain.js @@ -64,7 +64,7 @@ jQuery.noConflict(); * Events: * ajaxsubmit - ... * validate - ... - * reloadeditform - ... + * aftersubmitform - ... */ $('.cms-container').entwine({ @@ -102,10 +102,6 @@ jQuery.noConflict(); self.redraw(); }); - $('.cms-edit-form').live('reloadeditform', function(e, data) { - self.redraw(); - }); - // Remove loading screen $('.ss-loading-screen').hide(); $('body').removeClass('loading'); @@ -120,6 +116,9 @@ jQuery.noConflict(); onunmatch: function() { this._super(); }, + onaftersubmitform: function() { + this.redraw(); + }, redraw: function() { if(window.debug) console.log('redraw', this.attr('class'), this.get(0)); @@ -196,7 +195,7 @@ jQuery.noConflict(); // default to first button if none given - simulates browser behaviour if(!button) button = this.find('.Actions :submit:first'); - form.trigger('beforesave'); + form.trigger('beforesubmitform'); this.trigger('submitform', {form: form, button: button}); // set button to "submitting" state @@ -256,10 +255,7 @@ jQuery.noConflict(); newForm.find('#' + selectedTab.id).tabs('select', selectedTab.selected); }); - // Redraw the layout - $('.cms-container').redraw(); - - form.trigger('reloadeditform', {form: newForm, formData: formData, xmlhttp: xhr}); + newForm.trigger('aftersubmitform', {status: status, xhr: xhr, formData: formData}); }, dataType: 'json' }, ajaxOptions)); @@ -337,7 +333,7 @@ jQuery.noConflict(); var title = xhr.getResponseHeader('X-Title'); if(title) document.title = title; - var newFragments = {}, newContentEls = $([]); + var newFragments = {}, newContentEls; if(xhr.getResponseHeader('Content-Type') == 'text/json') { newFragments = data; } else { @@ -352,7 +348,8 @@ jQuery.noConflict(); }), newContentEl = $(html); // Add to result collection - newContentEls.add(newContentEl); + if(newContentEls) newContentEls.add(newContentEl); + else newContentEls = newContentEl; // Update panels if(newContentEl.find('.cms-container').length) { diff --git a/javascript/HtmlEditorField.js b/javascript/HtmlEditorField.js index bf7e7f24f..ff0eecdba 100644 --- a/javascript/HtmlEditorField.js +++ b/javascript/HtmlEditorField.js @@ -205,7 +205,7 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE; onmatch : function() { var self = this, edClass = this.data('editor') || ss.editorWrappers['default'], ed = edClass(); this.setEditor(ed); - this.closest('form').bind('beforesave', function() { + this.closest('form').bind('beforesubmitform', function() { // TinyMCE modifies input, so change tracking might get false // positives when comparing string values - don't save if the editor doesn't think its dirty. if(self.isChanged()) {