nicholas@2
|
1 /**
|
nicholas@2
|
2 * ape.js
|
nicholas@2
|
3 * Create the APE interface
|
nicholas@2
|
4 */
|
nicholas@2
|
5
|
n@38
|
6 var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?)
|
n@38
|
7 // preTest - In preTest state
|
n@38
|
8 // testRun-ID - In test running, test Id number at the end 'testRun-2'
|
n@38
|
9 // testRunPost-ID - Post test of test ID
|
n@38
|
10 // testRunPre-ID - Pre-test of test ID
|
n@38
|
11 // postTest - End of test, final submission!
|
n@38
|
12
|
n@32
|
13
|
nicholas@2
|
14 // Once this is loaded and parsed, begin execution
|
nicholas@2
|
15 loadInterface(projectXML);
|
nicholas@2
|
16
|
nicholas@2
|
17 function loadInterface(xmlDoc) {
|
nicholas@2
|
18
|
n@16
|
19 // Get the dimensions of the screen available to the page
|
nicholas@2
|
20 var width = window.innerWidth;
|
nicholas@2
|
21 var height = window.innerHeight;
|
nicholas@2
|
22
|
nicholas@2
|
23 // The injection point into the HTML page
|
nicholas@2
|
24 var insertPoint = document.getElementById("topLevelBody");
|
n@22
|
25 var testContent = document.createElement('div');
|
n@22
|
26 testContent.id = 'testContent';
|
nicholas@2
|
27
|
nicholas@7
|
28
|
nicholas@2
|
29 // Decode parts of the xmlDoc that are needed
|
nicholas@2
|
30 // xmlDoc MUST already be parsed by jQuery!
|
nicholas@2
|
31 var xmlSetup = xmlDoc.find('setup');
|
nicholas@2
|
32 // Should put in an error function here incase of malprocessed or malformed XML
|
nicholas@2
|
33
|
n@34
|
34 // Extract the different test XML DOM trees
|
n@50
|
35 var audioHolders = xmlDoc.find('audioHolder');
|
n@50
|
36 audioHolders.each(function(index,element) {
|
n@50
|
37 var repeatN = element.attributes['repeatCount'].value;
|
n@50
|
38 for (var r=0; r<=repeatN; r++) {
|
n@50
|
39 testXMLSetups[testXMLSetups.length] = element;
|
n@50
|
40 }
|
n@50
|
41 });
|
n@44
|
42
|
n@50
|
43 // New check if we need to randomise the test order
|
n@50
|
44 var randomise = xmlSetup[0].attributes['randomiseOrder'];
|
n@50
|
45 if (randomise != undefined) {
|
n@50
|
46 randomise = Boolean(randomise.value);
|
n@50
|
47 } else {
|
n@50
|
48 randomise = false;
|
n@50
|
49 }
|
n@50
|
50 if (randomise)
|
n@50
|
51 {
|
n@54
|
52 testXMLSetups = randomiseOrder(testXMLSetups);
|
n@50
|
53 }
|
n@44
|
54
|
n@50
|
55 // Obtain the metrics enabled
|
n@50
|
56 var metricNode = xmlSetup.find('Metric');
|
n@50
|
57 var metricNode = metricNode.find('metricEnable');
|
n@50
|
58 metricNode.each(function(index,node){
|
n@50
|
59 var enabled = node.textContent;
|
n@50
|
60 switch(enabled)
|
n@50
|
61 {
|
n@50
|
62 case 'testTimer':
|
n@50
|
63 sessionMetrics.prototype.enableTestTimer = true;
|
n@50
|
64 break;
|
n@50
|
65 case 'elementTimer':
|
n@50
|
66 sessionMetrics.prototype.enableElementTimer = true;
|
n@50
|
67 break;
|
n@50
|
68 case 'elementTracker':
|
n@50
|
69 sessionMetrics.prototype.enableElementTracker = true;
|
n@50
|
70 break;
|
n@50
|
71 case 'elementInitalPosition':
|
n@50
|
72 sessionMetrics.prototype.enableElementInitialPosition = true;
|
n@50
|
73 break;
|
n@50
|
74 case 'elementFlagListenedTo':
|
n@50
|
75 sessionMetrics.prototype.enableFlagListenedTo = true;
|
n@50
|
76 break;
|
n@50
|
77 case 'elementFlagMoved':
|
n@50
|
78 sessionMetrics.prototype.enableFlagMoved = true;
|
n@50
|
79 break;
|
n@50
|
80 case 'elementFlagComments':
|
n@50
|
81 sessionMetrics.prototype.enableFlagComments = true;
|
n@50
|
82 break;
|
n@50
|
83 }
|
n@50
|
84 });
|
n@34
|
85
|
n@52
|
86 // Create APE specific metric functions
|
n@52
|
87 audioEngineContext.metric.initialiseTest = function()
|
n@52
|
88 {
|
n@52
|
89 var sliders = document.getElementsByClassName('track-slider');
|
n@52
|
90 for (var i=0; i<sliders.length; i++)
|
n@52
|
91 {
|
n@52
|
92 audioEngineContext.audioObjects[i].metric.initialised(convSliderPosToRate(i));
|
n@52
|
93 }
|
n@52
|
94 };
|
n@52
|
95
|
n@52
|
96 audioEngineContext.metric.sliderMoveStart = function(id)
|
n@52
|
97 {
|
n@52
|
98 if (this.data == -1)
|
n@52
|
99 {
|
n@52
|
100 this.data = id;
|
n@52
|
101 } else {
|
n@52
|
102 console.log('ERROR: Metric tracker detecting two moves!');
|
n@52
|
103 this.data = -1;
|
n@52
|
104 }
|
n@52
|
105 };
|
n@52
|
106 audioEngineContext.metric.sliderMoved = function()
|
n@52
|
107 {
|
n@52
|
108 var time = audioEngineContext.timer.getTestTime();
|
n@52
|
109 var id = this.data;
|
n@52
|
110 this.data = -1;
|
n@52
|
111 var position = convSliderPosToRate(id);
|
n@52
|
112 if (audioEngineContext.timer.testStarted)
|
n@52
|
113 {
|
n@52
|
114 audioEngineContext.audioObjects[id].metric.moved(time,position);
|
n@52
|
115 }
|
n@52
|
116 };
|
n@52
|
117
|
n@52
|
118 audioEngineContext.metric.sliderPlayed = function(id)
|
n@52
|
119 {
|
n@52
|
120 var time = audioEngineContext.timer.getTestTime();
|
n@52
|
121 if (audioEngineContext.timer.testStarted)
|
n@52
|
122 {
|
n@52
|
123 if (this.lastClicked >= 0)
|
n@52
|
124 {
|
n@52
|
125 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
|
n@52
|
126 }
|
n@52
|
127 this.lastClicked = id;
|
n@52
|
128 audioEngineContext.audioObjects[id].metric.listening(time);
|
n@52
|
129 }
|
n@52
|
130 };
|
n@52
|
131
|
nicholas@2
|
132 // Create the top div for the Title element
|
nicholas@2
|
133 var titleAttr = xmlSetup[0].attributes['title'];
|
nicholas@2
|
134 var title = document.createElement('div');
|
nicholas@2
|
135 title.className = "title";
|
nicholas@2
|
136 title.align = "center";
|
nicholas@2
|
137 var titleSpan = document.createElement('span');
|
nicholas@2
|
138
|
nicholas@2
|
139 // Set title to that defined in XML, else set to default
|
nicholas@2
|
140 if (titleAttr != undefined) {
|
n@25
|
141 titleSpan.innerHTML = titleAttr.value;
|
nicholas@2
|
142 } else {
|
b@75
|
143 titleSpan.innerHTML = 'Listening test';
|
nicholas@2
|
144 }
|
nicholas@2
|
145 // Insert the titleSpan element into the title div element.
|
nicholas@2
|
146 title.appendChild(titleSpan);
|
nicholas@2
|
147
|
n@47
|
148 var pagetitle = document.createElement('div');
|
n@47
|
149 pagetitle.className = "pageTitle";
|
n@47
|
150 pagetitle.align = "center";
|
n@47
|
151 var titleSpan = document.createElement('span');
|
n@47
|
152 titleSpan.id = "pageTitle";
|
n@47
|
153 pagetitle.appendChild(titleSpan);
|
n@47
|
154
|
nicholas@7
|
155 // Store the return URL path in global projectReturn
|
nicholas@7
|
156 projectReturn = xmlSetup[0].attributes['projectReturn'].value;
|
nicholas@7
|
157
|
nicholas@7
|
158 // Create Interface buttons!
|
nicholas@7
|
159 var interfaceButtons = document.createElement('div');
|
nicholas@7
|
160 interfaceButtons.id = 'interface-buttons';
|
nicholas@7
|
161
|
nicholas@7
|
162 // MANUAL DOWNLOAD POINT
|
nicholas@7
|
163 // If project return is null, this MUST be specified as the location to create the download link
|
nicholas@7
|
164 var downloadPoint = document.createElement('div');
|
nicholas@7
|
165 downloadPoint.id = 'download-point';
|
nicholas@7
|
166
|
nicholas@7
|
167 // Create playback start/stop points
|
nicholas@7
|
168 var playback = document.createElement("button");
|
b@101
|
169 playback.innerHTML = 'Stop';
|
n@49
|
170 playback.id = 'playback-button';
|
n@16
|
171 // onclick function. Check if it is playing or not, call the correct function in the
|
n@16
|
172 // audioEngine, change the button text to reflect the next state.
|
nicholas@7
|
173 playback.onclick = function() {
|
b@101
|
174 if (audioEngineContext.status == 1) {
|
b@101
|
175 audioEngineContext.stop();
|
n@25
|
176 this.innerHTML = 'Stop';
|
nicholas@7
|
177 }
|
n@16
|
178 };
|
nicholas@7
|
179 // Create Submit (save) button
|
nicholas@7
|
180 var submit = document.createElement("button");
|
n@25
|
181 submit.innerHTML = 'Submit';
|
n@43
|
182 submit.onclick = buttonSubmitClick;
|
n@49
|
183 submit.id = 'submit-button';
|
n@16
|
184 // Append the interface buttons into the interfaceButtons object.
|
nicholas@7
|
185 interfaceButtons.appendChild(playback);
|
nicholas@7
|
186 interfaceButtons.appendChild(submit);
|
nicholas@7
|
187 interfaceButtons.appendChild(downloadPoint);
|
nicholas@7
|
188
|
nicholas@2
|
189 // Now create the slider and HTML5 canvas boxes
|
nicholas@2
|
190
|
n@16
|
191 // Create the div box to center align
|
nicholas@2
|
192 var sliderBox = document.createElement('div');
|
nicholas@2
|
193 sliderBox.className = 'sliderCanvasDiv';
|
n@16
|
194 sliderBox.id = 'sliderCanvasHolder';
|
nicholas@2
|
195 sliderBox.align = 'center';
|
nicholas@2
|
196
|
n@16
|
197 // Create the slider box to hold the slider elements
|
nicholas@5
|
198 var canvas = document.createElement('div');
|
nicholas@2
|
199 canvas.id = 'slider';
|
n@16
|
200 // Must have a known EXACT width, as this is used later to determine the ratings
|
nicholas@5
|
201 canvas.style.width = width - 100 +"px";
|
nicholas@5
|
202 canvas.align = "left";
|
nicholas@2
|
203 sliderBox.appendChild(canvas);
|
n@16
|
204
|
n@47
|
205 // Create the div to hold any scale objects
|
n@47
|
206 var scale = document.createElement('div');
|
n@47
|
207 scale.className = 'sliderScale';
|
n@47
|
208 scale.id = 'sliderScaleHolder';
|
n@47
|
209 scale.align = 'left';
|
n@47
|
210 sliderBox.appendChild(scale);
|
n@47
|
211
|
n@16
|
212 // Global parent for the comment boxes on the page
|
nicholas@3
|
213 var feedbackHolder = document.createElement('div');
|
n@34
|
214 feedbackHolder.id = 'feedbackHolder';
|
nicholas@2
|
215
|
n@38
|
216 testContent.style.zIndex = 1;
|
n@38
|
217 insertPoint.innerHTML = null; // Clear the current schema
|
n@38
|
218
|
n@22
|
219 // Create pre and post test questions
|
n@38
|
220 var blank = document.createElement('div');
|
n@38
|
221 blank.className = 'testHalt';
|
n@22
|
222
|
n@38
|
223 var popupHolder = document.createElement('div');
|
n@38
|
224 popupHolder.id = 'popupHolder';
|
n@38
|
225 popupHolder.className = 'popupHolder';
|
n@38
|
226 popupHolder.style.position = 'absolute';
|
n@38
|
227 popupHolder.style.left = (window.innerWidth/2)-250 + 'px';
|
n@38
|
228 popupHolder.style.top = (window.innerHeight/2)-125 + 'px';
|
n@38
|
229 insertPoint.appendChild(popupHolder);
|
n@38
|
230 insertPoint.appendChild(blank);
|
n@38
|
231 hidePopup();
|
n@22
|
232
|
n@36
|
233 var preTest = xmlSetup.find('PreTest');
|
n@36
|
234 var postTest = xmlSetup.find('PostTest');
|
n@22
|
235 preTest = preTest[0];
|
n@22
|
236 postTest = postTest[0];
|
n@38
|
237
|
n@38
|
238 currentState = 'preTest';
|
n@22
|
239
|
n@22
|
240 // Create Pre-Test Box
|
nicholas@105
|
241 if (preTest != undefined && preTest.childElementCount >= 1)
|
n@22
|
242 {
|
n@38
|
243 showPopup();
|
n@39
|
244 preTestPopupStart(preTest);
|
n@22
|
245 }
|
n@38
|
246
|
n@38
|
247 // Inject into HTML
|
n@38
|
248 testContent.appendChild(title); // Insert the title
|
n@47
|
249 testContent.appendChild(pagetitle);
|
n@38
|
250 testContent.appendChild(interfaceButtons);
|
n@38
|
251 testContent.appendChild(sliderBox);
|
n@38
|
252 testContent.appendChild(feedbackHolder);
|
n@38
|
253 insertPoint.appendChild(testContent);
|
n@22
|
254
|
n@36
|
255 // Load the full interface
|
n@39
|
256
|
nicholas@2
|
257 }
|
nicholas@5
|
258
|
n@39
|
259 function loadTest(id)
|
n@34
|
260 {
|
n@34
|
261 // Used to load a specific test page
|
n@39
|
262 var textXML = testXMLSetups[id];
|
n@34
|
263
|
n@34
|
264 var feedbackHolder = document.getElementById('feedbackHolder');
|
n@34
|
265 var canvas = document.getElementById('slider');
|
n@34
|
266 feedbackHolder.innerHTML = null;
|
n@34
|
267 canvas.innerHTML = null;
|
n@47
|
268
|
n@47
|
269 // Setup question title
|
n@47
|
270 var interfaceObj = $(textXML).find('interface');
|
n@47
|
271 var titleNode = interfaceObj.find('title');
|
n@47
|
272 if (titleNode[0] != undefined)
|
n@47
|
273 {
|
n@47
|
274 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
|
n@47
|
275 }
|
n@47
|
276 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
|
n@47
|
277 var offset = 50-8; // Half the offset of the slider (window width -100) minus the body padding of 8
|
n@47
|
278 // TODO: AUTOMATE ABOVE!!
|
n@47
|
279 var scale = document.getElementById('sliderScaleHolder');
|
n@47
|
280 scale.innerHTML = null;
|
n@47
|
281 interfaceObj.find('scale').each(function(index,scaleObj){
|
n@47
|
282 var position = Number(scaleObj.attributes['position'].value)*0.01;
|
n@47
|
283 var pixelPosition = (position*positionScale)+offset;
|
n@47
|
284 var scaleDOM = document.createElement('span');
|
n@47
|
285 scaleDOM.textContent = scaleObj.textContent;
|
n@47
|
286 scale.appendChild(scaleDOM);
|
n@47
|
287 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
|
n@47
|
288 });
|
n@34
|
289
|
n@34
|
290 // Extract the hostURL attribute. If not set, create an empty string.
|
n@34
|
291 var hostURL = textXML.attributes['hostURL'];
|
n@34
|
292 if (hostURL == undefined) {
|
n@34
|
293 hostURL = "";
|
n@34
|
294 } else {
|
n@34
|
295 hostURL = hostURL.value;
|
n@34
|
296 }
|
n@34
|
297 // Extract the sampleRate. If set, convert the string to a Number.
|
n@34
|
298 var hostFs = textXML.attributes['sampleRate'];
|
n@34
|
299 if (hostFs != undefined) {
|
n@34
|
300 hostFs = Number(hostFs.value);
|
n@34
|
301 }
|
n@34
|
302
|
n@34
|
303 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
n@34
|
304 if (hostFs != undefined) {
|
n@34
|
305 if (Number(hostFs) != audioContext.sampleRate) {
|
n@34
|
306 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
|
n@34
|
307 alert(errStr);
|
n@34
|
308 return;
|
n@34
|
309 }
|
n@34
|
310 }
|
n@45
|
311
|
nicholas@66
|
312 var commentShow = textXML.attributes['elementComments'];
|
nicholas@66
|
313 if (commentShow != undefined) {
|
nicholas@66
|
314 if (commentShow.value == 'false') {commentShow = false;}
|
nicholas@66
|
315 else {commentShow = true;}
|
nicholas@66
|
316 } else {commentShow = true;}
|
nicholas@66
|
317
|
n@57
|
318 var loopPlayback = textXML.attributes['loop'];
|
n@57
|
319 if (loopPlayback != undefined)
|
n@57
|
320 {
|
n@57
|
321 loopPlayback = loopPlayback.value;
|
n@57
|
322 if (loopPlayback == 'true') {
|
n@57
|
323 loopPlayback = true;
|
n@57
|
324 } else {
|
n@57
|
325 loopPlayback = false;
|
n@57
|
326 }
|
n@57
|
327 } else {
|
n@57
|
328 loopPlayback = false;
|
n@57
|
329 }
|
n@57
|
330 audioEngineContext.loopPlayback = loopPlayback;
|
n@57
|
331
|
n@57
|
332 // Create AudioEngine bindings for playback
|
n@57
|
333 if (loopPlayback) {
|
n@57
|
334 audioEngineContext.play = function() {
|
n@57
|
335 // Send play command to all playback buffers for synchronised start
|
n@57
|
336 // Also start timer callbacks to detect if playback has finished
|
n@57
|
337 if (this.status == 0) {
|
n@57
|
338 this.timer.startTest();
|
n@57
|
339 // First get current clock
|
n@57
|
340 var timer = audioContext.currentTime;
|
n@57
|
341 // Add 3 seconds
|
n@57
|
342 timer += 3.0;
|
n@57
|
343 // Send play to all tracks
|
n@57
|
344 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
345 {
|
n@57
|
346 this.audioObjects[i].play(timer);
|
n@57
|
347 }
|
n@57
|
348 this.status = 1;
|
n@57
|
349 }
|
n@57
|
350 };
|
n@57
|
351
|
n@57
|
352 audioEngineContext.stop = function() {
|
n@57
|
353 // Send stop and reset command to all playback buffers
|
n@57
|
354 if (this.status == 1) {
|
n@57
|
355 if (this.loopPlayback) {
|
n@57
|
356 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
357 {
|
n@57
|
358 this.audioObjects[i].stop();
|
n@57
|
359 }
|
n@57
|
360 }
|
n@57
|
361 this.status = 0;
|
n@57
|
362 }
|
n@57
|
363 };
|
n@57
|
364
|
n@57
|
365 audioEngineContext.selectedTrack = function(id) {
|
n@57
|
366 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
367 {
|
n@57
|
368 if (id == i) {
|
n@57
|
369 this.audioObjects[i].outputGain.gain.value = 1.0;
|
n@57
|
370 } else {
|
n@57
|
371 this.audioObjects[i].outputGain.gain.value = 0.0;
|
n@57
|
372 }
|
n@57
|
373 }
|
n@57
|
374 };
|
n@57
|
375 } else {
|
n@57
|
376 audioEngineContext.play = function() {
|
n@57
|
377 // Send play command to all playback buffers for synchronised start
|
n@57
|
378 // Also start timer callbacks to detect if playback has finished
|
n@57
|
379 if (this.status == 0) {
|
n@57
|
380 this.timer.startTest();
|
n@57
|
381 this.status = 1;
|
n@57
|
382 }
|
n@57
|
383 };
|
n@57
|
384
|
n@57
|
385 audioEngineContext.stop = function() {
|
n@57
|
386 // Send stop and reset command to all playback buffers
|
n@57
|
387 if (this.status == 1) {
|
n@99
|
388 for (var i=0; i<this.audioObjects.length; i++)
|
n@99
|
389 {
|
n@99
|
390 this.audioObjects[i].stop();
|
n@57
|
391 }
|
n@57
|
392 this.status = 0;
|
n@57
|
393 }
|
n@57
|
394 };
|
n@57
|
395
|
n@57
|
396 audioEngineContext.selectedTrack = function(id) {
|
n@57
|
397 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
398 {
|
n@97
|
399 this.audioObjects[i].outputGain.gain.value = 0.0;
|
n@97
|
400 this.audioObjects[i].stop();
|
n@57
|
401 }
|
n@99
|
402 if (this.status == 1) {
|
n@99
|
403 this.audioObjects[id].outputGain.gain.value = 1.0;
|
n@99
|
404 this.audioObjects[id].play(audioContext.currentTime+0.01);
|
n@99
|
405 }
|
n@57
|
406 };
|
n@57
|
407 }
|
n@57
|
408
|
n@46
|
409 currentTestHolder = document.createElement('audioHolder');
|
n@46
|
410 currentTestHolder.id = textXML.id;
|
n@46
|
411 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
|
n@46
|
412 var currentPreTestHolder = document.createElement('preTest');
|
n@46
|
413 var currentPostTestHolder = document.createElement('postTest');
|
n@46
|
414 currentTestHolder.appendChild(currentPreTestHolder);
|
n@46
|
415 currentTestHolder.appendChild(currentPostTestHolder);
|
n@46
|
416
|
n@45
|
417 var randomise = textXML.attributes['randomiseOrder'];
|
n@45
|
418 if (randomise != undefined) {randomise = randomise.value;}
|
n@45
|
419 else {randomise = false;}
|
n@45
|
420
|
n@34
|
421 var audioElements = $(textXML).find('audioElements');
|
nicholas@58
|
422 currentTrackOrder = [];
|
n@34
|
423 audioElements.each(function(index,element){
|
n@45
|
424 // Find any blind-repeats
|
b@100
|
425 // Not implemented yet, but just in case
|
n@45
|
426 currentTrackOrder[index] = element;
|
n@45
|
427 });
|
n@45
|
428 if (randomise) {
|
n@54
|
429 currentTrackOrder = randomiseOrder(currentTrackOrder);
|
n@45
|
430 }
|
n@45
|
431
|
nicholas@58
|
432 // Delete any previous audioObjects associated with the audioEngine
|
nicholas@58
|
433 audioEngineContext.audioObjects = [];
|
nicholas@58
|
434
|
n@45
|
435 // Find all the audioElements from the audioHolder
|
n@45
|
436 $(currentTrackOrder).each(function(index,element){
|
n@34
|
437 // Find URL of track
|
n@34
|
438 // In this jQuery loop, variable 'this' holds the current audioElement.
|
n@34
|
439
|
n@34
|
440 // Now load each audio sample. First create the new track by passing the full URL
|
n@34
|
441 var trackURL = hostURL + this.attributes['url'].value;
|
n@34
|
442 audioEngineContext.newTrack(trackURL);
|
nicholas@66
|
443
|
nicholas@66
|
444 if (commentShow) {
|
nicholas@66
|
445 // Create document objects to hold the comment boxes
|
nicholas@66
|
446 var trackComment = document.createElement('div');
|
nicholas@66
|
447 trackComment.className = 'comment-div';
|
nicholas@66
|
448 // Create a string next to each comment asking for a comment
|
nicholas@66
|
449 var trackString = document.createElement('span');
|
nicholas@66
|
450 trackString.innerHTML = 'Comment on track '+index;
|
nicholas@66
|
451 // Create the HTML5 comment box 'textarea'
|
nicholas@66
|
452 var trackCommentBox = document.createElement('textarea');
|
nicholas@66
|
453 trackCommentBox.rows = '4';
|
nicholas@66
|
454 trackCommentBox.cols = '100';
|
nicholas@66
|
455 trackCommentBox.name = 'trackComment'+index;
|
nicholas@66
|
456 trackCommentBox.className = 'trackComment';
|
nicholas@66
|
457 var br = document.createElement('br');
|
nicholas@66
|
458 // Add to the holder.
|
nicholas@66
|
459 trackComment.appendChild(trackString);
|
nicholas@66
|
460 trackComment.appendChild(br);
|
nicholas@66
|
461 trackComment.appendChild(trackCommentBox);
|
nicholas@66
|
462 feedbackHolder.appendChild(trackComment);
|
nicholas@66
|
463 }
|
n@34
|
464
|
n@34
|
465 // Create a slider per track
|
n@34
|
466
|
n@34
|
467 var trackSliderObj = document.createElement('div');
|
n@34
|
468 trackSliderObj.className = 'track-slider';
|
n@34
|
469 trackSliderObj.id = 'track-slider-'+index;
|
n@34
|
470 // Distribute it randomnly
|
n@34
|
471 var w = window.innerWidth - 100;
|
n@34
|
472 w = Math.random()*w;
|
n@34
|
473 trackSliderObj.style.left = Math.floor(w)+50+'px';
|
n@34
|
474 trackSliderObj.innerHTML = '<span>'+index+'</span>';
|
n@34
|
475 trackSliderObj.draggable = true;
|
n@34
|
476 trackSliderObj.ondragend = dragEnd;
|
n@49
|
477 trackSliderObj.ondragstart = function()
|
n@49
|
478 {
|
n@49
|
479 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
|
n@49
|
480 audioEngineContext.metric.sliderMoveStart(id);
|
n@49
|
481 };
|
n@34
|
482
|
n@34
|
483 // Onclick, switch playback to that track
|
n@34
|
484 trackSliderObj.onclick = function() {
|
n@34
|
485 // Get the track ID from the object ID
|
n@34
|
486 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
|
n@49
|
487 audioEngineContext.metric.sliderPlayed(id);
|
n@34
|
488 audioEngineContext.selectedTrack(id);
|
b@100
|
489 // Currently playing track red, rest green
|
b@100
|
490 document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
|
b@100
|
491 for (var i = 0; i<$(currentTrackOrder).length; i++)
|
b@100
|
492 {
|
b@102
|
493 if (i!=index) // Make all other sliders green
|
b@100
|
494 {
|
b@100
|
495 document.getElementById('track-slider-'+i).style.backgroundColor = "rgb(100,200,100)";
|
b@100
|
496 }
|
b@100
|
497
|
b@100
|
498 }
|
b@101
|
499 audioEngineContext.play();
|
n@34
|
500 };
|
n@34
|
501
|
n@34
|
502 canvas.appendChild(trackSliderObj);
|
b@102
|
503
|
n@34
|
504 });
|
n@39
|
505
|
nicholas@65
|
506 // Append any commentQuestion boxes
|
nicholas@65
|
507 var commentQuestions = $(textXML).find('CommentQuestion');
|
nicholas@65
|
508 $(commentQuestions).each(function(index,element) {
|
nicholas@65
|
509 // Create document objects to hold the comment boxes
|
nicholas@65
|
510 var trackComment = document.createElement('div');
|
nicholas@65
|
511 trackComment.className = 'comment-div commentQuestion';
|
nicholas@65
|
512 trackComment.id = element.attributes['id'].value;
|
nicholas@65
|
513 // Create a string next to each comment asking for a comment
|
nicholas@65
|
514 var trackString = document.createElement('span');
|
nicholas@65
|
515 trackString.innerHTML = element.textContent;
|
nicholas@65
|
516 // Create the HTML5 comment box 'textarea'
|
nicholas@65
|
517 var trackCommentBox = document.createElement('textarea');
|
nicholas@65
|
518 trackCommentBox.rows = '4';
|
nicholas@65
|
519 trackCommentBox.cols = '100';
|
nicholas@65
|
520 trackCommentBox.name = 'commentQuestion'+index;
|
nicholas@65
|
521 trackCommentBox.className = 'trackComment';
|
nicholas@65
|
522 var br = document.createElement('br');
|
nicholas@65
|
523 // Add to the holder.
|
nicholas@65
|
524 trackComment.appendChild(trackString);
|
nicholas@65
|
525 trackComment.appendChild(br);
|
nicholas@65
|
526 trackComment.appendChild(trackCommentBox);
|
nicholas@65
|
527 feedbackHolder.appendChild(trackComment);
|
nicholas@65
|
528 });
|
nicholas@65
|
529
|
n@39
|
530 // Now process any pre-test commands
|
n@39
|
531
|
n@44
|
532 var preTest = $(testXMLSetups[id]).find('PreTest')[0];
|
nicholas@105
|
533 if (preTest.childElementCount > 0)
|
n@39
|
534 {
|
n@39
|
535 currentState = 'testRunPre-'+id;
|
n@39
|
536 preTestPopupStart(preTest);
|
n@39
|
537 showPopup();
|
n@39
|
538 } else {
|
n@39
|
539 currentState = 'testRun-'+id;
|
n@39
|
540 }
|
n@39
|
541 }
|
n@39
|
542
|
n@39
|
543 function preTestPopupStart(preTest)
|
n@39
|
544 {
|
n@39
|
545 var popupHolder = document.getElementById('popupHolder');
|
n@39
|
546 popupHolder.innerHTML = null;
|
n@39
|
547 // Parse the first box
|
n@39
|
548 var preTestOption = document.createElement('div');
|
n@39
|
549 preTestOption.id = 'preTest';
|
n@39
|
550 preTestOption.style.marginTop = '25px';
|
n@39
|
551 preTestOption.align = "center";
|
nicholas@105
|
552 var child = $(preTest).children()[0];
|
n@39
|
553 if (child.nodeName == 'statement')
|
n@39
|
554 {
|
nicholas@105
|
555 preTestOption.innerHTML = '<span>'+child.textContent+'</span>';
|
n@39
|
556 } else if (child.nodeName == 'question')
|
n@39
|
557 {
|
n@39
|
558 var questionId = child.attributes['id'].value;
|
n@39
|
559 var textHold = document.createElement('span');
|
nicholas@105
|
560 textHold.innerHTML = child.textContent;
|
n@39
|
561 textHold.id = questionId + 'response';
|
n@39
|
562 var textEnter = document.createElement('textarea');
|
n@39
|
563 preTestOption.appendChild(textHold);
|
n@39
|
564 preTestOption.appendChild(textEnter);
|
n@39
|
565 }
|
n@39
|
566 var nextButton = document.createElement('button');
|
n@39
|
567 nextButton.className = 'popupButton';
|
n@39
|
568 nextButton.value = '0';
|
n@39
|
569 nextButton.innerHTML = 'Next';
|
n@39
|
570 nextButton.onclick = popupButtonClick;
|
n@39
|
571
|
n@39
|
572 popupHolder.appendChild(preTestOption);
|
n@39
|
573 popupHolder.appendChild(nextButton);
|
n@34
|
574 }
|
n@34
|
575
|
n@38
|
576 function popupButtonClick()
|
n@38
|
577 {
|
n@38
|
578 // Global call from the 'Next' button click
|
n@38
|
579 if (currentState == 'preTest')
|
n@38
|
580 {
|
n@38
|
581 // At the start of the preTest routine!
|
n@39
|
582 var xmlTree = projectXML.find('setup');
|
n@39
|
583 var preTest = xmlTree.find('PreTest')[0];
|
n@39
|
584 this.value = preTestButtonClick(preTest,this.value);
|
n@39
|
585 } else if (currentState.substr(0,10) == 'testRunPre')
|
n@39
|
586 {
|
n@39
|
587 //Specific test pre-test
|
n@39
|
588 var testId = currentState.substr(11,currentState.length-10);
|
n@44
|
589 var preTest = $(testXMLSetups[testId]).find('PreTest')[0];
|
n@39
|
590 this.value = preTestButtonClick(preTest,this.value);
|
n@42
|
591 } else if (currentState.substr(0,11) == 'testRunPost')
|
n@42
|
592 {
|
n@42
|
593 // Specific test post-test
|
n@42
|
594 var testId = currentState.substr(12,currentState.length-11);
|
n@44
|
595 var preTest = $(testXMLSetups[testId]).find('PostTest')[0];
|
n@42
|
596 this.value = preTestButtonClick(preTest,this.value);
|
n@41
|
597 } else if (currentState == 'postTest')
|
n@41
|
598 {
|
n@41
|
599 // At the end of the test, running global post test
|
n@41
|
600 var xmlTree = projectXML.find('setup');
|
n@41
|
601 var PostTest = xmlTree.find('PostTest')[0];
|
n@41
|
602 this.value = preTestButtonClick(PostTest,this.value);
|
n@38
|
603 }
|
n@38
|
604 }
|
n@38
|
605
|
n@39
|
606 function preTestButtonClick(preTest,index)
|
n@34
|
607 {
|
n@34
|
608 // Called on click of pre-test button
|
n@36
|
609 // Need to find and parse preTest again!
|
n@36
|
610 var preTestOption = document.getElementById('preTest');
|
n@36
|
611 // Check if current state is a question!
|
nicholas@105
|
612 if ($(preTest).children()[index].nodeName == 'question') {
|
nicholas@105
|
613 var questionId = $(preTest).children()[index].attributes['id'].value;
|
n@36
|
614 var questionHold = document.createElement('comment');
|
n@36
|
615 var questionResponse = document.getElementById(questionId + 'response');
|
nicholas@105
|
616 var mandatory = $(preTest).children()[index].attributes['mandatory'];
|
nicholas@64
|
617 if (mandatory != undefined){
|
nicholas@64
|
618 if (mandatory.value == 'true') {mandatory = true;}
|
nicholas@64
|
619 else {mandatory = false;}
|
nicholas@64
|
620 } else {mandatory = false;}
|
nicholas@64
|
621 if (mandatory == true && questionResponse.value.length == 0) {
|
nicholas@64
|
622 return index;
|
nicholas@64
|
623 }
|
n@36
|
624 questionHold.id = questionId;
|
n@36
|
625 questionHold.innerHTML = questionResponse.value;
|
n@46
|
626 postPopupResponse(questionHold);
|
n@36
|
627 }
|
n@38
|
628 index++;
|
nicholas@105
|
629 if (index < preTest.childElementCount)
|
n@36
|
630 {
|
n@36
|
631 // More to process
|
nicholas@105
|
632 var child = $(preTest).children()[index];
|
n@36
|
633 if (child.nodeName == 'statement')
|
n@36
|
634 {
|
nicholas@105
|
635 preTestOption.innerHTML = '<span>'+child.textContent+'</span>';
|
n@36
|
636 } else if (child.nodeName == 'question')
|
n@36
|
637 {
|
n@36
|
638 var textHold = document.createElement('span');
|
nicholas@105
|
639 textHold.innerHTML = child.textContent;
|
n@36
|
640 var textEnter = document.createElement('textarea');
|
n@36
|
641 textEnter.id = child.attributes['id'].value + 'response';
|
n@36
|
642 var br = document.createElement('br');
|
n@36
|
643 preTestOption.innerHTML = null;
|
n@36
|
644 preTestOption.appendChild(textHold);
|
n@36
|
645 preTestOption.appendChild(br);
|
n@36
|
646 preTestOption.appendChild(textEnter);
|
n@36
|
647 }
|
n@36
|
648 } else {
|
n@36
|
649 // Time to clear
|
n@37
|
650 preTestOption.innerHTML = null;
|
n@43
|
651 if (currentState != 'postTest') {
|
n@43
|
652 hidePopup();
|
n@43
|
653 // Progress the state!
|
n@43
|
654 advanceState();
|
n@43
|
655 } else {
|
n@43
|
656 a = createProjectSave(projectReturn);
|
n@43
|
657 preTestOption.appendChild(a);
|
n@43
|
658 }
|
n@36
|
659 }
|
n@38
|
660 return index;
|
n@36
|
661 }
|
n@36
|
662
|
n@46
|
663 function postPopupResponse(response)
|
n@46
|
664 {
|
n@46
|
665 if (currentState == 'preTest') {
|
n@46
|
666 preTestQuestions.appendChild(response);
|
n@46
|
667 } else if (currentState == 'postTest') {
|
n@46
|
668 postTestQuestions.appendChild(response);
|
n@46
|
669 } else {
|
n@46
|
670 // Inside a specific test
|
n@46
|
671 if (currentState.substr(0,10) == 'testRunPre') {
|
n@46
|
672 // Pre Test
|
n@46
|
673 var store = $(currentTestHolder).find('preTest');
|
n@46
|
674 } else {
|
n@46
|
675 // Post Test
|
n@46
|
676 var store = $(currentTestHolder).find('postTest');
|
n@46
|
677 }
|
n@46
|
678 store[0].appendChild(response);
|
n@46
|
679 }
|
n@46
|
680 }
|
n@46
|
681
|
n@36
|
682 function showPopup()
|
n@36
|
683 {
|
n@37
|
684 var popupHolder = document.getElementById('popupHolder');
|
n@38
|
685 popupHolder.style.zIndex = 3;
|
n@37
|
686 popupHolder.style.visibility = 'visible';
|
n@37
|
687 var blank = document.getElementsByClassName('testHalt')[0];
|
n@37
|
688 blank.style.zIndex = 2;
|
n@37
|
689 blank.style.visibility = 'visible';
|
n@36
|
690 }
|
n@36
|
691
|
n@36
|
692 function hidePopup()
|
n@36
|
693 {
|
n@37
|
694 var popupHolder = document.getElementById('popupHolder');
|
n@37
|
695 popupHolder.style.zIndex = -1;
|
n@37
|
696 popupHolder.style.visibility = 'hidden';
|
n@37
|
697 var blank = document.getElementsByClassName('testHalt')[0];
|
n@37
|
698 blank.style.zIndex = -2;
|
n@37
|
699 blank.style.visibility = 'hidden';
|
n@34
|
700 }
|
n@34
|
701
|
nicholas@5
|
702 function dragEnd(ev) {
|
nicholas@5
|
703 // Function call when a div has been dropped
|
n@33
|
704 var slider = document.getElementById('slider');
|
n@51
|
705 var w = slider.style.width;
|
n@51
|
706 w = Number(w.substr(0,w.length-2));
|
n@51
|
707 var x = ev.x;
|
n@51
|
708 if (x >= 42 && x < w+42) {
|
n@51
|
709 this.style.left = (x)+'px';
|
nicholas@5
|
710 } else {
|
n@51
|
711 if (x<42) {
|
n@51
|
712 this.style.left = '42px';
|
nicholas@5
|
713 } else {
|
n@51
|
714 this.style.left = (w+42) + 'px';
|
nicholas@5
|
715 }
|
nicholas@5
|
716 }
|
n@49
|
717 audioEngineContext.metric.sliderMoved();
|
nicholas@5
|
718 }
|
nicholas@7
|
719
|
n@39
|
720 function advanceState()
|
n@39
|
721 {
|
n@39
|
722 console.log(currentState);
|
n@39
|
723 if (currentState == 'preTest')
|
n@39
|
724 {
|
n@39
|
725 // End of pre-test, begin the test
|
n@39
|
726 loadTest(0);
|
n@39
|
727 } else if (currentState.substr(0,10) == 'testRunPre')
|
n@39
|
728 {
|
n@39
|
729 // Start the test
|
n@39
|
730 var testId = currentState.substr(11,currentState.length-10);
|
n@39
|
731 currentState = 'testRun-'+testId;
|
nicholas@107
|
732 //audioEngineContext.timer.startTest();
|
nicholas@107
|
733 audioEngineContext.play();
|
n@42
|
734 } else if (currentState.substr(0,11) == 'testRunPost')
|
n@42
|
735 {
|
n@44
|
736 var testId = currentState.substr(12,currentState.length-11);
|
n@42
|
737 testEnded(testId);
|
n@40
|
738 } else if (currentState.substr(0,7) == 'testRun')
|
n@40
|
739 {
|
n@40
|
740 var testId = currentState.substr(8,currentState.length-7);
|
n@40
|
741 // Check if we have any post tests to perform
|
n@44
|
742 var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
|
nicholas@69
|
743 if (postXML == undefined) {
|
nicholas@69
|
744 testEnded(testId);
|
nicholas@69
|
745 }
|
nicholas@105
|
746 else if (postXML.childElementCount > 0)
|
n@40
|
747 {
|
n@42
|
748 currentState = 'testRunPost-'+testId;
|
n@42
|
749 showPopup();
|
n@42
|
750 preTestPopupStart(postXML);
|
n@40
|
751 }
|
n@42
|
752 else {
|
n@40
|
753
|
n@40
|
754
|
n@42
|
755 // No post tests, check if we have another test to perform instead
|
nicholas@69
|
756
|
n@40
|
757 }
|
n@39
|
758 }
|
n@39
|
759 console.log(currentState);
|
n@39
|
760 }
|
n@39
|
761
|
n@42
|
762 function testEnded(testId)
|
n@42
|
763 {
|
n@45
|
764 pageXMLSave(testId);
|
n@42
|
765 if (testXMLSetups.length-1 > testId)
|
n@42
|
766 {
|
n@42
|
767 // Yes we have another test to perform
|
n@44
|
768 testId = (Number(testId)+1);
|
n@44
|
769 currentState = 'testRun-'+testId;
|
n@44
|
770 loadTest(testId);
|
n@42
|
771 } else {
|
n@42
|
772 console.log('Testing Completed!');
|
n@42
|
773 currentState = 'postTest';
|
n@42
|
774 // Check for any post tests
|
n@42
|
775 var xmlSetup = projectXML.find('setup');
|
n@42
|
776 var postTest = xmlSetup.find('PostTest')[0];
|
n@42
|
777 showPopup();
|
n@42
|
778 preTestPopupStart(postTest);
|
n@42
|
779 }
|
n@42
|
780 }
|
n@42
|
781
|
b@101
|
782 function buttonSubmitClick() // TODO: Only when all songs have been played!
|
n@40
|
783 {
|
nicholas@107
|
784 hasBeenPlayed = audioEngineContext.checkAllPlayed();
|
nicholas@107
|
785 if (hasBeenPlayed.length == 0) {
|
nicholas@107
|
786 if (audioEngineContext.status == 1) {
|
nicholas@107
|
787 var playback = document.getElementById('playback-button');
|
nicholas@107
|
788 playback.click();
|
nicholas@107
|
789 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
nicholas@107
|
790 } else
|
nicholas@107
|
791 {
|
nicholas@107
|
792 if (audioEngineContext.timer.testStarted == false)
|
nicholas@107
|
793 {
|
nicholas@107
|
794 alert('You have not started the test! Please press start to begin the test!');
|
nicholas@107
|
795 return;
|
nicholas@107
|
796 }
|
nicholas@107
|
797 }
|
nicholas@107
|
798 if (currentState.substr(0,7) == 'testRun')
|
nicholas@107
|
799 {
|
nicholas@107
|
800 hasBeenPlayed = []; // clear array to prepare for next test
|
nicholas@107
|
801 audioEngineContext.timer.stopTest();
|
nicholas@107
|
802 advanceState();
|
nicholas@107
|
803 }
|
b@102
|
804 } else // if a fragment has not been played yet
|
b@102
|
805 {
|
nicholas@107
|
806 str = "";
|
nicholas@107
|
807 if (hasBeenPlayed.length > 1) {
|
nicholas@107
|
808 for (var i=0; i<hasBeenPlayed.length; i++) {
|
nicholas@107
|
809 str = str + hasBeenPlayed[i];
|
nicholas@107
|
810 if (i < hasBeenPlayed.length-2){
|
nicholas@107
|
811 str += ", ";
|
nicholas@107
|
812 } else if (i == hasBeenPlayed.length-2) {
|
nicholas@107
|
813 str += " or ";
|
nicholas@107
|
814 }
|
nicholas@107
|
815 }
|
nicholas@107
|
816 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@107
|
817 } else {
|
nicholas@107
|
818 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@107
|
819 }
|
b@102
|
820 return;
|
b@102
|
821 }
|
n@40
|
822 }
|
n@40
|
823
|
n@51
|
824 function convSliderPosToRate(id)
|
n@51
|
825 {
|
n@51
|
826 var w = document.getElementById('slider').style.width;
|
n@51
|
827 var maxPix = w.substr(0,w.length-2);
|
n@51
|
828 var slider = document.getElementsByClassName('track-slider')[id];
|
n@51
|
829 var pix = slider.style.left;
|
n@51
|
830 pix = pix.substr(0,pix.length-2);
|
n@51
|
831 var rate = (pix-42)/maxPix;
|
n@51
|
832 return rate;
|
n@51
|
833 }
|
n@51
|
834
|
n@44
|
835 function pageXMLSave(testId)
|
n@44
|
836 {
|
n@44
|
837 // Saves a specific test page
|
n@46
|
838 var xmlDoc = currentTestHolder;
|
n@50
|
839 // Check if any session wide metrics are enabled
|
nicholas@67
|
840
|
nicholas@67
|
841 var commentShow = testXMLSetups[testId].attributes['elementComments'];
|
nicholas@67
|
842 if (commentShow != undefined) {
|
nicholas@67
|
843 if (commentShow.value == 'false') {commentShow = false;}
|
nicholas@67
|
844 else {commentShow = true;}
|
nicholas@67
|
845 } else {commentShow = true;}
|
nicholas@67
|
846
|
n@50
|
847 var metric = document.createElement('metric');
|
n@50
|
848 if (audioEngineContext.metric.enableTestTimer)
|
n@50
|
849 {
|
n@50
|
850 var testTime = document.createElement('metricResult');
|
n@50
|
851 testTime.id = 'testTime';
|
n@50
|
852 testTime.textContent = audioEngineContext.timer.testDuration;
|
n@50
|
853 metric.appendChild(testTime);
|
n@50
|
854 }
|
n@50
|
855 xmlDoc.appendChild(metric);
|
n@45
|
856 var trackSliderObjects = document.getElementsByClassName('track-slider');
|
n@45
|
857 var commentObjects = document.getElementsByClassName('comment-div');
|
n@45
|
858 for (var i=0; i<trackSliderObjects.length; i++)
|
n@45
|
859 {
|
n@45
|
860 var audioElement = document.createElement('audioElement');
|
n@45
|
861 audioElement.id = currentTrackOrder[i].attributes['id'].value;
|
n@45
|
862 audioElement.url = currentTrackOrder[i].attributes['url'].value;
|
n@51
|
863 var value = document.createElement('value');
|
n@51
|
864 value.innerHTML = convSliderPosToRate(i);
|
nicholas@67
|
865 if (commentShow) {
|
nicholas@67
|
866 var comment = document.createElement("comment");
|
nicholas@67
|
867 var question = document.createElement("question");
|
nicholas@67
|
868 var response = document.createElement("response");
|
nicholas@67
|
869 question.textContent = commentObjects[i].children[0].textContent;
|
nicholas@67
|
870 response.textContent = commentObjects[i].children[2].value;
|
nicholas@67
|
871 comment.appendChild(question);
|
nicholas@67
|
872 comment.appendChild(response);
|
nicholas@67
|
873 audioElement.appendChild(comment);
|
nicholas@67
|
874 }
|
n@45
|
875 audioElement.appendChild(value);
|
n@50
|
876 // Check for any per element metrics
|
n@50
|
877 var metric = document.createElement('metric');
|
n@50
|
878 var elementMetric = audioEngineContext.audioObjects[i].metric;
|
n@50
|
879 if (audioEngineContext.metric.enableElementTimer) {
|
n@50
|
880 var elementTimer = document.createElement('metricResult');
|
n@50
|
881 elementTimer.id = 'elementTimer';
|
n@50
|
882 elementTimer.textContent = elementMetric.listenedTimer;
|
n@50
|
883 metric.appendChild(elementTimer);
|
n@50
|
884 }
|
n@50
|
885 if (audioEngineContext.metric.enableElementTracker) {
|
n@50
|
886 var elementTrackerFull = document.createElement('metricResult');
|
n@50
|
887 elementTrackerFull.id = 'elementTrackerFull';
|
n@50
|
888 var data = elementMetric.movementTracker;
|
n@50
|
889 for (var k=0; k<data.length; k++)
|
n@50
|
890 {
|
n@50
|
891 var timePos = document.createElement('timePos');
|
n@50
|
892 timePos.id = k;
|
n@50
|
893 var time = document.createElement('time');
|
n@50
|
894 time.textContent = data[k][0];
|
n@50
|
895 var position = document.createElement('position');
|
n@50
|
896 position.textContent = data[k][1];
|
n@50
|
897 timePos.appendChild(time);
|
n@50
|
898 timePos.appendChild(position);
|
n@50
|
899 elementTrackerFull.appendChild(timePos);
|
n@50
|
900 }
|
n@50
|
901 metric.appendChild(elementTrackerFull);
|
n@50
|
902 }
|
n@50
|
903 if (audioEngineContext.metric.enableElementInitialPosition) {
|
n@50
|
904 var elementInitial = document.createElement('metricResult');
|
n@50
|
905 elementInitial.id = 'elementInitialPosition';
|
n@50
|
906 elementInitial.textContent = elementMetric.initialPosition;
|
n@50
|
907 metric.appendChild(elementInitial);
|
n@50
|
908 }
|
n@50
|
909 if (audioEngineContext.metric.enableFlagListenedTo) {
|
n@50
|
910 var flagListenedTo = document.createElement('metricResult');
|
n@50
|
911 flagListenedTo.id = 'elementFlagListenedTo';
|
n@50
|
912 flagListenedTo.textContent = elementMetric.wasListenedTo;
|
n@50
|
913 metric.appendChild(flagListenedTo);
|
n@50
|
914 }
|
n@50
|
915 if (audioEngineContext.metric.enableFlagMoved) {
|
n@50
|
916 var flagMoved = document.createElement('metricResult');
|
n@50
|
917 flagMoved.id = 'elementFlagMoved';
|
n@50
|
918 flagMoved.textContent = elementMetric.wasMoved;
|
n@50
|
919 metric.appendChild(flagMoved);
|
n@50
|
920 }
|
n@50
|
921 if (audioEngineContext.metric.enableFlagComments) {
|
n@50
|
922 var flagComments = document.createElement('metricResult');
|
n@50
|
923 flagComments.id = 'elementFlagComments';
|
n@50
|
924 if (response.textContent.length == 0) {flag.textContent = 'false';}
|
n@50
|
925 else {flag.textContet = 'true';}
|
n@50
|
926 metric.appendChild(flagComments);
|
n@50
|
927 }
|
n@50
|
928 audioElement.appendChild(metric);
|
n@45
|
929 xmlDoc.appendChild(audioElement);
|
n@45
|
930 }
|
nicholas@65
|
931 var commentQuestion = document.getElementsByClassName('commentQuestion');
|
nicholas@65
|
932 for (var i=0; i<commentQuestion.length; i++)
|
nicholas@65
|
933 {
|
nicholas@65
|
934 var cqHolder = document.createElement('CommentQuestion');
|
nicholas@65
|
935 var comment = document.createElement('comment');
|
nicholas@65
|
936 var question = document.createElement('question');
|
nicholas@65
|
937 cqHolder.id = commentQuestion[i].id;
|
nicholas@65
|
938 comment.textContent = commentQuestion[i].children[2].value;
|
nicholas@65
|
939 question.textContent = commentQuestion[i].children[0].textContent;
|
nicholas@65
|
940 cqHolder.appendChild(question);
|
nicholas@65
|
941 cqHolder.appendChild(comment);
|
nicholas@65
|
942 xmlDoc.appendChild(cqHolder);
|
nicholas@65
|
943 }
|
n@45
|
944 testResultsHolders[testId] = xmlDoc;
|
n@44
|
945 }
|
n@44
|
946
|
nicholas@7
|
947 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
|
nicholas@7
|
948 function interfaceXMLSave(){
|
nicholas@7
|
949 // Create the XML string to be exported with results
|
nicholas@7
|
950 var xmlDoc = document.createElement("BrowserEvaluationResult");
|
n@45
|
951 for (var i=0; i<testResultsHolders.length; i++)
|
nicholas@7
|
952 {
|
n@45
|
953 xmlDoc.appendChild(testResultsHolders[i]);
|
nicholas@7
|
954 }
|
n@23
|
955 // Append Pre/Post Questions
|
n@23
|
956 xmlDoc.appendChild(preTestQuestions);
|
n@23
|
957 xmlDoc.appendChild(postTestQuestions);
|
n@23
|
958
|
nicholas@7
|
959 return xmlDoc;
|
nicholas@67
|
960 } |