Survey summaries now use YUI datatables and charts for extra bling.
This commit is contained in:
parent
aefb658fd5
commit
af00b7a881
7 changed files with 149 additions and 38 deletions
|
|
@ -4,7 +4,6 @@
|
|||
- Survey summaries now added. In the Survey edit, select quiz mode, and a summary will be shown to the user at the end of the survey.
|
||||
- fixed #10110: Matrix 2.0 - "Data Error" on Pending Product Listing Updates
|
||||
- rfe #9965: matrix/pls reverse dropped event variables
|
||||
|
||||
7.7.2
|
||||
- fixed #10056: YUI javascripts included while adminOff (BNC)
|
||||
- fixed a bug that required you to hit "update cart" before the checkout
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -1157,7 +1157,8 @@ sub getSummary{
|
|||
my $self = shift;
|
||||
my $summary = $self->responseJSON->showSummary();
|
||||
my $out = $self->processTemplate( $summary, $self->get('surveySummaryTemplateId') );
|
||||
return $out;
|
||||
|
||||
return ($summary,$out);
|
||||
# return $self->session->style->process( $out, $self->get('styleTemplateId') );
|
||||
}
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -1191,7 +1192,8 @@ sub www_loadQuestions {
|
|||
$self->session->log->debug('Response surveyEnd, so calling surveyEnd');
|
||||
if ( $self->get('quizModeSummary') ) {
|
||||
if(! $self->session->form->param('shownsummary')){
|
||||
my $json = to_json( { type => 'summary', summary => $self->getSummary() });
|
||||
my ($summary,$html) = $self->getSummary();
|
||||
my $json = to_json( { type => 'summary', summary => $summary, html => $html });
|
||||
return $json;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1074,9 +1074,8 @@ sub showSummary{
|
|||
|
||||
return if(! $responses);
|
||||
|
||||
my ($sectionIndex, $questionIndex, $answerIndex) = (-1, -1, -1);
|
||||
my ($currentSection,$currentQuestion) = (-1, -1);
|
||||
|
||||
my ($sectionIndex, $responseIndex) = (-1, 1);
|
||||
my ($currentSection,$currentQuestion) = (-1,-1);
|
||||
($summaries->{totalCorrect},$summaries->{totalIncorrect}) = (0,0);
|
||||
|
||||
for my $response (@$responses){
|
||||
|
|
@ -1090,62 +1089,54 @@ sub showSummary{
|
|||
if($currentSection != $response->{address}->[0]){
|
||||
$summaries->{totalSections}++;
|
||||
$sectionIndex++;
|
||||
$questionIndex = -1;
|
||||
$answerIndex = -1;
|
||||
$currentQuestion = -1;
|
||||
$responseIndex = -1;
|
||||
$currentSection = $response->{address}->[0];
|
||||
_loadSectionIntoSummary(\%{$summaries->{sections}->[$sectionIndex]},$response);
|
||||
}
|
||||
if($currentQuestion != $response->{address}->[1]){
|
||||
$summaries->{totalQuestions}++;
|
||||
$questionIndex++;
|
||||
$answerIndex = -1;
|
||||
$currentQuestion = $response->{address}->[1];
|
||||
_loadQuestionIntoSummary(\%{$summaries->{sections}->[$sectionIndex]->{questions}->[$questionIndex]},$response);
|
||||
}
|
||||
$answerIndex++;
|
||||
_loadAnswerIntoSummary(\%{$summaries->{sections}->[$sectionIndex]->{questions}->[$questionIndex]->{answers}->[$answerIndex]},
|
||||
_loadSectionIntoSummary(\%{$summaries->{sections}->[$sectionIndex]}, $response);
|
||||
$responseIndex++;
|
||||
_loadResponseIntoSummary(\%{$summaries->{sections}->[$sectionIndex]->{responses}->[$responseIndex]},
|
||||
$response,
|
||||
$self->survey->{multipleChoiceTypes});
|
||||
}
|
||||
return $summaries;
|
||||
}
|
||||
sub _loadAnswerIntoSummary{
|
||||
sub _loadResponseIntoSummary{
|
||||
my $node = shift;
|
||||
my $response = shift;
|
||||
my $types = shift;
|
||||
|
||||
$node->{id} = $response->{address}->[2] + 1;
|
||||
$node->{"Question ID"} = $response->{address}->[1] + 1;
|
||||
$node->{"Question Text"} = $response->{questionText};
|
||||
$node->{"Answer ID"} = $response->{address}->[2] + 1;
|
||||
if($response->{isCorrect}){
|
||||
$node->{iscorrect} = 1;
|
||||
$node->{score} = $response->{value};
|
||||
$node->{Correct} = "Y";
|
||||
$node->{Score} = $response->{value};
|
||||
}else{
|
||||
$node->{iscorrect} = 0;
|
||||
$node->{score} = 0;
|
||||
$node->{Correct} = "N";
|
||||
$node->{Score} = 0;
|
||||
}
|
||||
$node->{text} = $response->{answerText};
|
||||
$node->{"Answer Text"} = $response->{answerText};
|
||||
|
||||
#test if it is a multiple choide type
|
||||
if($types->{$response->{questionType}}){
|
||||
$node->{value} = $response->{value};
|
||||
$node->{Value} = $response->{value};
|
||||
}else{
|
||||
$node->{value} = $response->{recordedValue};
|
||||
$node->{Value} = $response->{recordedValue};
|
||||
}
|
||||
}
|
||||
sub _loadQuestionIntoSummary{
|
||||
my $node = shift;
|
||||
my $response = shift;
|
||||
$node->{id} = $response->{address}->[1] + 1;
|
||||
$node->{text} = $response->{questionText};
|
||||
}
|
||||
sub _loadSectionIntoSummary{
|
||||
my $node = shift;
|
||||
my $response = shift;
|
||||
$node->{id} = $response->{address}->[0] + 1;
|
||||
$node->{inCorrect} = 0 if(!defined $node->{section}->{inCorrect});
|
||||
$node->{score} = 0 if(!defined $node->{section}->{score});
|
||||
$node->{correct} = 0 if(!defined $node->{section}->{correct});
|
||||
if($response->{isCorrect}){
|
||||
$node->{inCorrect} = 0 if(!defined $node->{inCorrect});
|
||||
$node->{score} = 0 if(!defined $node->{score});
|
||||
$node->{correct} = 0 if(!defined $node->{correct});
|
||||
$node->{total} = 0 if(!defined $node->{total});
|
||||
$node->{total}++;
|
||||
if($response->{isCorrect} == 1){
|
||||
$node->{score} += $response->{value};
|
||||
$node->{correct}++;
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -324,14 +324,125 @@ if (typeof Survey === "undefined") {
|
|||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
YAHOO.widget.Chart.SWFURL = "/extras/yui/build/charts/assets/charts.swf";
|
||||
// Public API
|
||||
Survey.Form = {
|
||||
showSummary: function(html){
|
||||
globalSummaryDataTip: function(item, index, series){
|
||||
var toolTipText = "hello";
|
||||
//var toolTipText = series.displayName + " for " + item.section;
|
||||
//toolTipText += "\n" + item[series.yField];
|
||||
return toolTipText;
|
||||
},
|
||||
showSummary: function(summary,html){
|
||||
var html = html;
|
||||
document.getElementById('survey').innerHTML = html;
|
||||
|
||||
|
||||
//Add totoal summary pie chart
|
||||
totalSummary =
|
||||
[
|
||||
{ correct: "Correct", count: summary.totalCorrect },
|
||||
{ correct: "Incorrect", count: summary.totalIncorrect }
|
||||
]
|
||||
|
||||
var totalSummaryDS = new YAHOO.util.DataSource( totalSummary );
|
||||
totalSummaryDS.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
|
||||
totalSummaryDS.responseSchema = { fields: [ "correct", "count" ] };
|
||||
|
||||
new YAHOO.widget.PieChart( "chart", totalSummaryDS,
|
||||
{
|
||||
dataField: "count",
|
||||
categoryField: "correct",
|
||||
style:
|
||||
{
|
||||
padding: 10,
|
||||
legend:
|
||||
{
|
||||
display: "left",
|
||||
padding: 10,
|
||||
spacing: 2,
|
||||
font:
|
||||
{
|
||||
family: "Arial",
|
||||
size: 13
|
||||
}
|
||||
}
|
||||
},
|
||||
//only needed for flash player express install
|
||||
expressInstall: "/extras/yui/build/charts/assets/charts.swf"
|
||||
});
|
||||
|
||||
//define section datatable columns
|
||||
var myColumnDefs = [
|
||||
{key:"Question ID", sortable:true, resizeable:true},
|
||||
{key:"Question Text", formatter: YAHOO.widget.DataTable.formatText, sortable:true, resizeable:true},
|
||||
{key:"Answer ID", sortable:true, resizeable:true},
|
||||
{key:"Correct", sortable:true, resizeable:true},
|
||||
{key:"Answer Text", formatter: YAHOO.widget.DataTable.formatText, sortable:true, resizeable:true},
|
||||
{key:"Score", sortable:true, resizeable:true},
|
||||
{key:"Value", formatter: YAHOO.widget.DataTable.formatText, sortable:true, resizeable:true}
|
||||
];
|
||||
var sectionSummary = [];
|
||||
//Load up datatables and create section data for bar chart
|
||||
for(var i = 0; i < summary.sections.length; i++){
|
||||
var temp = summary.sections[i];
|
||||
sectionSummary[sectionSummary.length] = {"Total Responses": temp.total, "Correct": temp.correct, "Incorrect": temp.inCorrect, "section": (i+1)};
|
||||
var myDataSource = new YAHOO.util.DataSource(summary.sections[i].responses);
|
||||
//These needs to be put in a destroy call list for when the html dom is recreated, if summaries are going to be uses with page reloads, else memory leak.
|
||||
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
|
||||
myDataSource.responseSchema = {
|
||||
fields: ["Question ID","Question Text","Answer ID","Correct","Answer Text","Score","Value"]
|
||||
};
|
||||
var tempText = "section"+ (i+1) + "datatable";
|
||||
new YAHOO.widget.DataTable(tempText, myColumnDefs, myDataSource, {caption:"Section "+(i+1)});
|
||||
}
|
||||
|
||||
//Now create section summary bar charts
|
||||
var sectionSummaryDS = new YAHOO.util.DataSource( sectionSummary );
|
||||
sectionSummaryDS.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
|
||||
sectionSummaryDS.responseSchema =
|
||||
{
|
||||
fields: [ "Total Responses", "Correct", "Incorrect", "section" ]
|
||||
};
|
||||
var sectionSummarySeriesDef =
|
||||
[
|
||||
{
|
||||
displayName: "Total Responses",
|
||||
yField: "Total Responses",
|
||||
style:{size:10}
|
||||
},
|
||||
{
|
||||
displayName: "Correct",
|
||||
yField: "Correct",
|
||||
style:{size:10}
|
||||
},
|
||||
{
|
||||
displayName: "Incorrect",
|
||||
yField: "Incorrect",
|
||||
style:{size:10}
|
||||
}
|
||||
];
|
||||
//create a Numeric Axis for displaying dollars
|
||||
var responseAxis = new YAHOO.widget.NumericAxis();
|
||||
responseAxis.title = "Responses";
|
||||
//create Category Axis to specify a title for the months
|
||||
var sectionAxis = new YAHOO.widget.CategoryAxis();
|
||||
sectionAxis.title = "Sections";
|
||||
//create the Chart
|
||||
var mychart = new YAHOO.widget.ColumnChart( "summarychart", sectionSummaryDS,
|
||||
{
|
||||
series: sectionSummarySeriesDef,
|
||||
xField: "section",
|
||||
xAxis: sectionAxis,
|
||||
yAxis: responseAxis,
|
||||
// dataTipFunction: Survey.Form.globalSummaryDataTip, //try again in 2.7
|
||||
expressInstall: "/extras/yui/build/charts/assets/charts.swf"
|
||||
});
|
||||
|
||||
YAHOO.util.Event.addListener("submitbutton", "click", function(){ Survey.Comm.submitSummary(); });
|
||||
},
|
||||
|
||||
displayQuestions: function(params){
|
||||
toValidate = [];
|
||||
var qs = params.questions;
|
||||
|
|
@ -530,3 +641,11 @@ YAHOO.util.Event.onDOMReady(function(){
|
|||
// Survey.Comm.setUrl('/' + document.getElementById('assetPath').value);
|
||||
Survey.Comm.callServer('', 'loadQuestions');
|
||||
});
|
||||
|
||||
YAHOO.example.getDataTipText = function( item, index, series )
|
||||
{
|
||||
var toolTipText = series.displayName + " for " + item.month;
|
||||
// toolTipText += "\n" + YAHOO.example.formatCurrencyAxisLabel( item[series.yField] );
|
||||
return toolTipText;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ if (typeof Survey === "undefined") {
|
|||
window.location = url;
|
||||
}
|
||||
else if(response.type === 'summary'){
|
||||
Survey.Form.showSummary(response.summary);
|
||||
Survey.Form.showSummary(response.summary,response.html);
|
||||
}
|
||||
else {
|
||||
alert("bad response");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue