unserver-unify
Version:
181 lines (177 loc) • 4.88 kB
JavaScript
angular.module('bamboo.common').service('ExamQuestionBizModel', function(oopHelper) {
var vm = this;
console.log(createInstiance);
vm.createInstiance = createInstiance;
vm.convertQ = convertQ;
vm.clearresult = clearresult;
function createInstiance(type, q) {
// return
var classStr = s.capitalize(type) + "Question";
var className = eval(classStr);
console.log(className.constructor);
}
function Question(type, q) {
this.type = type;
this.q = q;
this.checkResult = function() {}
}
/**
* single Q
* @param {*} type
* @param {*} q
*/
function SingleQuestion(type, q) {
SingleQuestion.uber.constructor.call(this, type, q);
this.checkResult = function() {}
}
oopHelper.extend(SingleQuestion, Question);
/**
* multi Q
* @param {*} type
* @param {*} q
*/
function MultiQuestion(type, q) {
MultiQuestion.uber.constructor.call(this, type, q);
this.checkResult = function() {}
}
oopHelper.extend(MultiQuestion, Question);
function convertQ(q) {
if (q.ver && q.ver == 1) {
return q;
}
console.log(q);
q.ver = 1;
q._options = [];
switch (q.type) {
case 'single':
if (q.options && q.options.length) {
angular.forEach(q.options, function(opt, index) {
var info = opt;
if (opt.text == q.ok_answer) {
info.correct = true;
}
q._options.push(info);
})
} else {
angular.forEach(q.answer, function(text, index) {
var info = {
text: text,
correct: true,
}
q._options.push(info);
})
angular.forEach(q.references, function(text, index) {
var info = {
text: text,
}
q._options.push(info);
})
}
delete q.ok_answer;
break;
case 'multiple':
if (q.options && q.options.length) {
angular.forEach(q.options, function(opt, index) {
q._options.push(opt);
})
} else {
angular.forEach(q.answer, function(text, index) {
var info = {
text: text,
correct: true,
}
q._options.push(info);
})
angular.forEach(q.references, function(text, index) {
var info = {
text: text,
}
q._options.push(info);
})
}
break;
case 'fill':
case 'mfill':
angular.forEach(q.answer, function(text, index) {
var info = {
texts: [{
text: text
}],
}
q._options.push(info);
})
angular.forEach(q.options, function(val, index) {
var _text = {
text: val.text,
}
var info = {
texts: [_text],
}
q._options.push(info);
})
break;
case 'tof':
if (q.tof_answer) {
var info = {
correct: q.tof_answer,
}
q._options.push(info);
delete q.tof_answer;
} else if (q.answer) {
var info = {
correct: q.answer[0],
}
q._options.push(info);
}
// console.log(q);
break;
}
delete q.answer;
delete q.references;
delete q.options;
return q;
}
function clearresult(questions) {
console.log(questions);
questions = questions || $scope.chapter.questions;
console.log(questions);
console.log("length:" + questions.length);
for (var i = 0; i < questions.length; i++) {
var q = questions[i];
console.log(i);
console.log(questions[i]);
switch (q.type) {
case 'single':
q.selection = undefined;
q.select = undefined;
q.judgement = undefined;
case 'multiple':
var opts = q._options;
q.judgement = null;
if (opts && opts.length > 0) {
for (var j = 0; j < opts.length; j += 1) {
opts[j].selection = null;
}
}
break;
case 'tof':
q.selection = null;
q.judgement = null;
break;
case 'fill':
q.selection = null;
q.judgement = null;
break;
case 'mfill':
console.log(q.options);
var opts = q._options;
q.judgement = null;
if (opts && opts.length > 0) {
for (var j = 0; j < opts.length; j++) {
opts[j].selection = null;
}
}
}
}
}
});