comparison core.js @ 1580:b6c808cac38c

Created Specification object to handle All XML decoding.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Thu, 04 Jun 2015 14:31:23 +0100
parents 4ffbccf448c2
children c867677af7f4
comparison
equal deleted inserted replaced
1579:4ffbccf448c2 1580:b6c808cac38c
319 r.send(); 319 r.send();
320 }; 320 };
321 321
322 function loadProjectSpecCallback(response) { 322 function loadProjectSpecCallback(response) {
323 // Function called after asynchronous download of XML project specification 323 // Function called after asynchronous download of XML project specification
324 var decode = $.parseXML(response); 324 //var decode = $.parseXML(response);
325 projectXML = $(decode); 325 //projectXML = $(decode);
326
327 var parse = new DOMParser();
328 projectXML = parse.parseFromString(response,'text/xml');
326 329
327 // Now extract the setup tag 330 // Now extract the setup tag
328 var xmlSetup = projectXML.find('setup'); 331 var xmlSetup = projectXML.find('setup');
329 332
330 333
971 },500,false); 974 },500,false);
972 } 975 }
973 } 976 }
974 977
975 var testWaitTimerIntervalHolder = null; 978 var testWaitTimerIntervalHolder = null;
979
980 function Specification() {
981 // Handles the decoding of the project specification XML into a simple JavaScript Object.
982
983 this.interfaceType;
984 this.projectReturn;
985 this.randomiseOrder;
986 this.collectMetrics;
987 this.preTest;
988 this.postTest;
989 this.metrics =[];
990
991 this.audioHolders = [];
992
993 this.decode = function() {
994 // projectXML - DOM Parsed document
995 var setupNode = projectXML.getElementsByTagName('setup')[0];
996 this.interfaceType = setupNode.getAttribute('interface');
997 this.projectReturn = setupNode.getAttribute('projectReturn');
998 if (setupNode.getAttribute('randomiseOrder') == "true") {
999 this.randomiseOrder = true;
1000 } else {this.setup.randomiseOrder = false;}
1001 if (setupNode.getAttribute('collectMetrics') == "true") {
1002 this.collectMetrics = true;
1003 } else {this.setup.collectMetrics = false;}
1004 var metricCollection = setupNode.getElementsByTagName('Metric');
1005
1006 this.preTest = new this.prepostNode('pre',setupNode.getElementsByTagName('PreTest'));
1007 this.postTest = new this.prepostNode('post',setupNode.getElementsByTagName('PostTest'));
1008
1009 if (metricCollection.length > 0) {
1010 metricCollection = metricCollection[0].getElementsByTagName('metricEnable');
1011 for (var i=0; i<metricCollection.length; i++) {
1012 this.metrics.push(new this.metricNode(metricCollection[0].textContent));
1013 }
1014 }
1015
1016 var audioHolders = projectXML.getElementsByTagName('audioHolder');
1017 for (var i=0; i<audioHolders.length; i++) {
1018 this.audioHolders.push(new this.audioHolderNode(this,audioHolders[i]));
1019 }
1020
1021 };
1022
1023 this.prepostNode = function(type,Collection) {
1024 this.type = type;
1025 this.options = [];
1026
1027 this.OptionNode = function(child) {
1028 this.type = child.nodeName;
1029 if (child.nodeName == "question") {
1030 this.id = child.id;
1031 this.mandatory;
1032 if (child.getAttribute('mandatory') == "true") {this.mandatory = true;}
1033 else {this.mandatory = false;}
1034 this.question = child.textContent;
1035 } else if (child.nodeName == "statement") {
1036 this.statment = child.textContent;
1037 }
1038 };
1039
1040 // On construction:
1041 if (Collection.length != 0) {
1042 Collection = Collection[0];
1043 for (var i=0; i<Collection.childElementCount; i++) {
1044 var child = Collection.children[i];
1045 this.options.push(new this.OptionNode(child));
1046 }
1047 }
1048 };
1049
1050 this.metricNode = function(name) {
1051 this.enabled = name;
1052 };
1053
1054 this.audioHolderNode = function(parent,xml) {
1055 this.interfaceNode = function(DOM) {
1056 var title = DOM.getElementsByTagName('title');
1057 if (title.length == 0) {this.title = null;}
1058 else {this.title = title[0].textContent;}
1059
1060 var scale = DOM.getElementsByTagName('scale');
1061 this.scale = [];
1062 for (var i=0; i<scale.length; i++) {
1063 var arr = [null, null];
1064 arr[0] = scale[i].getAttribute('position');
1065 arr[1] = scale[i].textContent;
1066 this.scale.push(arr);
1067 }
1068 };
1069
1070 this.audioElementNode = function(xml) {
1071 this.url = xml.getAttribute('url');
1072 this.id = xml.id;
1073 };
1074
1075 this.commentQuestionNode = function(xml) {
1076 this.id = xml.id;
1077 if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;}
1078 else {this.mandatory = false;}
1079 this.question = xml.textContent;
1080 };
1081
1082 this.id = xml.id;
1083 this.hostURL = xml.getAttribute('hostURL');
1084 this.sampleRate = xml.getAttribute('sampleRate');
1085 if (xml.getAttribute('randomiseOrder') == "true") {this.randomiseOrder = true;}
1086 else {this.randomiseOrder = false;}
1087 this.repeatCount = xml.getAttribute('repeatCount');
1088 if (xml.getAttribute('loop') == 'true') {this.loop = true;}
1089 else {this.loop == false;}
1090 if (xml.getAttribute('elementComments') == "true") {this.elementComments = true;}
1091 else {this.elementComments = false;}
1092
1093 this.preTest = new parent.prepostNode('pre',xml.getElementsByTagName('PreTest'));
1094 this.postTest = new parent.prepostNode('post',xml.getElementsByTagName('PostTest'));
1095
1096 this.interfaces = [];
1097 var interfaceDOM = xml.getElementsByTagName('interface');
1098 for (var i=0; i<interfaceDOM.length; i++) {
1099 this.interfaces.push(new this.interfaceNode(interfaceDOM[i]));
1100 }
1101
1102 this.commentBoxPrefix = xml.getElementsByTagName('commentBoxPrefix');
1103 if (this.commentBoxPrefix.length != 0) {
1104 this.commentBoxPrefix = this.commentBoxPrefix[0].textContent;
1105 } else {
1106 this.commentBoxPrefix = "Comment on track";
1107 }
1108
1109 this.audioElements =[];
1110 var audioElementsDOM = xml.getElementsByTagName('audioElements');
1111 for (var i=0; i<audioElementsDOM.length; i++) {
1112 this.audioElements.push(new this.audioElementNode(audioElementsDOM[i]));
1113 }
1114
1115 this.commentQuestions = [];
1116 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
1117 for (var i=0; i<commentQuestionsDOM.length; i++) {
1118 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i]));
1119 }
1120 };
1121 }
1122
1123 function Interface() {
1124 // This handles the bindings between the interface and the audioEngineContext;
1125
1126 }
1127