(function($) {
/**
* Available Custom Events:
*
* - ajaxsubmit
* - validate
* - loadnewpage
*
* @class Main LeftAndMain interface with some control
* panel and an edit form.
* @name ss.LeftAndMain
*/
$('.LeftAndMain').concrete('ss', function($){return
/** @lends ss.EditMemberProfile */
{
/**
* @type Number
*/
PingIntervalSeconds: 5*60,
onmatch: function() {
this._setupPinging();
this._setupButtons();
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();
},
_setupPinging: function() {
// setup pinging for login expiry
setInterval(function() {
jQuery.get("Security/ping");
}, this.PingIntervalSeconds() * 1000);
},
/**
* Make all buttons "hoverable" with jQuery theming.
*/
_setupButtons: function() {
// Initialize buttons
this.find(':submit, button, :reset').livequery(function() {
jQuery(this).addClass(
'ui-state-default ' +
'ui-corner-all'
)
.hover(
function() {
$(this).addClass('ui-state-hover');
},
function() {
$(this).removeClass('ui-state-hover');
}
)
.focus(function() {
$(this).addClass('ui-state-focus');
})
.blur(function() {
$(this).removeClass('ui-state-focus');
});
});
},
/**
* Resize elements in center panel
* to fit the boundary box provided by the layout manager
*/
_resizeChildren: function() {
$('#Form_EditForm').fitHeightToParent();
$('#Form_EditForm fieldset', this).fitHeightToParent();
// Order of resizing is important: Outer to inner
// TODO Only supports two levels of tabs at the moment
$('#Form_EditForm fieldset > .ss-tabset', this).fitHeightToParent();
$('#Form_EditForm fieldset > .ss-tabset > .tab', this).fitHeightToParent();
$('#Form_EditForm fieldset > .ss-tabset > .tab > .ss-tabset', this).fitHeightToParent();
$('#Form_EditForm fieldset > .ss-tabset > .tab > .ss-tabset > .tab', this).fitHeightToParent();
}
}});
/**
* @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