Skip to content

Commit

Permalink
BUGFIX Fixes to CMS EditForm javascript change tracking and event tri…
Browse files Browse the repository at this point in the history
…ggering

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92689 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu committed Nov 21, 2009
1 parent f267dac commit 4c5e847
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions javascript/LeftAndMain.EditForm.js
Expand Up @@ -6,10 +6,16 @@
* Takes care of resizing tabsets within the layout container. * Takes care of resizing tabsets within the layout container.
* @name ss.Form_EditForm * @name ss.Form_EditForm
* @require jquery.changetracker * @require jquery.changetracker
*
* <h3>Events</h3>
* - ajaxsubmit: Form is about to be submitted through ajax
* - validate: Contains validation result
* - removeform: A form is about to be removed from the DOM
* - load: Form is about to be loaded through ajax
*/ */
$('#Form_EditForm').concrete('ss',function($){ $('#Form_EditForm').concrete('ss',function($){
return/** @lends ss.Form_EditForm */{ return/** @lends ss.Form_EditForm */{

/** /**
* @type String HTML text to show when the form has been deleted. * @type String HTML text to show when the form has been deleted.
* @todo i18n * @todo i18n
Expand Down Expand Up @@ -51,12 +57,16 @@


// @todo TinyMCE coupling // @todo TinyMCE coupling
if(typeof tinyMCE != 'undefined') tinyMCE.triggerSave(); if(typeof tinyMCE != 'undefined') tinyMCE.triggerSave();

// check for form changes
if(self.is('.changed')) { if(self.is('.changed')) {
var msg = ss.i18n._t('LeftAndMain.CONFIRMUNSAVED'); var msg = ss.i18n._t('LeftAndMain.CONFIRMUNSAVED');
// returned string will trigger a confirm() dialog, // returned string will trigger a confirm() dialog,
// but only if the method is triggered by an event // but only if the method is triggered by an event
return (doConfirm) ? confirm(msg) : msg; return (doConfirm) ? confirm(msg) : msg;
} }

return null;
}, },


/** /**
Expand Down Expand Up @@ -150,9 +160,11 @@
load: function(url, callback, ajaxOptions) { load: function(url, callback, ajaxOptions) {
var self = this; var self = this;


// Alert when unsaved changes are present // Alert when unsaved changes are present
if(!this._checkChangeTracker(true)) return false; if(this._checkChangeTracker(true) == false) return false;


this.trigger('load');

return jQuery.ajax(jQuery.extend({ return jQuery.ajax(jQuery.extend({
url: url, url: url,
complete: function(xmlhttp, status) { complete: function(xmlhttp, status) {
Expand All @@ -170,13 +182,23 @@
/** /**
* Remove everying inside the <form> tag * Remove everying inside the <form> tag
* with a custom HTML fragment. Useful e.g. for deleting a page in the CMS. * with a custom HTML fragment. Useful e.g. for deleting a page in the CMS.
* Checks for unsaved changes before removing the form
* *
* @param {String} removeText Short note why the form has been removed, displayed in <p> tags. * @param {String} placeholderHtml Short note why the form has been removed, displayed in <p> tags.
* Falls back to the default RemoveText() option (Optional) * Falls back to the default RemoveText() option (Optional)
*/ */
removeForm: function(removeText) { removeForm: function(placeholderHtml) {
if(!removeText) removeText = this.RemoveText(); if(!placeholderHtml) placeholderHtml = this.PlaceholderHtml();
this.html('<p>' + removeText + '</p>');
// Alert when unsaved changes are present
if(this._checkChangeTracker(true) == false) return false;

this.trigger('removeform');

this.html(placeholderHtml);

// TODO This should be using the plugin API
this.removeClass('changed');
}, },


/** /**
Expand Down

0 comments on commit 4c5e847

Please sign in to comment.