diff core.js @ 903:3464a477c021

Feature #1224: Added number box
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 08 Jun 2015 11:56:14 +0100
parents 4041e5abcde5
children b94bb53ce4ac
line wrap: on
line diff
--- a/core.js	Mon Jun 08 11:17:26 2015 +0100
+++ b/core.js	Mon Jun 08 11:56:14 2015 +0100
@@ -187,6 +187,17 @@
 				optHold.appendChild(hold);
 			}
 			this.popupContent.appendChild(optHold);
+		} else if (node.type == 'number') {
+			var span = document.createElement('span');
+			span.textContent = node.statement;
+			this.popupContent.appendChild(span);
+			this.popupContent.appendChild(document.createElement('br'));
+			var input = document.createElement('input');
+			input.type = 'number';
+			if (node.min != null) {input.min = node.min;}
+			if (node.max != null) {input.max = node.max;}
+			if (node.step != null) {input.step = node.step;}
+			this.popupContent.appendChild(input);
 		}
 		this.popupContent.appendChild(this.popupButton);
 	};
@@ -262,6 +273,16 @@
 			hold.setAttribute('name',node.options[responseID].name);
 			hold.textContent = node.options[responseID].text;
 			this.responses.appendChild(hold);
+		} else if (node.type == "number") {
+			var input = this.popupContent.getElementsByTagName('input')[0];
+			if (node.mandatory == true && input.value.length == 0) {
+				alert('This question is mandatory');
+				return;
+			}
+			var hold = document.createElement('number');
+			hold.id = node.id;
+			hold.textContent = input.value;
+			this.responses.appendChild(hold);
 		}
 		this.currentIndex++;
 		if (this.currentIndex < this.popupOptions.length) {
@@ -1152,6 +1173,12 @@
 						element = element.nextElementSibling;
 					}
 				}
+			} else if (child.nodeName == "number") {
+				this.statement = child.textContent;
+				this.id = child.id;
+				this.min = child.getAttribute('min');
+				this.max = child.getAttribute('max');
+				this.step = child.getAttribute('step');
 			}
 		};