comparison js/specification.js @ 2854:aed359997687

More functional changes to specification.js
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Wed, 26 Apr 2017 17:15:24 +0100
parents 8372c220db7a
children 80a3b693b3f6
comparison
equal deleted inserted replaced
2853:f75db4482006 2854:aed359997687
17 this.preSilence = undefined; 17 this.preSilence = undefined;
18 this.postSilence = undefined; 18 this.postSilence = undefined;
19 this.playOne = undefined; 19 this.playOne = undefined;
20 20
21 // nodes 21 // nodes
22 this.metrics = undefined; 22 this.metrics = new metricNode();
23 this.preTest = undefined; 23 this.preTest = undefined;
24 this.postTest = undefined; 24 this.postTest = undefined;
25 this.pages = []; 25 this.pages = [];
26 this.interfaces = undefined; 26 this.interfaces = new interfaceNode(this);
27 this.errors = []; 27 this.errors = [];
28 this.exitText = "Thank you."; 28 this.exitText = "Thank you.";
29 29
30 var processAttribute = function (attribute, schema) { 30 var processAttribute = function (attribute, schema) {
31 // attribute is the string returned from getAttribute on the XML 31 // attribute is the string returned from getAttribute on the XML
125 var exitTextNode = setupNode.getElementsByTagName('exitText'); 125 var exitTextNode = setupNode.getElementsByTagName('exitText');
126 if (exitTextNode.length == 1) { 126 if (exitTextNode.length == 1) {
127 this.exitText = exitTextNode[0].textContent; 127 this.exitText = exitTextNode[0].textContent;
128 } 128 }
129 129
130 this.metrics = new this.metricNode();
131
132 this.metrics.decode(this, setupNode.getElementsByTagName('metric')[0]); 130 this.metrics.decode(this, setupNode.getElementsByTagName('metric')[0]);
133 131
134 // Now process the survey node options 132 // Now process the survey node options
135 var survey = setupNode.getElementsByTagName('survey'); 133 var survey = setupNode.getElementsByTagName('survey');
136 for (i = 0; i < survey.length; i++) { 134 for (i = 0; i < survey.length; i++) {
137 var location = survey[i].getAttribute('location'); 135 var location = survey[i].getAttribute('location');
138 switch (location) { 136 switch (location) {
139 case 'pre': 137 case 'pre':
140 case 'before': 138 case 'before':
141 this.preTest = new this.surveyNode(this); 139 this.preTest = new surveyNode(this);
142 this.preTest.decode(this, survey[i]); 140 this.preTest.decode(this, survey[i]);
143 break; 141 break;
144 case 'post': 142 case 'post':
145 case 'after': 143 case 'after':
146 this.postTest = new this.surveyNode(this); 144 this.postTest = new surveyNode(this);
147 this.postTest.decode(this, survey[i]); 145 this.postTest.decode(this, survey[i]);
148 break; 146 break;
149 } 147 }
150 } 148 }
151 149
152 var interfaceNode = setupNode.getElementsByTagName('interface'); 150 var interfaceNode = setupNode.getElementsByTagName('interface');
153 if (interfaceNode.length > 1) { 151 if (interfaceNode.length > 1) {
154 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!"); 152 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!");
155 } 153 }
156 this.interfaces = new this.interfaceNode(this); 154
157 if (interfaceNode.length !== 0) { 155 if (interfaceNode.length !== 0) {
158 interfaceNode = interfaceNode[0]; 156 interfaceNode = interfaceNode[0];
159 this.interfaces.decode(this, interfaceNode, this.schema.querySelectorAll('[name=interface]')[1]); 157 this.interfaces.decode(this, interfaceNode, this.schema.querySelectorAll('[name=interface]')[1]);
160 } 158 }
161 159
162 // Page tags 160 // Page tags
163 var pageTags = projectXML.getElementsByTagName('page'); 161 var pageTags = projectXML.getElementsByTagName('page');
164 var pageSchema = this.schema.querySelector('[name=page]'); 162 var pageSchema = this.schema.querySelector('[name=page]');
165 for (i = 0; i < pageTags.length; i++) { 163 for (i = 0; i < pageTags.length; i++) {
166 var node = new this.page(this); 164 var node = new page(this);
167 node.decode(this, pageTags[i], pageSchema); 165 node.decode(this, pageTags[i], pageSchema);
168 this.pages.push(node); 166 this.pages.push(node);
169 } 167 }
170 }; 168 };
171 169
203 root.appendChild(page.encode(RootDocument)); 201 root.appendChild(page.encode(RootDocument));
204 }); 202 });
205 return RootDocument; 203 return RootDocument;
206 }; 204 };
207 205
208 this.surveyNode = function (specification) { 206 function surveyNode(specification) {
209 this.location = undefined; 207 this.location = undefined;
210 this.options = []; 208 this.options = [];
211 this.parent = undefined; 209 this.parent = undefined;
212 this.schema = schemaRoot.querySelector('[name=survey]'); 210 this.schema = schemaRoot.querySelector('[name=survey]');
213 this.specification = specification; 211 this.specification = specification;
410 } 408 }
411 return node; 409 return node;
412 }; 410 };
413 }; 411 };
414 412
415 this.interfaceNode = function (specification) { 413 function interfaceNode(specification) {
416 this.title = undefined; 414 this.title = undefined;
417 this.name = undefined; 415 this.name = undefined;
418 this.image = undefined; 416 this.image = undefined;
419 this.options = []; 417 this.options = [];
420 this.scales = []; 418 this.scales = [];
421 this.schema = schemaRoot.querySelectorAll('[name=interface]')[1]; 419 this.schema = undefined;
422 420
423 this.decode = function (parent, xml) { 421 this.decode = function (parent, xml) {
422 this.schema = schemaRoot.querySelectorAll('[name=interface]')[1];
424 this.name = xml.getAttribute('name'); 423 this.name = xml.getAttribute('name');
425 var titleNode = xml.getElementsByTagName('title'); 424 var titleNode = xml.getElementsByTagName('title');
426 if (titleNode.length == 1) { 425 if (titleNode.length == 1) {
427 this.title = titleNode[0].textContent; 426 this.title = titleNode[0].textContent;
428 } 427 }
503 } 502 }
504 return node; 503 return node;
505 }; 504 };
506 }; 505 };
507 506
508 this.metricNode = function () { 507 function metricNode() {
509 this.enabled = []; 508 this.enabled = [];
510 this.decode = function (parent, xml) { 509 this.decode = function (parent, xml) {
511 var children = xml.getElementsByTagName('metricenable'); 510 var children = xml.getElementsByTagName('metricenable');
512 for (var i in children) { 511 for (var i in children) {
513 if (isNaN(Number(i)) === true) { 512 if (isNaN(Number(i)) === true) {
528 } 527 }
529 return node; 528 return node;
530 }; 529 };
531 }; 530 };
532 531
533 this.page = function (specification) { 532 function page(specification) {
534 this.presentedId = undefined; 533 this.presentedId = undefined;
535 this.id = undefined; 534 this.id = undefined;
536 this.title = undefined; 535 this.title = undefined;
537 this.hostURL = undefined; 536 this.hostURL = undefined;
538 this.randomiseOrder = undefined; 537 this.randomiseOrder = undefined;
578 if (CBP.length !== 0 && CBP[0].parentElement == xml) { 577 if (CBP.length !== 0 && CBP[0].parentElement == xml) {
579 this.commentBoxPrefix = CBP[0].textContent; 578 this.commentBoxPrefix = CBP[0].textContent;
580 } 579 }
581 580
582 // Now decode the interfaces 581 // Now decode the interfaces
583 var interfaceNode = xml.getElementsByTagName('interface'); 582 var interfaceNodes = xml.getElementsByTagName('interface');
584 for (i = 0; i < interfaceNode.length; i++) { 583 for (i = 0; i < interfaceNodes.length; i++) {
585 node = new parent.interfaceNode(this.specification); 584 node = new interfaceNode(this.specification);
586 node.decode(this, interfaceNode[i], parent.schema.querySelectorAll('[name=interface]')[1]); 585 node.decode(this, interfaceNodes[i], parent.schema.querySelectorAll('[name=interface]')[1]);
587 this.interfaces.push(node); 586 this.interfaces.push(node);
588 } 587 }
589 588
590 // Now process the survey node options 589 // Now process the survey node options
591 var survey = xml.getElementsByTagName('survey'); 590 var survey = xml.getElementsByTagName('survey');
594 var location = survey[i].getAttribute('location'); 593 var location = survey[i].getAttribute('location');
595 if (location == 'pre' || location == 'before') { 594 if (location == 'pre' || location == 'before') {
596 if (this.preTest !== undefined) { 595 if (this.preTest !== undefined) {
597 this.errors.push("Already a pre/before test survey defined! Ignoring second!!"); 596 this.errors.push("Already a pre/before test survey defined! Ignoring second!!");
598 } else { 597 } else {
599 this.preTest = new parent.surveyNode(this.specification); 598 this.preTest = new surveyNode(this.specification);
600 this.preTest.decode(parent, survey[i], surveySchema); 599 this.preTest.decode(parent, survey[i], surveySchema);
601 } 600 }
602 } else if (location == 'post' || location == 'after') { 601 } else if (location == 'post' || location == 'after') {
603 if (this.postTest !== undefined) { 602 if (this.postTest !== undefined) {
604 this.errors.push("Already a post/after test survey defined! Ignoring second!!"); 603 this.errors.push("Already a post/after test survey defined! Ignoring second!!");
605 } else { 604 } else {
606 this.postTest = new parent.surveyNode(this.specification); 605 this.postTest = new surveyNode(this.specification);
607 this.postTest.decode(parent, survey[i], surveySchema); 606 this.postTest.decode(parent, survey[i], surveySchema);
608 } 607 }
609 } 608 }
610 } 609 }
611 610
612 // Now process the audioelement tags 611 // Now process the audioelement tags
613 var audioElements = xml.getElementsByTagName('audioelement'); 612 var audioElements = xml.getElementsByTagName('audioelement');
614 for (i = 0; i < audioElements.length; i++) { 613 for (i = 0; i < audioElements.length; i++) {
615 var audioNode = new this.audioElementNode(this.specification); 614 var audioNode = new audioElementNode(this.specification);
616 audioNode.decode(this, audioElements[i]); 615 audioNode.decode(this, audioElements[i]);
617 this.audioElements.push(audioNode); 616 this.audioElements.push(audioNode);
618 } 617 }
619 618
620 // Now decode the commentquestions 619 // Now decode the commentquestions
621 var cqNode = xml.getElementsByTagName('commentquestions'); 620 var cqNode = xml.getElementsByTagName('commentquestions');
622 if (cqNode.length !== 0) { 621 if (cqNode.length !== 0) {
623 cqNode = cqNode[0]; 622 cqNode = cqNode[0];
624 var commentQuestion = cqNode.firstElementChild; 623 var commentQuestion = cqNode.firstElementChild;
625 while (commentQuestion) { 624 while (commentQuestion) {
626 node = new this.commentQuestionNode(this.specification); 625 node = new commentQuestionNode(this.specification);
627 node.decode(parent, commentQuestion); 626 node.decode(parent, commentQuestion);
628 this.commentQuestions.push(node); 627 this.commentQuestions.push(node);
629 commentQuestion = commentQuestion.nextElementSibling; 628 commentQuestion = commentQuestion.nextElementSibling;
630 } 629 }
631 } 630 }
665 AHNode.appendChild(this.preTest.encode(root)); 664 AHNode.appendChild(this.preTest.encode(root));
666 AHNode.appendChild(this.postTest.encode(root)); 665 AHNode.appendChild(this.postTest.encode(root));
667 return AHNode; 666 return AHNode;
668 }; 667 };
669 668
670 this.commentQuestionNode = function (specification) { 669 function commentQuestionNode(specification) {
671 this.id = undefined; 670 this.id = undefined;
672 this.name = undefined; 671 this.name = undefined;
673 this.type = undefined; 672 this.type = undefined;
674 this.statement = undefined; 673 this.statement = undefined;
675 this.schema = schemaRoot.querySelector('[name=commentquestion]'); 674 this.schema = schemaRoot.querySelector('[name=commentquestion]');
793 } 792 }
794 return node; 793 return node;
795 }; 794 };
796 }; 795 };
797 796
798 this.audioElementNode = function (specification) { 797 function audioElementNode(specification) {
799 this.url = undefined; 798 this.url = undefined;
800 this.id = undefined; 799 this.id = undefined;
801 this.name = undefined; 800 this.name = undefined;
802 this.parent = undefined; 801 this.parent = undefined;
803 this.type = undefined; 802 this.type = undefined;