Skip to content
Snippets Groups Projects
Commit 22dd8925 authored by Robin Drangmeister's avatar Robin Drangmeister Committed by Andreas Gärtner
Browse files

Put exportButton in own var, put export code into QuestionExport controller

parent e3ed4b0e
No related merge requests found
This commit is part of merge request !39. Comments created here will be created in the context of that merge request.
......@@ -159,6 +159,39 @@ Ext.define("ARSnova.controller.QuestionExport", {
this.saveFileOnFileSystem(csv, this.filename());
},
downloadQuestionAnswers: function (questionObj, answers) {
//Format
var exp = "data:text/csv;charset=utf-8,";
//Subeject and Question
exp += Messages.QUESTION_SUBJECT + ": " + questionObj.subject + ";" + Messages.QUESTION + ": " + questionObj.text;
if (questionObj.questionType === 'freetext') {
//Table header
exp += "\n" + Messages.QUESTION_DATE + ";" + Messages.QUESTIONS_CSV_EXPORT_ANSWERS_TIME + ";" + Messages.QUESTIONS_CSV_EXPORT_ANSWERS_SUBJECT + ";" + Messages.FREETEXT_DETAIL_ANSWER + ";Timestamp";
//Table contents (answers)
answers._data.all.forEach(function (item) {
exp += "\n" + item._data.groupDate + ";" + item._data.formattedTime + ";" + item._data.answerSubject + ";" + item._data.answerText.replace(/(?:\r\n|\r|\n)/g, ' ') + ";" + item._data.timestamp;
});
} else {
//Table header
exp += "\n" + Messages.ANSWERS + ";"
+ Messages.FIRST_ROUND + " " + Messages.GRID_LABEL_RELATIVE + ";" + Messages.FIRST_ROUND + " " + Messages.GRID_LABEL_ABSOLUTE + ";"
+ Messages.SECOND_ROUND + " " + Messages.GRID_LABEL_RELATIVE + ";" + Messages.SECOND_ROUND + " " + Messages.GRID_LABEL_ABSOLUTE;
//Table contents (answers)
answers.each(function (record) {
exp += "\n" + record.get('text') + ";" + record.get('percent-round1') + ";" + record.get('value-round1') + ";" + record.get('percent-round2') + ";" + record.get('value-round2');
});
}
//Download file
//stackoverflow.com/questions/14964035/
var encodedUri = encodeURI(exp);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", questionObj.subject + "_" + questionObj.text + "-Answers.csv");
document.body.appendChild(link);// Required for FF
link.click();
},
parseAnswerOptionsForClick: function (answerOptions, questionType) {
var clickAnswerOptions = [];
for (var i = 0; i < answerOptions.length; i++) {
......
......@@ -120,36 +120,21 @@ Ext.define('ARSnova.view.FreetextAnswerPanel', {
}
});
this.exportButton = Ext.create('Ext.Button', {
xtype: 'button',
text: Messages.QUESTIONS_CSV_EXPORT_ANSWERS_BUTTON,
align: 'right',
handler: function () {
ARSnova.app.getController('QuestionExport').downloadQuestionAnswers(self.questionObj, self.freetextAnswerStore);
},
hidden: (ARSnova.app.userRole === ARSnova.app.USER_ROLE_STUDENT)
});
this.toolbar = Ext.create('Ext.TitleBar', {
docked: 'top',
ui: 'light',
title: Ext.util.Format.htmlEncode(this.questionObj.subject),
items: [this.backButton, {
xtype: 'button',
text: Messages.QUESTIONS_CSV_EXPORT_ANSWERS_BUTTON,
align: 'right',
handler: function () {
//Format
var exp = "data:text/csv;charset=utf-8,";
//Subject and Question
exp += Messages.QUESTION_SUBJECT + ": " + self.questionObj.subject + ";" + Messages.QUESTION + ": " + self.questionObj.text;
//Table header
exp += "\n" + Messages.QUESTION_DATE + ";" + Messages.QUESTIONS_CSV_EXPORT_ANSWERS_TIME + ";" + Messages.QUESTIONS_CSV_EXPORT_ANSWERS_SUBJECT + ";" + Messages.FREETEXT_DETAIL_ANSWER + ";Timestamp";
//Table contents (answers)
self.freetextAnswerStore._data.all.forEach(function (item) {
exp += "\n" + item._data.groupDate + ";" + item._data.formattedTime + ";" + item._data.answerSubject + ";" + item._data.answerText + ";" + item._data.timestamp;
});
//Download file
//stackoverflow.com/questions/14964035/
var encodedUri = encodeURI(exp);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", self.questionObj.subject + "_" + self.questionObj.text + "-Answers.csv");
document.body.appendChild(link);// Required for FF
link.click();
},
hidden: (ARSnova.app.userRole === ARSnova.app.USER_ROLE_STUDENT)
}]
items: [this.backButton, this.exportButton]
});
// Create standard panel with framework support
......
......@@ -169,27 +169,7 @@ Ext.define('ARSnova.view.speaker.QuestionStatisticChart', {
text: Messages.QUESTIONS_CSV_EXPORT_ANSWERS_BUTTON,
align: 'right',
handler: function () {
//Format
var exp = "data:text/csv;charset=utf-8,";
//Subeject and Question
exp += Messages.QUESTION_SUBJECT + ": " + me.questionObj.subject + ";" + Messages.QUESTION + ": " + me.questionObj.text;
//Table header
exp += "\n" + Messages.ANSWERS + ";"
+ Messages.FIRST_ROUND + " " + Messages.GRID_LABEL_RELATIVE + ";" + Messages.FIRST_ROUND + " " + Messages.GRID_LABEL_ABSOLUTE + ";"
+ Messages.SECOND_ROUND + " " + Messages.GRID_LABEL_RELATIVE + ";" + Messages.SECOND_ROUND + " " + Messages.GRID_LABEL_ABSOLUTE;
//Table contents (answers)
me.questionStore.each(function (record) {
exp += "\n" + record.get('text') + ";" + record.get('percent-round1') + ";" + record.get('value-round1') + ";" + record.get('percent-round2') + ";" + record.get('value-round2');
});
//Download file
//stackoverflow.com/questions/14964035/
var encodedUri = encodeURI(exp);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", me.questionObj.subject + "_" + me.questionObj.text + "-Answers.csv");
document.body.appendChild(link);// Required for FF
link.click();
ARSnova.app.getController('QuestionExport').downloadQuestionAnswers(me.questionObj, me.questionStore);
},
hidden: (ARSnova.app.userRole === ARSnova.app.USER_ROLE_STUDENT || me.questionObj.questionType === 'grid')
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment