# HG changeset patch # User Nicholas Jillings # Date 1433927625 -3600 # Node ID 30b9d9538cb76d69c4e635611b62e68f5840a679 # Parent a7b377b86ed6180865a2c5d1272e5e7a71d8459a Feature #1234: Added back button to pre/post surveys diff -r a7b377b86ed6 -r 30b9d9538cb7 core.css --- a/core.css Wed Jun 10 09:31:44 2015 +0100 +++ b/core.css Wed Jun 10 10:13:45 2015 +0100 @@ -49,8 +49,6 @@ width: 50px; height: 25px; position: absolute; - left: 440px; - top: 215px; border-radius: 5px; border: #444; border-width: 1px; diff -r a7b377b86ed6 -r 30b9d9538cb7 core.js --- a/core.js Wed Jun 10 09:31:44 2015 +0100 +++ b/core.js Wed Jun 10 10:13:45 2015 +0100 @@ -50,6 +50,7 @@ this.popup = null; this.popupContent = null; this.buttonProceed = null; + this.buttonPrevious = null; this.popupOptions = null; this.currentIndex = null; this.responses = null; @@ -75,8 +76,18 @@ this.buttonProceed = document.createElement('button'); this.buttonProceed.className = 'popupButton'; + this.buttonProceed.style.left = '440px'; + this.buttonProceed.style.top = '215px'; this.buttonProceed.innerHTML = 'Next'; this.buttonProceed.onclick = function(){popup.proceedClicked();}; + + this.buttonPrevious = document.createElement('button'); + this.buttonPrevious.className = 'popupButton'; + this.buttonPrevious.style.left = '10px'; + this.buttonPrevious.style.top = '215px'; + this.buttonPrevious.innerHTML = 'Back'; + this.buttonPrevious.onclick = function(){popup.previousClick();}; + this.popup.style.zIndex = -1; this.popup.style.visibility = 'hidden'; blank.style.zIndex = -2; @@ -200,6 +211,13 @@ this.popupContent.appendChild(input); } this.popupContent.appendChild(this.buttonProceed); + if(this.currentIndex+1 == this.popupOptions.length) { + this.buttonProceed.textContent = 'Submit'; + } else { + this.buttonProceed.textContent = 'Next'; + } + if(this.currentIndex > 0) + this.popupContent.appendChild(this.buttonPrevious); }; this.initState = function(node) { @@ -299,9 +317,6 @@ } this.currentIndex++; if (this.currentIndex < this.popupOptions.length) { - if(this.currentIndex+1 == this.popupOptions.length) { - this.buttonProceed.textContent = 'Submit'; - } this.postNode(); } else { // Reached the end of the popupOptions @@ -314,6 +329,46 @@ advanceState(); } }; + + this.previousClick = function() { + // Triggered when the 'Back' button is clicked in the survey + if (this.currentIndex > 0) { + this.currentIndex--; + var node = this.popupOptions[this.currentIndex]; + if (node.type != 'statement') { + var prevResp = this.responses.childNodes[this.responses.childElementCount-1]; + this.responses.removeChild(prevResp); + } + this.postNode(); + if (node.type == 'question') { + this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent; + } else if (node.type == 'checkbox') { + var options = this.popupContent.getElementsByTagName('input'); + var savedOptions = prevResp.getElementsByTagName('option'); + for (var i=0; i