var _AJAX_LOADING = false; Behaviour.register({ '#MainMenu li' : { onclick : function(event) { return LeftAndMain_window_unload(); // Confirm if there are unsaved changes window.location.href = this.getElementsByTagName('a')[0].href; Event.stop(event); } }, '#Menu-help' : { onclick : function() { var w = window.open(this.getElementsByTagName('a')[0].href, 'help'); w.focus(); return false; } }, '#Logo' : { onclick : function() { var w = window.open(this.getElementsByTagName('a')[0].href); w.focus(); return false; } }, '#EditMemberProfile': { onclick: function(e) { var el = Event.element(e); GB_show('Edit Profile', el.attributes.href.value, 290, 500); Event.stop(e); } } }); LeftAndMain_window_unload = function() { window.exiting = true; // this is used by prototype if(typeof autoSave == 'function') { return autoSave(true); } } // Event.observe(window, 'beforeunload', LeftAndMain_window_unload); /** * Unlock the locked status message. * Show a queued message, if one exists */ function unlockStatusMessage() { statusMessage.locked = false; if(statusMessage.queued) { statusMessage( statusMessage.queued.msg, statusMessage.queued.type, statusMessage.queued.showNetworkActivity); 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 * * The bound function can then be called, with the arguments passed */ function ajaxSubmitForm(automated, callAfter, form, action, verb) { var alreadySaved = false; if($(form).elements.length < 2) alreadySaved = true; if(alreadySaved) { if(callAfter) callAfter(); } else { statusMessage(verb + '...', '', true); var success = function(response) { Ajax.Evaluator(response); if(callAfter) callAfter(); } if(callAfter) success = success.bind({callAfter : callAfter}); Ajax.SubmitForm(form, action, { onSuccess : success, onFailure : function(response) { errorMessage('Error ' + verb, response); } }); } 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; } this.innerHTML = message; this.className = type; Element.setOpacity(this, 1); //this.style.position = 'absolute'; this.style.display = ''; this.style.visibility = ''; 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; // Wait a bit before fading if(waitTime) { this.fadeTimer = setTimeout((function() { this.fade(fadeTime); }).bind(this), waitTime * 1000); // Fade straight away } else { this.currentEffect = new Effect.Opacity(this, { duration: 0.5, transition: Effect.Transitions.linear, from: 1.0, to: 0.0, afterFinish : this.afterFade.bind(this) }); } }, afterFade : function() { this.style.visibility = 'hidden'; this.style.display = 'none'; this.innerHTML = ''; } } }); /** * Show a status message. * * @param msg String * @param type String (optional) can be 'good' or 'bad' * @param clearManually boolean Don't automatically fade message. * @param container custom #statusMessage element to show message. */ function statusMessage(msg, type, clearManually, container) { var statusMessageEl = $('statusMessage'); if(container != null) statusMessageEl = container; if(statusMessageEl) { if(msg) { statusMessageEl.showMessage(msg, type, msg.length / 10, clearManually); } else { statusMessageEl.clearMessage(); } } } function clearStatusMessage() { $('statusMessage').clearMessage(); } /** * Called when something goes wrong */ function errorMessage(msg, fullMessage) { // Show complex error for developers in the console if(fullMessage) { // Get the message from an Ajax response object try { if(typeof fullMessage == 'object') fullMessage = fullMessage.status + '//' + fullMessage.responseText; } catch(er) { fullMessage = ""; } console.error(fullMessage); } msg = msg.replace(/\n/g,'
'); $('statusMessage').showMessage(msg,'bad'); } function ajaxErrorHandler(response) { errorMessage('Server Error', response); } /** * Applying StatusTitle to an element will mean that the title attribute is shown as a statusmessage * upon hover */ /* 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. StatusTitle = Class.create(); StatusTitle.prototype = { onmouseover : function() { if(this.title) { this.message = this.title; this.title = null; } if(this.message) { $('statusMessage').showMessage(this.message); } }, onmouseout : function() { if(this.message) { $('statusMessage').fade(0.3,1); } } } */ /** * 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(); }, /** * 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); } } }, field_changed: function() { // 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); }, /** * 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++) { // NOTE: TinyMCE coupling // Ignore mce-generated elements if(element.className.substr(0,3) == 'mce') continue; if(!element.isChanged) element.isChanged = this.field_changed; if(!this.changeDetection_fieldsToIgnore[element.name] && element.isChanged()) { //console.log('Changed:'+ element.id + '(' + this.originalSerialized +')->('+Form.Element.serialize(element)+')' ); //console.log(element) return true; } } return false; }, changeDetection_fieldsToIgnore : { 'Sort' : true }, /** * 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; var forceFields = {}; if(arguments) {for(var i=0;i method; context-menu operations to get called */ 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'; 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); } document.body.appendChild(menu); document.body.onclick = contextmenu_close; _CURRENT_CONTEXT_MENU = menu; 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. * * @param id String Identifier for the newly created image * @param container ID/DOM Element * @param imgSrc String (optional) * @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 = ''; new insertionType(container, html); } Effect.Appear(id); } function hideIndicator(id) { Effect.Fade(id, {duration: 0.3}); } setInterval(function() { new Ajax.Request("Security/ping"); }, 180*1000); /** * 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); if (inst) inst.startContent = tinymce.trim(inst.getContent({format : 'raw', no_events : 1})); } } } });