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"/>
|
giuliomoro@1304
|
5 <link rel='stylesheet' type="text/css" href="custom.css"/>
|
nickjillings@1370
|
6 <script type="text/javascript">
|
giuliomoro@1304
|
7 window.onbeforeunload = function (e) {var message = 'If you leave the page now, any unsaved changes will be lost', e = e || window.event; if (e) { e.returnValue = message;}return message;};
|
nickjillings@1370
|
8 // Copy of Specifiation node from Core.js
|
nickjillings@1370
|
9 function Specification() {
|
nickjillings@1370
|
10 // Handles the decoding of the project specification XML into a simple JavaScript Object.
|
nickjillings@1370
|
11
|
nickjillings@1370
|
12 this.interface = null;
|
nickjillings@1373
|
13 this.projectReturn = "null";
|
nickjillings@1370
|
14 this.randomiseOrder = null;
|
nickjillings@1370
|
15 this.testPages = null;
|
nickjillings@1370
|
16 this.pages = [];
|
nickjillings@1370
|
17 this.metrics = null;
|
nickjillings@1370
|
18 this.interfaces = null;
|
nickjillings@1370
|
19 this.loudness = null;
|
nickjillings@1370
|
20 this.errors = [];
|
nickjillings@1370
|
21 this.schema = null;
|
nickjillings@1370
|
22
|
nickjillings@1370
|
23 this.processAttribute = function(attribute,schema)
|
nickjillings@1370
|
24 {
|
nickjillings@1370
|
25 // attribute is the string returned from getAttribute on the XML
|
nickjillings@1370
|
26 // schema is the <xs:attribute> node
|
nickjillings@1370
|
27 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined)
|
nickjillings@1370
|
28 {
|
nickjillings@1370
|
29 schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0];
|
nickjillings@1370
|
30 }
|
nickjillings@1370
|
31 var defaultOpt = schema.getAttribute('default');
|
nickjillings@1370
|
32 if (attribute == null) {
|
nickjillings@1370
|
33 attribute = defaultOpt;
|
nickjillings@1370
|
34 }
|
nickjillings@1370
|
35 var dataType = schema.getAttribute('type');
|
nickjillings@1370
|
36 if (typeof dataType == "string") { dataType = dataType.substr(3);}
|
nickjillings@1370
|
37 else {dataType = "string";}
|
nickjillings@1370
|
38 if (attribute == null)
|
nickjillings@1370
|
39 {
|
nickjillings@1370
|
40 return attribute;
|
nickjillings@1370
|
41 }
|
nickjillings@1370
|
42 switch(dataType)
|
nickjillings@1370
|
43 {
|
nickjillings@1370
|
44 case "boolean":
|
nickjillings@1370
|
45 if (attribute == 'true'){attribute = true;}else{attribute=false;}
|
nickjillings@1370
|
46 break;
|
nickjillings@1370
|
47 case "negativeInteger":
|
nickjillings@1370
|
48 case "positiveInteger":
|
nickjillings@1370
|
49 case "nonNegativeInteger":
|
nickjillings@1370
|
50 case "nonPositiveInteger":
|
nickjillings@1370
|
51 case "integer":
|
nickjillings@1370
|
52 case "decimal":
|
nickjillings@1370
|
53 case "short":
|
nickjillings@1370
|
54 attribute = Number(attribute);
|
nickjillings@1370
|
55 break;
|
nickjillings@1370
|
56 case "string":
|
nickjillings@1370
|
57 default:
|
nickjillings@1370
|
58 attribute = String(attribute);
|
nickjillings@1370
|
59 break;
|
nickjillings@1370
|
60 }
|
nickjillings@1370
|
61 return attribute;
|
nickjillings@1370
|
62 };
|
nickjillings@1370
|
63
|
nickjillings@1370
|
64 this.decode = function(projectXML) {
|
nickjillings@1370
|
65 this.errors = [];
|
nickjillings@1370
|
66 // projectXML - DOM Parsed document
|
nickjillings@1370
|
67 this.projectXML = projectXML.childNodes[0];
|
nickjillings@1370
|
68 var setupNode = projectXML.getElementsByTagName('setup')[0];
|
nickjillings@1370
|
69 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
|
nickjillings@1370
|
70 // First decode the attributes
|
nickjillings@1370
|
71 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
|
nickjillings@1370
|
72 for (var i in attributes)
|
nickjillings@1370
|
73 {
|
nickjillings@1370
|
74 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
75 var attributeName = attributes[i].getAttribute('name');
|
nickjillings@1370
|
76 var projectAttr = setupNode.getAttribute(attributeName);
|
nickjillings@1370
|
77 projectAttr = this.processAttribute(projectAttr,attributes[i]);
|
nickjillings@1370
|
78 switch(typeof projectAttr)
|
nickjillings@1370
|
79 {
|
nickjillings@1370
|
80 case "number":
|
nickjillings@1370
|
81 case "boolean":
|
nickjillings@1370
|
82 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1370
|
83 break;
|
nickjillings@1370
|
84 case "string":
|
nickjillings@1370
|
85 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1370
|
86 break;
|
nickjillings@1370
|
87 }
|
nickjillings@1370
|
88
|
nickjillings@1370
|
89 }
|
nickjillings@1370
|
90
|
nickjillings@1370
|
91 this.metrics = new this.metricNode();
|
nickjillings@1370
|
92
|
nickjillings@1370
|
93 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]);
|
nickjillings@1370
|
94
|
nickjillings@1370
|
95 // Now process the survey node options
|
nickjillings@1370
|
96 var survey = setupNode.getElementsByTagName('survey');
|
nickjillings@1370
|
97 for (var i in survey) {
|
nickjillings@1370
|
98 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
99 var location = survey[i].getAttribute('location');
|
nickjillings@1370
|
100 if (location == 'pre' || location == 'before')
|
nickjillings@1370
|
101 {
|
nickjillings@1370
|
102 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
|
nickjillings@1370
|
103 else {
|
nickjillings@1370
|
104 this.preTest = new this.surveyNode();
|
nickjillings@1370
|
105 this.preTest.decode(this,survey[i]);
|
nickjillings@1370
|
106 }
|
nickjillings@1370
|
107 } else if (location == 'post' || location == 'after') {
|
nickjillings@1370
|
108 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
|
nickjillings@1370
|
109 else {
|
nickjillings@1370
|
110 this.postTest = new this.surveyNode();
|
nickjillings@1370
|
111 this.postTest.decode(this,survey[i]);
|
nickjillings@1370
|
112 }
|
nickjillings@1370
|
113 }
|
nickjillings@1370
|
114 }
|
nickjillings@1370
|
115
|
nickjillings@1370
|
116 var interfaceNode = setupNode.getElementsByTagName('interface');
|
nickjillings@1370
|
117 if (interfaceNode.length > 1)
|
nickjillings@1370
|
118 {
|
nickjillings@1370
|
119 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!");
|
nickjillings@1370
|
120 }
|
nickjillings@1370
|
121 this.interfaces = new this.interfaceNode();
|
nickjillings@1370
|
122 if (interfaceNode.length != 0)
|
nickjillings@1370
|
123 {
|
nickjillings@1370
|
124 interfaceNode = interfaceNode[0];
|
nickjillings@1370
|
125 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]);
|
nickjillings@1370
|
126 }
|
nickjillings@1370
|
127
|
nickjillings@1370
|
128 // Page tags
|
nickjillings@1370
|
129 var pageTags = projectXML.getElementsByTagName('page');
|
nickjillings@1370
|
130 var pageSchema = this.schema.getAllElementsByName('page')[0];
|
nickjillings@1370
|
131 for (var i=0; i<pageTags.length; i++)
|
nickjillings@1370
|
132 {
|
nickjillings@1370
|
133 var node = new this.page();
|
nickjillings@1370
|
134 node.decode(this,pageTags[i],pageSchema);
|
nickjillings@1370
|
135 this.pages.push(node);
|
nickjillings@1370
|
136 }
|
nickjillings@1370
|
137 };
|
nickjillings@1370
|
138
|
nickjillings@1370
|
139 this.encode = function()
|
nickjillings@1370
|
140 {
|
nickjillings@1372
|
141 var RootDocument = document.implementation.createDocument(null,"waet");
|
nickjillings@1372
|
142 var root = RootDocument.children[0];
|
nickjillings@1372
|
143 root.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
|
nickjillings@1372
|
144 root.setAttribute("xsi:noNamespaceSchemaLocation","test-schema.xsd");
|
nickjillings@1370
|
145 // Build setup node
|
nickjillings@1372
|
146 var setup = RootDocument.createElement("setup");
|
nickjillings@1372
|
147 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
|
nickjillings@1372
|
148 // First decode the attributes
|
nickjillings@1372
|
149 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
|
nickjillings@1372
|
150 for (var i=0; i<attributes.length; i++)
|
nickjillings@1372
|
151 {
|
nickjillings@1372
|
152 var name = attributes[i].getAttribute("name");
|
nickjillings@1372
|
153 if (name == undefined) {
|
nickjillings@1372
|
154 name = attributes[i].getAttribute("ref");
|
nickjillings@1372
|
155 }
|
nickjillings@1372
|
156 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
|
nickjillings@1372
|
157 {
|
nickjillings@1372
|
158 eval("setup.setAttribute('"+name+"',this."+name+")");
|
nickjillings@1372
|
159 }
|
nickjillings@1372
|
160 }
|
nickjillings@1372
|
161 root.appendChild(setup);
|
nickjillings@1372
|
162 // Survey node
|
nickjillings@1372
|
163 setup.appendChild(this.preTest.encode(RootDocument));
|
nickjillings@1372
|
164 setup.appendChild(this.postTest.encode(RootDocument));
|
nickjillings@1372
|
165 setup.appendChild(this.metrics.encode(RootDocument));
|
nickjillings@1372
|
166 setup.appendChild(this.interfaces.encode(RootDocument));
|
nickjillings@1372
|
167 for (var page of this.pages)
|
nickjillings@1372
|
168 {
|
nickjillings@1372
|
169 root.appendChild(page.encode(RootDocument));
|
nickjillings@1372
|
170 }
|
nickjillings@1372
|
171 return RootDocument;
|
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@1372
|
231 this.exportXML = function(doc)
|
nickjillings@1370
|
232 {
|
nickjillings@2111
|
233 var node = doc.createElement('surveyentry');
|
nickjillings@1370
|
234 node.setAttribute('type',this.type);
|
nickjillings@1372
|
235 var statement = doc.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@2111
|
244 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);}
|
nickjillings@2111
|
245 if (this.boxsize != undefined) {node.setAttribute("boxsize",this.boxsize);}
|
nickjillings@1370
|
246 break;
|
nickjillings@1370
|
247 case "number":
|
nickjillings@1370
|
248 node.id = this.id;
|
nickjillings@2111
|
249 if (this.mandatory != undefined) { node.setAttribute("mandatory",this.mandatory);}
|
nickjillings@2111
|
250 if (this.min != undefined) {node.setAttribute("min", this.min);}
|
nickjillings@2111
|
251 if (this.max != undefined) {node.setAttribute("max", this.max);}
|
nickjillings@1370
|
252 break;
|
nickjillings@1370
|
253 case "checkbox":
|
nickjillings@1370
|
254 case "radio":
|
nickjillings@1370
|
255 node.id = this.id;
|
nickjillings@1370
|
256 for (var i=0; i<this.options.length; i++)
|
nickjillings@1370
|
257 {
|
nickjillings@1370
|
258 var option = this.options[i];
|
nickjillings@1372
|
259 var optionNode = doc.createElement("option");
|
nickjillings@1370
|
260 optionNode.setAttribute("name",option.name);
|
nickjillings@1370
|
261 optionNode.textContent = option.text;
|
nickjillings@1370
|
262 node.appendChild(optionNode);
|
nickjillings@1370
|
263 }
|
nickjillings@1370
|
264 break;
|
nickjillings@1370
|
265 }
|
nickjillings@1370
|
266 return node;
|
nickjillings@1370
|
267 };
|
nickjillings@1370
|
268 };
|
nickjillings@1370
|
269 this.decode = function(parent,xml) {
|
nickjillings@1370
|
270 this.location = xml.getAttribute('location');
|
nickjillings@1370
|
271 if (this.location == 'before'){this.location = 'pre';}
|
nickjillings@1370
|
272 else if (this.location == 'after'){this.location = 'post';}
|
nickjillings@1370
|
273 for (var i in xml.children)
|
nickjillings@1370
|
274 {
|
nickjillings@1370
|
275 if(isNaN(Number(i))==true){break;}
|
nickjillings@1370
|
276 var node = new this.OptionNode();
|
nickjillings@1370
|
277 node.decode(parent,xml.children[i]);
|
nickjillings@1370
|
278 this.options.push(node);
|
nickjillings@1370
|
279 }
|
nickjillings@1370
|
280 };
|
nickjillings@1372
|
281 this.encode = function(doc) {
|
nickjillings@1372
|
282 var node = doc.createElement('survey');
|
nickjillings@1370
|
283 node.setAttribute('location',this.location);
|
nickjillings@1370
|
284 for (var i=0; i<this.options.length; i++)
|
nickjillings@1370
|
285 {
|
nickjillings@1372
|
286 node.appendChild(this.options[i].exportXML(doc));
|
nickjillings@1370
|
287 }
|
nickjillings@1370
|
288 return node;
|
nickjillings@1370
|
289 };
|
nickjillings@1370
|
290 };
|
nickjillings@1370
|
291
|
nickjillings@1370
|
292 this.interfaceNode = function()
|
nickjillings@1370
|
293 {
|
nickjillings@1370
|
294 this.title = null;
|
nickjillings@1370
|
295 this.name = null;
|
nickjillings@1370
|
296 this.options = [];
|
nickjillings@1370
|
297 this.scales = [];
|
nickjillings@1370
|
298 this.schema = specification.schema.getAllElementsByName('interface')[1];
|
nickjillings@1370
|
299
|
nickjillings@1370
|
300 this.decode = function(parent,xml) {
|
nickjillings@1370
|
301 this.name = xml.getAttribute('name');
|
nickjillings@1370
|
302 var titleNode = xml.getElementsByTagName('title');
|
nickjillings@1370
|
303 if (titleNode.length == 1)
|
nickjillings@1370
|
304 {
|
nickjillings@1370
|
305 this.title = titleNode[0].textContent;
|
nickjillings@1370
|
306 }
|
nickjillings@1370
|
307 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption');
|
nickjillings@1370
|
308 // Extract interfaceoption node schema
|
nickjillings@1370
|
309 var interfaceOptionNodeSchema = this.schema.getAllElementsByName('interfaceoption')[0];
|
nickjillings@1370
|
310 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1370
|
311 for (var i=0; i<interfaceOptionNodes.length; i++)
|
nickjillings@1370
|
312 {
|
nickjillings@1370
|
313 var ioNode = interfaceOptionNodes[i];
|
nickjillings@1370
|
314 var option = {};
|
nickjillings@1370
|
315 for (var j=0; j<attributeMap.length; j++)
|
nickjillings@1370
|
316 {
|
nickjillings@1370
|
317 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
|
nickjillings@1370
|
318 var projectAttr = ioNode.getAttribute(attributeName);
|
nickjillings@1370
|
319 projectAttr = parent.processAttribute(projectAttr,attributeMap[j]);
|
nickjillings@1370
|
320 switch(typeof projectAttr)
|
nickjillings@1370
|
321 {
|
nickjillings@1370
|
322 case "number":
|
nickjillings@1370
|
323 case "boolean":
|
nickjillings@1370
|
324 eval('option.'+attributeName+' = '+projectAttr);
|
nickjillings@1370
|
325 break;
|
nickjillings@1370
|
326 case "string":
|
nickjillings@1370
|
327 eval('option.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1370
|
328 break;
|
nickjillings@1370
|
329 }
|
nickjillings@1370
|
330 }
|
nickjillings@1370
|
331 this.options.push(option);
|
nickjillings@1370
|
332 }
|
nickjillings@1370
|
333
|
nickjillings@1370
|
334 // Now the scales nodes
|
nickjillings@1370
|
335 var scaleParent = xml.getElementsByTagName('scales');
|
nickjillings@1370
|
336 if (scaleParent.length == 1) {
|
nickjillings@1370
|
337 scaleParent = scaleParent[0];
|
nickjillings@1370
|
338 for (var i=0; i<scaleParent.children.length; i++) {
|
nickjillings@1370
|
339 var child = scaleParent.children[i];
|
nickjillings@1370
|
340 this.scales.push({
|
nickjillings@1370
|
341 text: child.textContent,
|
nickjillings@1370
|
342 position: Number(child.getAttribute('position'))
|
nickjillings@1370
|
343 });
|
nickjillings@1370
|
344 }
|
nickjillings@1370
|
345 }
|
nickjillings@1370
|
346 };
|
nickjillings@1370
|
347
|
nickjillings@1372
|
348 this.encode = function(doc) {
|
nickjillings@1372
|
349 var node = doc.createElement("interface");
|
nickjillings@1372
|
350 if (typeof name == "string")
|
nickjillings@1372
|
351 node.setAttribute("name",this.name);
|
nickjillings@1372
|
352 for (var option of this.options)
|
nickjillings@1372
|
353 {
|
nickjillings@1372
|
354 var child = doc.createElement("interfaceoption");
|
nickjillings@1372
|
355 child.setAttribute("type",option.type);
|
nickjillings@1372
|
356 child.setAttribute("name",option.name);
|
nickjillings@1372
|
357 node.appendChild(child);
|
nickjillings@1372
|
358 }
|
nickjillings@1372
|
359 if (this.scales.length != 0) {
|
nickjillings@1372
|
360 var scales = doc.createElement("scales");
|
nickjillings@1372
|
361 for (var scale of this.scales)
|
nickjillings@1372
|
362 {
|
nickjillings@1372
|
363 var child = doc.createElement("scalelabel");
|
nickjillings@1372
|
364 child.setAttribute("position",scale.position);
|
nickjillings@1372
|
365 child.textContent = scale.text;
|
nickjillings@1372
|
366 scales.appendChild(child);
|
nickjillings@1372
|
367 }
|
nickjillings@1372
|
368 node.appendChild(scales);
|
nickjillings@1372
|
369 }
|
nickjillings@1372
|
370 return node;
|
nickjillings@1370
|
371 };
|
nickjillings@1370
|
372 };
|
nickjillings@1370
|
373
|
nickjillings@1370
|
374 this.metricNode = function() {
|
nickjillings@1370
|
375 this.enabled = [];
|
nickjillings@1370
|
376 this.decode = function(parent, xml) {
|
nickjillings@1370
|
377 var children = xml.getElementsByTagName('metricenable');
|
nickjillings@1370
|
378 for (var i in children) {
|
nickjillings@1370
|
379 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
380 this.enabled.push(children[i].textContent);
|
nickjillings@1370
|
381 }
|
nickjillings@1370
|
382 }
|
nickjillings@1372
|
383 this.encode = function(doc) {
|
nickjillings@1372
|
384 var node = doc.createElement('metric');
|
nickjillings@1370
|
385 for (var i in this.enabled)
|
nickjillings@1370
|
386 {
|
nickjillings@1370
|
387 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1372
|
388 var child = doc.createElement('metricenable');
|
nickjillings@1370
|
389 child.textContent = this.enabled[i];
|
nickjillings@1370
|
390 node.appendChild(child);
|
nickjillings@1370
|
391 }
|
nickjillings@1370
|
392 return node;
|
nickjillings@1370
|
393 }
|
nickjillings@1370
|
394 }
|
nickjillings@1370
|
395
|
nickjillings@1370
|
396 this.page = function() {
|
nickjillings@1370
|
397 this.presentedId = undefined;
|
nickjillings@1370
|
398 this.id = undefined;
|
nickjillings@1370
|
399 this.hostURL = undefined;
|
nickjillings@1370
|
400 this.randomiseOrder = undefined;
|
nickjillings@1370
|
401 this.loop = undefined;
|
nickjillings@1370
|
402 this.showElementComments = undefined;
|
nickjillings@1370
|
403 this.outsideReference = null;
|
nickjillings@1370
|
404 this.loudness = null;
|
nickjillings@1370
|
405 this.preTest = null;
|
nickjillings@1370
|
406 this.postTest = null;
|
nickjillings@1370
|
407 this.interfaces = [];
|
nickjillings@1370
|
408 this.commentBoxPrefix = "Comment on track";
|
nickjillings@1370
|
409 this.audioElements = [];
|
nickjillings@1370
|
410 this.commentQuestions = [];
|
nickjillings@1370
|
411 this.schema = specification.schema.getAllElementsByName("page")[0];
|
nickjillings@1370
|
412
|
nickjillings@1370
|
413 this.decode = function(parent,xml)
|
nickjillings@1370
|
414 {
|
nickjillings@1370
|
415 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1370
|
416 for (var i=0; i<attributeMap.length; i++)
|
nickjillings@1370
|
417 {
|
nickjillings@1370
|
418 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1370
|
419 var projectAttr = xml.getAttribute(attributeName);
|
nickjillings@1370
|
420 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1370
|
421 switch(typeof projectAttr)
|
nickjillings@1370
|
422 {
|
nickjillings@1370
|
423 case "number":
|
nickjillings@1370
|
424 case "boolean":
|
nickjillings@1370
|
425 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1370
|
426 break;
|
nickjillings@1370
|
427 case "string":
|
nickjillings@1370
|
428 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1370
|
429 break;
|
nickjillings@1370
|
430 }
|
nickjillings@1370
|
431 }
|
nickjillings@1370
|
432
|
nickjillings@1370
|
433 // Get the Comment Box Prefix
|
nickjillings@1370
|
434 var CBP = xml.getElementsByTagName('commentboxprefix');
|
nickjillings@1370
|
435 if (CBP.length != 0) {
|
nickjillings@1370
|
436 this.commentBoxPrefix = CBP[0].textContent;
|
nickjillings@1370
|
437 }
|
nickjillings@1370
|
438
|
nickjillings@1370
|
439 // Now decode the interfaces
|
nickjillings@1370
|
440 var interfaceNode = xml.getElementsByTagName('interface');
|
nickjillings@1370
|
441 for (var i=0; i<interfaceNode.length; i++)
|
nickjillings@1370
|
442 {
|
nickjillings@1370
|
443 var node = new parent.interfaceNode();
|
nickjillings@1370
|
444 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]);
|
nickjillings@1370
|
445 this.interfaces.push(node);
|
nickjillings@1370
|
446 }
|
nickjillings@1370
|
447
|
nickjillings@1370
|
448 // Now process the survey node options
|
nickjillings@1370
|
449 var survey = xml.getElementsByTagName('survey');
|
nickjillings@1370
|
450 var surveySchema = parent.schema.getAllElementsByName('survey')[0];
|
nickjillings@1370
|
451 for (var i in survey) {
|
nickjillings@1370
|
452 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
453 var location = survey[i].getAttribute('location');
|
nickjillings@1370
|
454 if (location == 'pre' || location == 'before')
|
nickjillings@1370
|
455 {
|
nickjillings@1370
|
456 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
|
nickjillings@1370
|
457 else {
|
nickjillings@1370
|
458 this.preTest = new parent.surveyNode();
|
nickjillings@1370
|
459 this.preTest.decode(parent,survey[i],surveySchema);
|
nickjillings@1370
|
460 }
|
nickjillings@1370
|
461 } else if (location == 'post' || location == 'after') {
|
nickjillings@1370
|
462 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
|
nickjillings@1370
|
463 else {
|
nickjillings@1370
|
464 this.postTest = new parent.surveyNode();
|
nickjillings@1370
|
465 this.postTest.decode(parent,survey[i],surveySchema);
|
nickjillings@1370
|
466 }
|
nickjillings@1370
|
467 }
|
nickjillings@1370
|
468 }
|
nickjillings@1370
|
469
|
nickjillings@1370
|
470 // Now process the audioelement tags
|
nickjillings@1370
|
471 var audioElements = xml.getElementsByTagName('audioelement');
|
nickjillings@1370
|
472 for (var i=0; i<audioElements.length; i++)
|
nickjillings@1370
|
473 {
|
nickjillings@1370
|
474 var node = new this.audioElementNode();
|
nickjillings@1370
|
475 node.decode(this,audioElements[i]);
|
nickjillings@1370
|
476 this.audioElements.push(node);
|
nickjillings@1370
|
477 }
|
nickjillings@1370
|
478
|
nickjillings@1370
|
479 // Now decode the commentquestions
|
nickjillings@1370
|
480 var commentQuestions = xml.getElementsByTagName('commentquestion');
|
nickjillings@1370
|
481 for (var i=0; i<commentQuestions.length; i++)
|
nickjillings@1370
|
482 {
|
nickjillings@1370
|
483 var node = new this.commentQuestionNode();
|
nickjillings@1370
|
484 node.decode(parent,commentQuestions[i]);
|
nickjillings@1370
|
485 this.commentQuestions.push(node);
|
nickjillings@1370
|
486 }
|
nickjillings@1370
|
487 };
|
nickjillings@1370
|
488
|
nickjillings@1370
|
489 this.encode = function(root)
|
nickjillings@1370
|
490 {
|
nickjillings@1372
|
491 var AHNode = root.createElement("page");
|
nickjillings@1372
|
492 // First decode the attributes
|
nickjillings@1372
|
493 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1372
|
494 for (var i=0; i<attributes.length; i++)
|
nickjillings@1372
|
495 {
|
nickjillings@1372
|
496 var name = attributes[i].getAttribute("name");
|
nickjillings@1372
|
497 if (name == undefined) {
|
nickjillings@1372
|
498 name = attributes[i].getAttribute("ref");
|
nickjillings@1372
|
499 }
|
nickjillings@1372
|
500 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
|
nickjillings@1372
|
501 {
|
nickjillings@1372
|
502 eval("AHNode.setAttribute('"+name+"',this."+name+")");
|
nickjillings@1372
|
503 }
|
nickjillings@1372
|
504 }
|
nickjillings@1370
|
505 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);}
|
nickjillings@1372
|
506 // <commentboxprefix>
|
nickjillings@1372
|
507 var commentboxprefix = root.createElement("commentboxprefix");
|
nickjillings@1372
|
508 commentboxprefix.textContent = this.commentBoxPrefix;
|
nickjillings@1372
|
509 AHNode.appendChild(commentboxprefix);
|
nickjillings@1372
|
510
|
nickjillings@1370
|
511 for (var i=0; i<this.interfaces.length; i++)
|
nickjillings@1370
|
512 {
|
nickjillings@1370
|
513 AHNode.appendChild(this.interfaces[i].encode(root));
|
nickjillings@1370
|
514 }
|
nickjillings@1370
|
515
|
nickjillings@1370
|
516 for (var i=0; i<this.audioElements.length; i++) {
|
nickjillings@1370
|
517 AHNode.appendChild(this.audioElements[i].encode(root));
|
nickjillings@1370
|
518 }
|
nickjillings@1370
|
519 // Create <CommentQuestion>
|
nickjillings@1370
|
520 for (var i=0; i<this.commentQuestions.length; i++)
|
nickjillings@1370
|
521 {
|
nickjillings@1372
|
522 AHNode.appendChild(this.commentQuestions[i].encode(root));
|
nickjillings@1370
|
523 }
|
nickjillings@1370
|
524
|
nickjillings@1372
|
525 AHNode.appendChild(this.preTest.encode(root));
|
nickjillings@1372
|
526 AHNode.appendChild(this.postTest.encode(root));
|
nickjillings@1370
|
527 return AHNode;
|
nickjillings@1370
|
528 };
|
nickjillings@1370
|
529
|
nickjillings@1370
|
530 this.commentQuestionNode = function() {
|
nickjillings@1370
|
531 this.id = null;
|
nickjillings@1370
|
532 this.type = undefined;
|
nickjillings@1370
|
533 this.options = [];
|
nickjillings@1370
|
534 this.statement = undefined;
|
nickjillings@1370
|
535 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
|
nickjillings@1370
|
536 this.decode = function(parent,xml)
|
nickjillings@1370
|
537 {
|
nickjillings@1370
|
538 this.id = xml.id;
|
nickjillings@1370
|
539 this.type = xml.getAttribute('type');
|
nickjillings@1370
|
540 this.statement = xml.getElementsByTagName('statement')[0].textContent;
|
nickjillings@1370
|
541 var optNodes = xml.getElementsByTagName('option');
|
nickjillings@1370
|
542 for (var i=0; i<optNodes.length; i++)
|
nickjillings@1370
|
543 {
|
nickjillings@1370
|
544 var optNode = optNodes[i];
|
nickjillings@1370
|
545 this.options.push({
|
nickjillings@1370
|
546 name: optNode.getAttribute('name'),
|
nickjillings@1370
|
547 text: optNode.textContent
|
nickjillings@1370
|
548 });
|
nickjillings@1370
|
549 }
|
nickjillings@1370
|
550 };
|
nickjillings@1370
|
551
|
nickjillings@1370
|
552 this.encode = function(root)
|
nickjillings@1370
|
553 {
|
nickjillings@1372
|
554 var node = root.createElement("commentquestion");
|
nickjillings@1372
|
555 node.id = this.id;
|
nickjillings@1372
|
556 node.setAttribute("type",this.type);
|
nickjillings@1372
|
557 var statement = root.createElement("statement");
|
nickjillings@1372
|
558 statement.textContent = this.statement;
|
nickjillings@1372
|
559 node.appendChild(statement);
|
nickjillings@1372
|
560 for (var option of this.options)
|
nickjillings@1372
|
561 {
|
nickjillings@1372
|
562 var child = root.createElement("option");
|
nickjillings@1372
|
563 child.setAttribute("name",option.name);
|
nickjillings@1372
|
564 child.textContent = option.text;
|
nickjillings@1372
|
565 node.appendChild(child);
|
nickjillings@1372
|
566 }
|
nickjillings@1372
|
567 return node;
|
nickjillings@1370
|
568 };
|
nickjillings@1370
|
569 };
|
nickjillings@1370
|
570
|
nickjillings@1370
|
571 this.audioElementNode = function() {
|
nickjillings@1370
|
572 this.url = null;
|
nickjillings@1370
|
573 this.id = null;
|
nickjillings@1370
|
574 this.parent = null;
|
nickjillings@1370
|
575 this.type = null;
|
nickjillings@1310
|
576 this.marker = null;
|
nickjillings@1370
|
577 this.enforce = false;
|
nickjillings@1370
|
578 this.gain = 1.0;
|
nickjillings@1370
|
579 this.schema = specification.schema.getAllElementsByName('audioelement')[0];;
|
nickjillings@1370
|
580 this.parent = null;
|
nickjillings@1370
|
581 this.decode = function(parent,xml)
|
nickjillings@1370
|
582 {
|
nickjillings@1370
|
583 this.parent = parent;
|
nickjillings@1370
|
584 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1370
|
585 for (var i=0; i<attributeMap.length; i++)
|
nickjillings@1370
|
586 {
|
nickjillings@1370
|
587 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1370
|
588 var projectAttr = xml.getAttribute(attributeName);
|
nickjillings@1370
|
589 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1370
|
590 switch(typeof projectAttr)
|
nickjillings@1370
|
591 {
|
nickjillings@1370
|
592 case "number":
|
nickjillings@1370
|
593 case "boolean":
|
nickjillings@1370
|
594 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1370
|
595 break;
|
nickjillings@1370
|
596 case "string":
|
nickjillings@1370
|
597 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1370
|
598 break;
|
nickjillings@1370
|
599 }
|
nickjillings@1370
|
600 }
|
nickjillings@1370
|
601
|
nickjillings@1370
|
602 };
|
nickjillings@1370
|
603 this.encode = function(root)
|
nickjillings@1370
|
604 {
|
nickjillings@1372
|
605 var AENode = root.createElement("audioelement");
|
nickjillings@1372
|
606 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1372
|
607 for (var i=0; i<attributes.length; i++)
|
nickjillings@1370
|
608 {
|
nickjillings@1372
|
609 var name = attributes[i].getAttribute("name");
|
nickjillings@1372
|
610 if (name == undefined) {
|
nickjillings@1372
|
611 name = attributes[i].getAttribute("ref");
|
nickjillings@1372
|
612 }
|
nickjillings@1372
|
613 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
|
nickjillings@1372
|
614 {
|
nickjillings@1372
|
615 eval("AENode.setAttribute('"+name+"',this."+name+")");
|
nickjillings@1372
|
616 }
|
nickjillings@1370
|
617 }
|
nickjillings@1370
|
618 return AENode;
|
nickjillings@1370
|
619 };
|
nickjillings@1370
|
620 };
|
nickjillings@1370
|
621 };
|
nickjillings@1370
|
622 }
|
nickjillings@1372
|
623
|
nickjillings@1370
|
624 </script>
|
nickjillings@1381
|
625 <script src="../jquery-2.1.4.js"></script>
|
nickjillings@1370
|
626 <script type="text/javascript" src="test_core.js"/>
|
nickjillings@1370
|
627 <script type="text/javascript">
|
nickjillings@1370
|
628
|
nickjillings@1370
|
629 </script>
|
nickjillings@1370
|
630 </head>
|
nickjillings@1370
|
631 <body>
|
nickjillings@1370
|
632 <div id="popupHolder"></div>
|
nickjillings@1370
|
633 <div id="blanket"></div>
|
nickjillings@1370
|
634 <div id="content"></div>
|
nickjillings@1370
|
635 </body>
|
giuliomoro@1304
|
636 </html>
|