ENHANCEMENT Better integration between new form javascript and tree in CMS

MINOR Various event and property renamings in CMSMain.js

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92635 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-11-21 02:37:45 +00:00
parent 502855cf24
commit 0b0e10d01d
2 changed files with 69 additions and 17 deletions

View File

@ -24,6 +24,20 @@
this._setupPinging(); this._setupPinging();
this._setupButtons(); this._setupButtons();
this._resizeChildren(); this._resizeChildren();
// artificially delay the resize event 200ms
// to avoid overlapping height changes in different onresize() methods
$(window).resize(function () {
var timerID = "timerLeftAndMainResize";
if (window[timerID]) clearTimeout(window[timerID]);
window[timerID] = setTimeout(function() {self._resizeChildren();}, 200);
});
// trigger resize whenever new tabs are shown
// @todo This is called multiple times when tabs are loaded
this.find('.ss-tabset').bind('tabsshow', function() {self._resizeChildren();});
$('#Form_EditForm').bind('loadnewpage', function() {self._resizeChildren();});
this._super(); this._super();
}, },
@ -101,15 +115,15 @@
}, },
/** /**
* @param DOMElement button The pressed button (optiona) * @param {DOMElement} button The pressed button (optional)
*/ */
ajaxSubmit: function(button) { ajaxSubmit: function(button) {
// default to first button if none given - simulates browser behaviour // default to first button if none given - simulates browser behaviour
if(!button) button = this.find(':submit:first'); if(!button) button = this.find(':submit:first');
var $form = this; var self = this;
this.trigger('beforeSubmit', [button]); this.trigger('ajaxsubmit', {button: button});
// set button to "submitting" state // set button to "submitting" state
$(button).addClass('loading'); $(button).addClass('loading');
@ -119,12 +133,10 @@
// validate if required // validate if required
if(!this.validate()) { if(!this.validate()) {
this.trigger('validationError', [button]);
// TODO Automatically switch to the tab/position of the first error // TODO Automatically switch to the tab/position of the first error
statusMessage("Validation failed.", "bad"); statusMessage("Validation failed.", "bad");
if($('Form_EditForm_action_save') && $('Form_EditForm_action_save').stopLoading) $('Form_EditForm_action_save').stopLoading(); $(button).removeClass('loading');
return false; return false;
} }
@ -136,12 +148,10 @@
$.post( $.post(
this.attr('action'), this.attr('action'),
data, data,
function(result) { function(response) {
$(button).removeClass('loading'); $(button).removeClass('loading');
$form.trigger('afterSubmit', [result]); self._loadResponse(response);
$form.loadNewPage();
}, },
// @todo Currently all responses are assumed to be evaluated // @todo Currently all responses are assumed to be evaluated
'script' 'script'
@ -159,22 +169,56 @@
* @return {boolean} * @return {boolean}
*/ */
validate: function() { validate: function() {
this.trigger('beforeValidate');
var isValid = true; var isValid = true;
this.trigger('afterValidate', [isValid]); this.trigger('validate', {isValid: isValid});
return isValid; return isValid;
}, },
loadNewPage: function(result) { /**
* @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 <form> tag
* with a custom HTML fragment. Useful e.g. for deleting a page in the CMS.
*
* @param {String} removeText
*/
remove: function(removeHTML) {
},
/**
* @param {String} result Either HTML for straight insertion, or eval'ed JavaScript.
* If passed as HTML, it is assumed that everying inside the <form> tag is replaced,
* but the old <form> tag itself stays intact.
*/
_loadResponse: function(response) {
// TinyMCE coupling // TinyMCE coupling
if(typeof tinymce_removeAll != 'undefined') tinymce_removeAll(); if(typeof tinymce_removeAll != 'undefined') tinymce_removeAll();
var html = response;
// Rewrite # links // Rewrite # links
result = result.replace(/(<a[^>]+href *= *")#/g, '$1' + window.location.href.replace(/#.*$/,'') + '#'); html = html.replace(/(<a[^>]+href *= *")#/g, '$1' + window.location.href.replace(/#.*$/,'') + '#');
// Rewrite iframe links (for IE) // Rewrite iframe links (for IE)
result = result.replace(/(<iframe[^>]*src=")([^"]+)("[^>]*>)/g, '$1' + $('base').attr('href') + '$2$3'); html = html.replace(/(<iframe[^>]*src=")([^"]+)("[^>]*>)/g, '$1' + $('base').attr('href') + '$2$3');
// Prepare iframes for removal, otherwise we get loading bugs // Prepare iframes for removal, otherwise we get loading bugs
this.find('iframe').each(function() { this.find('iframe').each(function() {
@ -182,7 +226,7 @@
this.remove(); this.remove();
}) })
this.html(result); this.html(html);
if(this.hasClass('validationerror')) { if(this.hasClass('validationerror')) {
statusMessage(ss.i18n._t('ModelAdmin.VALIDATIONERROR', 'Validation Error'), 'bad'); statusMessage(ss.i18n._t('ModelAdmin.VALIDATIONERROR', 'Validation Error'), 'bad');

View File

@ -204,7 +204,15 @@ TreeNodeAPI.prototype = {
}, },
getPageFromServer : function() { getPageFromServer : function() {
$('Form_EditForm').getPageFromServer(this.id.replace('record-',''), this); jQuery('#Form_EditForm').concrete('ss').load(
jQuery(this).find('a').attr('href'),
function(response) {
var pageID = jQuery(this).find(':input[name=ID]').val();
if(pageID) {
jQuery('#sitetree')[0].setCurrentByIdx(pageID);
}
}
);
_AJAX_LOADING = false; _AJAX_LOADING = false;
}, },
ajaxExpansion : function() { ajaxExpansion : function() {