From 62dd81a1655441e42377045d2aa86d83b6ad7aed Mon Sep 17 00:00:00 2001 From: Martin Kamerbeek Date: Wed, 2 Jun 2010 18:09:55 +0200 Subject: [PATCH] Add better feedback for schedule, test and cancel operations. --- lib/WebGUI/Mailing.pm | 58 ++++++++++++++++++----- lib/WebGUI/i18n/Dutch/MailingManager.pm | 19 +++++++- lib/WebGUI/i18n/English/MailingManager.pm | 23 +++++++-- 3 files changed, 83 insertions(+), 17 deletions(-) diff --git a/lib/WebGUI/Mailing.pm b/lib/WebGUI/Mailing.pm index 406e0e2..c823e6c 100644 --- a/lib/WebGUI/Mailing.pm +++ b/lib/WebGUI/Mailing.pm @@ -247,6 +247,7 @@ sub queueEmails { recipientEmail => undef, isTest => 0, } ); + } return; @@ -272,6 +273,15 @@ sub queueScheduled { return; } +#---------------------------------------------------------------------------- +sub renderInConsole { + my $self = shift; + my $content = shift; + my $title = shift; + + return WebGUI::Mailing::Admin->new($self->session)->getAdminConsole->render( $content, $title ); +} + #---------------------------------------------------------------------------- sub send { my $self = shift; @@ -321,17 +331,24 @@ sub sendQueuedEmails { sub www_cancel { my $self = shift; my $session = $self->session; - my $admin = WebGUI::Mailing::Admin->new( $session ); my $i18n = WebGUI::International->new( $session, 'MailingManager' ); - return $admin->adminConsole->render( - sprintf( $i18n->get( 'cannot cancel mailing' ), $self->getId ), - $i18n->get( 'error' ) - ) unless $self->canCancel; + if ( $self->canCancel ) { + $self->cancel; - $self->cancel; + return $self->renderInConsole( + $i18n->get('cancel mailing success'), + $i18n->get('cancel mailing'), + ); + } + else { + return $self->renderInConsole( + $i18n->get('cancel mailing failure'), + $i18n->get('cancel mailing'), + ); + } - return WebGUI::Mailing::Admin->new($session)->www_view; + return; } #---------------------------------------------------------------------------- @@ -546,9 +563,7 @@ sub www_sendBatch { extras => qq{onclick="window.location='$cancelUrl'" class="backwardButton"}, ); - return WebGUI::Mailing::Admin->new($session)->getAdminConsole->render( $f->print, 'Send test emails' ); - - return WebGUI::Mailing::Admin->new($session)->getAdminConsole->render( $f->print, $i18n->get('schedule mailing') ); + return $self->renderInConsole( $f->print, $i18n->get('schedule mailing') ); } #---------------------------------------------------------------------------- @@ -579,6 +594,7 @@ sub www_sendBatchConfirm { my $self = shift; my $session = $self->session; my $form = $session->form; + my $i18n = WebGUI::International->new( $session, 'MailingManager' ); my $scheduled = $form->dateTime( 'sendDate' ); @@ -589,7 +605,13 @@ sub www_sendBatchConfirm { $self->schedule( $scheduled ); - return WebGUI::Mailing::Admin->new( $session )->www_view; + return $self->renderInConsole( + sprintf( $i18n->get('schedule mailing success'), + $session->datetime->epochToHuman( $scheduled ), + $session->url->page('newsletter=manage'), + ), + $i18n->get( 'schedule mailing' ) + ); } #---------------------------------------------------------------------------- @@ -646,7 +668,7 @@ sub www_sendTestEmails { extras => qq{onclick="window.location='$cancelUrl'" class="backwardButton"}, ); - return WebGUI::Mailing::Admin->new($session)->getAdminConsole->render( $f->print, 'Send test emails' ); + return $self->renderInConsole( $f->print, $i18n->get('send test mails') ); } #---------------------------------------------------------------------------- @@ -654,13 +676,23 @@ sub www_sendTestEmailsConfirm { my $self = shift; my $session = $self->session; my $form = $session->form; + my $i18n = WebGUI::International->new( $session, 'MailingManager' ); my $to = $form->get( 'to' ); my @userIds = $form->selectList( 'userIds' ); $self->queueTestEmails( $to, \@userIds ); - return WebGUI::Mailing::Admin->new( $session )->www_view; + return $self->renderInConsole( + sprintf( $i18n->get('send test mail success'), + scalar( @userIds ), + $to, + $session->url->page('newsletter=manage'), + ), + $i18n->get( 'send test mails' ) + ); + + } 1; diff --git a/lib/WebGUI/i18n/Dutch/MailingManager.pm b/lib/WebGUI/i18n/Dutch/MailingManager.pm index 5bcc421..005fb5c 100644 --- a/lib/WebGUI/i18n/Dutch/MailingManager.pm +++ b/lib/WebGUI/i18n/Dutch/MailingManager.pm @@ -1,4 +1,4 @@ -package WebGUI::i18n::English::MailingManager; +package WebGUI::i18n::Dutch::MailingManager; use strict; @@ -65,6 +65,23 @@ our $I18N = { message => 'Afbreken', }, + 'send test mail success' => { + message => qq{

Er zijn %i testemails klaargezet om verstuurd te worden naar %s.

Terug naar mailingbeheer.

}, + }, + + 'schedule mailing success' => { + message => qq{

Deze mailing is geplanned om verzonden te worden op %s.

Terug naar mailingbeheer.

}, + }, + + 'cancel mailing' => { + message => 'Mailing afbreken', + }, + 'cancel mailing success' => { + message => 'De mailing is afgebroken.', + }, + 'cancel mailing failure' => { + message => 'De mailing kan niet afgebroken worden. Dit kan voorkomen als de mailing geplanned stond om verzonden te worden vlak voor het moment waarop deze afgebroken werd.', + }, }; 1; diff --git a/lib/WebGUI/i18n/English/MailingManager.pm b/lib/WebGUI/i18n/English/MailingManager.pm index 5115aeb..18fb565 100644 --- a/lib/WebGUI/i18n/English/MailingManager.pm +++ b/lib/WebGUI/i18n/English/MailingManager.pm @@ -27,9 +27,6 @@ our $I18N = { message => 'Bounce score', }, - 'cannot cancel' => { - message => 'Cannot cancel mailing \'%s\'.', - }, 'error' => { message => 'An error occurred', }, @@ -65,6 +62,26 @@ our $I18N = { message => 'Cancel', }, + 'send test mail' => { + message => 'Send test emails', + }, + 'send test mail success' => { + message => qq{

%i test emails have been queued for sending to %s.

Back to mailing manager.

}, + }, + + 'schedule mailing success' => { + message => qq{This mailing is successfully scheduled for distribution on %s.

Back to mailing manager.

}, + }, + + 'cancel mailing' => { + message => 'Cancel mailing', + }, + 'cancel mailing success' => { + message => 'The mailing has sucessfully been canceled.', + }, + 'cancel mailing failure' => { + message => 'The mailing could not be canceled. This can happen when the mailing has been scheduled just before it was canceled.', + }, }; 1;