function action_send_right() { $('action_send_options').toggle(); } CMSForm.applyTo('#Form_MemberForm','rightbottom'); Behaviour.register({ '#Form_EditForm' : { initialise : function() { this.openTab = null; this.prepareForm(); }, /** * Processing called whenever a page is loaded in the right - including the initial one */ prepareForm : function() { ajaxActionsAtTop('Form_EditForm', 'form_actions', 'right'); }, /** * Request a page from the server via Ajax */ getPageFromServer : function(id, type, otherid,openTabName) { this.openTab = openTabName; if(id && parseInt(id) == id) { this.receivingID = id; // Treenode might not exist if that part of the tree is closed var treeNode = $('sitetree').getTreeNodeByIdx(id); if(treeNode) treeNode.addNodeClass('loading'); statusMessage("loading..."); var requestURL = 'admin/newsletter/showtype/' + id; if( otherid ) requestURL = 'admin/newsletter/shownewsletter/' + otherid; new Ajax.Request(requestURL, { asynchronous : true, method : 'post', postBody : /*'ID=' + id + 'type=' + type + */'ajax=1'+ (otherid?('&otherid='+otherid):''), onSuccess : this.successfullyReceivedPage.bind(this), onFailure : function(response) { errorMessage('error loading page',response); } }); } else { throw("getPageFromServer: Bad page ID: " + id); } }, successfullyReceivedPage : function(response) { this.loadNewPage(response.responseText); // Treenode might not exist if that part of the tree is closed var treeNode = $('sitetree').getTreeNodeByIdx(this.receivingID); if(treeNode) { $('sitetree').changeCurrentTo(treeNode); treeNode.removeNodeClass('loading'); } statusMessage(''); onload_init_tabstrip(); if( this.openTab ) { openTab( this.openTab ); this.openTab = null; } }, didntReceivePage : function(response) { errorMessage('error loading page', response); $('sitetree').getTreeNodeByIdx(this.elements.ID.value).removeNodeClass('loading'); }, /** * Load a new page into the right-hand form */ loadNewPage : function(formContent) { rightHTML = formContent; rightHTML = rightHTML.replace(/href *= *"#/g, 'href="' + window.location.href.replace(/#.*$/,'') + '#'); // Prepare iframes for removal, otherwise we get loading bugs var i, allIframes = this.getElementsByTagName('iframe'); if(allIframes) for(i=0;i= parseInt( processParts[3] ) ) { this.onComplete( response ); return; } // update the progress bar $('SendProgressBar').setProgress( ( parseInt( processParts[2] ) / parseInt( processParts[3] ) ) * 100 ); var estimate = $('SendProgressBar').estimateTime(); $('SendProgressBar').setText( 'Sent ' + processParts[2] + ' of ' + processParts[3] + '. ' + estimate + ' remaining...' ); // set the action to the batch process controller var updateRequest = baseHref() + 'processes/next/' + processParts[1] + '/10?ajax=1'; var request = new Ajax.Request( updateRequest, { onSuccess: this.incrementProcess.bind(this), onFailure: function( response ) { errorMessage( response.responseText ); } }); }, /** * Process the action's Ajax response */ onComplete: function( response ) { // $('SendProgressBar').setProgress( 100 ); // $('SendProgressBar').setText( 'Done!' ); $('SendProgressBar').reset(); // this.elements.Message.value = ''; this.close(); if( response ) Ajax.Evaluator(response); }, onCompleteTest: function( response ) { // this.sendingText.innerHTML = ''; if( this.sendingText.parentNode == this ) this.removeChild( this.sendingText ); this.close(); if( response ) Ajax.Evaluator(response); } } }); function save(ifChanged, callAfter, confirmation) { tinyMCE.triggerSave(true); var form = $('Form_EditForm'); var alreadySaved = false; if(ifChanged) { if(form.elements.length < 2) alreadySaved = true; else alreadySaved = !form.isChanged(); } if(alreadySaved && ifChanged) { // pressing save always saves if(!ifChanged && !confirmation) { statusMessage("There's nothing to save"); } if(callAfter) callAfter(); } else { var options = { save: (function() { statusMessage('saving...', '', true); var success = function(response) { Ajax.Evaluator(response); if(this.callAfter) this.callAfter(); } if(callAfter) success = success.bind(this); if( $('Form_EditForm_Type').value == 'Newsletter' ) var data = form.serializeChangedFields('ID','type') + '&ajax=1&action_savenewsletter=1'; else var data = form.serializeChangedFields('ID','type') + '&ajax=1&action_save=1'; new Ajax.Request(form.action, { method : form.method, postBody: data, onSuccess : success, onFailure : function(response) { errorMessage('Error saving content', response); } }); }).bind({callAfter : callAfter}), discard: callAfter, cancel: function() { } } if(confirmation) doYouWantToSave(options); else options.save(); } return false; } Behaviour.register({ /** * When the iframe has loaded, apply the listeners */ 'div#ImportFile' : { frameLoaded: function( doc ) { this.showTable = true; var fileField = doc.getElementsByTagName('input')[0]; var idField = doc.getElementsByTagName('input')[1]; idField.value = $('Form_EditForm_ID').value; fileField.onchange = this.selectedFile.bind(this); }, loadTable: function( doc ) { this.innerHTML = doc.getElementsByTagName('body')[0].innerHTML; } } }); NewsletterList = Class.create(); NewsletterList.applyTo('table.NewsletterList'); NewsletterList.prototype = { initialize: function() { this.tableBody = this.getElementsByTagName('tbody')[0]; this.deleteLinks = this.getElementsByTagName('a'); for( var i = 0; i < this.deleteLinks.length; i++ ) { this.deleteLinks[i].onclick = this.deleteNewsletter.bindAsEventListener(this); } }, deleteNewsletter: function( event ) { var link = event.target; if( event.srcElement ) link = event.srcElement; var rowNode = link.parentNode.parentNode; new Ajax.Request( link.href, { onSuccess: this.removeRow, onFailure: function( response ) { alert('The newsletter could not be deleted'); } }); }, removeRow: function( response ) { this.tableBody.removeChild( $(response.responseText) ); } } /** * Add page action * @todo Remove duplication between this and the CMSMain Add page action */ Behaviour.register( { '#Form_EditForm_action_save': { onclick : function() { $('Form_EditForm').save(); return false; } } }); /** * Handle auto-saving. Detects if changes have been made, and if so save everything on the page. * If confirmation is true it will ask for confirmation. */ function autoSave(confirmation, callAfter) { if(typeof tinyMCE != 'undefined') tinyMCE.triggerSave(); var __forms = [] if($('Form_EditForm')) __forms.push($('Form_EditForm')); if($('Form_SubForm')) __forms.push($('Form_SubForm')); if($('Form_MemberForm')) __forms.push($('Form_MemberForm')); var __somethingHasChanged = false; var __callAfter = callAfter; __forms.each(function(form) { if(form.isChanged && form.isChanged()) { __somethingHasChanged = true; } }); if(__somethingHasChanged) { var options = { save: function() { statusMessage('saving...', '', true); var i; for(i=0;i<__forms.length;i++) { if(__forms[i].isChanged && __forms[i].isChanged()) { if(i == 0) __forms[i].save(true, __callAfter); else __forms[i].save(true); } } }, discard: function() { __forms.each(function(form) { form.resetElements(false); }); if(__callAfter) __callAfter(); }, cancel: function() { } } if(confirmation) doYouWantToSave(options); else options.save(); } else { if(__callAfter) __callAfter(); } } function reloadRecipientsList() { var id = $('Form_EditForm_ID').value; var request = new Ajax.Request( 'admin/newsletter/getrecipientslist/' + id + '?ajax=1', { onSuccess: function( response ) { $('MemberList').outerHTML = response.responseText; Behaviour.apply( $('MemberList') ); }, onFailure: function(response) { statusMessage('Could not automatically refresh recipients list', 'bad'); } }); } /*RecipientImportField = Class.create(); RecipientImportField.applyTo('iframe.RecipientImportField'); RecipientImportField.prototype = { initialize: function() { this.src = document.getElementsByTagName('base')[0].href + this.src; } }*/ /** * We don't want hitting the enter key in the subject field * to submit the form. */ Behaviour.register({ '#Form_EditForm_Subject' : { onkeypress : function(event) { event = (event) ? event : window.event; var kc = event.keyCode ? event.keyCode : event.charCode; if(kc == 13) { return false; } } } });