- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
function saveQuestion() {
var questionContent = {};
var questionResult = {};
switch(questionFields.attr('class')) {
case 'check-question':
questionResult.text = questionFields.children('.question-text')[0].innerText;
questionResult.type = 'check';
questionResult.answers = [];
[].forEach.call(questionFields.children('.answer-preview'), function(answerElement, i, arr) {
var answer = {};
answer.text = $(answerElement).children('.answer-text')[0].innerText;
answer.right = ($(answerElement).children('.answer-check')[0].checked) ? 1 : 0;
answer.weight = (!answer.right) ? $(answerElement).children('.answer-weight')[0].getPosition() : 1;
answer.weight = (answer.weight > 0 && answer.weight <= 1) ? answer.weight : 0;
questionResult.answers.push(answer);
});
if (checkQuestionCorrect(questionResult)) {
questionResult= JSON.stringify(questionResult);
questionContent = JSON.parse(questionResult); //клонируем объект
[].forEach.call(questionContent.answers, function(answer, i, answers) { delete answer.right; delete answer.weight; });
questionContent = JSON.stringify(questionContent);
console.log('result: ' + questionResult);
console.log('content: ' + questionContent);
net.addQuestion(loID, questionContent, questionResult, function(r){
$('.add-question').slideUp(200, function(){
$('.add-question-row').remove();
openLOPreview(loID);
});
});
}
break;
case 'input-question':
var highlights = highlighter.highlights;
questionResult.type = 'input';
questionResult.text = $('#question-text-area').get(0).innerText;
questionResult.answers = [];
for (i = 0; i < highlights.length; i++) {
var answer = {};
answer.id = highlights[i].id;
answer.posStart = highlights[i].characterRange.start;
answer.posEnd = highlights[i].characterRange.end;
answer.text = highlights[i].answerText;
answer.strict = ('strict' in highlights[i]) ? highlights[i].strict : true;
questionResult.answers.push(answer);
}
questionResult.answers.sort(function(a, b){ return a.posStart - b.posStart; });
questionResult.serializedHighlight = highlighter.serialize();
questionResult = JSON.stringify(questionResult);
questionContent = JSON.stringify(questionContent);
net.addQuestion(loID, questionContent, questionResult, function(r){
$('.add-question').slideUp(200, function(){
$('.add-question-row').remove();
openLOPreview(loID);
});
});
break;
default: break;
}
}
Моя дипломная работа по теме "тестирование студентов". Конструктор тестов, обработчик кнопки сохранения вопроса. Используются библиотеки jQuery и Rangy (для работы с выделением текста).