diff --git a/code/Newsletter/BouncedList.php b/code/Newsletter/BouncedList.php index fe516903..d49f6ec7 100755 --- a/code/Newsletter/BouncedList.php +++ b/code/Newsletter/BouncedList.php @@ -1,14 +1,10 @@ "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 ); } - */ -} -?> +} +?> \ No newline at end of file diff --git a/code/NewsletterAdmin.php b/code/NewsletterAdmin.php index e6f7c7e4..46449e18 100755 --- a/code/NewsletterAdmin.php +++ b/code/NewsletterAdmin.php @@ -290,9 +290,7 @@ class NewsletterAdmin extends LeftAndMain { new Tab("Unsubscribers", $unsubscribedList = new UnsubscribedList("Unsubscribed", $mailType) ), - new Tab("Bounced", - new LiteralField('Instructions', '

Instructions:

'), - $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(); } diff --git a/javascript/NewsletterAdmin_right.js b/javascript/NewsletterAdmin_right.js index 4775f47b..c0da149c 100755 --- a/javascript/NewsletterAdmin_right.js +++ b/javascript/NewsletterAdmin_right.js @@ -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({ diff --git a/templates/Includes/NewsletterAdmin_BouncedList.ss b/templates/Includes/NewsletterAdmin_BouncedList.ss index 6f105bb7..4c83f241 100755 --- a/templates/Includes/NewsletterAdmin_BouncedList.ss +++ b/templates/Includes/NewsletterAdmin_BouncedList.ss @@ -1,55 +1,39 @@ -
- <% include TableListField_PageControls %> - - - - <% if Markable %><% end_if %> - <% control Headings %> - - <% end_control %> - <% if Can(delete) %><% end_if %> - - - - <% if HasSummary %> - - - <% if Markable %><% end_if %> - - <% control SummaryFields %> - class="$Function"<% end_if %>>  - <% end_control %> - <% if Can(delete) %><% end_if %> - - +<% if Entries %> +

Instructions:

+ +
 $Title 
 $SummaryTitle 
+ + + + + + + + + + + + <% control Entries %> + + - <% if Items %> - <% control Items %> - class="$HighlightClasses"<% end_if %>> - <% if Markable %><% end_if %> - <% control Fields %> - - <% end_control %> - <% if Can(delete) %> - - <% end_if %> - - <% end_control %> - <% else %> - - <% if Markable %><% end_if %> - - <% if Can(delete) %><% end_if %> - - <% end_if %> - <% if Can(add) %>$AddRecordForm.AsTableRow<% end_if %> - -
 User nameEmail addressReason:Last bounce at 
+ <% if Member.BlacklistedEmail %> + + <% else %> + <% end_if %> - -
$MarkingCheckbox$Valuedelete
 No bounce records found 
-
- <% if Can(export) %> - $ExportButton - <% end_if %> -
-
\ No newline at end of file + + $Member.FirstName $Member.Surname + $Member.Email + $Record.BounceMessage + $Record.Created.Long +delete + + <% end_control %> + + +<% else %> +

No emails sent have bounced.

+<% end_if %> \ No newline at end of file