comparison test_create/test_create.html @ 2156:08fab304c10e

Updated specification object to reflect schema changes
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 09 Mar 2016 15:00:19 +0000
parents 749adcb68e99
children ba6b9e1aaef5
comparison
equal deleted inserted replaced
2155:9abb207d2f6a 2156:08fab304c10e
178 178
179 this.OptionNode = function() { 179 this.OptionNode = function() {
180 this.type = undefined; 180 this.type = undefined;
181 this.schema = specification.schema.getAllElementsByName('surveyentry')[0]; 181 this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
182 this.id = undefined; 182 this.id = undefined;
183 this.name = undefined;
183 this.mandatory = undefined; 184 this.mandatory = undefined;
184 this.statement = undefined; 185 this.statement = undefined;
185 this.boxsize = undefined; 186 this.boxsize = undefined;
186 this.options = []; 187 this.options = [];
187 this.min = undefined; 188 this.min = undefined;
233 var node = doc.createElement('surveyentry'); 234 var node = doc.createElement('surveyentry');
234 node.setAttribute('type',this.type); 235 node.setAttribute('type',this.type);
235 var statement = doc.createElement('statement'); 236 var statement = doc.createElement('statement');
236 statement.textContent = this.statement; 237 statement.textContent = this.statement;
237 node.appendChild(statement); 238 node.appendChild(statement);
238 switch(this.type) 239 if (this.type != "statement") {
239 {
240 case "statement":
241 break;
242 case "question":
243 node.id = this.id; 240 node.id = this.id;
241 if (this.name != undefined) { node.setAttribute("name",this.name);}
244 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);} 242 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);}
245 if (this.boxsize != undefined) {node.setAttribute("boxsize",this.boxsize);} 243 switch(this.type)
246 break;
247 case "number":
248 node.id = this.id;
249 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);}
250 if (this.min != undefined) {node.setAttribute("min", this.min);}
251 if (this.max != undefined) {node.setAttribute("max", this.max);}
252 break;
253 case "checkbox":
254 case "radio":
255 node.id = this.id;
256 for (var i=0; i<this.options.length; i++)
257 { 244 {
258 var option = this.options[i]; 245 case "question":
259 var optionNode = doc.createElement("option"); 246 if (this.boxsize != undefined) {node.setAttribute("boxsize",this.boxsize);}
260 optionNode.setAttribute("name",option.name); 247 break;
261 optionNode.textContent = option.text; 248 case "number":
262 node.appendChild(optionNode); 249 if (this.min != undefined) {node.setAttribute("min", this.min);}
263 } 250 if (this.max != undefined) {node.setAttribute("max", this.max);}
264 break; 251 break;
252 case "checkbox":
253 case "radio":
254 for (var i=0; i<this.options.length; i++)
255 {
256 var option = this.options[i];
257 var optionNode = doc.createElement("option");
258 optionNode.setAttribute("name",option.name);
259 optionNode.textContent = option.text;
260 node.appendChild(optionNode);
261 }
262 break;
263 }
265 } 264 }
266 return node; 265 return node;
267 }; 266 };
268 }; 267 };
269 this.decode = function(parent,xml) { 268 this.decode = function(parent,xml) {
527 return AHNode; 526 return AHNode;
528 }; 527 };
529 528
530 this.commentQuestionNode = function() { 529 this.commentQuestionNode = function() {
531 this.id = null; 530 this.id = null;
531 this.name = undefined;
532 this.type = undefined; 532 this.type = undefined;
533 this.options = []; 533 this.options = [];
534 this.statement = undefined; 534 this.statement = undefined;
535 this.schema = specification.schema.getAllElementsByName('commentquestion')[0]; 535 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
536 this.decode = function(parent,xml) 536 this.decode = function(parent,xml)
537 { 537 {
538 this.id = xml.id; 538 this.id = xml.id;
539 this.name = xml.getAttribute('name');
539 this.type = xml.getAttribute('type'); 540 this.type = xml.getAttribute('type');
540 this.statement = xml.getElementsByTagName('statement')[0].textContent; 541 this.statement = xml.getElementsByTagName('statement')[0].textContent;
541 var optNodes = xml.getElementsByTagName('option'); 542 var optNodes = xml.getElementsByTagName('option');
542 for (var i=0; i<optNodes.length; i++) 543 for (var i=0; i<optNodes.length; i++)
543 { 544 {
552 this.encode = function(root) 553 this.encode = function(root)
553 { 554 {
554 var node = root.createElement("commentquestion"); 555 var node = root.createElement("commentquestion");
555 node.id = this.id; 556 node.id = this.id;
556 node.setAttribute("type",this.type); 557 node.setAttribute("type",this.type);
558 if (this.name != undefined){node.setAttribute("name",this.name);}
557 var statement = root.createElement("statement"); 559 var statement = root.createElement("statement");
558 statement.textContent = this.statement; 560 statement.textContent = this.statement;
559 node.appendChild(statement); 561 node.appendChild(statement);
560 for (var option of this.options) 562 for (var option of this.options)
561 { 563 {
569 }; 571 };
570 572
571 this.audioElementNode = function() { 573 this.audioElementNode = function() {
572 this.url = null; 574 this.url = null;
573 this.id = null; 575 this.id = null;
576 this.name = null;
574 this.parent = null; 577 this.parent = null;
575 this.type = null; 578 this.type = null;
576 this.marker = null; 579 this.marker = null;
577 this.enforce = false; 580 this.enforce = false;
578 this.gain = 0.0; 581 this.gain = 0.0;