2009-11-21 03:36:00 +01:00
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Main LeftAndMain interface with some control
|
|
|
|
|
* panel and an edit form.
|
|
|
|
|
*
|
|
|
|
|
* Events:
|
|
|
|
|
* - beforeSave
|
|
|
|
|
* - afterSave
|
|
|
|
|
* - beforeValidate
|
|
|
|
|
* - afterValidate
|
|
|
|
|
*/
|
|
|
|
|
$('.LeftAndMain').concrete({ss:{leftAndMain:{
|
|
|
|
|
onmatch: function() {
|
|
|
|
|
this.ss().leftAndMain()._setupPinging();
|
|
|
|
|
this.ss().leftAndMain()._setupButtons();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_setupPinging: function() {
|
|
|
|
|
var pingIntervalSeconds = 5*60;
|
|
|
|
|
|
|
|
|
|
// setup pinging for login expiry
|
|
|
|
|
setInterval(function() {
|
|
|
|
|
$.get("Security/ping");
|
|
|
|
|
}, pingIntervalSeconds * 1000);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make all buttons "hoverable" with jQuery theming.
|
|
|
|
|
*/
|
|
|
|
|
_setupButtons: function() {
|
|
|
|
|
// Initialize buttons
|
|
|
|
|
this.find(':submit, button').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');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}}});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base edit form, provides ajaxified saving
|
|
|
|
|
* and reloading itself through the ajax return values.
|
|
|
|
|
* Takes care of resizing tabsets within the layout container.
|
|
|
|
|
*/
|
|
|
|
|
$('#Form_EditForm').concrete({ss:{
|
|
|
|
|
onmatch: function() {
|
|
|
|
|
var $this = this;
|
|
|
|
|
// artificially delay the resize event 200ms
|
|
|
|
|
// to avoid overlapping height changes in different onresize() methods
|
|
|
|
|
$(window).resize(function () {
|
|
|
|
|
var timerID = "timerLayout_"+this.id;
|
|
|
|
|
if (window[timerID]) clearTimeout(window[timerID]);
|
|
|
|
|
window[timerID] = setTimeout(function() {$this.ss()._resizeChildren();}, 200);
|
|
|
|
|
}).trigger('resize');
|
|
|
|
|
|
|
|
|
|
// trigger resize whenever new tabs are shown
|
|
|
|
|
// @todo This is called multiple times when tabs are loaded
|
|
|
|
|
this.find('.ss-tabset').bind('tabsshow', function() {$this.ss()._resizeChildren();});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Suppress submission unless it is handled through save()
|
|
|
|
|
*/
|
|
|
|
|
onsubmit: function(e) {
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param DOMElement button The pressed button (optiona)
|
|
|
|
|
*/
|
|
|
|
|
ajaxSubmit: function(button) {
|
|
|
|
|
// default to first button if none given - simulates browser behaviour
|
|
|
|
|
if(!button) button = this.find(':submit:first');
|
|
|
|
|
|
|
|
|
|
var $form = this;
|
|
|
|
|
|
|
|
|
|
this.trigger('beforeSubmit', [button]);
|
|
|
|
|
|
|
|
|
|
// set button to "submitting" state
|
|
|
|
|
$(button).addClass('loading');
|
|
|
|
|
|
|
|
|
|
// @todo TinyMCE coupling
|
|
|
|
|
if(typeof tinyMCE != 'undefined') tinyMCE.triggerSave();
|
|
|
|
|
|
|
|
|
|
// validate if required
|
|
|
|
|
if(!this.ss().validate()) {
|
|
|
|
|
this.trigger('validationError', [button]);
|
|
|
|
|
|
|
|
|
|
// TODO Automatically switch to the tab/position of the first error
|
|
|
|
|
statusMessage("Validation failed.", "bad");
|
|
|
|
|
|
|
|
|
|
if($('Form_EditForm_action_save') && $('Form_EditForm_action_save').stopLoading) $('Form_EditForm_action_save').stopLoading();
|
|
|
|
|
|
|
|
|
|
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(result) {
|
|
|
|
|
$(button).removeClass('loading');
|
|
|
|
|
|
|
|
|
|
$form.trigger('afterSubmit', [result]);
|
|
|
|
|
|
|
|
|
|
$form.ss().loadNewPage();
|
|
|
|
|
},
|
|
|
|
|
// @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.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
validate: function() {
|
|
|
|
|
this.trigger('beforeValidate');
|
|
|
|
|
var isValid = true;
|
|
|
|
|
this.trigger('afterValidate', [isValid]);
|
|
|
|
|
|
|
|
|
|
return isValid;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
loadNewPage: function(result) {
|
|
|
|
|
// TinyMCE coupling
|
|
|
|
|
if(typeof tinymce_removeAll != 'undefined') tinymce_removeAll();
|
|
|
|
|
|
|
|
|
|
// Rewrite # links
|
|
|
|
|
result = result.replace(/(<a[^>]+href *= *")#/g, '$1' + window.location.href.replace(/#.*$/,'') + '#');
|
|
|
|
|
|
|
|
|
|
// Rewrite iframe links (for IE)
|
|
|
|
|
result = result.replace(/(<iframe[^>]*src=")([^"]+)("[^>]*>)/g, '$1' + $('base').attr('href') + '$2$3');
|
|
|
|
|
|
|
|
|
|
// Prepare iframes for removal, otherwise we get loading bugs
|
|
|
|
|
this.find('iframe').each(function() {
|
|
|
|
|
this.contentWindow.location.href = 'about:blank';
|
|
|
|
|
this.remove();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.html(result);
|
|
|
|
|
|
|
|
|
|
if(this.hasClass('validationerror')) {
|
|
|
|
|
statusMessage(ss.i18n._t('ModelAdmin.VALIDATIONERROR', 'Validation Error'), 'bad');
|
|
|
|
|
} else {
|
|
|
|
|
statusMessage(ss.i18n._t('ModelAdmin.SAVED', 'Saved'), 'good');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Behaviour.apply(); // refreshes ComplexTableField
|
|
|
|
|
|
|
|
|
|
// If there's a title field and it's got a "new XX" value, focus/select that first
|
|
|
|
|
// This is really a little too CMS-specific (as opposed to LeftAndMain), but the cleanup can happen after jQuery refactoring
|
|
|
|
|
if($('input#Form_EditForm_Title') && $('input#Form_EditForm_Title').value.match(/^new/i)) {
|
|
|
|
|
$('input#Form_EditForm_Title').select();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resize elements in center panel
|
|
|
|
|
* to fit the boundary box provided by the layout manager
|
|
|
|
|
*/
|
|
|
|
|
_resizeChildren: function() {
|
|
|
|
|
this.fitHeightToParent();
|
|
|
|
|
$('fieldset', this).fitHeightToParent();
|
|
|
|
|
// Order of resizing is important: Outer to inner
|
|
|
|
|
// TODO Only supports two levels of tabs at the moment
|
|
|
|
|
$('fieldset > .ss-tabset', this).fitHeightToParent();
|
|
|
|
|
$('fieldset > .ss-tabset > .tab', this).fitHeightToParent();
|
|
|
|
|
$('fieldset > .ss-tabset > .tab > .ss-tabset', this).fitHeightToParent();
|
|
|
|
|
$('fieldset > .ss-tabset > .tab > .ss-tabset > .tab', this).fitHeightToParent();
|
|
|
|
|
}
|
|
|
|
|
}});
|
|
|
|
|
|
|
|
|
|
$('#Form_EditForm .Actions :submit').concrete({ss:{
|
|
|
|
|
onclick: function(e) {
|
|
|
|
|
$(this[0].form).ss().ajaxSubmit(this);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}});
|
|
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
|
|
jQuery(document).ready(function() {
|
|
|
|
|
// @todo remove
|
|
|
|
|
jQuery.concrete.triggerMatching();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
var _AJAX_LOADING = false;
|
|
|
|
|
|
|
|
|
|
Behaviour.register({
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
'#MainMenu li' : {
|
2007-09-15 03:25:07 +02:00
|
|
|
|
onclick : function(event) {
|
2007-09-14 21:30:11 +02:00
|
|
|
|
return LeftAndMain_window_unload(); // Confirm if there are unsaved changes
|
2007-09-15 03:25:07 +02:00
|
|
|
|
window.location.href = this.getElementsByTagName('a')[0].href;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
Event.stop(event);
|
|
|
|
|
}
|
|
|
|
|
},
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
'#Menu-help' : {
|
|
|
|
|
onclick : function() {
|
|
|
|
|
var w = window.open(this.getElementsByTagName('a')[0].href, 'help');
|
|
|
|
|
w.focus();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-09-14 21:30:11 +02:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'#Logo' : {
|
|
|
|
|
onclick : function() {
|
|
|
|
|
var w = window.open(this.getElementsByTagName('a')[0].href);
|
|
|
|
|
w.focus();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-09-27 23:16:23 +02:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'#EditMemberProfile': {
|
|
|
|
|
onclick: function(e) {
|
|
|
|
|
var el = Event.element(e);
|
2009-02-03 04:26:44 +01:00
|
|
|
|
GB_show('Edit Profile', el.attributes.href.value, 290, 500);
|
2007-09-27 23:16:23 +02:00
|
|
|
|
Event.stop(e);
|
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-27 23:16:23 +02:00
|
|
|
|
});
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LeftAndMain_window_unload = function() {
|
|
|
|
|
window.exiting = true; // this is used by prototype
|
2007-09-14 21:30:11 +02:00
|
|
|
|
if(typeof autoSave == 'function') {
|
|
|
|
|
return autoSave(true);
|
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-14 21:30:11 +02:00
|
|
|
|
// Event.observe(window, 'beforeunload', LeftAndMain_window_unload);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unlock the locked status message.
|
|
|
|
|
* Show a queued message, if one exists
|
|
|
|
|
*/
|
|
|
|
|
function unlockStatusMessage() {
|
2007-09-15 03:25:07 +02:00
|
|
|
|
statusMessage.locked = false;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
if(statusMessage.queued) {
|
|
|
|
|
statusMessage(
|
|
|
|
|
statusMessage.queued.msg,
|
|
|
|
|
statusMessage.queued.type,
|
2007-09-15 03:25:07 +02:00
|
|
|
|
statusMessage.queued.showNetworkActivity);
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
statusMessage.queued = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Submit the given form and evaluate the Ajax response.
|
|
|
|
|
* Needs to be bound to an object with the following parameters to work:
|
|
|
|
|
* - form
|
|
|
|
|
* - action
|
|
|
|
|
* - verb
|
2007-09-15 03:25:07 +02:00
|
|
|
|
*
|
2007-07-19 12:40:05 +02:00
|
|
|
|
* The bound function can then be called, with the arguments passed
|
|
|
|
|
*/
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
function ajaxSubmitForm(automated, callAfter, form, action, verb) {
|
|
|
|
|
var alreadySaved = false;
|
|
|
|
|
if($(form).elements.length < 2) alreadySaved = true;
|
|
|
|
|
|
|
|
|
|
if(alreadySaved) {
|
|
|
|
|
if(callAfter) callAfter();
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
} else {
|
|
|
|
|
statusMessage(verb + '...', '', true);
|
|
|
|
|
|
|
|
|
|
var success = function(response) {
|
|
|
|
|
Ajax.Evaluator(response);
|
|
|
|
|
if(callAfter) callAfter();
|
|
|
|
|
}
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
if(callAfter) success = success.bind({callAfter : callAfter});
|
|
|
|
|
Ajax.SubmitForm(form, action, {
|
|
|
|
|
onSuccess : success,
|
|
|
|
|
onFailure : function(response) {
|
|
|
|
|
errorMessage('Error ' + verb, response);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Behaviour of the statuts message.
|
|
|
|
|
*/
|
|
|
|
|
Behaviour.register({
|
|
|
|
|
'#statusMessage' : {
|
|
|
|
|
showMessage : function(message, type, waitTime, clearManually) {
|
|
|
|
|
if(this.fadeTimer) {
|
|
|
|
|
clearTimeout(this.fadeTimer);
|
|
|
|
|
this.fadeTimer = null;
|
|
|
|
|
}
|
|
|
|
|
if(this.currentEffect) {
|
|
|
|
|
this.currentEffect.cancel();
|
|
|
|
|
this.currentEffect = null;
|
|
|
|
|
}
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
this.innerHTML = message;
|
|
|
|
|
this.className = type;
|
2007-09-15 03:25:07 +02:00
|
|
|
|
Element.setOpacity(this, 1);
|
|
|
|
|
|
2008-09-30 05:04:35 +02:00
|
|
|
|
//this.style.position = 'absolute';
|
2007-07-19 12:40:05 +02:00
|
|
|
|
this.style.display = '';
|
|
|
|
|
this.style.visibility = '';
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
if(!clearManually) {
|
|
|
|
|
this.fade(0.5,waitTime ? waitTime : 5);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
clearMessage : function(waitTime) {
|
|
|
|
|
this.fade(0.5, waitTime);
|
|
|
|
|
},
|
|
|
|
|
fade: function(fadeTime, waitTime) {
|
|
|
|
|
if(!fadeTime) fadeTime = 0.5;
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
|
|
|
|
// Wait a bit before fading
|
2007-07-19 12:40:05 +02:00
|
|
|
|
if(waitTime) {
|
|
|
|
|
this.fadeTimer = setTimeout((function() {
|
|
|
|
|
this.fade(fadeTime);
|
|
|
|
|
}).bind(this), waitTime * 1000);
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
// Fade straight away
|
|
|
|
|
} else {
|
|
|
|
|
this.currentEffect = new Effect.Opacity(this,
|
2007-09-15 03:25:07 +02:00
|
|
|
|
{ duration: 0.5,
|
|
|
|
|
transition: Effect.Transitions.linear,
|
2007-07-19 12:40:05 +02:00
|
|
|
|
from: 1.0, to: 0.0,
|
|
|
|
|
afterFinish : this.afterFade.bind(this) });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
afterFade : function() {
|
|
|
|
|
this.style.visibility = 'hidden';
|
|
|
|
|
this.style.display = 'none';
|
|
|
|
|
this.innerHTML = '';
|
|
|
|
|
}
|
2007-09-15 03:25:07 +02:00
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
2007-09-15 03:25:07 +02:00
|
|
|
|
* Show a status message.
|
|
|
|
|
*
|
2007-07-19 12:40:05 +02:00
|
|
|
|
* @param msg String
|
|
|
|
|
* @param type String (optional) can be 'good' or 'bad'
|
|
|
|
|
* @param clearManually boolean Don't automatically fade message.
|
2007-09-16 04:25:07 +02:00
|
|
|
|
* @param container custom #statusMessage element to show message.
|
2007-07-19 12:40:05 +02:00
|
|
|
|
*/
|
2007-09-16 04:25:07 +02:00
|
|
|
|
function statusMessage(msg, type, clearManually, container) {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
var statusMessageEl = $('statusMessage');
|
2007-09-16 04:25:07 +02:00
|
|
|
|
if(container != null) statusMessageEl = container;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
if(statusMessageEl) {
|
|
|
|
|
if(msg) {
|
2009-03-12 17:39:25 +01:00
|
|
|
|
statusMessageEl.showMessage(msg, type, msg.length / 10, clearManually);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
} else {
|
|
|
|
|
statusMessageEl.clearMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearStatusMessage() {
|
|
|
|
|
$('statusMessage').clearMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when something goes wrong
|
|
|
|
|
*/
|
|
|
|
|
function errorMessage(msg, fullMessage) {
|
2008-09-16 23:46:08 +02:00
|
|
|
|
// Show complex error for developers in the console
|
|
|
|
|
if(fullMessage) {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
// Get the message from an Ajax response object
|
|
|
|
|
try {
|
|
|
|
|
if(typeof fullMessage == 'object') fullMessage = fullMessage.status + '//' + fullMessage.responseText;
|
|
|
|
|
} catch(er) {
|
|
|
|
|
fullMessage = "";
|
|
|
|
|
}
|
2008-09-17 00:08:02 +02:00
|
|
|
|
console.error(fullMessage);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
2008-09-16 23:46:08 +02:00
|
|
|
|
|
|
|
|
|
msg = msg.replace(/\n/g,'<br>');
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2008-09-16 23:46:08 +02:00
|
|
|
|
$('statusMessage').showMessage(msg,'bad');
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ajaxErrorHandler(response) {
|
2008-09-16 23:46:08 +02:00
|
|
|
|
errorMessage('Server Error', response);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Applying StatusTitle to an element will mean that the title attribute is shown as a statusmessage
|
|
|
|
|
* upon hover
|
|
|
|
|
*/
|
2007-09-15 02:57:22 +02:00
|
|
|
|
/* Commenting out because on IE6, IE7, and Safari 3, the statusmessage becomes
|
|
|
|
|
* 'null' on 2nd hover and because there is not room for long titles when
|
|
|
|
|
* action buttons are on the same line.
|
2007-07-19 12:40:05 +02:00
|
|
|
|
StatusTitle = Class.create();
|
|
|
|
|
StatusTitle.prototype = {
|
|
|
|
|
onmouseover : function() {
|
|
|
|
|
if(this.title) {
|
|
|
|
|
this.message = this.title;
|
|
|
|
|
this.title = null;
|
|
|
|
|
}
|
|
|
|
|
if(this.message) {
|
|
|
|
|
$('statusMessage').showMessage(this.message);
|
2007-09-15 03:25:07 +02:00
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
},
|
|
|
|
|
onmouseout : function() {
|
|
|
|
|
if(this.message) {
|
|
|
|
|
$('statusMessage').fade(0.3,1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-09-15 02:57:22 +02:00
|
|
|
|
*/
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ChangeTracker is a class that can be applied to forms to support change tracking on forms.
|
|
|
|
|
*/
|
|
|
|
|
ChangeTracker = Class.create();
|
|
|
|
|
ChangeTracker.prototype = {
|
|
|
|
|
initialize: function() {
|
|
|
|
|
this.resetElements();
|
|
|
|
|
},
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Reset all the 'changed field' data.
|
|
|
|
|
*/
|
|
|
|
|
resetElements: function(debug) {
|
|
|
|
|
var elements = Form.getElements(this);
|
|
|
|
|
var i, element;
|
|
|
|
|
for(i=0;element=elements[i];i++) {
|
|
|
|
|
// Initialise each element
|
|
|
|
|
if(element.resetChanged) {
|
|
|
|
|
element.resetChanged();
|
|
|
|
|
} else {
|
|
|
|
|
element.originalSerialized = Form.Element.serialize(element);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
field_changed: function() {
|
2009-04-29 03:44:28 +02:00
|
|
|
|
// Something a value will go from 'undefined' to ''. Ignore such changes
|
|
|
|
|
if((this.originalSerialized+'') == 'undefined') return Form.Element.serialize(this) ? true : false;
|
|
|
|
|
else return this.originalSerialized != Form.Element.serialize(this);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
},
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Returns true if something in the form has been changed
|
|
|
|
|
*/
|
|
|
|
|
isChanged: function() {
|
|
|
|
|
var elements = Form.getElements(this);
|
|
|
|
|
var i, element;
|
|
|
|
|
for(i=0;element=elements[i];i++) {
|
2009-02-03 04:56:56 +01:00
|
|
|
|
// NOTE: TinyMCE coupling
|
|
|
|
|
// Ignore mce-generated elements
|
|
|
|
|
if(element.className.substr(0,3) == 'mce') continue;
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
if(!element.isChanged) element.isChanged = this.field_changed;
|
|
|
|
|
if(!this.changeDetection_fieldsToIgnore[element.name] && element.isChanged()) {
|
2009-04-29 03:44:28 +02:00
|
|
|
|
//console.log('Changed:'+ element.id + '(' + this.originalSerialized +')->('+Form.Element.serialize(element)+')' );
|
|
|
|
|
//console.log(element)
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
changeDetection_fieldsToIgnore : {
|
|
|
|
|
'Sort' : true
|
|
|
|
|
},
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Serialize only the fields to change.
|
|
|
|
|
* You can specify the names of fields that must be included as arguments
|
|
|
|
|
*/
|
|
|
|
|
serializeChangedFields: function() {
|
|
|
|
|
var elements = Form.getElements(this);
|
|
|
|
|
var queryComponent, queryComponents = new Array();
|
|
|
|
|
var i, element;
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
var forceFields = {};
|
|
|
|
|
if(arguments) {for(var i=0;i<arguments.length;i++) forceFields[arguments[i]] = true;}
|
|
|
|
|
|
|
|
|
|
for(i=0;element=elements[i];i++) {
|
|
|
|
|
if(!element.name.match(/^action_(.+)$/i)) // For dropdown those 'action_xxx' fields.
|
|
|
|
|
{ if(!element.isChanged) element.isChanged = this.field_changed;
|
|
|
|
|
if(forceFields[element.name] || (element.isChanged()) || element.name.match(/\[.*\]/g) ) {
|
|
|
|
|
queryComponent = Form.Element.serialize(element);
|
2007-09-15 03:25:07 +02:00
|
|
|
|
if (queryComponent)
|
2007-07-19 12:40:05 +02:00
|
|
|
|
queryComponents.push(queryComponent);
|
|
|
|
|
} else {
|
|
|
|
|
// Used by the Sapphire code to preserve the form field value
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
if( element.name.match( '/\]$/' ) )
|
|
|
|
|
queryComponents.push(element.name.substring( 0, element.name.length - 1 ) + '_unchanged' + ']=1' );
|
|
|
|
|
else
|
|
|
|
|
queryComponents.push(element.name + '_unchanged=1');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//alert(queryComponents.join('&'));
|
|
|
|
|
return queryComponents.join('&');
|
|
|
|
|
},
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Serialize all the fields on the page
|
|
|
|
|
*/
|
|
|
|
|
serializeAllFields: function() {
|
|
|
|
|
return Form.serializeWithoutButtons(this);
|
2007-09-15 03:25:07 +02:00
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideLoading() {
|
2008-10-08 03:10:38 +02:00
|
|
|
|
if($('Loading')) $('Loading').style.display = 'none';
|
2008-08-06 05:28:25 +02:00
|
|
|
|
Element.removeClassName(document.body, 'stillLoading');
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
function baseHref() {
|
|
|
|
|
var baseTags = document.getElementsByTagName('base');
|
|
|
|
|
if(baseTags) return baseTags[0].href;
|
|
|
|
|
else return "";
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-15 03:25:07 +02:00
|
|
|
|
returnFalse = function() {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
showResponseAsSuccessMessage = function(response) {
|
|
|
|
|
statusMessage(response.responseText, 'good');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function is called by prototype when it receives notification that the user was logged out.
|
|
|
|
|
* It redirects back to the login form.
|
|
|
|
|
*/
|
|
|
|
|
function onSessionLost() {
|
2008-09-24 06:18:29 +02:00
|
|
|
|
w = window.open('Security/login');
|
|
|
|
|
if(w) {
|
|
|
|
|
alert("Please log in and then try again");
|
|
|
|
|
} else {
|
|
|
|
|
alert("Please enable pop-ups for this site");
|
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _CURRENT_CONTEXT_MENU = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new context menu
|
|
|
|
|
* @param event The event object
|
|
|
|
|
* @param owner The DOM element that this context-menu was requested from
|
2007-09-15 03:25:07 +02:00
|
|
|
|
* @param menuItems A map of title -> method; context-menu operations to get called
|
2007-07-19 12:40:05 +02:00
|
|
|
|
*/
|
|
|
|
|
function createContextMenu(event, owner, menuItems) {
|
|
|
|
|
if(_CURRENT_CONTEXT_MENU) {
|
|
|
|
|
document.body.removeChild(_CURRENT_CONTEXT_MENU);
|
|
|
|
|
_CURRENT_CONTEXT_MENU = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var menu = document.createElement("ul");
|
|
|
|
|
menu.className = 'contextMenu';
|
|
|
|
|
menu.style.position = 'absolute';
|
|
|
|
|
menu.style.left = event.clientX + 'px';
|
|
|
|
|
menu.style.top = event.clientY + 'px';
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
var menuItemName, menuItemTag, menuATag;
|
|
|
|
|
for(menuItemName in menuItems) {
|
|
|
|
|
menuItemTag = document.createElement("li");
|
|
|
|
|
|
|
|
|
|
menuATag = document.createElement("a");
|
|
|
|
|
menuATag.href = "#";
|
|
|
|
|
menuATag.onclick = menuATag.oncontextmenu = contextmenu_onclick;
|
|
|
|
|
menuATag.innerHTML = menuItemName;
|
|
|
|
|
menuATag.handler = menuItems[menuItemName];
|
|
|
|
|
menuATag.owner = owner;
|
|
|
|
|
|
|
|
|
|
menuItemTag.appendChild(menuATag);
|
|
|
|
|
menu.appendChild(menuItemTag);
|
|
|
|
|
}
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
document.body.appendChild(menu);
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
document.body.onclick = contextmenu_close;
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
_CURRENT_CONTEXT_MENU = menu;
|
2007-09-15 03:25:07 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function contextmenu_close() {
|
|
|
|
|
if(_CURRENT_CONTEXT_MENU) {
|
|
|
|
|
document.body.removeChild(_CURRENT_CONTEXT_MENU);
|
|
|
|
|
_CURRENT_CONTEXT_MENU = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function contextmenu_onclick() {
|
|
|
|
|
this.handler(this.owner);
|
|
|
|
|
contextmenu_close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shows an ajax loading indicator.
|
2007-09-15 03:25:07 +02:00
|
|
|
|
*
|
2007-07-19 12:40:05 +02:00
|
|
|
|
* @param id String Identifier for the newly created image
|
|
|
|
|
* @param container ID/DOM Element
|
2007-09-15 03:25:07 +02:00
|
|
|
|
* @param imgSrc String (optional)
|
2007-07-19 12:40:05 +02:00
|
|
|
|
* @param insertionType Object (optional) Prototype-style insertion-classes, defaults to Insertion.Bottom
|
|
|
|
|
* @param displayType String (optional) "inline" or "block"
|
|
|
|
|
*/
|
|
|
|
|
function showIndicator(id, container, imgSrc, insertionType, displayType) {
|
|
|
|
|
if(!id || !$(container)) return false;
|
|
|
|
|
if(!imgSrc) imgSrc = "cms/images/network-save.gif";
|
|
|
|
|
if(!displayType) displayType = "inline";
|
|
|
|
|
if(!insertionType) insertionType = Insertion.Bottom;
|
|
|
|
|
|
|
|
|
|
if(!$(id)) {
|
|
|
|
|
var html = '<img src="' + imgSrc + '" class="indicator ' + displayType + '" id="' + id + '" style="display: none" />';
|
|
|
|
|
new insertionType(container, html);
|
2007-09-15 03:25:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
Effect.Appear(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideIndicator(id) {
|
|
|
|
|
Effect.Fade(id, {duration: 0.3});
|
2007-11-06 06:39:14 +01:00
|
|
|
|
}
|
2008-09-24 06:18:29 +02:00
|
|
|
|
|
2009-11-21 03:36:00 +01:00
|
|
|
|
|
2009-05-14 08:11:18 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Find and enable TinyMCE on all htmleditor fields
|
|
|
|
|
* Pulled in from old tinymce.template.js
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
function nullConverter(url) {
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Behaviour.register({
|
|
|
|
|
'textarea.htmleditor' : {
|
|
|
|
|
initialize : function() {
|
|
|
|
|
tinyMCE.execCommand("mceAddControl", true, this.id);
|
|
|
|
|
this.isChanged = function() {
|
|
|
|
|
return tinyMCE.getInstanceById(this.id).isDirty();
|
|
|
|
|
}
|
|
|
|
|
this.resetChanged = function() {
|
|
|
|
|
inst = tinyMCE.getInstanceById(this.id);
|
2009-05-15 02:13:11 +02:00
|
|
|
|
if (inst) inst.startContent = tinymce.trim(inst.getContent({format : 'raw', no_events : 1}));
|
2009-05-14 08:11:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
ENHANCEMENT Using jQuery layout manager plugin to size panels in main CMS interface. Removed custom javascript resizing and CSS rules.
API CHANGE Removed custom resizing javascript methods: window.ontabschanged, window.onresize, fixRightWidth(), fixHeight_left()
API CHANGE Removed DraggableSeparator, SideTabs, SideTabItem javascript classes
API CHANGE Removed Effect.ReSize and Highlighter javascript helper classes
API CHANGE Modified template structure in CMSMain_left.ss, CMSMain_right.ss and LeftAndMain.ss
API CHANGE Modified markup IDs in LeftAndMain/CMSMain templates, removed "left", "right", "contentPanel", "bottom"
ENHANCEMENT Using jquery-latest (currently 1.3) in CMSMain and LeftAndMain
ENHANCEMENT Added jQuery UI library and "smoothness" theme to default CMS interface
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92581 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-11-21 03:35:20 +01:00
|
|
|
|
});
|