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.

This commit is contained in:
Ingo Schommer 2012-06-12 17:13:36 +02:00
parent ed9c856442
commit 2637969bcd
6 changed files with 20 additions and 33 deletions

View File

@ -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;
},

View File

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

View File

@ -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();
});

View File

@ -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,

View File

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

View File

@ -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()) {