diff --git a/lib/WebGUI/Mailing.pm b/lib/WebGUI/Mailing.pm index 31ced29..93d8124 100644 --- a/lib/WebGUI/Mailing.pm +++ b/lib/WebGUI/Mailing.pm @@ -40,7 +40,7 @@ sub cancel { ); }; - $self->update( { + $self->update( { state => 'idle', sendDate => undef, } ); @@ -65,7 +65,7 @@ sub crud_definition { assetId => { fieldType => 'guid', }, - + issueId => { fieldType => 'guid', }, @@ -83,7 +83,7 @@ sub crud_definition { }, ); - $definition->{ properties } = { + $definition->{ properties } = { %{ $definition->{ properties } || {} }, %properties, }; @@ -94,7 +94,7 @@ sub crud_definition { #---------------------------------------------------------------------------- sub delete { my $self = shift; - + $self->deleteQueuedEmails; return $self->SUPER::delete; @@ -103,12 +103,12 @@ sub delete { #---------------------------------------------------------------------------- sub deleteQueuedEmails { my $self = shift; - + my $it = $self->getQueuedEmailIterator; while ( my $email = $it->() ) { $email->delete; } - + $it = $self->getQueuedTestEmailIterator; while ( my $email = $it->() ) { $email->delete; @@ -180,8 +180,8 @@ sub getStatusLine { my $self = shift; my $db = $self->session->db; - my $sth = $db->read( - 'select status, isTest, count( status ) as cnt from Mailing_email where mailingId=? group by status,isTest', + my $sth = $db->read( + 'select status, isTest, count( status ) as cnt from Mailing_email where mailingId=? group by status,isTest', [ $self->getId, ], @@ -260,7 +260,7 @@ sub queue { $state, ); }; - + $self->queueEmails( $self->getAsset->getRecipients ); $self->update( { @@ -285,7 +285,7 @@ sub queueEmails { recipientEmail => undef, isTest => 0, } ); - + } return; @@ -334,7 +334,7 @@ sub send { $state, ); }; - + $self->update( { state => 'sending' } ); my $complete = $self->sendQueuedEmails( $timeLimit ); @@ -361,7 +361,7 @@ sub sendQueuedEmails { $email->send; } - + return 1; } @@ -380,7 +380,7 @@ sub www_cancel { $i18n->get('cancel mailing success'), $i18n->get('cancel mailing'), ); - } + } else { return $self->renderInConsole( $i18n->get('cancel mailing failure'), @@ -415,13 +415,13 @@ sub www_delete { #---------------------------------------------------------------------------- sub www_edit { - my $self = shift; - my $session = $self->session; - my $i18n = WebGUI::International->new( $session, 'MailingManager' ); + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new( $session, 'MailingManager' ); return $session->privilege->insufficient unless $self->admin->canManage; - my $f = WebGUI::HTMLForm->new( $session ); + my $f = $self->getEditForm; $f->hidden( name => 'newsletter', value => 'mailing', @@ -435,6 +435,16 @@ sub www_edit { value => $self->getId, ); + return $self->renderInConsole( $f->print, $i18n->get('configure mailing') ); +} + +#---------------------------------------------------------------------------- +sub getEditForm { + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new( $session, 'MailingManager' ); + my $f = WebGUI::HTMLForm->new( $session ); + my %fields = %{ $self->getAsset->getMailingProperties( $self ) }; my $configuration = $self->get('configuration') || {}; while ( my( $name, $properties ) = each %fields ) { @@ -444,7 +454,7 @@ sub www_edit { my $formField = WebGUI::Form::DynamicField->new( $session, %{ $properties } ); my $element = $formField->toHtml; # Works around a bug in WG::Form::Template in < 7.9.8 my $readonly = $formField->getValueAsHtml; # where getValueAsHtml wouldn't set the correct options hashref - + my $html = $self->admin->canOverride || $properties->{ managerCanEdit } ? $element : $readonly @@ -458,12 +468,12 @@ sub www_edit { $f->submit( value => $i18n->get( 'generate mailing' ) ); my $cancelUrl = $session->url->page( 'newsletter=manage' ); - $f->button( + $f->button( value => $i18n->get( 'cancel' ), extras => qq{onclick="window.location='$cancelUrl'" class="backwardButton"}, ); - return $self->renderInConsole( $f->print, $i18n->get('configure mailing') ); + return $f; } #---------------------------------------------------------------------------- @@ -486,7 +496,7 @@ sub www_previewEmail { my $session = $self->session; my ( $form, $url ) = $session->quick( 'form', 'url' ); my $i18n = WebGUI::International->new( $session, 'MailingManager' ); - + return $session->privilege->insufficient unless $self->admin->canManage; my $asset = $self->getAsset; @@ -494,7 +504,7 @@ sub www_previewEmail { my $manageUrl = $url->page('newsletter=manage'); my $subject = $asset->getSubject( $self->get('configuration') ); - my $userSelection = + my $userSelection = qq{
@@ -516,11 +526,11 @@ sub www_previewEmail { } - - - - - + + + + +