nickjillings@1370
|
1 <html>
|
nickjillings@1370
|
2 <head>
|
nickjillings@1370
|
3 <!-- This defines the test creator tool for the Web Audio Evaluation Toolbox -->
|
nickjillings@1370
|
4 <link rel='stylesheet' type="text/css" href="style.css"/>
|
nickjillings@1370
|
5 <script type="text/javascript">
|
nickjillings@1370
|
6 // Copy of Specifiation node from Core.js
|
nickjillings@1370
|
7 function Specification() {
|
nickjillings@1370
|
8 // Handles the decoding of the project specification XML into a simple JavaScript Object.
|
nickjillings@1370
|
9
|
nickjillings@1370
|
10 this.interface = null;
|
nickjillings@1370
|
11 this.projectReturn = null;
|
nickjillings@1370
|
12 this.randomiseOrder = null;
|
nickjillings@1370
|
13 this.testPages = null;
|
nickjillings@1370
|
14 this.pages = [];
|
nickjillings@1370
|
15 this.metrics = null;
|
nickjillings@1370
|
16 this.interfaces = null;
|
nickjillings@1370
|
17 this.loudness = null;
|
nickjillings@1370
|
18 this.errors = [];
|
nickjillings@1370
|
19 this.schema = null;
|
nickjillings@1370
|
20
|
nickjillings@1370
|
21 this.randomiseOrder = function(input)
|
nickjillings@1370
|
22 {
|
nickjillings@1370
|
23 // This takes an array of information and randomises the order
|
nickjillings@1370
|
24 var N = input.length;
|
nickjillings@1370
|
25
|
nickjillings@1370
|
26 var inputSequence = []; // For safety purposes: keep track of randomisation
|
nickjillings@1370
|
27 for (var counter = 0; counter < N; ++counter)
|
nickjillings@1370
|
28 inputSequence.push(counter) // Fill array
|
nickjillings@1370
|
29 var inputSequenceClone = inputSequence.slice(0);
|
nickjillings@1370
|
30
|
nickjillings@1370
|
31 var holdArr = [];
|
nickjillings@1370
|
32 var outputSequence = [];
|
nickjillings@1370
|
33 for (var n=0; n<N; n++)
|
nickjillings@1370
|
34 {
|
nickjillings@1370
|
35 // First pick a random number
|
nickjillings@1370
|
36 var r = Math.random();
|
nickjillings@1370
|
37 // Multiply and floor by the number of elements left
|
nickjillings@1370
|
38 r = Math.floor(r*input.length);
|
nickjillings@1370
|
39 // Pick out that element and delete from the array
|
nickjillings@1370
|
40 holdArr.push(input.splice(r,1)[0]);
|
nickjillings@1370
|
41 // Do the same with sequence
|
nickjillings@1370
|
42 outputSequence.push(inputSequence.splice(r,1)[0]);
|
nickjillings@1370
|
43 }
|
nickjillings@1370
|
44 console.log(inputSequenceClone.toString()); // print original array to console
|
nickjillings@1370
|
45 console.log(outputSequence.toString()); // print randomised array to console
|
nickjillings@1370
|
46 return holdArr;
|
nickjillings@1370
|
47 };
|
nickjillings@1370
|
48
|
nickjillings@1370
|
49 this.processAttribute = function(attribute,schema)
|
nickjillings@1370
|
50 {
|
nickjillings@1370
|
51 // attribute is the string returned from getAttribute on the XML
|
nickjillings@1370
|
52 // schema is the <xs:attribute> node
|
nickjillings@1370
|
53 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined)
|
nickjillings@1370
|
54 {
|
nickjillings@1370
|
55 schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0];
|
nickjillings@1370
|
56 }
|
nickjillings@1370
|
57 var defaultOpt = schema.getAttribute('default');
|
nickjillings@1370
|
58 if (attribute == null) {
|
nickjillings@1370
|
59 attribute = defaultOpt;
|
nickjillings@1370
|
60 }
|
nickjillings@1370
|
61 var dataType = schema.getAttribute('type');
|
nickjillings@1370
|
62 if (typeof dataType == "string") { dataType = dataType.substr(3);}
|
nickjillings@1370
|
63 else {dataType = "string";}
|
nickjillings@1370
|
64 if (attribute == null)
|
nickjillings@1370
|
65 {
|
nickjillings@1370
|
66 return attribute;
|
nickjillings@1370
|
67 }
|
nickjillings@1370
|
68 switch(dataType)
|
nickjillings@1370
|
69 {
|
nickjillings@1370
|
70 case "boolean":
|
nickjillings@1370
|
71 if (attribute == 'true'){attribute = true;}else{attribute=false;}
|
nickjillings@1370
|
72 break;
|
nickjillings@1370
|
73 case "negativeInteger":
|
nickjillings@1370
|
74 case "positiveInteger":
|
nickjillings@1370
|
75 case "nonNegativeInteger":
|
nickjillings@1370
|
76 case "nonPositiveInteger":
|
nickjillings@1370
|
77 case "integer":
|
nickjillings@1370
|
78 case "decimal":
|
nickjillings@1370
|
79 case "short":
|
nickjillings@1370
|
80 attribute = Number(attribute);
|
nickjillings@1370
|
81 break;
|
nickjillings@1370
|
82 case "string":
|
nickjillings@1370
|
83 default:
|
nickjillings@1370
|
84 attribute = String(attribute);
|
nickjillings@1370
|
85 break;
|
nickjillings@1370
|
86 }
|
nickjillings@1370
|
87 return attribute;
|
nickjillings@1370
|
88 };
|
nickjillings@1370
|
89
|
nickjillings@1370
|
90 this.decode = function(projectXML) {
|
nickjillings@1370
|
91 this.errors = [];
|
nickjillings@1370
|
92 // projectXML - DOM Parsed document
|
nickjillings@1370
|
93 this.projectXML = projectXML.childNodes[0];
|
nickjillings@1370
|
94 var setupNode = projectXML.getElementsByTagName('setup')[0];
|
nickjillings@1370
|
95 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
|
nickjillings@1370
|
96 // First decode the attributes
|
nickjillings@1370
|
97 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
|
nickjillings@1370
|
98 for (var i in attributes)
|
nickjillings@1370
|
99 {
|
nickjillings@1370
|
100 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
101 var attributeName = attributes[i].getAttribute('name');
|
nickjillings@1370
|
102 var projectAttr = setupNode.getAttribute(attributeName);
|
nickjillings@1370
|
103 projectAttr = this.processAttribute(projectAttr,attributes[i]);
|
nickjillings@1370
|
104 switch(typeof projectAttr)
|
nickjillings@1370
|
105 {
|
nickjillings@1370
|
106 case "number":
|
nickjillings@1370
|
107 case "boolean":
|
nickjillings@1370
|
108 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1370
|
109 break;
|
nickjillings@1370
|
110 case "string":
|
nickjillings@1370
|
111 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1370
|
112 break;
|
nickjillings@1370
|
113 }
|
nickjillings@1370
|
114
|
nickjillings@1370
|
115 }
|
nickjillings@1370
|
116
|
nickjillings@1370
|
117 this.metrics = new this.metricNode();
|
nickjillings@1370
|
118
|
nickjillings@1370
|
119 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]);
|
nickjillings@1370
|
120
|
nickjillings@1370
|
121 // Now process the survey node options
|
nickjillings@1370
|
122 var survey = setupNode.getElementsByTagName('survey');
|
nickjillings@1370
|
123 for (var i in survey) {
|
nickjillings@1370
|
124 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
125 var location = survey[i].getAttribute('location');
|
nickjillings@1370
|
126 if (location == 'pre' || location == 'before')
|
nickjillings@1370
|
127 {
|
nickjillings@1370
|
128 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
|
nickjillings@1370
|
129 else {
|
nickjillings@1370
|
130 this.preTest = new this.surveyNode();
|
nickjillings@1370
|
131 this.preTest.decode(this,survey[i]);
|
nickjillings@1370
|
132 }
|
nickjillings@1370
|
133 } else if (location == 'post' || location == 'after') {
|
nickjillings@1370
|
134 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
|
nickjillings@1370
|
135 else {
|
nickjillings@1370
|
136 this.postTest = new this.surveyNode();
|
nickjillings@1370
|
137 this.postTest.decode(this,survey[i]);
|
nickjillings@1370
|
138 }
|
nickjillings@1370
|
139 }
|
nickjillings@1370
|
140 }
|
nickjillings@1370
|
141
|
nickjillings@1370
|
142 var interfaceNode = setupNode.getElementsByTagName('interface');
|
nickjillings@1370
|
143 if (interfaceNode.length > 1)
|
nickjillings@1370
|
144 {
|
nickjillings@1370
|
145 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!");
|
nickjillings@1370
|
146 }
|
nickjillings@1370
|
147 this.interfaces = new this.interfaceNode();
|
nickjillings@1370
|
148 if (interfaceNode.length != 0)
|
nickjillings@1370
|
149 {
|
nickjillings@1370
|
150 interfaceNode = interfaceNode[0];
|
nickjillings@1370
|
151 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]);
|
nickjillings@1370
|
152 }
|
nickjillings@1370
|
153
|
nickjillings@1370
|
154 // Page tags
|
nickjillings@1370
|
155 var pageTags = projectXML.getElementsByTagName('page');
|
nickjillings@1370
|
156 var pageSchema = this.schema.getAllElementsByName('page')[0];
|
nickjillings@1370
|
157 for (var i=0; i<pageTags.length; i++)
|
nickjillings@1370
|
158 {
|
nickjillings@1370
|
159 var node = new this.page();
|
nickjillings@1370
|
160 node.decode(this,pageTags[i],pageSchema);
|
nickjillings@1370
|
161 this.pages.push(node);
|
nickjillings@1370
|
162 }
|
nickjillings@1370
|
163 };
|
nickjillings@1370
|
164
|
nickjillings@1370
|
165 this.encode = function()
|
nickjillings@1370
|
166 {
|
nickjillings@1370
|
167 var root = document.implementation.createDocument(null,"waet");
|
nickjillings@1370
|
168
|
nickjillings@1370
|
169 // Build setup node
|
nickjillings@1370
|
170
|
nickjillings@1370
|
171 return root;
|
nickjillings@1370
|
172 };
|
nickjillings@1370
|
173
|
nickjillings@1370
|
174 this.surveyNode = function() {
|
nickjillings@1370
|
175 this.location = null;
|
nickjillings@1370
|
176 this.options = [];
|
nickjillings@1370
|
177 this.schema = specification.schema.getAllElementsByName('survey')[0];
|
nickjillings@1370
|
178
|
nickjillings@1370
|
179 this.OptionNode = function() {
|
nickjillings@1370
|
180 this.type = undefined;
|
nickjillings@1370
|
181 this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
|
nickjillings@1370
|
182 this.id = undefined;
|
nickjillings@1370
|
183 this.mandatory = undefined;
|
nickjillings@1370
|
184 this.statement = undefined;
|
nickjillings@1370
|
185 this.boxsize = undefined;
|
nickjillings@1370
|
186 this.options = [];
|
nickjillings@1370
|
187 this.min = undefined;
|
nickjillings@1370
|
188 this.max = undefined;
|
nickjillings@1370
|
189 this.step = undefined;
|
nickjillings@1370
|
190
|
nickjillings@1370
|
191 this.decode = function(parent,child)
|
nickjillings@1370
|
192 {
|
nickjillings@1370
|
193 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1370
|
194 for (var i in attributeMap){
|
nickjillings@1370
|
195 if(isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
196 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1370
|
197 var projectAttr = child.getAttribute(attributeName);
|
nickjillings@1370
|
198 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1370
|
199 switch(typeof projectAttr)
|
nickjillings@1370
|
200 {
|
nickjillings@1370
|
201 case "number":
|
nickjillings@1370
|
202 case "boolean":
|
nickjillings@1370
|
203 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1370
|
204 break;
|
nickjillings@1370
|
205 case "string":
|
nickjillings@1370
|
206 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1370
|
207 break;
|
nickjillings@1370
|
208 }
|
nickjillings@1370
|
209 }
|
nickjillings@1370
|
210 this.statement = child.getElementsByTagName('statement')[0].textContent;
|
nickjillings@1370
|
211 if (this.type == "checkbox" || this.type == "radio") {
|
nickjillings@1370
|
212 var children = child.getElementsByTagName('option');
|
nickjillings@1370
|
213 if (children.length == null) {
|
nickjillings@1370
|
214 console.log('Malformed' +child.nodeName+ 'entry');
|
nickjillings@1370
|
215 this.statement = 'Malformed' +child.nodeName+ 'entry';
|
nickjillings@1370
|
216 this.type = 'statement';
|
nickjillings@1370
|
217 } else {
|
nickjillings@1370
|
218 this.options = [];
|
nickjillings@1370
|
219 for (var i in children)
|
nickjillings@1370
|
220 {
|
nickjillings@1370
|
221 if (isNaN(Number(i))==true){break;}
|
nickjillings@1370
|
222 this.options.push({
|
nickjillings@1370
|
223 name: children[i].getAttribute('name'),
|
nickjillings@1370
|
224 text: children[i].textContent
|
nickjillings@1370
|
225 });
|
nickjillings@1370
|
226 }
|
nickjillings@1370
|
227 }
|
nickjillings@1370
|
228 }
|
nickjillings@1370
|
229 };
|
nickjillings@1370
|
230
|
nickjillings@1370
|
231 this.exportXML = function(root)
|
nickjillings@1370
|
232 {
|
nickjillings@1370
|
233 var node = root.createElement('surveyelement');
|
nickjillings@1370
|
234 node.setAttribute('type',this.type);
|
nickjillings@1370
|
235 var statement = root.createElement('statement');
|
nickjillings@1370
|
236 statement.textContent = this.statement;
|
nickjillings@1370
|
237 node.appendChild(statement);
|
nickjillings@1370
|
238 switch(this.type)
|
nickjillings@1370
|
239 {
|
nickjillings@1370
|
240 case "statement":
|
nickjillings@1370
|
241 break;
|
nickjillings@1370
|
242 case "question":
|
nickjillings@1370
|
243 node.id = this.id;
|
nickjillings@1370
|
244 node.setAttribute("mandatory",this.mandatory);
|
nickjillings@1370
|
245 node.setAttribute("boxsize",this.boxsize);
|
nickjillings@1370
|
246 break;
|
nickjillings@1370
|
247 case "number":
|
nickjillings@1370
|
248 node.id = this.id;
|
nickjillings@1370
|
249 node.setAttribute("mandatory",this.mandatory);
|
nickjillings@1370
|
250 node.setAttribute("min", this.min);
|
nickjillings@1370
|
251 node.setAttribute("max", this.max);
|
nickjillings@1370
|
252 node.setAttribute("step", this.step);
|
nickjillings@1370
|
253 break;
|
nickjillings@1370
|
254 case "checkbox":
|
nickjillings@1370
|
255 case "radio":
|
nickjillings@1370
|
256 node.id = this.id;
|
nickjillings@1370
|
257 for (var i=0; i<this.options.length; i++)
|
nickjillings@1370
|
258 {
|
nickjillings@1370
|
259 var option = this.options[i];
|
nickjillings@1370
|
260 var optionNode = root.createElement("option");
|
nickjillings@1370
|
261 optionNode.setAttribute("name",option.name);
|
nickjillings@1370
|
262 optionNode.textContent = option.text;
|
nickjillings@1370
|
263 node.appendChild(optionNode);
|
nickjillings@1370
|
264 }
|
nickjillings@1370
|
265 break;
|
nickjillings@1370
|
266 }
|
nickjillings@1370
|
267 return node;
|
nickjillings@1370
|
268 };
|
nickjillings@1370
|
269 };
|
nickjillings@1370
|
270 this.decode = function(parent,xml) {
|
nickjillings@1370
|
271 this.location = xml.getAttribute('location');
|
nickjillings@1370
|
272 if (this.location == 'before'){this.location = 'pre';}
|
nickjillings@1370
|
273 else if (this.location == 'after'){this.location = 'post';}
|
nickjillings@1370
|
274 for (var i in xml.children)
|
nickjillings@1370
|
275 {
|
nickjillings@1370
|
276 if(isNaN(Number(i))==true){break;}
|
nickjillings@1370
|
277 var node = new this.OptionNode();
|
nickjillings@1370
|
278 node.decode(parent,xml.children[i]);
|
nickjillings@1370
|
279 this.options.push(node);
|
nickjillings@1370
|
280 }
|
nickjillings@1370
|
281 };
|
nickjillings@1370
|
282 this.encode = function(root) {
|
nickjillings@1370
|
283 var node = root.createElement('survey');
|
nickjillings@1370
|
284 node.setAttribute('location',this.location);
|
nickjillings@1370
|
285 for (var i=0; i<this.options.length; i++)
|
nickjillings@1370
|
286 {
|
nickjillings@1370
|
287 node.appendChild(this.options[i].exportXML());
|
nickjillings@1370
|
288 }
|
nickjillings@1370
|
289 return node;
|
nickjillings@1370
|
290 };
|
nickjillings@1370
|
291 };
|
nickjillings@1370
|
292
|
nickjillings@1370
|
293 this.interfaceNode = function()
|
nickjillings@1370
|
294 {
|
nickjillings@1370
|
295 this.title = null;
|
nickjillings@1370
|
296 this.name = null;
|
nickjillings@1370
|
297 this.options = [];
|
nickjillings@1370
|
298 this.scales = [];
|
nickjillings@1370
|
299 this.schema = specification.schema.getAllElementsByName('interface')[1];
|
nickjillings@1370
|
300
|
nickjillings@1370
|
301 this.decode = function(parent,xml) {
|
nickjillings@1370
|
302 this.name = xml.getAttribute('name');
|
nickjillings@1370
|
303 var titleNode = xml.getElementsByTagName('title');
|
nickjillings@1370
|
304 if (titleNode.length == 1)
|
nickjillings@1370
|
305 {
|
nickjillings@1370
|
306 this.title = titleNode[0].textContent;
|
nickjillings@1370
|
307 }
|
nickjillings@1370
|
308 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption');
|
nickjillings@1370
|
309 // Extract interfaceoption node schema
|
nickjillings@1370
|
310 var interfaceOptionNodeSchema = this.schema.getAllElementsByName('interfaceoption')[0];
|
nickjillings@1370
|
311 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1370
|
312 for (var i=0; i<interfaceOptionNodes.length; i++)
|
nickjillings@1370
|
313 {
|
nickjillings@1370
|
314 var ioNode = interfaceOptionNodes[i];
|
nickjillings@1370
|
315 var option = {};
|
nickjillings@1370
|
316 for (var j=0; j<attributeMap.length; j++)
|
nickjillings@1370
|
317 {
|
nickjillings@1370
|
318 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
|
nickjillings@1370
|
319 var projectAttr = ioNode.getAttribute(attributeName);
|
nickjillings@1370
|
320 projectAttr = parent.processAttribute(projectAttr,attributeMap[j]);
|
nickjillings@1370
|
321 switch(typeof projectAttr)
|
nickjillings@1370
|
322 {
|
nickjillings@1370
|
323 case "number":
|
nickjillings@1370
|
324 case "boolean":
|
nickjillings@1370
|
325 eval('option.'+attributeName+' = '+projectAttr);
|
nickjillings@1370
|
326 break;
|
nickjillings@1370
|
327 case "string":
|
nickjillings@1370
|
328 eval('option.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1370
|
329 break;
|
nickjillings@1370
|
330 }
|
nickjillings@1370
|
331 }
|
nickjillings@1370
|
332 this.options.push(option);
|
nickjillings@1370
|
333 }
|
nickjillings@1370
|
334
|
nickjillings@1370
|
335 // Now the scales nodes
|
nickjillings@1370
|
336 var scaleParent = xml.getElementsByTagName('scales');
|
nickjillings@1370
|
337 if (scaleParent.length == 1) {
|
nickjillings@1370
|
338 scaleParent = scaleParent[0];
|
nickjillings@1370
|
339 for (var i=0; i<scaleParent.children.length; i++) {
|
nickjillings@1370
|
340 var child = scaleParent.children[i];
|
nickjillings@1370
|
341 this.scales.push({
|
nickjillings@1370
|
342 text: child.textContent,
|
nickjillings@1370
|
343 position: Number(child.getAttribute('position'))
|
nickjillings@1370
|
344 });
|
nickjillings@1370
|
345 }
|
nickjillings@1370
|
346 }
|
nickjillings@1370
|
347 };
|
nickjillings@1370
|
348
|
nickjillings@1370
|
349 this.encode = function(root) {
|
nickjillings@1370
|
350
|
nickjillings@1370
|
351 };
|
nickjillings@1370
|
352 };
|
nickjillings@1370
|
353
|
nickjillings@1370
|
354 this.metricNode = function() {
|
nickjillings@1370
|
355 this.enabled = [];
|
nickjillings@1370
|
356 this.decode = function(parent, xml) {
|
nickjillings@1370
|
357 var children = xml.getElementsByTagName('metricenable');
|
nickjillings@1370
|
358 for (var i in children) {
|
nickjillings@1370
|
359 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
360 this.enabled.push(children[i].textContent);
|
nickjillings@1370
|
361 }
|
nickjillings@1370
|
362 }
|
nickjillings@1370
|
363 this.encode = function(root) {
|
nickjillings@1370
|
364 var node = root.createElement('metric');
|
nickjillings@1370
|
365 for (var i in this.enabled)
|
nickjillings@1370
|
366 {
|
nickjillings@1370
|
367 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
368 var child = root.createElement('metricenable');
|
nickjillings@1370
|
369 child.textContent = this.enabled[i];
|
nickjillings@1370
|
370 node.appendChild(child);
|
nickjillings@1370
|
371 }
|
nickjillings@1370
|
372 return node;
|
nickjillings@1370
|
373 }
|
nickjillings@1370
|
374 }
|
nickjillings@1370
|
375
|
nickjillings@1370
|
376 this.page = function() {
|
nickjillings@1370
|
377 this.presentedId = undefined;
|
nickjillings@1370
|
378 this.id = undefined;
|
nickjillings@1370
|
379 this.hostURL = undefined;
|
nickjillings@1370
|
380 this.randomiseOrder = undefined;
|
nickjillings@1370
|
381 this.loop = undefined;
|
nickjillings@1370
|
382 this.showElementComments = undefined;
|
nickjillings@1370
|
383 this.outsideReference = null;
|
nickjillings@1370
|
384 this.loudness = null;
|
nickjillings@1370
|
385 this.preTest = null;
|
nickjillings@1370
|
386 this.postTest = null;
|
nickjillings@1370
|
387 this.interfaces = [];
|
nickjillings@1370
|
388 this.commentBoxPrefix = "Comment on track";
|
nickjillings@1370
|
389 this.audioElements = [];
|
nickjillings@1370
|
390 this.commentQuestions = [];
|
nickjillings@1370
|
391 this.schema = specification.schema.getAllElementsByName("page")[0];
|
nickjillings@1370
|
392
|
nickjillings@1370
|
393 this.decode = function(parent,xml)
|
nickjillings@1370
|
394 {
|
nickjillings@1370
|
395 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1370
|
396 for (var i=0; i<attributeMap.length; i++)
|
nickjillings@1370
|
397 {
|
nickjillings@1370
|
398 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1370
|
399 var projectAttr = xml.getAttribute(attributeName);
|
nickjillings@1370
|
400 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1370
|
401 switch(typeof projectAttr)
|
nickjillings@1370
|
402 {
|
nickjillings@1370
|
403 case "number":
|
nickjillings@1370
|
404 case "boolean":
|
nickjillings@1370
|
405 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1370
|
406 break;
|
nickjillings@1370
|
407 case "string":
|
nickjillings@1370
|
408 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1370
|
409 break;
|
nickjillings@1370
|
410 }
|
nickjillings@1370
|
411 }
|
nickjillings@1370
|
412
|
nickjillings@1370
|
413 // Get the Comment Box Prefix
|
nickjillings@1370
|
414 var CBP = xml.getElementsByTagName('commentboxprefix');
|
nickjillings@1370
|
415 if (CBP.length != 0) {
|
nickjillings@1370
|
416 this.commentBoxPrefix = CBP[0].textContent;
|
nickjillings@1370
|
417 }
|
nickjillings@1370
|
418
|
nickjillings@1370
|
419 // Now decode the interfaces
|
nickjillings@1370
|
420 var interfaceNode = xml.getElementsByTagName('interface');
|
nickjillings@1370
|
421 for (var i=0; i<interfaceNode.length; i++)
|
nickjillings@1370
|
422 {
|
nickjillings@1370
|
423 var node = new parent.interfaceNode();
|
nickjillings@1370
|
424 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]);
|
nickjillings@1370
|
425 this.interfaces.push(node);
|
nickjillings@1370
|
426 }
|
nickjillings@1370
|
427
|
nickjillings@1370
|
428 // Now process the survey node options
|
nickjillings@1370
|
429 var survey = xml.getElementsByTagName('survey');
|
nickjillings@1370
|
430 var surveySchema = parent.schema.getAllElementsByName('survey')[0];
|
nickjillings@1370
|
431 for (var i in survey) {
|
nickjillings@1370
|
432 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
433 var location = survey[i].getAttribute('location');
|
nickjillings@1370
|
434 if (location == 'pre' || location == 'before')
|
nickjillings@1370
|
435 {
|
nickjillings@1370
|
436 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
|
nickjillings@1370
|
437 else {
|
nickjillings@1370
|
438 this.preTest = new parent.surveyNode();
|
nickjillings@1370
|
439 this.preTest.decode(parent,survey[i],surveySchema);
|
nickjillings@1370
|
440 }
|
nickjillings@1370
|
441 } else if (location == 'post' || location == 'after') {
|
nickjillings@1370
|
442 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
|
nickjillings@1370
|
443 else {
|
nickjillings@1370
|
444 this.postTest = new parent.surveyNode();
|
nickjillings@1370
|
445 this.postTest.decode(parent,survey[i],surveySchema);
|
nickjillings@1370
|
446 }
|
nickjillings@1370
|
447 }
|
nickjillings@1370
|
448 }
|
nickjillings@1370
|
449
|
nickjillings@1370
|
450 // Now process the audioelement tags
|
nickjillings@1370
|
451 var audioElements = xml.getElementsByTagName('audioelement');
|
nickjillings@1370
|
452 for (var i=0; i<audioElements.length; i++)
|
nickjillings@1370
|
453 {
|
nickjillings@1370
|
454 var node = new this.audioElementNode();
|
nickjillings@1370
|
455 node.decode(this,audioElements[i]);
|
nickjillings@1370
|
456 this.audioElements.push(node);
|
nickjillings@1370
|
457 }
|
nickjillings@1370
|
458
|
nickjillings@1370
|
459 // Now decode the commentquestions
|
nickjillings@1370
|
460 var commentQuestions = xml.getElementsByTagName('commentquestion');
|
nickjillings@1370
|
461 for (var i=0; i<commentQuestions.length; i++)
|
nickjillings@1370
|
462 {
|
nickjillings@1370
|
463 var node = new this.commentQuestionNode();
|
nickjillings@1370
|
464 node.decode(parent,commentQuestions[i]);
|
nickjillings@1370
|
465 this.commentQuestions.push(node);
|
nickjillings@1370
|
466 }
|
nickjillings@1370
|
467 };
|
nickjillings@1370
|
468
|
nickjillings@1370
|
469 this.encode = function(root)
|
nickjillings@1370
|
470 {
|
nickjillings@1370
|
471 var AHNode = root.createElement("audioHolder");
|
nickjillings@1370
|
472 AHNode.id = this.id;
|
nickjillings@1370
|
473 AHNode.setAttribute("hostURL",this.hostURL);
|
nickjillings@1370
|
474 AHNode.setAttribute("sampleRate",this.sampleRate);
|
nickjillings@1370
|
475 AHNode.setAttribute("randomiseOrder",this.randomiseOrder);
|
nickjillings@1370
|
476 AHNode.setAttribute("repeatCount",this.repeatCount);
|
nickjillings@1370
|
477 AHNode.setAttribute("loop",this.loop);
|
nickjillings@1370
|
478 AHNode.setAttribute("elementComments",this.elementComments);
|
nickjillings@1370
|
479 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);}
|
nickjillings@1370
|
480 if(this.initialPosition != null) {
|
nickjillings@1370
|
481 AHNode.setAttribute("loudness",this.initialPosition*100);
|
nickjillings@1370
|
482 }
|
nickjillings@1370
|
483 for (var i=0; i<this.interfaces.length; i++)
|
nickjillings@1370
|
484 {
|
nickjillings@1370
|
485 AHNode.appendChild(this.interfaces[i].encode(root));
|
nickjillings@1370
|
486 }
|
nickjillings@1370
|
487
|
nickjillings@1370
|
488 for (var i=0; i<this.audioElements.length; i++) {
|
nickjillings@1370
|
489 AHNode.appendChild(this.audioElements[i].encode(root));
|
nickjillings@1370
|
490 }
|
nickjillings@1370
|
491 // Create <CommentQuestion>
|
nickjillings@1370
|
492 for (var i=0; i<this.commentQuestions.length; i++)
|
nickjillings@1370
|
493 {
|
nickjillings@1370
|
494 AHNode.appendChild(this.commentQuestions[i].exportXML(root));
|
nickjillings@1370
|
495 }
|
nickjillings@1370
|
496
|
nickjillings@1370
|
497 // Create <PreTest>
|
nickjillings@1370
|
498 var AHPreTest = root.createElement("PreTest");
|
nickjillings@1370
|
499 for (var i=0; i<this.preTest.options.length; i++)
|
nickjillings@1370
|
500 {
|
nickjillings@1370
|
501 AHPreTest.appendChild(this.preTest.options[i].exportXML(root));
|
nickjillings@1370
|
502 }
|
nickjillings@1370
|
503
|
nickjillings@1370
|
504 var AHPostTest = root.createElement("PostTest");
|
nickjillings@1370
|
505 for (var i=0; i<this.postTest.options.length; i++)
|
nickjillings@1370
|
506 {
|
nickjillings@1370
|
507 AHPostTest.appendChild(this.postTest.options[i].exportXML(root));
|
nickjillings@1370
|
508 }
|
nickjillings@1370
|
509 AHNode.appendChild(AHPreTest);
|
nickjillings@1370
|
510 AHNode.appendChild(AHPostTest);
|
nickjillings@1370
|
511 return AHNode;
|
nickjillings@1370
|
512 };
|
nickjillings@1370
|
513
|
nickjillings@1370
|
514 this.commentQuestionNode = function() {
|
nickjillings@1370
|
515 this.id = null;
|
nickjillings@1370
|
516 this.type = undefined;
|
nickjillings@1370
|
517 this.options = [];
|
nickjillings@1370
|
518 this.statement = undefined;
|
nickjillings@1370
|
519 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
|
nickjillings@1370
|
520 this.decode = function(parent,xml)
|
nickjillings@1370
|
521 {
|
nickjillings@1370
|
522 this.id = xml.id;
|
nickjillings@1370
|
523 this.type = xml.getAttribute('type');
|
nickjillings@1370
|
524 this.statement = xml.getElementsByTagName('statement')[0].textContent;
|
nickjillings@1370
|
525 var optNodes = xml.getElementsByTagName('option');
|
nickjillings@1370
|
526 for (var i=0; i<optNodes.length; i++)
|
nickjillings@1370
|
527 {
|
nickjillings@1370
|
528 var optNode = optNodes[i];
|
nickjillings@1370
|
529 this.options.push({
|
nickjillings@1370
|
530 name: optNode.getAttribute('name'),
|
nickjillings@1370
|
531 text: optNode.textContent
|
nickjillings@1370
|
532 });
|
nickjillings@1370
|
533 }
|
nickjillings@1370
|
534 };
|
nickjillings@1370
|
535
|
nickjillings@1370
|
536 this.encode = function(root)
|
nickjillings@1370
|
537 {
|
nickjillings@1370
|
538
|
nickjillings@1370
|
539 };
|
nickjillings@1370
|
540 };
|
nickjillings@1370
|
541
|
nickjillings@1370
|
542 this.audioElementNode = function() {
|
nickjillings@1370
|
543 this.url = null;
|
nickjillings@1370
|
544 this.id = null;
|
nickjillings@1370
|
545 this.parent = null;
|
nickjillings@1370
|
546 this.type = null;
|
nickjillings@1370
|
547 this.marker = false;
|
nickjillings@1370
|
548 this.enforce = false;
|
nickjillings@1370
|
549 this.gain = 1.0;
|
nickjillings@1370
|
550 this.schema = specification.schema.getAllElementsByName('audioelement')[0];;
|
nickjillings@1370
|
551 this.parent = null;
|
nickjillings@1370
|
552 this.decode = function(parent,xml)
|
nickjillings@1370
|
553 {
|
nickjillings@1370
|
554 this.parent = parent;
|
nickjillings@1370
|
555 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1370
|
556 for (var i=0; i<attributeMap.length; i++)
|
nickjillings@1370
|
557 {
|
nickjillings@1370
|
558 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1370
|
559 var projectAttr = xml.getAttribute(attributeName);
|
nickjillings@1370
|
560 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1370
|
561 switch(typeof projectAttr)
|
nickjillings@1370
|
562 {
|
nickjillings@1370
|
563 case "number":
|
nickjillings@1370
|
564 case "boolean":
|
nickjillings@1370
|
565 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1370
|
566 break;
|
nickjillings@1370
|
567 case "string":
|
nickjillings@1370
|
568 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1370
|
569 break;
|
nickjillings@1370
|
570 }
|
nickjillings@1370
|
571 }
|
nickjillings@1370
|
572
|
nickjillings@1370
|
573 };
|
nickjillings@1370
|
574 this.encode = function(root)
|
nickjillings@1370
|
575 {
|
nickjillings@1370
|
576 var AENode = root.createElement("audioElements");
|
nickjillings@1370
|
577 AENode.id = this.id;
|
nickjillings@1370
|
578 AENode.setAttribute("url",this.url);
|
nickjillings@1370
|
579 AENode.setAttribute("type",this.type);
|
nickjillings@1370
|
580 AENode.setAttribute("gain",linearToDecibel(this.gain));
|
nickjillings@1370
|
581 if (this.marker != false)
|
nickjillings@1370
|
582 {
|
nickjillings@1370
|
583 AENode.setAttribute("marker",this.marker*100);
|
nickjillings@1370
|
584 }
|
nickjillings@1370
|
585 return AENode;
|
nickjillings@1370
|
586 };
|
nickjillings@1370
|
587 };
|
nickjillings@1370
|
588 };
|
nickjillings@1370
|
589 }
|
nickjillings@1370
|
590 </script>
|
nickjillings@1370
|
591 <script type="text/javascript" src="test_core.js"/>
|
nickjillings@1370
|
592 <script type="text/javascript">
|
nickjillings@1370
|
593
|
nickjillings@1370
|
594 </script>
|
nickjillings@1370
|
595 </head>
|
nickjillings@1370
|
596 <body>
|
nickjillings@1370
|
597 <div id="popupHolder"></div>
|
nickjillings@1370
|
598 <div id="blanket"></div>
|
nickjillings@1370
|
599 <div id="content"></div>
|
nickjillings@1370
|
600 </body>
|
nickjillings@1370
|
601 </html> |