Commit 527fe0ac by Valera Rozuvan

Connected client side check of state at initialization.

parent b0c616e2
...@@ -26,6 +26,8 @@ PollMain.prototype = { ...@@ -26,6 +26,8 @@ PollMain.prototype = {
tickSets = {}; tickSets = {};
c1 = 0; c1 = 0;
logme('poll_answers: ', poll_answers, '_this.jsonConfig.answers: ', _this.jsonConfig.answers);
$.each(poll_answers, function (index, value) { $.each(poll_answers, function (index, value) {
var numValue, text; var numValue, text;
...@@ -113,6 +115,7 @@ PollMain.prototype = { ...@@ -113,6 +115,7 @@ PollMain.prototype = {
'total': '10' 'total': '10'
}; };
logme('One.');
_this.showAnswerGraph(response.poll_answers, response.total); _this.showAnswerGraph(response.poll_answers, response.total);
}()); }());
} else { } else {
...@@ -123,19 +126,9 @@ PollMain.prototype = { ...@@ -123,19 +126,9 @@ PollMain.prototype = {
function (response) { function (response) {
logme('response:', response); logme('response:', response);
logme('Two.');
_this.showAnswerGraph(response.poll_answers, response.total); _this.showAnswerGraph(response.poll_answers, response.total);
_this.jsonConfig.poll_answer = answer;
_this.jsonConfig.total = response.total;
$.each(response.poll_answers, function (index, value) {
_this.jsonConfig.poll_answers[index] = value;
});
logme('Current "jsonConfig": ');
logme(_this.jsonConfig);
_this.questionEl.children('.poll_question_div').html(JSON.stringify(_this.jsonConfig));
/* /*
_this.vertModEl.find('.xmodule_ConditionalModule').each( _this.vertModEl.find('.xmodule_ConditionalModule').each(
function (index, value) { function (index, value) {
...@@ -154,6 +147,18 @@ PollMain.prototype = { ...@@ -154,6 +147,18 @@ PollMain.prototype = {
// Access this object inside inner functions. // Access this object inside inner functions.
_this = this; _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. // Get the DOM id of the question.
this.id = this.questionEl.attr('id'); this.id = this.questionEl.attr('id');
...@@ -193,6 +198,7 @@ PollMain.prototype = { ...@@ -193,6 +198,7 @@ PollMain.prototype = {
// If it turns out that the user already answered the question, show the answers graph. // If it turns out that the user already answered the question, show the answers graph.
if (this.questionAnswered === true) { if (this.questionAnswered === true) {
logme('Three');
this.showAnswerGraph(this.jsonConfig.poll_answers, this.jsonConfig.total); this.showAnswerGraph(this.jsonConfig.poll_answers, this.jsonConfig.total);
} }
} // End-of: 'postInit': function () { } // End-of: 'postInit': function () {
...@@ -290,9 +296,35 @@ function PollMain(el) { ...@@ -290,9 +296,35 @@ function PollMain(el) {
_this.postInit(); _this.postInit();
}()); }());
return;
} else { } else {
try { try {
this.jsonConfig = JSON.parse(this.questionEl.children('.poll_question_div').html()); this.jsonConfig = JSON.parse(this.questionEl.children('.poll_question_div').html());
$.postWithPrefix(
'' + this.questionEl.data('ajax-url') + '/' + 'get_state', {},
function (response) {
logme('Get pre init state.');
logme('response:', response);
_this.jsonConfig.poll_answer = response.poll_answer;
_this.jsonConfig.total = response.total;
$.each(response.poll_answers, function (index, value) {
_this.jsonConfig.poll_answers[index] = value;
});
logme('Current "jsonConfig": ');
logme(_this.jsonConfig);
_this.questionEl.children('.poll_question_div').html(JSON.stringify(_this.jsonConfig));
_this.postInit();
}
);
return;
} catch (err) { } catch (err) {
logme( logme(
'ERROR: Invalid JSON config for poll ID "' + this.id + '".', 'ERROR: Invalid JSON config for poll ID "' + this.id + '".',
...@@ -302,28 +334,6 @@ function PollMain(el) { ...@@ -302,28 +334,6 @@ function PollMain(el) {
return; return;
} }
} }
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;
}
$.postWithPrefix(
_this.ajax_url + '/' + 'get_state', {},
function (response) {
logme('Get pre init state.');
logme('response:', response);
_this.postInit();
}
);
} // End-of: function PollMain(el) { } // End-of: function PollMain(el) {
}); // End-of: define('PollMain', ['logme'], function (logme) { }); // End-of: define('PollMain', ['logme'], function (logme) {
......
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