Skip to content
Snippets Groups Projects

Flashcards revisited

Merged Andreas Gärtner requested to merge flashcards-revisited into master
Viewing commit e31d4d28
Show latest version
2 files
+ 182
37
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -39,47 +39,38 @@ Ext.define("ARSnova.controller.FlashcardExport", {
controller.getQuestions(sessionStorage.getItem('keyword'), {
success: function (response) {
var flashcards = me.preparseJson(Ext.decode(response.responseText));
for (var i = 0, json = ''; i < flashcards.length; i++) {
json += JSON.stringify(flashcards[i], null, '\t');
json += i < flashcards.length - 1 ? ', ' : '';
}
var json = this.stringifyFlashcards(flashcards);
me.exportJsonFile(json);
}
});
},
parseBackPage: function (questionData) {
var correctAnswers = [];
var answer = '';
stringifyFlashcards: function (flashcards) {
for (var i = 0, json = ''; i < flashcards.length; i++) {
json += JSON.stringify(flashcards[i], null, '\t');
json += i < flashcards.length - 1 ? ', ' : '';
}
return json;
},
for (var i = 0, back = null; i < questionData.possibleAnswers.length; i++) {
if (questionData.possibleAnswers[i].correct) {
answer = questionData.possibleAnswers[i].text;
if (questionData.questionType === 'abcd') {
answer = answer.slice(3, answer.length);
preparseJson: function (records) {
var flashcards = [];
for (var i = 0, flashcard; i < records.length; i++) {
if (this.suitableTypes.indexOf(records[i].questionType) !== -1) {
flashcard = this.formatFlashcard(records[i]);
if (flashcard.back && flashcard.front) {
flashcards.push(flashcard);
}
correctAnswers.push(answer);
}
}
if (correctAnswers.length) {
back = correctAnswers.join(', ');
}
return back;
},
return flashcards;
},
formatFlashcard: function (questionData) {
var flashcard = {};
var questionType = questionData.questionType;
if (this.suitableTypes.indexOf(questionData.questionType) === -1) {
return null;
}
switch(questionType) {
switch (questionData.questionType) {
case 'mc': case 'abcd': case 'yesno': case 'flashcard':
flashcard.back = this.parseBackPage(questionData);
break;
@@ -89,19 +80,19 @@ Ext.define("ARSnova.controller.FlashcardExport", {
return flashcard;
},
preparseJson: function (records) {
var flashcards = [];
for (var i = 0, flashcard; i < records.length; i++) {
if (this.suitableTypes.indexOf(records[i].questionType) !== -1) {
flashcard = this.formatFlashcard(records[i]);
parseBackPage: function (questionData) {
var possibleAnswers = questionData.possibleAnswers;
var correctAnswers = [];
if (flashcard.back && flashcard.front) {
flashcards.push(flashcard);
}
for (var i = 0, answer = ''; i < possibleAnswers.length; i++) {
if (possibleAnswers[i].correct) {
answer = possibleAnswers[i].text;
correctAnswers.push(questionData.questionType !== 'abcd' ?
answer : answer.slice(3, answer.length));
}
}
return flashcards;
return correctAnswers.join(', ');
},
saveFileOnFileSystem: function (data, filename) {