diff --git a/common/lib/xmodule/xmodule/js/src/poll/poll_main.js b/common/lib/xmodule/xmodule/js/src/poll/poll_main.js index a5cec07095..b32b4e8bca 100644 --- a/common/lib/xmodule/xmodule/js/src/poll/poll_main.js +++ b/common/lib/xmodule/xmodule/js/src/poll/poll_main.js @@ -50,7 +50,32 @@ PollMain.prototype = { _this.ajax_url + '/' + answer, {}, function (response) { _this.showAnswerGraph(response.poll_answers, response.total); + _this.resetButton.show(); + if (_this.wrapperSectionEl !== null) { + $(_this.wrapperSectionEl).find('.xmodule_ConditionalModule').each(function (index, value) { + new window.Conditional(value, _this.id.replace(/^poll_/, '')); + }); + } + } + ); + +}, // End-of: 'submitAnswer': function (answer, answerEl) { + + +'submitReset': function () { + var _this; + _this = this; + // Send the data to the server as an AJAX request. Attach a callback that will + // be fired on server's response. + $.postWithPrefix( + _this.ajax_url + '/' + 'reset', {}, + function (response) { + _this.questionAnswered = false; + $(_this.questionEl).find('.button').removeClass('answered'); + _this.graphAnswerEl.hide(); + $(_this.questionEl).find('.stats').hide(); + _this.resetButton.hide(); if (_this.wrapperSectionEl !== null) { $(_this.wrapperSectionEl).find('.xmodule_ConditionalModule').each(function (index, value) { new window.Conditional(value, _this.id.replace(/^poll_/, '')); @@ -158,6 +183,15 @@ PollMain.prototype = { this.graphAnswerEl.hide(); this.graphAnswerEl.appendTo(this.questionEl); + if (_this.jsonConfig.reset === "True") + { + _this.resetButton = $('
'); + _this.resetButton.appendTo(_this.questionEl); + _this.resetButton.hide(); + _this.resetButton.on('click', function () { + _this.submitReset(); + }); + } // 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); @@ -234,6 +268,7 @@ function PollMain(el) { }); _this.questionEl.children('.poll_question_div').html(JSON.stringify(_this.jsonConfig)); + _this.postInit(); } ); diff --git a/common/lib/xmodule/xmodule/poll_module.py b/common/lib/xmodule/xmodule/poll_module.py index a79781ef86..ff13301b0a 100644 --- a/common/lib/xmodule/xmodule/poll_module.py +++ b/common/lib/xmodule/xmodule/poll_module.py @@ -75,6 +75,16 @@ class PollModule(XModule): 'poll_answers': self.poll_answers, 'total': sum(self.poll_answers.values()) }) + elif dispatch == 'reset_poll' and self.voted: + self.voted = False + + # FIXME: fix this, when xblock will support mutable types. + # Now we use this hack. + temp_poll_answers = self.poll_answers + temp_poll_answers[self.poll_answer] -= 1 + self.poll_answers = temp_poll_answers + + self.poll_answer = '' else: # return error message return json.dumps({'error': 'Unknown Command!'}) @@ -119,7 +129,8 @@ class PollModule(XModule): # to show answered poll after reload: 'poll_answer': self.poll_answer, 'poll_answers': self.poll_answers if self.voted else {}, - 'total': sum(self.poll_answers.values()) if self.voted else 0}) + 'total': sum(self.poll_answers.values()) if self.voted else 0, + 'reset': self.descriptor.xml_attributes.get('reset', True)}) class PollDescriptor(MakoModuleDescriptor, XmlDescriptor):