2007-07-19 12:40:05 +02:00
|
|
|
if(typeof SiteTreeHandlers == 'undefined') SiteTreeHandlers = {};
|
|
|
|
SiteTreeHandlers.showNLDraft_url = 'admin/newsletter/shownewsletter/';
|
|
|
|
SiteTreeHandlers.showNLType_url = 'admin/newsletter/showtype/';
|
2007-09-04 06:12:30 +02:00
|
|
|
SiteTreeHandlers.controller_url = 'admin/newsletter';
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
SiteTree.prototype = {
|
|
|
|
castAsTreeNode: function(li) {
|
|
|
|
behaveAs(li, SiteTreeNode, this.options);
|
|
|
|
},
|
|
|
|
|
|
|
|
getIdxOf : function(treeNode) {
|
|
|
|
if(treeNode && treeNode.id)
|
|
|
|
return treeNode.id;
|
|
|
|
},
|
|
|
|
|
|
|
|
getTreeNodeByIdx : function(idx) {
|
|
|
|
if(!idx) idx = "0";
|
|
|
|
return document.getElementById(idx);
|
|
|
|
},
|
|
|
|
|
|
|
|
initialise: function() {
|
|
|
|
this.observeMethod('SelectionChanged', this.changeCurrentTo);
|
|
|
|
},
|
|
|
|
|
|
|
|
createTreeNode : function(idx, title, pageType, secondIdx) {
|
|
|
|
var i;
|
|
|
|
var node = document.createElement('li');
|
|
|
|
node.className = pageType;
|
|
|
|
|
|
|
|
var aTag = document.createElement('a');
|
|
|
|
|
|
|
|
node.id = idx;
|
|
|
|
|
|
|
|
if( pageType == 'Draft' ) {
|
|
|
|
aTag.href = SiteTreeHandlers.showNLDraft_url + idx;
|
|
|
|
} else {
|
|
|
|
aTag.href = SiteTreeHandlers.showNLType_url + idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
aTag.innerHTML = title;
|
|
|
|
node.appendChild(aTag);
|
|
|
|
|
|
|
|
SiteTreeNode.create(node, this.options);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
},
|
|
|
|
|
|
|
|
addDraftNode: function( title, parentID, draftID ) {
|
|
|
|
var draftNode = this.createTreeNode( 'draft_' + parentID + '_' + draftID, title, 'Draft', parentID );
|
|
|
|
this.getTreeNodeByIdx('drafts_' + parentID).appendTreeNode( draftNode );
|
|
|
|
this.changeCurrentTo( draftNode );
|
|
|
|
},
|
|
|
|
|
|
|
|
addTypeNode: function( title, parentID ) {
|
|
|
|
var typeNode = this.createTreeNode( 'mailtype_' + parentID, title, 'MailType' );
|
|
|
|
var draftsNode = this.createTreeNode( 'drafts_' + parentID, 'Drafts', 'DraftFolder' );
|
|
|
|
var sentItemsNode = this.createTreeNode( 'sent_' + parentID, 'Sent Items', 'SentFolder' );
|
|
|
|
var mailingListNode = this.createTreeNode( 'recipients_' + parentID, 'Mailing List', 'Recipients' );
|
|
|
|
typeNode.appendTreeNode( draftsNode );
|
|
|
|
Element.addClassName( draftsNode, 'nodelete');
|
|
|
|
typeNode.appendTreeNode( sentItemsNode );
|
|
|
|
Element.addClassName(sentItemsNode,'nodelete');
|
|
|
|
typeNode.appendTreeNode( mailingListNode );
|
|
|
|
Element.addClassName(mailingListNode,'nodelete');
|
|
|
|
this.appendTreeNode( typeNode );
|
|
|
|
this.changeCurrentTo( typeNode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete pages action
|
|
|
|
*/
|
|
|
|
deletedraft = {
|
|
|
|
button_onclick : function() {
|
|
|
|
if(treeactions.toggleSelection(this)) {
|
|
|
|
deletedraft.o1 = $('sitetree').observeMethod('SelectionChanged', deletedraft.treeSelectionChanged);
|
|
|
|
deletedraft.o2 = $('deletedrafts_options').observeMethod('Close', deletedraft.popupClosed);
|
|
|
|
addClass($('sitetree'),'multiselect');
|
|
|
|
|
|
|
|
var sel = $('sitetree').firstSelected();
|
|
|
|
|
|
|
|
if(sel) {
|
|
|
|
var selIdx = $('sitetree').getIdxOf(sel);
|
|
|
|
deletedraft.selectedNodes = { };
|
|
|
|
deletedraft.selectedNodes[selIdx] = true;
|
|
|
|
sel.removeNodeClass('current');
|
|
|
|
sel.addNodeClass('selected');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
treeSelectionChanged : function(selectedNode) {
|
|
|
|
var idx = $('sitetree').getIdxOf(selectedNode);
|
|
|
|
|
|
|
|
if(selectedNode.selected) {
|
|
|
|
selectedNode.removeNodeClass('selected');
|
|
|
|
selectedNode.selected = false;
|
|
|
|
deletedraft.selectedNodes[idx] = false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
selectedNode.addNodeClass('selected');
|
|
|
|
selectedNode.selected = true;
|
|
|
|
deletedraft.selectedNodes[idx] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
popupClosed : function() {
|
|
|
|
removeClass($('sitetree'),'multiselect');
|
|
|
|
$('sitetree').stopObserving(deletedraft.o1);
|
|
|
|
$('deletedrafts_options').stopObserving(deletedraft.o2);
|
|
|
|
|
|
|
|
for(var idx in deletedraft.selectedNodes) {
|
|
|
|
if(deletedraft.selectedNodes[idx]) {
|
|
|
|
node = $('sitetree').getTreeNodeByIdx(idx);
|
|
|
|
if(node) {
|
|
|
|
node.removeNodeClass('selected');
|
|
|
|
node.selected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
form_submit : function() {
|
|
|
|
var csvIDs = "";
|
|
|
|
for(var idx in deletedraft.selectedNodes) {
|
|
|
|
if(deletedraft.selectedNodes[idx]) csvIDs += (csvIDs ? "," : "") + idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(csvIDs) {
|
|
|
|
$('deletedrafts_options').elements.csvIDs.value = csvIDs;
|
|
|
|
|
|
|
|
Ajax.SubmitForm('deletedrafts_options', null, {
|
|
|
|
onSuccess : function(response) {
|
|
|
|
Ajax.Evaluator(response);
|
|
|
|
|
|
|
|
var sel;
|
|
|
|
if((sel = $('sitetree').selected) && sel.parentNode) sel.addNodeClass('current');
|
|
|
|
// else $('Form_EditForm').innerHTML = "";
|
|
|
|
|
|
|
|
treeactions.closeSelection($('deletedrafts'));
|
|
|
|
},
|
|
|
|
onFailure : function(response) {
|
|
|
|
errorMessage('Error deleting drafts', response);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2007-09-15 02:54:13 +02:00
|
|
|
$('deletedrafts').getElementsByTagName('button')[0].onclick();
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
alert("Please select at least 1 page.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
treeSelectionChanged : function(selectedNode) {
|
|
|
|
var idx = $('sitetree').getIdxOf(selectedNode);
|
|
|
|
|
|
|
|
if( !deletedraft.selectedNodes )
|
|
|
|
deletedraft.selectedNodes = {};
|
|
|
|
|
|
|
|
if(selectedNode.className.indexOf('nodelete') == -1) {
|
|
|
|
if(selectedNode.selected) {
|
|
|
|
selectedNode.removeNodeClass('selected');
|
|
|
|
selectedNode.selected = false;
|
|
|
|
deletedraft.selectedNodes[idx] = false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
selectedNode.addNodeClass('selected');
|
|
|
|
selectedNode.selected = true;
|
|
|
|
deletedraft.selectedNodes[idx] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SiteTreeNode.prototype.onselect = function() {
|
|
|
|
$('sitetree').changeCurrentTo(this);
|
|
|
|
if($('sitetree').notify('SelectionChanged', this)) {
|
2007-09-15 02:51:12 +02:00
|
|
|
autoSave(true, this.getPageFromServer.bind(this));
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
SiteTreeNode.prototype.getPageFromServer = function() {
|
|
|
|
|
|
|
|
var match = this.id.match(/(mailtype|drafts|draft|sent|recipients)_([\d]+)$/);
|
|
|
|
var openTabName = null;
|
|
|
|
var currentPageID = null;
|
|
|
|
|
|
|
|
if( $('Form_EditForm_ID') )
|
|
|
|
currentPageID = $('Form_EditForm_ID').value;
|
|
|
|
|
|
|
|
var newPageID = null;
|
|
|
|
var otherID = null;
|
|
|
|
var type = null;
|
|
|
|
|
|
|
|
if( match ) {
|
|
|
|
|
|
|
|
newPageID = match[2];
|
|
|
|
type = match[1];
|
|
|
|
} else if(this.id.match(/(mailtype|drafts|draft|sent|recipients)_([\d]+)_([\d]+)$/)) {
|
|
|
|
newPageID = RegExp.$2;
|
|
|
|
type = RegExp.$1;
|
|
|
|
otherID = RegExp.$3;
|
|
|
|
}
|
2007-09-14 19:29:08 +02:00
|
|
|
$('Form_EditForm').getPageFromServer(newPageID, type, otherID, openTabName);
|
2007-07-19 12:40:05 +02:00
|
|
|
};
|
|
|
|
|
2007-09-16 03:04:10 +02:00
|
|
|
function draft_sent_ok( newsletterID, draftID, numEmails ) {
|
2007-07-19 12:40:05 +02:00
|
|
|
var draftsListNode = $('drafts_' + newsletterID);
|
|
|
|
var sentListNode = $('sent_' + newsletterID);
|
|
|
|
var draftNode = $('draft_' + newsletterID + '_' + draftID );
|
|
|
|
|
|
|
|
draftsListNode.removeTreeNode( draftNode );
|
|
|
|
draftNode.id = 'sent_' + newsletterID + '_' + draftID;
|
|
|
|
sentListNode.appendTreeNode( draftNode, null );
|
2007-09-16 03:04:10 +02:00
|
|
|
statusMessage('Sent newsletter to mailing list. Sent ' + numEmails + ' emails successfully.', 'good');
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
2007-09-16 03:04:10 +02:00
|
|
|
function resent_ok( newsletterID, sentID, numEmails ) {
|
|
|
|
statusMessage('Resent newsletter to mailing list. Sent ' + numEmails + ' emails successfully.', 'good');
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function reloadSiteTree() {
|
|
|
|
|
|
|
|
new Ajax.Request( 'admin/newsletter/getsitetree', {
|
|
|
|
method: get,
|
|
|
|
onSuccess: function( response ) {
|
|
|
|
$('sitetree_holder').innerHTML = response.responseText;
|
|
|
|
},
|
|
|
|
onFailure: function( response ) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_HANDLER_FORMS['addtype'] = 'addtype_options';
|
|
|
|
_HANDLER_FORMS['deletedrafts'] = 'deletedrafts_options';
|
|
|
|
|
|
|
|
AddForm = Class.extend('addpage');
|
|
|
|
AddForm.applyTo('#addtype');
|
|
|
|
AddForm.prototype = {
|
|
|
|
initialize: function () {
|
|
|
|
Observable.applyTo($(_HANDLER_FORMS[this.id]));
|
2007-09-15 02:54:13 +02:00
|
|
|
this.getElementsByTagName('button')[0].onclick = returnFalse;
|
2007-07-19 12:40:05 +02:00
|
|
|
$(_HANDLER_FORMS[this.id]).onsubmit = this.form_submit;
|
|
|
|
},
|
|
|
|
|
2007-09-16 03:30:05 +02:00
|
|
|
form_submit : function() {
|
2007-07-19 12:40:05 +02:00
|
|
|
var st = $('sitetree');
|
2007-09-16 03:29:40 +02:00
|
|
|
if (st) {
|
|
|
|
if( st.selected && st.selected.length ) {
|
|
|
|
selectedNode = st.selected[0];
|
|
|
|
} else {
|
|
|
|
selectedNode = st.selected;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var selectedNode = null;
|
|
|
|
}
|
2007-09-16 03:30:05 +02:00
|
|
|
var parentID = null;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-09-16 03:30:05 +02:00
|
|
|
while( selectedNode && !parentID ) {
|
|
|
|
if( selectedNode && selectedNode.id && selectedNode.id.match(/mailtype_([0-9a-z\-]+)$/) )
|
|
|
|
parentID = RegExp.$1;
|
|
|
|
else
|
|
|
|
selectedNode = selectedNode.parentNode;
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
if(parentID && parentID.substr(0,3) == 'new') {
|
|
|
|
alert("You have to save a page before adding children underneath it");
|
|
|
|
|
|
|
|
} else {
|
2007-09-16 03:29:40 +02:00
|
|
|
if (this.elements) {
|
|
|
|
this.elements.ParentID.value = parentID;
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-09-16 03:30:05 +02:00
|
|
|
var type = 'draft';
|
|
|
|
var selectIDPrefix = 'draft_' + parentID + '_';
|
|
|
|
|
|
|
|
if( $('add_type').value == 'type' ) {
|
|
|
|
type = 'type';
|
|
|
|
selectIDPrefix = 'mailtype_';
|
|
|
|
}
|
|
|
|
// Call either addtype or adddraft
|
2007-09-16 03:01:06 +02:00
|
|
|
var request = new Ajax.Request( this.action + type + '?ajax=1' + '&ParentID=' + parentID, {
|
2007-09-16 03:30:05 +02:00
|
|
|
method: 'get',
|
|
|
|
asynchronous: true,
|
2007-07-19 12:40:05 +02:00
|
|
|
onSuccess : function( response ) {
|
2007-09-16 03:30:05 +02:00
|
|
|
|
|
|
|
$('Form_EditForm').loadNewPage(response.responseText);
|
|
|
|
|
|
|
|
// create a new node and add it to the site tree
|
|
|
|
if( type == 'draft' ) {
|
|
|
|
$('sitetree').addDraftNode('New draft newsletter', parentID, $('Form_EditForm_ID').value );
|
|
|
|
} else {
|
|
|
|
$('sitetree').addTypeNode('New newsletter type', $('Form_EditForm_ID').value );
|
|
|
|
}
|
|
|
|
// Save it so that change detection will work
|
|
|
|
$('Form_EditForm').save();
|
|
|
|
|
|
|
|
statusMessage('Added new ' + type);
|
|
|
|
},
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
onFailure : function(response) {
|
|
|
|
alert(response.responseText);
|
2007-09-16 03:30:05 +02:00
|
|
|
statusMessage('Could not add new ' + type );
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
reloadSiteTree: function( response ) {
|
|
|
|
statusMessage('Added new newsletter type', 'good' );
|
|
|
|
$('sitetree_holder').innerHTML = response.responseText;
|
|
|
|
Behaviour.apply( $('sitetree_holder') );
|
|
|
|
},
|
|
|
|
|
|
|
|
button_onclick : function() {
|
|
|
|
if(treeactions.toggleSelection(this)) {
|
|
|
|
var selectedNode = $('sitetree').firstSelected();
|
|
|
|
if(selectedNode) {
|
|
|
|
while(selectedNode.parentTreeNode && !selectedNode.hints.defaultChild) {
|
|
|
|
$('sitetree').changeCurrentTo(selectedNode.parentTreeNode);
|
|
|
|
selectedNode = selectedNode.parentTreeNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.o1 = $('sitetree').observeMethod('SelectionChanged', this.treeSelectionChanged.bind(this));
|
|
|
|
this.o2 = $(_HANDLER_FORMS[this.id]).observeMethod('Close', this.popupClosed.bind(this));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
treeSelectionChanged: function( treeNode ) {
|
|
|
|
this.selected = treeNode;
|
|
|
|
},
|
|
|
|
|
|
|
|
popupClosed: function() {
|
|
|
|
$('sitetree').stopObserving(this.o1);
|
|
|
|
$(_HANDLER_FORMS.addtype).stopObserving(this.o2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeTreeNodeByIdx( tree, nodeID ) {
|
|
|
|
var node = tree.getTreeNodeByIdx( nodeID );
|
|
|
|
if( node )
|
|
|
|
if( node.parentTreeNode )
|
|
|
|
node.parentTreeNode.removeTreeNode( node );
|
|
|
|
else
|
|
|
|
$('sitetree').removeTreeNode( node );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialisation function to set everything up
|
|
|
|
*/
|
|
|
|
Behaviour.addLoader(function () {
|
|
|
|
// Set up add draft
|
|
|
|
Observable.applyTo($('addtype_options'));
|
|
|
|
|
|
|
|
if( $('addtype') ) {
|
|
|
|
if( AddForm.button_click )
|
|
|
|
$('addtype').getElementsByTagName('a')[0].onclick = function() {return false;};
|
|
|
|
if( AddForm.button_click )
|
|
|
|
$('addtype_options').onsubmit = AddForm.form_submit;
|
|
|
|
}
|
|
|
|
// Set up delete drafts
|
|
|
|
Observable.applyTo($('deletedrafts_options'));
|
|
|
|
|
|
|
|
var deleteDrafts = $('deletedrafts');
|
|
|
|
|
|
|
|
if( deleteDrafts ) {
|
|
|
|
deleteDrafts.onclick = deletedraft.button_onclick;
|
2007-09-15 02:54:13 +02:00
|
|
|
deleteDrafts.getElementsByTagName('button')[0].onclick = function() {return false;};
|
2007-07-19 12:40:05 +02:00
|
|
|
$('deletedrafts_options').onsubmit = deletedraft.form_submit;
|
|
|
|
}
|
|
|
|
});
|