Added "Preview" button for survey builders
This commit is contained in:
parent
8a4f26215a
commit
63e74f14f4
3 changed files with 62 additions and 5 deletions
|
|
@ -298,6 +298,54 @@ sub www_submitObjectEdit {
|
||||||
return $self->www_loadSurvey( { address => \@address } );
|
return $self->www_loadSurvey( { address => \@address } );
|
||||||
} ## end sub www_submitObjectEdit
|
} ## end sub www_submitObjectEdit
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
=head2 Allow survey editors to "jump to" a particular section of question in a
|
||||||
|
Survey by tricking Survey into thinking they've completed the survey up to that
|
||||||
|
point. Useful for survey builders.
|
||||||
|
Note that calling this method will delete any existing survey responses for the
|
||||||
|
current user (although only survey builders can call this method so that shouldn't be
|
||||||
|
a problem
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_jumpTo {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->session->privilege->insufficient()
|
||||||
|
unless ( $self->session->user->isInGroup( $self->get('groupToEditSurvey') ) );
|
||||||
|
|
||||||
|
my $data = $self->session->form->paramsHashRef();
|
||||||
|
|
||||||
|
$self->session->log->debug("jumpTo to $data->{id}");
|
||||||
|
|
||||||
|
# Remove existing responses for current user
|
||||||
|
$self->session->db->write( 'delete from Survey_response where assetId = ? and userId = ?',
|
||||||
|
[ $self->getId, $self->session->user->userId() ] );
|
||||||
|
my $responseId = $self->getResponseId();
|
||||||
|
|
||||||
|
$self->loadBothJSON();
|
||||||
|
|
||||||
|
# iterate over surveyOrder looking for the jumpTo target
|
||||||
|
for my $i ( 0 .. $#{ $self->response->surveyOrder() } ) {
|
||||||
|
my $address = $self->response->surveyOrder()->[$i];
|
||||||
|
|
||||||
|
my @possibilities = (
|
||||||
|
$self->survey->section($address),
|
||||||
|
$self->survey->question($address),
|
||||||
|
);
|
||||||
|
foreach my $possibilty (@possibilities) {
|
||||||
|
if ( ref $possibilty eq 'HASH' && $possibilty->{id} eq $data->{id} ) {
|
||||||
|
$self->session->log->debug("Found jumpTo target");
|
||||||
|
$self->response->lastResponse( $i - 1 );
|
||||||
|
$self->saveResponseJSON();
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$self->session->log->debug("Unable to find jumpTo target");
|
||||||
|
|
||||||
|
return $self->www_takeSurvey;
|
||||||
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
sub copyObject {
|
sub copyObject {
|
||||||
my ( $self, $address ) = @_;
|
my ( $self, $address ) = @_;
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ Survey.OnLoad = function() {
|
||||||
initHandler: function(){
|
initHandler: function(){
|
||||||
new YAHOO.util.DDTarget("sections","sections");
|
new YAHOO.util.DDTarget("sections","sections");
|
||||||
Survey.Comm.loadSurvey();
|
Survey.Comm.loadSurvey();
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,14 @@ Survey.ObjectTemplate = new function(){
|
||||||
{ text:"Cancel", handler:function(){this.cancel();}},
|
{ text:"Cancel", handler:function(){this.cancel();}},
|
||||||
{ text:"Delete", handler:function(){document.getElementById('delete').value = 1; this.submit();}}
|
{ text:"Delete", handler:function(){document.getElementById('delete').value = 1; this.submit();}}
|
||||||
];
|
];
|
||||||
|
if (type !== 'answer') {
|
||||||
|
butts.push({
|
||||||
|
text: "Preview",
|
||||||
|
handler: jumpTo
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var form = new YAHOO.widget.Dialog(type,
|
var dialog = new YAHOO.widget.Dialog(type,
|
||||||
{
|
{
|
||||||
width : "600px",
|
width : "600px",
|
||||||
context: [document.body, 'tr', 'tr'],
|
context: [document.body, 'tr', 'tr'],
|
||||||
|
|
@ -31,8 +37,11 @@ Survey.ObjectTemplate = new function(){
|
||||||
buttons : butts
|
buttons : butts
|
||||||
} );
|
} );
|
||||||
|
|
||||||
form.callback = Survey.Comm.callback;
|
dialog.callback = Survey.Comm.callback;
|
||||||
form.render();
|
dialog.render();
|
||||||
|
function jumpTo() {
|
||||||
|
window.location.search = 'func=jumpTo;id=' + dialog.form.id.value;
|
||||||
|
}
|
||||||
|
|
||||||
var textareaId = type+'Text';
|
var textareaId = type+'Text';
|
||||||
var textarea = YAHOO.util.Dom.get(textareaId);
|
var textarea = YAHOO.util.Dom.get(textareaId);
|
||||||
|
|
@ -52,7 +61,7 @@ Survey.ObjectTemplate = new function(){
|
||||||
}
|
}
|
||||||
myTextarea.render();
|
myTextarea.render();
|
||||||
|
|
||||||
form.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue