Make preview userinterface scalable for large amounts of users.
This commit is contained in:
parent
fd3ecc8256
commit
e53193b638
1 changed files with 83 additions and 21 deletions
|
|
@ -5,6 +5,7 @@ use warnings;
|
|||
use Carp;
|
||||
|
||||
use WebGUI::Mailing::Admin;
|
||||
use JSON qw{ to_json };
|
||||
|
||||
use base 'WebGUI::Crud';
|
||||
|
||||
|
|
@ -397,45 +398,87 @@ sub www_previewEmail {
|
|||
my $i18n = WebGUI::International->new( $session, 'MailingManager' );
|
||||
|
||||
my $asset = $self->getAsset;
|
||||
my %recipients =
|
||||
map { $_->getId => $_->username }
|
||||
map { WebGUI::User->new( $session, $_ ) }
|
||||
@{ $asset->getRecipients };
|
||||
|
||||
my $userId = $form->get('userId') || ( %recipients )[0];
|
||||
|
||||
my $manageUrl = $url->page('newsletter=manage');
|
||||
my $contentUrl = $url->page( "newsletter=mailing;func=previewContent;userId=$userId;id=".$self->getId );
|
||||
my $subject = $asset->getSubject( $self->get('configuration') );
|
||||
|
||||
my $userSelection =
|
||||
WebGUI::Form::formHeader( $session )
|
||||
. WebGUI::Form::hidden( $session, { name => 'newsletter', value => 'mailing' } )
|
||||
. WebGUI::Form::hidden( $session, { name => 'func', value => 'previewEmail' } )
|
||||
. WebGUI::Form::hidden( $session, { name => 'id', value => $self->getId } )
|
||||
. WebGUI::Form::selectBox( $session, {
|
||||
name => 'userId',
|
||||
options => \%recipients,
|
||||
value => $userId,
|
||||
} )
|
||||
. WebGUI::Form::submit( $session, { value => $i18n->get( 'switch user') } )
|
||||
. " <a href=\"$manageUrl\">" . $i18n->get( 'return to manager' ) . "</a>"
|
||||
. WebGUI::Form::formFooter( $session );
|
||||
'<div id="ac">
|
||||
Kies een gebruiker:
|
||||
<input id="acElem" type="text" />
|
||||
<div id="acCont"></div>
|
||||
</div>';
|
||||
|
||||
my $js = $self->getAutoCompleteJS;
|
||||
|
||||
return <<EOHTML;
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
#ac {
|
||||
width:25em; /* set width here or else widget will expand to fit its container */
|
||||
padding-bottom:2em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- Individual YUI CSS files -->
|
||||
<link rel="stylesheet" type="text/css" href="/extras/yui/build/autocomplete/assets/skins/sam/autocomplete.css">
|
||||
<!-- Individual YUI JS files -->
|
||||
<script type="text/javascript" src="/extras/yui/build/yahoo-dom-event/yahoo-dom-event.js"></script>
|
||||
<script type="text/javascript" src="/extras/yui/build/datasource/datasource-min.js"></script>
|
||||
<script type="text/javascript" src="/extras/yui/build/autocomplete/autocomplete-min.js"></script>
|
||||
<script type="text/javascript" src="/extras/yui/build/connection/connection-min.js"></script>
|
||||
<script type="text/javascript" src="/extras/yui/build/json/json-min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$js
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<body class="yui-skin-sam">
|
||||
$userSelection
|
||||
<b>Subject :</b>$subject
|
||||
<iframe src="$contentUrl" id="previewFrame" style="width: 100%; height: 90%">
|
||||
<iframe id="previewFrame" style="width: 100%; height: 90%">
|
||||
</iframe>
|
||||
</body>
|
||||
</html>
|
||||
EOHTML
|
||||
}
|
||||
|
||||
sub getAutoCompleteJS {
|
||||
my $self = shift;
|
||||
my $url = $self->session->url;
|
||||
my $jsonUrl = $url->page( 'newsletter=mailing;func=getRecipientsList;id='.$self->getId .';');
|
||||
my $contentBase = $url->page( "newsletter=mailing;func=previewContent;id=".$self->getId );
|
||||
|
||||
return <<EOJS;
|
||||
YAHOO.util.Event.onDOMReady( function() {
|
||||
var jsonUrl = '$jsonUrl';
|
||||
var contentBase = '$contentBase';
|
||||
var contentFrame = YAHOO.util.Dom.get('previewFrame');
|
||||
|
||||
var dataSource = new YAHOO.util.XHRDataSource("$jsonUrl");
|
||||
dataSource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
|
||||
dataSource.responseSchema = {
|
||||
resultsList : 'recipients',
|
||||
fields : [ 'name', 'id' ]
|
||||
};
|
||||
|
||||
// Instantiate the AutoComplete
|
||||
var autoComplete = new YAHOO.widget.AutoComplete("acElem", "acCont", dataSource);
|
||||
autoComplete.resultTypeList = false;
|
||||
autoComplete.queryQuestionMark = false;
|
||||
|
||||
// Define an event handler to populate a hidden form field
|
||||
// when an item gets selected
|
||||
var myHiddenField = YAHOO.util.Dom.get("autoCompleteHiddenField");
|
||||
var myHandler = function(type, args) {
|
||||
// myHiddenField.value = args[2].id
|
||||
contentFrame.src = contentBase + ';userId=' + args[2].id;
|
||||
};
|
||||
autoComplete.itemSelectEvent.subscribe(myHandler);
|
||||
} );
|
||||
EOJS
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub www_editSave {
|
||||
my $self = shift;
|
||||
|
|
@ -588,5 +631,24 @@ sub www_sendTestEmailsConfirm {
|
|||
return WebGUI::Mailing::Admin->new( $session )->www_view;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub www_getRecipientsList {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $query = $session->form->get( 'query' );
|
||||
my @users =
|
||||
map { {
|
||||
id => $_->getId,
|
||||
name => $_->username . " (" . $_->get('email') . ")",
|
||||
} }
|
||||
grep { defined $_ && ( $_->username =~ m{$query}i || $_->get('email') =~ m{$query}i ) }
|
||||
map { WebGUI::User->new( $session, $_ ) }
|
||||
@{ $self->getAsset->getRecipients };
|
||||
|
||||
$session->http->setMimeType('application/json');
|
||||
return to_json( { recipients => \@users } );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue