elofgren: NEW FEATURE: Make it possible to blacklist and remove bounced Newsletter recipients from the Bounced tab of the Mailing List. @TODO: Make this features work corectly in IE.

Make class BouncedList? just extend FormField? like it used to, extending TableListField? added unneeded complexity. 
Remove the unused Save button from the 'Mailing List' section. Fixes gsoc track ticket: #26 Remove uneeded "Save" button in "Mailing List" section of Newsletters 
(merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@42039 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-16 02:17:51 +00:00
parent be99502d53
commit 706580c443
4 changed files with 138 additions and 114 deletions

View File

@ -1,14 +1,10 @@
<?php
// @TODO Make it possible to disable sending to bounced emails by unchecking a box and delete the email from the mailing list by clicking the red "X"
class BouncedList extends TableListField {
class BouncedList extends FormField {
protected $nlType;
function __construct( $name, $newsletterType ) {
parent::__construct($name, "Email_BounceRecord", array("BounceEmail" => "Email address", "Created" => "Last bounce at", "BounceMessage" => "Reason:"), "", "Created");
$this->Markable = true;
$this->IsReadOnly = false;
$this->setPermissions(array('edit', 'delete', 'add'));
parent::__construct( $name, '', null );
if( is_object( $newsletterType ) )
$this->nlType = $newsletterType;
@ -16,47 +12,14 @@ class BouncedList extends TableListField {
$this->nlType = DataObject::get_by_id( 'NewsletterType', $newsletterType );
}
function sourceItems() {
$id = $this->nlType->GroupID;
// @TODO Try to find way to show Firstname and Surname under a 'Username' heading";
// Get a list of all bounces for all subscribers to this mailing list
$bouncedSubscribers = DataObject::get( 'Email_BounceRecord', "`GroupID`='$id'", null, "INNER JOIN `Group_Members` USING(`MemberID`)" );
// @TODO Find faster/elegenter way to do this. Probably some sort of SQL JOIN would work instead
// If there are bounces logged for this Mailing List
if ($bouncedSubscribers) {
$bouncedSubscribersWithMemberID = new DataObjectSet();
// Convert bounce to array so we can easily iterate through them
$bouncedSubscribersArray = $bouncedSubscribers->toArray();
// Iterate through each bounce record and add 'GroupID' to it (this is clumsy)
foreach($bouncedSubscribersArray as $key => $bouncedSubscriberObject)
{
$bouncedSubscriberArray = $bouncedSubscriberObject->getAllFields();
// Add MemberID to DataObjectSet so the removebouncedmember link will work
$bouncedSubscriberArray['GroupID'] = $id;
$bouncedSubscribersWithMemberID->push(new ArrayData($bouncedSubscriberArray));
}
return $bouncedSubscribersWithMemberID;
} else {
return null;
}
}
/**
* Sets the template to be rendered with
*/
function FieldHolder() {
return $this->renderWith('NewsletterAdmin_BouncedList');
}
function setController($controller) {
$this->controller = $controller;
}
// Not needed now that we are extending TableListField instead of FormField
/*
function FieldHolder() {
return $this->renderWith( 'NewsletterAdmin_BouncedList' );
}
function Entries() {
$id = $this->nlType->GroupID;
@ -72,6 +35,7 @@ class BouncedList extends TableListField {
if( $bounceRecord ) {
$bouncedUsers[] = new ArrayData( array(
'Record' => $bounceRecord,
'GroupID' => $id,
'Member' => DataObject::get_by_id( 'Member', $bounceRecord->MemberID )
));
}
@ -79,6 +43,5 @@ class BouncedList extends TableListField {
return new DataObjectSet( $bouncedUsers );
}
*/
}
?>
}
?>

View File

@ -290,9 +290,7 @@ class NewsletterAdmin extends LeftAndMain {
new Tab("Unsubscribers",
$unsubscribedList = new UnsubscribedList("Unsubscribed", $mailType)
),
new Tab("Bounced",
new LiteralField('Instructions', '<p><b>Instructions:</b></p><ul><li>Uncheck the box and click the "Save" button to disable sending to an email address. <b>@TODO Make this functional</b></li><li>To remove a recipients\'s email address from your mailing list, click the red "X" icon.</li></ul>'),
$bouncedList = new BouncedList("Bounced", $mailType )
new Tab("Bounced", $bouncedList = new BouncedList("Bounced", $mailType )
)
)
);
@ -307,8 +305,8 @@ class NewsletterAdmin extends LeftAndMain {
$fields->push($idField = new HiddenField("ID"));
$fields->push( new HiddenField( "executeForm", "", "MailingListEditForm" ) );
$idField->setValue($id);
$actions = new FieldSet(new FormAction('save','Save'));
// Save button is not used in Mailing List section
$actions = new FieldSet(new HiddenField("save"));
$form = new Form($this, "EditForm", $fields, $actions);
$form->loadDataFrom(array(
@ -330,9 +328,9 @@ class NewsletterAdmin extends LeftAndMain {
*/
function removebouncedmember($urlParams) {
// First remove the Bounce entry
$memberID = Convert::raw2sql($urlParams['ID']);
if (is_numeric($memberID)) {
$bounceObject = DataObject::get_by_id('Email_BounceRecord', $memberID);
$id = Convert::raw2sql($urlParams['ID']);
if (is_numeric($id)) {
$bounceObject = DataObject::get_by_id('Email_BounceRecord', $id);
if($bounceObject) {
// Remove this bounce record
$bounceObject->delete();
@ -343,13 +341,14 @@ class NewsletterAdmin extends LeftAndMain {
// Remove the member from the mailing list
$memberObject->Groups()->remove($groupID);
} else {
user_error("MemberTableField::delete: Bad parameters: Group=$groupID, Member=$memberID", E_USER_ERROR);
user_error("NewsletterAdmin::removebouncedmember: Bad parameters: Group=$groupID, Member=".$bounceObject->MemberID, E_USER_ERROR);
}
// @TODO Reload whole right frame so that Recipients and Bounced tabs will be updated after bounced member is removed.
return 1;
FormResponse::status_message($memberObject->Email.' was removed from the mailing list', 'good');
FormResponse::add("$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value, 'recipients');");
return FormResponse::respond();
}
}else{
return 0;
} else {
user_error("NewsletterAdmin::removebouncedmember: Bad parameters: Group=$groupID, Member=".$bounceObject->MemberID, E_USER_ERROR);
}
}
@ -548,6 +547,26 @@ class NewsletterAdmin extends LeftAndMain {
return FormResponse::respond();
}
/*
* Saves the settings on the 'Bounced' tab of the 'Mailing List' allowing members to be added to Email_BlackList
*
*/
public function memberblacklisttoggle($urlParams) {
$id = $urlParams['ID'];
$bounceObject = DataObject::get_by_id('Email_BounceRecord', $id);
$memberObject = DataObject::get_by_id('Member', $bounceObject->MemberID);
// If the email is currently not blocked, block it
if (FALSE == $memberObject->BlacklistedEmail) {
$memberObject->setBlacklistedEmail(TRUE);
FormResponse::status_message($memberObject->Email.' was added to blacklist', 'good');
} else {
// Unblock the email
$memberObject->setBlacklistedEmail(FALSE);
FormResponse::status_message($memberObject->Email.' was removed from blacklist', 'good');
}
return FormResponse::respond();
}
function NewsletterAdminSiteTree() {
return $this->getsitetree();
}

View File

@ -14,6 +14,64 @@ Behaviour.register( {
}
});
// Called when checkbox on Bounced tab of Mailing List is clicked
Behaviour.register( {
'#BouncedListTable tr td.markingcheckbox input': {
onchange : function(e) {
new Ajax.Request(
'admin/newsletter/memberblacklisttoggle/' + this.value,
{
method: 'post',
postBody: 'forceajax=1',
onComplete: function(response){
Ajax.Evaluator(response);
}.bind(this),
onFailure: ajaxErrorHandler
}
);
}
}
});
// Don't show unsaved changes confirm() for changes to Bounced tab checkboxes
Behaviour.register({
'#Form_EditForm' : {
changeDetection_fieldsToIgnore : {
'BouncedList[]' : true
}
}
});
// Called when X link on Bounced tab of Mailing List is clicked (adapted from TableListField.js)
Behaviour.register( {
'#BouncedListTable a.deletelink': {
onclick : function(e) {
var img = Event.element(e);
var link = Event.findElement(e,"a");
var row = Event.findElement(e,"tr");
var confirmed = confirm("Are you sure you want to remove this recipient from your mailing list?");
if(confirmed)
{
img.setAttribute("src",'cms/images/network-save.gif');
new Ajax.Request(
link.getAttribute("href"),
{
method: 'post',
postBody: 'forceajax=1',
onComplete: function(response){
Effect.Fade(row);
Ajax.Evaluator(response);
}.bind(this),
onFailure: ajaxErrorHandler
}
);
}
Event.stop(e);
}
}
});
CMSForm.applyTo('#Form_MemberForm','rightbottom');
Behaviour.register({

View File

@ -1,55 +1,39 @@
<div id="$id" class="$Classes TableField">
<% include TableListField_PageControls %>
<table class="data BouncedList">
<thead>
<tr>
<% if Markable %><th width="16">&nbsp;</th><% end_if %>
<% control Headings %>
<th class="$Name">$Title</th>
<% end_control %>
<% if Can(delete) %><th width="18">&nbsp;</th><% end_if %>
</tr>
</thead>
<% if HasSummary %>
<tfoot>
<tr class="summary">
<% if Markable %><th width="16">&nbsp;</th><% end_if %>
<td><i>$SummaryTitle</i></td>
<% control SummaryFields %>
<td<% if Function %> class="$Function"<% end_if %>>&nbsp;</td>
<% end_control %>
<% if Can(delete) %><td width="18">&nbsp;</td><% end_if %>
</tr>
</tfoot>
<% if Entries %>
<p><b>Instructions:</b></p>
<ul>
<li>Uncheck the box to disable sending to an email address.</li>
<li>To remove a recipients's email address from your mailing list, click the <img src="cms/images/delete.gif" alt="delete" /> icon.</li>
</ul>
<table id="BouncedListTable" class="CMSList BouncedList" summary="Emails that have bounced">
<thead>
<tr>
<th width="18">&nbsp;</th>
<th>User name</th>
<th>Email address</th>
<th>Reason:</th>
<th>Last bounce at</th>
<th width="18">&nbsp;</th>
</tr>
</thead>
<tbody>
<% control Entries %>
<tr>
<td class="markingcheckbox">
<% if Member.BlacklistedEmail %>
<input class="checkbox" type="checkbox" name="BouncedList[]" value="$Record.ID" />
<% else %>
<input class="checkbox" type="checkbox" checked="checked" name="BouncedList[]" value="$Record.ID" />
<% end_if %>
<tbody>
<% if Items %>
<% control Items %>
<tr id="record-$ID"<% if HighlightClasses %> class="$HighlightClasses"<% end_if %>>
<% if Markable %><td width="16">$MarkingCheckbox</td><% end_if %>
<% control Fields %>
<td>$Value</td>
<% end_control %>
<% if Can(delete) %>
<td width="16"><a class="deletelink" href="admin/newsletter/removebouncedmember/$ID/?GroupID=$GroupID"><img src="cms/images/delete.gif" alt="delete" /></a></td>
<% end_if %>
</tr>
<% end_control %>
<% else %>
<tr class="notfound">
<% if Markable %><th width="18">&nbsp;</th><% end_if %>
<td colspan="$Headings.Count"><i>No bounce records found</i></td>
<% if Can(delete) %><td width="18">&nbsp;</td><% end_if %>
</tr>
<% end_if %>
<% if Can(add) %>$AddRecordForm.AsTableRow<% end_if %>
</tbody>
</table>
<div class="utility">
<% if Can(export) %>
$ExportButton
<% end_if %>
</div>
</div>
</td>
<td>$Member.FirstName $Member.Surname</td>
<td>$Member.Email</td>
<td>$Record.BounceMessage</td>
<td>$Record.Created.Long</td>
<td width="16"><a class="deletelink" href="admin/newsletter/removebouncedmember/$Record.ID/?GroupID=$GroupID"><img src="cms/images/delete.gif" alt="delete" /></a></td>
</tr>
<% end_control %>
</tbody>
</table>
<% else %>
<p>No emails sent have bounced.</p>
<% end_if %>