comparison test_create/test_create.html @ 1898:db85dec2b0b0

Fixed errors caused by specifcation nesting, specifically if <page> interface nodes have <interfaceoption> nodes.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Fri, 18 Mar 2016 14:52:30 +0000
parents 37c5e99ef828
children 2dd5f7071e3f
comparison
equal deleted inserted replaced
1897:494a03dfdb07 1898:db85dec2b0b0
18 this.interfaces = null; 18 this.interfaces = null;
19 this.loudness = null; 19 this.loudness = null;
20 this.errors = []; 20 this.errors = [];
21 this.schema = null; 21 this.schema = null;
22 22
23 this.processAttribute = function(attribute,schema) 23 this.processAttribute = function(attribute,schema,schemaRoot)
24 { 24 {
25 // attribute is the string returned from getAttribute on the XML 25 // attribute is the string returned from getAttribute on the XML
26 // schema is the <xs:attribute> node 26 // schema is the <xs:attribute> node
27 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) 27 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined)
28 { 28 {
29 schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0]; 29 schema = schemaRoot.getAllElementsByName(schema.getAttribute('ref'))[0];
30 } 30 }
31 var defaultOpt = schema.getAttribute('default'); 31 var defaultOpt = schema.getAttribute('default');
32 if (attribute == null) { 32 if (attribute == null) {
33 attribute = defaultOpt; 33 attribute = defaultOpt;
34 } 34 }
70 // First decode the attributes 70 // First decode the attributes
71 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); 71 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
72 for (var i in attributes) 72 for (var i in attributes)
73 { 73 {
74 if (isNaN(Number(i)) == true){break;} 74 if (isNaN(Number(i)) == true){break;}
75 var attributeName = attributes[i].getAttribute('name'); 75 var attributeName = attributes[i].getAttribute('name') || attributes[i].getAttribute('ref');
76 var projectAttr = setupNode.getAttribute(attributeName); 76 var projectAttr = setupNode.getAttribute(attributeName);
77 projectAttr = this.processAttribute(projectAttr,attributes[i]); 77 projectAttr = this.processAttribute(projectAttr,attributes[i],this.schema);
78 switch(typeof projectAttr) 78 switch(typeof projectAttr)
79 { 79 {
80 case "number": 80 case "number":
81 case "boolean": 81 case "boolean":
82 eval('this.'+attributeName+' = '+projectAttr); 82 eval('this.'+attributeName+' = '+projectAttr);
172 }; 172 };
173 173
174 this.surveyNode = function() { 174 this.surveyNode = function() {
175 this.location = null; 175 this.location = null;
176 this.options = []; 176 this.options = [];
177 this.parent = null;
177 this.schema = specification.schema.getAllElementsByName('survey')[0]; 178 this.schema = specification.schema.getAllElementsByName('survey')[0];
178 179
179 this.OptionNode = function() { 180 this.OptionNode = function() {
180 this.type = undefined; 181 this.type = undefined;
181 this.schema = specification.schema.getAllElementsByName('surveyentry')[0]; 182 this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
194 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); 195 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
195 for (var i in attributeMap){ 196 for (var i in attributeMap){
196 if(isNaN(Number(i)) == true){break;} 197 if(isNaN(Number(i)) == true){break;}
197 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); 198 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
198 var projectAttr = child.getAttribute(attributeName); 199 var projectAttr = child.getAttribute(attributeName);
199 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]); 200 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema);
200 switch(typeof projectAttr) 201 switch(typeof projectAttr)
201 { 202 {
202 case "number": 203 case "number":
203 case "boolean": 204 case "boolean":
204 eval('this.'+attributeName+' = '+projectAttr); 205 eval('this.'+attributeName+' = '+projectAttr);
264 } 265 }
265 return node; 266 return node;
266 }; 267 };
267 }; 268 };
268 this.decode = function(parent,xml) { 269 this.decode = function(parent,xml) {
270 this.parent = parent;
269 this.location = xml.getAttribute('location'); 271 this.location = xml.getAttribute('location');
270 if (this.location == 'before'){this.location = 'pre';} 272 if (this.location == 'before'){this.location = 'pre';}
271 else if (this.location == 'after'){this.location = 'post';} 273 else if (this.location == 'after'){this.location = 'post';}
272 for (var i in xml.children) 274 for (var i in xml.children)
273 { 275 {
313 var option = {}; 315 var option = {};
314 for (var j=0; j<attributeMap.length; j++) 316 for (var j=0; j<attributeMap.length; j++)
315 { 317 {
316 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref'); 318 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
317 var projectAttr = ioNode.getAttribute(attributeName); 319 var projectAttr = ioNode.getAttribute(attributeName);
318 projectAttr = parent.processAttribute(projectAttr,attributeMap[j]); 320 if(parent.processAttribute) {
321 parent.processAttribute(projectAttr, attributeMap[j], parent.schema)
322 } else {
323 parent.parent.processAttribute(projectAttr, attributeMap[j], parent.parent.schema)
324 }
319 switch(typeof projectAttr) 325 switch(typeof projectAttr)
320 { 326 {
321 case "number": 327 case "number":
322 case "boolean": 328 case "boolean":
323 eval('option.'+attributeName+' = '+projectAttr); 329 eval('option.'+attributeName+' = '+projectAttr);
399 this.randomiseOrder = undefined; 405 this.randomiseOrder = undefined;
400 this.loop = undefined; 406 this.loop = undefined;
401 this.showElementComments = undefined; 407 this.showElementComments = undefined;
402 this.outsideReference = null; 408 this.outsideReference = null;
403 this.loudness = null; 409 this.loudness = null;
410 this.label = null;
404 this.preTest = null; 411 this.preTest = null;
405 this.postTest = null; 412 this.postTest = null;
406 this.interfaces = []; 413 this.interfaces = [];
407 this.commentBoxPrefix = "Comment on track"; 414 this.commentBoxPrefix = "Comment on track";
408 this.audioElements = []; 415 this.audioElements = [];
409 this.commentQuestions = []; 416 this.commentQuestions = [];
410 this.schema = specification.schema.getAllElementsByName("page")[0]; 417 this.schema = specification.schema.getAllElementsByName("page")[0];
418 this.parent = null;
411 419
412 this.decode = function(parent,xml) 420 this.decode = function(parent,xml)
413 { 421 {
422 this.parent = parent;
414 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); 423 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
415 for (var i=0; i<attributeMap.length; i++) 424 for (var i=0; i<attributeMap.length; i++)
416 { 425 {
417 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); 426 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
418 var projectAttr = xml.getAttribute(attributeName); 427 var projectAttr = xml.getAttribute(attributeName);
419 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]); 428 projectAttr = parent.processAttribute(projectAttr,attributeMap[i],parent.schema);
420 switch(typeof projectAttr) 429 switch(typeof projectAttr)
421 { 430 {
422 case "number": 431 case "number":
423 case "boolean": 432 case "boolean":
424 eval('this.'+attributeName+' = '+projectAttr); 433 eval('this.'+attributeName+' = '+projectAttr);
587 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); 596 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
588 for (var i=0; i<attributeMap.length; i++) 597 for (var i=0; i<attributeMap.length; i++)
589 { 598 {
590 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); 599 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
591 var projectAttr = xml.getAttribute(attributeName); 600 var projectAttr = xml.getAttribute(attributeName);
592 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]); 601 projectAttr = parent.parent.processAttribute(projectAttr,attributeMap[i],parent.parent.schema);
593 switch(typeof projectAttr) 602 switch(typeof projectAttr)
594 { 603 {
595 case "number": 604 case "number":
596 case "boolean": 605 case "boolean":
597 eval('this.'+attributeName+' = '+projectAttr); 606 eval('this.'+attributeName+' = '+projectAttr);