164 lines
4.4 KiB
Perl
164 lines
4.4 KiB
Perl
package WebGUI::AssetAspect::Mailable;
|
|
|
|
use strict;
|
|
use warnings;
|
|
use Class::C3;
|
|
|
|
use WebGUI::Macro;
|
|
|
|
##----------------------------------------------------------------------------
|
|
#sub configureMailingForm {
|
|
# my $self = shift;
|
|
# my $f = WebGUI::HTMLForm->new( $session, { action => $self->getUrl } );
|
|
# $f->hidden(
|
|
# name => 'func'
|
|
# value => '
|
|
#
|
|
# return $f;
|
|
#}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub definition {
|
|
my $class = shift;
|
|
my $session = shift;
|
|
my $definition = shift;
|
|
my $i18n = WebGUI::International->new( $session,'AssetAspect_Mailable' );
|
|
|
|
tie my %properties, 'Tie::IxHash', (
|
|
mailStyleTemplateId => {
|
|
fieldType => 'template',
|
|
label => 'Mail template',
|
|
tab => 'mailable',
|
|
namespace => 'style',
|
|
},
|
|
);
|
|
|
|
push( @{ $definition }, {
|
|
autoGenerateForms => 1,
|
|
tableName => 'assetAspectMailable',
|
|
className => 'WebGUI::AssetAspect::Mailable',
|
|
properties => \%properties
|
|
} );
|
|
|
|
return $class->next::method( $session, $definition );
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub getEditTabs {
|
|
my $self = shift;
|
|
|
|
return ( $self->next::method, [ 'mailable', 'Mailing list', 9 ] );
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub generateEmailContent {
|
|
WebGUI::Error::OverrideMe->throw;
|
|
return;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub getIssueList {
|
|
WebGUI::Error::OverrideMe->throw;
|
|
return;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub getRecipients {
|
|
WebGUI::Error::OverrideMe->throw;
|
|
return;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub processContentAsUser {
|
|
my $self = shift;
|
|
my $userId = shift;
|
|
my $session = $self->session;
|
|
my $currentUser = $session->user;
|
|
|
|
# Become the desired user
|
|
$session->user( { userId => $userId } );
|
|
$session->log->preventDebugOutput;
|
|
|
|
my $styleTemplateId =
|
|
$self->get('mailStyleTemplateId')
|
|
|| $self->get('styleTemplateId');
|
|
|
|
# Generate email body for this user
|
|
my $content = $session->style->process(
|
|
$self->generateEmailContent,
|
|
$styleTemplateId,
|
|
);
|
|
|
|
# Process macros
|
|
WebGUI::Macro::process( $session, \$content );
|
|
|
|
# Become ourselves again.
|
|
$session->user( { userId => $currentUser->getId } );
|
|
|
|
return $content;
|
|
}
|
|
|
|
##----------------------------------------------------------------------------
|
|
#sub www_configureMailing {
|
|
# my $self = shift;
|
|
#
|
|
# my $f = $self->configureMailingForm;
|
|
#
|
|
# $f->submit( 'Next step' );
|
|
#
|
|
# return $self->processStyle( $f->print );
|
|
#}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub www_previewContent {
|
|
my $self = shift;
|
|
my $form = $self->session->form;
|
|
|
|
my $userId = $form->get('userId');
|
|
|
|
return $self->processContentAsUser( $userId );
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub www_previewEmail {
|
|
my $self = shift;
|
|
my $session = $self->session;
|
|
my $form = $session->form;
|
|
|
|
my %recipients =
|
|
map { $_->getId => $_->username }
|
|
map { WebGUI::User->new( $session, $_ ) }
|
|
@{ $self->getRecipients };
|
|
|
|
my $issueId = $form->get('issueId');
|
|
my $userId = $form->get('userId') || ( %recipients )[0];
|
|
|
|
my $userSelection =
|
|
WebGUI::Form::formHeader( $session )
|
|
. WebGUI::Form::hidden( $session, { name => 'func', value => 'previewEmail' } )
|
|
. WebGUI::Form::hidden( $session, { name => 'issueId', value => $issueId } )
|
|
. WebGUI::Form::selectBox( $session, {
|
|
name => 'userId',
|
|
options => \%recipients,
|
|
value => $userId,
|
|
} )
|
|
. WebGUI::Form::submit( $session, { value => 'Switch' } )
|
|
. WebGUI::Form::formFooter( $session );
|
|
|
|
my $url = $self->getUrl("func=previewContent;issueId=$issueId;userId=$userId");
|
|
|
|
return <<EOHTML;
|
|
<html>
|
|
<head>
|
|
</head>
|
|
<body>
|
|
$userSelection
|
|
<iframe src="$url" id="previewFrame" style="width: 100%; height: 90%">
|
|
</iframe>
|
|
</body>
|
|
</html>
|
|
EOHTML
|
|
}
|
|
|
|
1;
|
|
|