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 <?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 FormField {
class BouncedList extends TableListField {
protected $nlType; protected $nlType;
function __construct( $name, $newsletterType ) { function __construct( $name, $newsletterType ) {
parent::__construct($name, "Email_BounceRecord", array("BounceEmail" => "Email address", "Created" => "Last bounce at", "BounceMessage" => "Reason:"), "", "Created"); parent::__construct( $name, '', null );
$this->Markable = true;
$this->IsReadOnly = false;
$this->setPermissions(array('edit', 'delete', 'add'));
if( is_object( $newsletterType ) ) if( is_object( $newsletterType ) )
$this->nlType = $newsletterType; $this->nlType = $newsletterType;
@ -16,47 +12,14 @@ class BouncedList extends TableListField {
$this->nlType = DataObject::get_by_id( 'NewsletterType', $newsletterType ); $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) { function setController($controller) {
$this->controller = $controller; $this->controller = $controller;
} }
// Not needed now that we are extending TableListField instead of FormField function FieldHolder() {
/* return $this->renderWith( 'NewsletterAdmin_BouncedList' );
}
function Entries() { function Entries() {
$id = $this->nlType->GroupID; $id = $this->nlType->GroupID;
@ -72,6 +35,7 @@ class BouncedList extends TableListField {
if( $bounceRecord ) { if( $bounceRecord ) {
$bouncedUsers[] = new ArrayData( array( $bouncedUsers[] = new ArrayData( array(
'Record' => $bounceRecord, 'Record' => $bounceRecord,
'GroupID' => $id,
'Member' => DataObject::get_by_id( 'Member', $bounceRecord->MemberID ) 'Member' => DataObject::get_by_id( 'Member', $bounceRecord->MemberID )
)); ));
} }
@ -79,6 +43,5 @@ class BouncedList extends TableListField {
return new DataObjectSet( $bouncedUsers ); return new DataObjectSet( $bouncedUsers );
} }
*/ }
} ?>
?>

View File

@ -290,9 +290,7 @@ class NewsletterAdmin extends LeftAndMain {
new Tab("Unsubscribers", new Tab("Unsubscribers",
$unsubscribedList = new UnsubscribedList("Unsubscribed", $mailType) $unsubscribedList = new UnsubscribedList("Unsubscribed", $mailType)
), ),
new Tab("Bounced", new Tab("Bounced", $bouncedList = new BouncedList("Bounced", $mailType )
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 )
) )
) )
); );
@ -307,8 +305,8 @@ class NewsletterAdmin extends LeftAndMain {
$fields->push($idField = new HiddenField("ID")); $fields->push($idField = new HiddenField("ID"));
$fields->push( new HiddenField( "executeForm", "", "MailingListEditForm" ) ); $fields->push( new HiddenField( "executeForm", "", "MailingListEditForm" ) );
$idField->setValue($id); $idField->setValue($id);
// Save button is not used in Mailing List section
$actions = new FieldSet(new FormAction('save','Save')); $actions = new FieldSet(new HiddenField("save"));
$form = new Form($this, "EditForm", $fields, $actions); $form = new Form($this, "EditForm", $fields, $actions);
$form->loadDataFrom(array( $form->loadDataFrom(array(
@ -330,9 +328,9 @@ class NewsletterAdmin extends LeftAndMain {
*/ */
function removebouncedmember($urlParams) { function removebouncedmember($urlParams) {
// First remove the Bounce entry // First remove the Bounce entry
$memberID = Convert::raw2sql($urlParams['ID']); $id = Convert::raw2sql($urlParams['ID']);
if (is_numeric($memberID)) { if (is_numeric($id)) {
$bounceObject = DataObject::get_by_id('Email_BounceRecord', $memberID); $bounceObject = DataObject::get_by_id('Email_BounceRecord', $id);
if($bounceObject) { if($bounceObject) {
// Remove this bounce record // Remove this bounce record
$bounceObject->delete(); $bounceObject->delete();
@ -343,13 +341,14 @@ class NewsletterAdmin extends LeftAndMain {
// Remove the member from the mailing list // Remove the member from the mailing list
$memberObject->Groups()->remove($groupID); $memberObject->Groups()->remove($groupID);
} else { } 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. FormResponse::status_message($memberObject->Email.' was removed from the mailing list', 'good');
return 1; FormResponse::add("$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value, 'recipients');");
return FormResponse::respond();
} }
}else{ } else {
return 0; 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(); 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() { function NewsletterAdminSiteTree() {
return $this->getsitetree(); 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'); CMSForm.applyTo('#Form_MemberForm','rightbottom');
Behaviour.register({ Behaviour.register({

View File

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