140 lines
3.8 KiB
Perl
140 lines
3.8 KiB
Perl
package WebGUI::AssetAspect::Mailable;
|
|
|
|
use strict;
|
|
use warnings;
|
|
use Class::C3;
|
|
|
|
use WebGUI::Macro;
|
|
use Tie::IxHash;
|
|
|
|
#----------------------------------------------------------------------------
|
|
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 => $i18n->get( '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;
|
|
my $session = $self->session;
|
|
my $i18n = WebGUI::International->new( $session,'AssetAspect_Mailable' );
|
|
|
|
return ( $self->next::method, [ 'mailable', $i18n->get( 'mailing' ), 9 ] );
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub generateEmailContent {
|
|
WebGUI::Error::OverrideMe->throw;
|
|
return;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub getIssueList {
|
|
WebGUI::Error::OverrideMe->throw;
|
|
return;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub getSubject {
|
|
my $self = shift;
|
|
my $configuration = shift || {};
|
|
|
|
return $configuration->{ subject } || '(No subject)';
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub getMailingProperties {
|
|
my $self = shift;
|
|
my $mailing = shift;
|
|
my $session = $self->session;
|
|
my $i18n = WebGUI::International->new( $session,'AssetAspect_Mailable' );
|
|
|
|
my $issue = $mailing->getIssue
|
|
? $mailing->getIssue
|
|
: $self
|
|
;
|
|
|
|
tie my %properties, 'Tie::IxHash', (
|
|
subject => {
|
|
fieldType => 'text',
|
|
label => $i18n->get( 'subject' ),
|
|
defaultValue=> $issue->getTitle,
|
|
},
|
|
styleTemplateId => {
|
|
fieldType => 'template',
|
|
label => $i18n->get( 'mail template' ),
|
|
defaultValue=> $self->get('mailStyleTemplateId'),
|
|
namespace => 'style',
|
|
},
|
|
);
|
|
|
|
return \%properties;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub getRecipients {
|
|
WebGUI::Error::OverrideMe->throw;
|
|
return;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub processContentAsUser {
|
|
my $self = shift;
|
|
my $issueId = shift;
|
|
my $userId = shift;
|
|
my $configuration = shift || {};
|
|
my $session = $self->session;
|
|
my $var = $session->var;
|
|
|
|
# Save state
|
|
my $currentUser = $session->user;
|
|
my $adminOn = $var->isAdminOn;
|
|
$var->switchAdminOff;
|
|
|
|
# Become the desired user
|
|
$session->user( { userId => $userId } );
|
|
$session->log->preventDebugOutput;
|
|
|
|
my $styleTemplateId =
|
|
$configuration->{ styleTemplateId }
|
|
|| $self->get('mailStyleTemplateId')
|
|
|| $self->get('styleTemplateId');
|
|
|
|
# Generate email body for this user
|
|
my $content = $session->style->process(
|
|
$self->generateEmailContent( $issueId, $configuration ),
|
|
$styleTemplateId,
|
|
);
|
|
|
|
# Process macros
|
|
WebGUI::Macro::process( $session, \$content );
|
|
|
|
# Become ourselves again.
|
|
$session->user( { userId => $currentUser->getId } );
|
|
$var->switchAdminOn if $adminOn;
|
|
|
|
return $content;
|
|
}
|
|
|
|
1;
|
|
|