2007-07-19 12:40:05 +02:00
function action _send _right ( ) {
$ ( 'action_send_options' ) . toggle ( ) ;
}
2007-09-14 21:27:34 +02:00
/ * *
* Hides the drop - down Send newsletter form if Cancel button is clicked
* /
Behaviour . register ( {
'#action_send_cancel' : {
onclick : function ( ) {
$ ( 'action_send_options' ) . toggle ( ) ;
return false ;
}
}
} ) ;
2007-07-19 12:40:05 +02:00
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 ( ) {
2007-09-15 03:11:25 +02:00
ajaxActionsAtTop ( 'Form_EditForm' , 'form_actions_right' , 'right' ) ;
2007-07-19 12:40:05 +02:00
} ,
/ * *
* 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..." ) ;
2007-09-14 19:29:08 +02:00
var requestURL = 'admin/newsletter/show' + type + '/' + id ;
2007-07-19 12:40:05 +02:00
2007-09-14 19:29:08 +02:00
if ( otherid ) {
requestURL = 'admin/newsletter/shownewsletter/' + otherid ;
}
2007-07-19 12:40:05 +02:00
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 ) ;
}
} ) ;
2007-09-14 19:29:08 +02:00
// Hide the action buttons if 'Drafts' or 'Sent Items' is clicked on
if ( 'drafts' == type || 'sent' == type )
{
Element . hide ( 'form_actions' ) ;
Element . hide ( 'form_actions_right' ) ;
}
2007-07-19 12:40:05 +02:00
} 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 < allIframes . length ; i ++ ) {
allIframes [ i ] . contentWindow . location . href = 'about:blank' ;
allIframes [ i ] . parentNode . removeChild ( allIframes [ i ] ) ;
}
this . innerHTML = rightHTML ;
allIframes = this . getElementsByTagName ( 'iframe' ) ;
if ( allIframes ) for ( i = 0 ; i < allIframes . length ; i ++ ) {
try {
allIframes [ i ] . contentWindow . location . href = allIframes [ i ] . src ;
2007-09-16 02:49:10 +02:00
} catch ( er ) { alert ( 'Error in NewsletterAdmin_right.js #Form_EditForm::loadNewPage(): ' + er . message ) ; }
2007-07-19 12:40:05 +02:00
}
_TAB _DIVS _ON _PAGE = [ ] ;
try {
var tabs = document . getElementsBySelector ( '#Form_EditForm ul.tabstrip' ) ;
} catch ( er ) { /* alert('a: '+ er.message + '\n' + er.line);*/ }
try {
for ( var i = 0 ; i < tabs . length ; i ++ ) if ( tabs [ i ] . tagName ) initTabstrip ( tabs [ i ] ) ;
} catch ( er ) { /*alert('b: '+ er.message + '\n' + er.line); */ }
if ( ( typeof tinyMCE != 'undefined' ) && tinyMCE . instances ) {
tinyMCE . instances = [ ] ;
tinyMCE . isLoaded = false ;
tinyMCE . onLoad ( ) ;
}
onload _init _tabstrip ( ) ;
// if(this.prepareForm) this.prepareForm();
Behaviour . apply ( $ ( 'Form_EditForm' ) ) ;
if ( this . prepareForm )
this . prepareForm ( ) ;
this . resetElements ( ) ;
window . ontabschanged ( ) ;
} ,
/ * *
* Save the contens of the form , by submitting it and resetting is changed checker
* on success .
* /
save : function ( ifChanged , callAfter ) {
_AJAX _LOADING = true ;
if ( typeof tinyMCE != 'undefined' ) tinyMCE . triggerSave ( ) ;
var _ _callAfter = callAfter ;
var _ _form = this ;
if ( _ _form . notify ) _ _form . notify ( 'BeforeSave' , _ _form . elements . ID . value ) ;
var success = function ( response ) {
Ajax . Evaluator ( response ) ;
_ _form . resetElements ( ) ;
if ( _ _callAfter ) _ _callAfter ( ) ;
if ( _ _form . notify ) _ _form . notify ( 'PageSaved' , _ _form . elements . ID . value ) ;
_AJAX _LOADING = false ;
}
var action = 'action_save' ;
if ( ifChanged ) {
var data = this . serializeChangedFields ( 'ID' ) + '&ajax=1&' + action + '=1' ;
} else {
var data = this . serializeAllFields ( ) + '&ajax=1&' + action + '=1' ;
}
// alert(this.action + '\n\n' + data);
new Ajax . Request ( this . action , {
method : this . method ,
postBody : data ,
onSuccess : success ,
onFailure : function ( response ) {
alert ( response . responseText ) ;
errorMessage ( 'Error saving content' , response ) ;
_AJAX _LOADING = false ;
}
} ) ;
}
}
} ) ;
Behaviour . register ( {
'#action_send_options' : {
/ * *
* Open the form
* /
open : function ( ) {
this . elements . NewsletterID . value = $ ( 'Form_EditForm' ) . elements . ID . value ;
var allInputs = this . getElementsByTagName ( 'input' ) ;
this . submitButton = allInputs [ allInputs . length - 1 ] ;
this . submitButton . onclick = this . send . bind ( this ) ;
this . style . display = '' ;
} ,
close : function ( ) {
this . style . display = 'none' ;
} ,
toggle : function ( ) {
if ( this . style . display == '' ) this . close ( ) ;
else this . open ( ) ;
} ,
send _test : function ( ) {
// Show a "submitting..." box
if ( ! this . sendingText ) {
this . sendingText = document . createElement ( 'div' ) ;
this . sendingText . innerHTML = 'Sending newsletter...' ;
this . sendingText . className = 'sendingText' ;
Element . setOpacity ( this . sendingText , 0.9 ) ;
this . appendChild ( this . sendingText ) ;
}
this . sendingText . style . display = '' ;
var form = $ ( 'Form_EditForm' ) ;
if ( form . isChanged ( ) )
form . save ( ) ;
// Send the request
ajaxSubmitForm ( false , this . onCompleteTest . bind ( this ) , this , '' , 'sendnewsletter' )
return false ;
} ,
2007-09-16 03:04:35 +02:00
/ * *
* Called by AJAX when 'Send newsletter' button is clicked
*
* /
2007-07-19 12:40:05 +02:00
send : function ( ) {
2007-09-16 03:04:35 +02:00
// If 'Send to the entire mailing list' option is chosen
if ( $ ( 'SendTypeList' ) . checked ) {
return this . send _to _list ( 'List' ) ;
// If 'Send to only people not previously sent to' option is chosen
} else if ( $ ( 'SendTypeUnsent' ) . checked ) {
return this . send _to _list ( 'Unsent' ) ;
} else {
2007-07-19 12:40:05 +02:00
return this . send _test ( ) ;
2007-09-16 03:04:35 +02:00
}
2007-07-19 12:40:05 +02:00
} ,
/ * *
* Submit the option form and carry out the action
2007-09-16 03:04:35 +02:00
*
* @ param sendType string 'List' if sending to entire list and 'Unsent' if only sending to people not previously sent to
2007-07-19 12:40:05 +02:00
* /
2007-09-16 03:04:35 +02:00
send _to _list : function ( sendType ) {
2007-07-19 12:40:05 +02:00
// Show a "submitting..." box
/ * i f ( ! t h i s . s e n d i n g T e x t ) {
this . sendingText = document . createElement ( 'div' ) ;
this . sendingText . innerHTML = 'Sending newsletter...' ;
this . sendingText . className = 'sendingText' ;
Element . setOpacity ( this . sendingText , 0.9 ) ;
this . appendChild ( this . sendingText ) ;
}
this . sendingText . style . display = '' ; * /
var form = $ ( 'Form_EditForm' ) ;
if ( form . isChanged ( ) )
form . save ( ) ;
if ( $ ( 'SendProgressBar' ) )
$ ( 'SendProgressBar' ) . start ( ) ;
// Send the request
Ajax . SubmitForm ( $ ( 'Form_EditForm' ) , 'action_sendnewsletter' , {
2007-09-16 03:04:35 +02:00
extraData : '&SendType=' + sendType ,
2007-07-19 12:40:05 +02:00
onSuccess : this . incrementProcess . bind ( this ) ,
onFailure : function ( response ) {
statusMessage ( response . responseText ) ;
}
} ) ;
/ * v a r f o r m = $ ( ' F o r m _ E d i t F o r m ' ) ;
var data = form . serializeChangedFields ( 'ID' , 'type' ) + '&ajax=1&action_savenewsletter=1&SendType=List' ;
new Ajax . Request ( form . action , {
method : form . method ,
postBody : data ,
onSuccess : this . incrementProcess . bind ( this ) ,
onFailure : function ( response ) {
errorMessage ( 'Error sending to mailing list' , response ) ;
}
} ) ; * /
return false ;
} ,
incrementProcess : function ( response ) {
var processParts = response . responseText . match ( /(\d+):(\d+)\/(\d+)/ ) ;
if ( ! processParts || parseInt ( processParts [ 2 ] ) >= 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 = '';
2007-09-16 02:57:31 +02:00
// Reload the "Sent Status Report" tab after a Newsletter is sent
var id = this . elements . NewsletterID . value ;
var request = new Ajax . Request ( baseHref ( ) + 'admin/newsletter/getsentstatusreport/' + id + '?ajax=1' , {
onSuccess : function ( response ) {
$ ( 'Root_SentStatusReport' ) . innerHTML = response . responseText ;
} ,
onFailure : function ( response ) {
statusMessage ( 'Could not automatically refresh Sent Status Report tab' , 'bad' ) ;
}
} ) ;
2007-07-19 12:40:05 +02:00
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 ) ;
}
}
} ) ;
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 ;
}
}
} ) ;
2007-09-16 02:57:31 +02:00
// @TODO: Check if this code is used anymore now that NewsletterList was removed.
2007-07-19 12:40:05 +02:00
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 ) ) ;
}
}
/ * *
* 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 ) {
2007-09-14 21:30:54 +02:00
// Note: discard and cancel options are no longer used since switching to confirm dialog.
// save is still used if confirmation = false
2007-07-19 12:40:05 +02:00
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 ( ) {
}
}
2007-09-14 21:30:54 +02:00
if ( confirmation ) {
if ( confirm ( "Are you sure you want to navigate away from this page?\n\nWARNING: Your changes have not been saved.\n\nPress OK to continue, or Cancel to stay on the current page." ) )
{
// OK was pressed, call function for what was clicked on
if ( _ _callAfter ) _ _callAfter ( ) ;
} else {
// Cancel was pressed, stay on the current page
return false ;
}
} else {
options . save ( ) ;
}
2007-07-19 12:40:05 +02:00
} else {
if ( _ _callAfter ) _ _callAfter ( ) ;
}
}
function reloadRecipientsList ( ) {
var id = $ ( 'Form_EditForm_ID' ) . value ;
2007-09-16 00:02:06 +02:00
if ( navigator . appName == "Microsoft Internet Explorer" ) {
var url = 'admin/newsletter/getrecipientslist/' ;
} else {
var url = 'getrecipientslist/' ;
}
var request = new Ajax . Request ( url + id + '?ajax=1' , {
2007-07-19 12:40:05 +02:00
onSuccess : function ( response ) {
2007-09-16 00:02:06 +02:00
$ ( 'Root_Recipients' ) . innerHTML = response . responseText ;
2007-07-19 12:40:05 +02:00
Behaviour . apply ( $ ( 'MemberList' ) ) ;
} ,
onFailure : function ( response ) {
statusMessage ( 'Could not automatically refresh recipients list' , 'bad' ) ;
}
} ) ;
}
/ * R e c i p i e n t I m p o r t F i e l d = C l a s s . c r e a t e ( ) ;
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 ;
}
}
}
} ) ;
2007-09-14 19:29:08 +02:00
/ * *
* Handle 'add one' link action . Adds a new draft to the site tree and loads it up to edit .
* /
function addNewDraft ( parentID ) {
2007-09-16 03:01:06 +02:00
$ ( 'add_type' ) . value = 'draft' ;
$ ( 'addtype_options' ) . onsubmit ( ) ;
2007-09-14 19:29:08 +02:00
}