diff core.js @ 1248:f04d8ababef7

Updated specification object to reflect schema changes
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Wed, 09 Mar 2016 15:00:19 +0000
parents 3c083ee1b743
children ba6b9e1aaef5
line wrap: on
line diff
--- a/core.js	Wed Mar 09 14:40:12 2016 +0000
+++ b/core.js	Wed Mar 09 15:00:19 2016 +0000
@@ -1917,6 +1917,7 @@
 			this.type = undefined;
 			this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
 			this.id = undefined;
+            this.name = undefined;
 			this.mandatory = undefined;
 			this.statement = undefined;
 			this.boxsize = undefined;
@@ -1972,34 +1973,32 @@
 				var statement = doc.createElement('statement');
 				statement.textContent = this.statement;
 				node.appendChild(statement);
-				switch(this.type)
-				{
-				case "statement":
-					break;
-				case "question":
+                if (this.type != "statement") {
                     node.id = this.id;
+                    if (this.name != undefined) { node.setAttribute("name",this.name);}
                     if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);}
-                    if (this.boxsize != undefined) {node.setAttribute("boxsize",this.boxsize);}
-                    break;
-                case "number":
-                    node.id = this.id;
-                    if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);}
-                    if (this.min != undefined) {node.setAttribute("min", this.min);}
-                    if (this.max != undefined) {node.setAttribute("max", this.max);}
-                    break;
-				case "checkbox":
-				case "radio":
-					node.id = this.id;
-					for (var i=0; i<this.options.length; i++)
-					{
-						var option = this.options[i];
-						var optionNode = doc.createElement("option");
-						optionNode.setAttribute("name",option.name);
-						optionNode.textContent = option.text;
-						node.appendChild(optionNode);
-					}
-					break;
-				}
+                    switch(this.type)
+                    {
+                    case "question":
+                        if (this.boxsize != undefined) {node.setAttribute("boxsize",this.boxsize);}
+                        break;
+                    case "number":
+                        if (this.min != undefined) {node.setAttribute("min", this.min);}
+                        if (this.max != undefined) {node.setAttribute("max", this.max);}
+                        break;
+                    case "checkbox":
+                    case "radio":
+                        for (var i=0; i<this.options.length; i++)
+                        {
+                            var option = this.options[i];
+                            var optionNode = doc.createElement("option");
+                            optionNode.setAttribute("name",option.name);
+                            optionNode.textContent = option.text;
+                            node.appendChild(optionNode);
+                        }
+                        break;
+                    }
+                }
 				return node;
 			};
 		};
@@ -2266,6 +2265,7 @@
 		
 		this.commentQuestionNode = function() {
 			this.id = null;
+            this.name = undefined;
 			this.type = undefined;
 			this.options = [];
 			this.statement = undefined;
@@ -2273,6 +2273,7 @@
 			this.decode = function(parent,xml)
 			{
 				this.id = xml.id;
+                this.name = xml.getAttribute('name');
 				this.type = xml.getAttribute('type');
 				this.statement = xml.getElementsByTagName('statement')[0].textContent;
 				var optNodes = xml.getElementsByTagName('option');
@@ -2291,6 +2292,7 @@
 				var node = root.createElement("commentquestion");
                 node.id = this.id;
                 node.setAttribute("type",this.type);
+                if (this.name != undefined){node.setAttribute("name",this.name);}
                 var statement = root.createElement("statement");
                 statement.textContent = this.statement;
                 node.appendChild(statement);
@@ -2308,6 +2310,7 @@
 		this.audioElementNode = function() {
 			this.url = null;
 			this.id = null;
+            this.name = null;
 			this.parent = null;
 			this.type = null;
 			this.marker = null;