diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index d1fe098c..42540903 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -228,6 +228,7 @@ class LeftAndMain extends Controller { Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain_left.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain_right.js'); + Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.EditForm.js'); Requirements::javascript(CMS_DIR . '/javascript/SideTabs.js'); Requirements::javascript(CMS_DIR . '/javascript/SideReports.js'); diff --git a/javascript/LeftAndMain.EditForm.js b/javascript/LeftAndMain.EditForm.js new file mode 100644 index 00000000..7daff135 --- /dev/null +++ b/javascript/LeftAndMain.EditForm.js @@ -0,0 +1,178 @@ +(function($) { + + /** + * @class Base edit form, provides ajaxified saving + * and reloading itself through the ajax return values. + * Takes care of resizing tabsets within the layout container. + * @name ss.Form_EditForm + */ + $('#Form_EditForm').concrete('ss',function($){ + return/** @lends ss.Form_EditForm */{ + + /** + * @type String HTML text to show when the form has been deleted. + */ + RemoveHtml: null, + + /** + * Suppress submission unless it is handled through ajaxSubmit() + */ + onsubmit: function(e) { + return false; + }, + + /** + * @param {DOMElement} button The pressed button (optional) + */ + ajaxSubmit: function(button) { + // default to first button if none given - simulates browser behaviour + if(!button) button = this.find(':submit:first'); + + var self = this; + + this.trigger('ajaxsubmit', {button: button}); + + // set button to "submitting" state + $(button).addClass('loading'); + + // @todo TinyMCE coupling + if(typeof tinyMCE != 'undefined') tinyMCE.triggerSave(); + + // validate if required + if(!this.validate()) { + // TODO Automatically switch to the tab/position of the first error + statusMessage("Validation failed.", "bad"); + + $(button).removeClass('loading'); + + return false; + } + + // get all data from the form + var data = this.serializeArray(); + // add button action + data.push({name: $(button).attr('name'), value:'1'}); + $.post( + this.attr('action'), + data, + function(response) { + $(button).removeClass('loading'); + + self._loadResponse(response); + }, + // @todo Currently all responses are assumed to be evaluated + 'script' + ); + + return false; + }, + + /** + * Hook in (optional) validation routines. + * Currently clientside validation is not supported out of the box in the CMS. + * + * @todo Placeholder implementation + * + * @return {boolean} + */ + validate: function() { + var isValid = true; + this.trigger('validate', {isValid: isValid}); + + return isValid; + }, + + /** + * @param String url + * @param Function callback (Optional) + */ + load: function(url, callback) { + var self = this; + $.get( + url, + function(response) { + self._loadResponse(response); + if(callback) callback.apply(self, [response]); + }, + // @todo Currently all responses are assumed to be evaluated + 'script' + ); + }, + + /** + * Remove everying inside the