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