Commit f5e015ff by Vasyl Nakvasiuk

Merge branch 'feature/alex/poll-storage-model' of github.com:MITx/mitx into…

Merge branch 'feature/alex/poll-storage-model' of github.com:MITx/mitx into feature/alex/poll-storage-model
parents 96d81bce 527fe0ac
......@@ -26,6 +26,8 @@ PollMain.prototype = {
tickSets = {};
c1 = 0;
logme('poll_answers: ', poll_answers, '_this.jsonConfig.answers: ', _this.jsonConfig.answers);
$.each(poll_answers, function (index, value) {
var numValue, text;
......@@ -113,6 +115,7 @@ PollMain.prototype = {
'total': '10'
};
logme('One.');
_this.showAnswerGraph(response.poll_answers, response.total);
}());
} else {
......@@ -123,6 +126,7 @@ PollMain.prototype = {
function (response) {
logme('response:', response);
logme('Two.');
_this.showAnswerGraph(response.poll_answers, response.total);
/*
......@@ -135,7 +139,69 @@ PollMain.prototype = {
}
);
}
} // End-of: 'submitAnswer': function (answer, answerEl) {
}, // End-of: 'submitAnswer': function (answer, answerEl) {
'postInit': function () {
var _this;
// Access this object inside inner functions.
_this = this;
if (
(this.jsonConfig.poll_answer.length > 0) &&
(this.jsonConfig.answers.hasOwnProperty(this.jsonConfig.poll_answer) === false)
) {
this.questionEl.append(
'<h3>Error!</h3>' +
'<p>XML data format changed. List of answers was modified, but poll data was not updated.</p>'
);
return;
}
// Get the DOM id of the question.
this.id = this.questionEl.attr('id');
// Get the URL to which we will post the users answer to the question.
this.ajax_url = this.questionEl.data('ajax-url');
this.questionHtmlMarkup = $('<div />').html(this.jsonConfig.question).text();
this.questionEl.append(this.questionHtmlMarkup);
// When the user selects and answer, we will set this flag to true.
this.questionAnswered = false;
logme('this.jsonConfig.answers: ', this.jsonConfig.answers);
logme('this.jsonConfig.poll_answer: ', this.jsonConfig.poll_answer);
$.each(this.jsonConfig.answers, function (index, value) {
var answerEl;
answerEl = $('<div class="poll_answer">' + value + '</li>');
answerEl.on('click', function () {
_this.submitAnswer(index, answerEl);
});
if (index === _this.jsonConfig.poll_answer) {
answerEl.addClass('answered');
_this.questionAnswered = true;
}
answerEl.appendTo(_this.questionEl);
});
this.graphAnswerEl = $('<div class="graph_answer"></div>');
this.graphAnswerEl.hide();
this.graphAnswerEl.appendTo(this.questionEl);
logme('PollMain object: ', this);
// If it turns out that the user already answered the question, show the answers graph.
if (this.questionAnswered === true) {
logme('Three');
this.showAnswerGraph(this.jsonConfig.poll_answers, this.jsonConfig.total);
}
} // End-of: 'postInit': function () {
}; // End-of: PollMain.prototype = {
return PollMain;
......@@ -227,72 +293,46 @@ function PollMain(el) {
"three of them to kill and eat the cabin boy, in order to save their own lives?&lt;/p&gt;"
};
}
_this.postInit();
}());
return;
} else {
try {
this.jsonConfig = JSON.parse(this.questionEl.children('.poll_question_div').html());
} catch (err) {
logme(
'ERROR: Invalid JSON config for poll ID "' + this.id + '".',
'Error messsage: "' + err.message + '".'
);
return;
}
}
$.postWithPrefix(
'' + this.questionEl.data('ajax-url') + '/' + 'get_state', {},
function (response) {
logme('Get pre init state.');
logme('response:', response);
if (
(this.jsonConfig.poll_answer.length > 0) &&
(this.jsonConfig.answers.hasOwnProperty(this.jsonConfig.poll_answer) === false)
) {
this.questionEl.append(
'<h3>Error!</h3>' +
'<p>XML data format changed. List of answers was modified, but poll data was not updated.</p>'
);
_this.jsonConfig.poll_answer = response.poll_answer;
_this.jsonConfig.total = response.total;
return;
}
// Get the DOM id of the question.
this.id = this.questionEl.attr('id');
$.each(response.poll_answers, function (index, value) {
_this.jsonConfig.poll_answers[index] = value;
});
// Get the URL to which we will post the users answer to the question.
this.ajax_url = this.questionEl.data('ajax-url');
logme('Current "jsonConfig": ');
logme(_this.jsonConfig);
this.questionHtmlMarkup = $('<div />').html(this.jsonConfig.question).text();
this.questionEl.append(this.questionHtmlMarkup);
// When the user selects and answer, we will set this flag to true.
this.questionAnswered = false;
logme('this.jsonConfig.answers: ', this.jsonConfig.answers);
logme('this.jsonConfig.poll_answer: ', this.jsonConfig.poll_answer);
_this.questionEl.children('.poll_question_div').html(JSON.stringify(_this.jsonConfig));
$.each(this.jsonConfig.answers, function (index, value) {
var answerEl;
_this.postInit();
}
);
answerEl = $('<div class="poll_answer">' + value + '</li>');
answerEl.on('click', function () {
_this.submitAnswer(index, answerEl);
});
return;
} catch (err) {
logme(
'ERROR: Invalid JSON config for poll ID "' + this.id + '".',
'Error messsage: "' + err.message + '".'
);
if (index === _this.jsonConfig.poll_answer) {
answerEl.addClass('answered');
_this.questionAnswered = true;
return;
}
answerEl.appendTo(_this.questionEl);
});
this.graphAnswerEl = $('<div class="graph_answer"></div>');
this.graphAnswerEl.hide();
this.graphAnswerEl.appendTo(this.questionEl);
logme('PollMain object: ', this);
// If it turns out that the user already answered the question, show the answers graph.
if (this.questionAnswered === true) {
this.showAnswerGraph(this.jsonConfig.poll_answers, this.jsonConfig.total);
}
} // End-of: function PollMain(el) {
......
......@@ -69,8 +69,13 @@ class PollModule(XModule):
'total': sum(self.poll_answers.values()),
'callback': {'objectName': 'Conditional'}
})
# return error message
return json.dumps({'error': 'Unknown Command!'})
elif dispatch == 'get_state':
return json.dumps({'poll_answer': self.poll_answer,
'poll_answers': self.poll_answers,
'total': sum(self.poll_answers.values())
})
else: # return error message
return json.dumps({'error': 'Unknown Command!'})
def get_html(self):
"""Renders parameters to template."""
......
......@@ -179,6 +179,12 @@ end
TEST_TASK_DIRS = []
task :fastlms do
# this is >2 times faster that rake [lms], and does not need web, good for local dev
django_admin = ENV['DJANGO_ADMIN_PATH'] || select_executable('django-admin.py', 'django-admin')
sh("#{django_admin} runserver --traceback --settings=lms.envs.dev --pythonpath=.")
end
[:lms, :cms].each do |system|
report_dir = report_dir_path(system)
......
Markdown is supported
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