diff js/core.js @ 2774:2fc62a50d593

#145. Added minWait to all <surveyx> elements. Specify the amount of time to wait in seconds.
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Fri, 21 Apr 2017 14:03:51 +0100
parents 9d31ddedae2b
children 87d71c41c174
line wrap: on
line diff
--- a/js/core.js	Fri Apr 21 13:44:21 2017 +0100
+++ b/js/core.js	Fri Apr 21 14:03:51 2017 +0100
@@ -553,6 +553,7 @@
     this.currentIndex = null;
     this.node = null;
     this.store = null;
+    var lastNodeStart = undefined;
     $(window).keypress(function (e) {
         if (e.keyCode == 13 && popup.popup.style.visibility == 'visible') {
             console.log(e);
@@ -1048,6 +1049,7 @@
         var node = this.popupOptions[this.currentIndex],
             converter = new showdown.Converter(),
             p = new DOMParser();
+        lastNodeStart = new Date();
         this.popupResponse.innerHTML = "";
         this.popupTitle.innerHTML = "";
         this.popupTitle.appendChild(p.parseFromString(converter.makeHtml(node.specification.statement), "text/html").getElementsByTagName("body")[0].firstElementChild);
@@ -1110,7 +1112,12 @@
             return;
         }
         var node = this.popupOptions[this.currentIndex],
-            pass = true;
+            pass = true,
+            timeDelta = (new Date() - lastNodeStart)/1000.0;
+        if (timeDelta < node.specification.minWait) {
+            interfaceContext.lightbox.post("Error", "Not enough time has elapsed, please wait "+(node.specification.minWait-timeDelta).toFixed(0)+" seconds");
+            return;
+        }
         if (node.specification.type == 'question') {
             // Must extract the question data
             pass = processQuestion.call(this, node);