From 268e5b4bf7c5e3a6044f5dcdd87aa05248d46f34 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Mon, 25 Feb 2013 12:13:44 +0200 Subject: [PATCH 1/2] Front end stuff clean up. --- .../xmodule/xmodule/js/src/poll/poll_main.js | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) 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 b32b4e8bca..c9e8490d60 100644 --- a/common/lib/xmodule/xmodule/js/src/poll/poll_main.js +++ b/common/lib/xmodule/xmodule/js/src/poll/poll_main.js @@ -42,6 +42,8 @@ PollMain.prototype = { _this = this; + console.log('submiting answer'); + answerObj.buttonEl.addClass('answered'); // Send the data to the server as an AJAX request. Attach a callback that will @@ -49,6 +51,9 @@ PollMain.prototype = { $.postWithPrefix( _this.ajax_url + '/' + answer, {}, function (response) { + console.log('success! response = '); + console.log(response); + _this.showAnswerGraph(response.poll_answers, response.total); _this.resetButton.show(); if (_this.wrapperSectionEl !== null) { @@ -65,17 +70,28 @@ PollMain.prototype = { 'submitReset': function () { var _this; + _this = this; + + console.log('submiting rset'); + // 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', {}, + this.ajax_url + '/' + 'reset_poll', + {}, function (response) { + console.log('success! response = '); + console.log(response); + _this.questionAnswered = false; - $(_this.questionEl).find('.button').removeClass('answered'); - _this.graphAnswerEl.hide(); - $(_this.questionEl).find('.stats').hide(); + + _this.questionEl.find('.button.answered').removeClass('answered'); + + _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_/, '')); @@ -179,19 +195,20 @@ PollMain.prototype = { } }); - this.graphAnswerEl = $('
'); - this.graphAnswerEl.hide(); - this.graphAnswerEl.appendTo(this.questionEl); + if (this.jsonConfig.reset === "True"){ + this.resetButton = $('
Reset
'); - if (_this.jsonConfig.reset === "True") - { - _this.resetButton = $('
Reset
'); - _this.resetButton.appendTo(_this.questionEl); - _this.resetButton.hide(); - _this.resetButton.on('click', function () { - _this.submitReset(); - }); + if (this.questionAnswered === false) { + this.resetButton.hide(); } + + this.resetButton.appendTo(this.questionEl); + + 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); From 653154f11e65dae2f95e239258788bb4920808d3 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Mon, 25 Feb 2013 12:33:49 +0200 Subject: [PATCH 2/2] UI changes. --- .../lib/xmodule/xmodule/css/poll/display.scss | 9 ++------- .../xmodule/js/src/conditional/display.coffee | 16 +++++++++------ .../xmodule/xmodule/js/src/poll/poll_main.js | 20 ++++++------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/common/lib/xmodule/xmodule/css/poll/display.scss b/common/lib/xmodule/xmodule/css/poll/display.scss index 53192823be..cfc03bcf91 100644 --- a/common/lib/xmodule/xmodule/css/poll/display.scss +++ b/common/lib/xmodule/xmodule/css/poll/display.scss @@ -214,13 +214,8 @@ section.poll_question { text-shadow: rgb(7, 103, 148) 0px 1px 0px; } - .graph_answer { - display: none; + .button.reset-button { clear: both; - width: 400px; - height: 400px; - margin-top: 30px; - margin-left: auto; - margin-right: auto; + float: right; } } diff --git a/common/lib/xmodule/xmodule/js/src/conditional/display.coffee b/common/lib/xmodule/xmodule/js/src/conditional/display.coffee index af59a3a465..3301acf1b0 100644 --- a/common/lib/xmodule/xmodule/js/src/conditional/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/conditional/display.coffee @@ -1,16 +1,20 @@ class @Conditional - constructor: (element, callerElId) -> + constructor: (element, callerElId, reset) -> @el = $(element).find('.conditional-wrapper') @callerElId = callerElId - if @el.data('passed') is true - return - else if @el.data('passed') is false - @passed = false - else + if reset is true + @el.data('passed', null) @passed = null + else + if @el.data('passed') is true + return + else if @el.data('passed') is false + @passed = false + else + @passed = null if callerElId isnt undefined and @passed isnt null dependencies = @el.data('depends') 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 c9e8490d60..3e1c015852 100644 --- a/common/lib/xmodule/xmodule/js/src/poll/poll_main.js +++ b/common/lib/xmodule/xmodule/js/src/poll/poll_main.js @@ -42,8 +42,6 @@ PollMain.prototype = { _this = this; - console.log('submiting answer'); - answerObj.buttonEl.addClass('answered'); // Send the data to the server as an AJAX request. Attach a callback that will @@ -51,11 +49,11 @@ PollMain.prototype = { $.postWithPrefix( _this.ajax_url + '/' + answer, {}, function (response) { - console.log('success! response = '); - console.log(response); - _this.showAnswerGraph(response.poll_answers, response.total); + _this.resetButton.show(); + + // Initialize Conditional constructors. if (_this.wrapperSectionEl !== null) { $(_this.wrapperSectionEl).find('.xmodule_ConditionalModule').each(function (index, value) { new window.Conditional(value, _this.id.replace(/^poll_/, '')); @@ -73,28 +71,22 @@ PollMain.prototype = { _this = this; - console.log('submiting rset'); - // 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_poll', {}, function (response) { - console.log('success! response = '); - console.log(response); - _this.questionAnswered = false; - _this.questionEl.find('.button.answered').removeClass('answered'); - _this.questionEl.find('.stats').hide(); - _this.resetButton.hide(); + // Initialize Conditional constructors. We will specify the third parameter as 'true' + // notifying the constructor that this is a reset operation. if (_this.wrapperSectionEl !== null) { $(_this.wrapperSectionEl).find('.xmodule_ConditionalModule').each(function (index, value) { - new window.Conditional(value, _this.id.replace(/^poll_/, '')); + new window.Conditional(value, _this.id.replace(/^poll_/, ''), true); }); } }