comparison test_create/test_create.html @ 169:5aff374de11c Dev_main

create_test: Imports from drag and drop project XML
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Wed, 03 Jun 2015 14:56:30 +0100
parents f95a30a25a87
children 3ee7219b1700
comparison
equal deleted inserted replaced
168:f95a30a25a87 169:5aff374de11c
183 var attributes = elem.getElementsByClassName('attrib')[0].getElementsByTagName('input'); 183 var attributes = elem.getElementsByClassName('attrib')[0].getElementsByTagName('input');
184 if (elem.getAttribute('name') == 'question-node') { 184 if (elem.getAttribute('name') == 'question-node') {
185 var node = document.createElement('question'); 185 var node = document.createElement('question');
186 node.setAttribute('id',attributes[0].value); 186 node.setAttribute('id',attributes[0].value);
187 node.textContent = attributes[1].value; 187 node.textContent = attributes[1].value;
188 node.setAttribute('mandatory',attributes[2].checked);
188 } else if (elem.getAttribute('name') == 'statement-node') { 189 } else if (elem.getAttribute('name') == 'statement-node') {
189 var node = document.createElement('statment'); 190 var node = document.createElement('statement');
190 node.textContent = attributes[0].value; 191 node.textContent = attributes[0].value;
191 } 192 }
192 parent.appendChild(node); 193 parent.appendChild(node);
193 } 194 }
194 } 195 }
262 nodeTitle.textContent = "Question"; 263 nodeTitle.textContent = "Question";
263 var attributes = document.createElement("div"); 264 var attributes = document.createElement("div");
264 attributes.setAttribute('class','attrib'); 265 attributes.setAttribute('class','attrib');
265 var id = attributePair("ID:","text", true); 266 var id = attributePair("ID:","text", true);
266 var question = attributePair("Question:","text", false); 267 var question = attributePair("Question:","text", false);
268 question[1].style.width = "500px";
269 var mandatory = attributePair("Mandatory:","checkbox", false);
267 node.appendChild(nodeTitle); 270 node.appendChild(nodeTitle);
268 id.forEach(function(item){attributes.appendChild(item);},false); 271 id.forEach(function(item){attributes.appendChild(item);},false);
269 question.forEach(function(item){attributes.appendChild(item);},false); 272 question.forEach(function(item){attributes.appendChild(item);},false);
273 mandatory.forEach(function(item){attributes.appendChild(item);},false);
270 node.appendChild(attributes); 274 node.appendChild(attributes);
271 275
272 var removeButton = document.createElement("button"); 276 var removeButton = document.createElement("button");
273 removeButton.textContent = "Remove"; 277 removeButton.textContent = "Remove";
274 removeButton.onclick = removeNode; 278 removeButton.onclick = removeNode;
283 var nodeTitle = document.createElement("span"); 287 var nodeTitle = document.createElement("span");
284 nodeTitle.textContent = "Statement"; 288 nodeTitle.textContent = "Statement";
285 var attributes = document.createElement("div"); 289 var attributes = document.createElement("div");
286 attributes.setAttribute('class','attrib'); 290 attributes.setAttribute('class','attrib');
287 var statement = attributePair("Statement:","text",false); 291 var statement = attributePair("Statement:","text",false);
292 statement[1].style.width = "500px";
288 node.appendChild(nodeTitle); 293 node.appendChild(nodeTitle);
289 statement.forEach(function(item){attributes.appendChild(item);},false); 294 statement.forEach(function(item){attributes.appendChild(item);},false);
290 node.appendChild(attributes); 295 node.appendChild(attributes);
291 296
292 var removeButton = document.createElement("button"); 297 var removeButton = document.createElement("button");
381 node.appendChild(removeButton); 386 node.appendChild(removeButton);
382 return node; 387 return node;
383 } 388 }
384 389
385 function audioElementNode() { 390 function audioElementNode() {
386 var parentStructure = event.srcElement.parentElement.childNodes;
387 var audioElemCounts = 0;
388 for (var i=0; i<parentStructure.length; i++) {
389 if (parentStructure[i].getAttribute('name') == "audio-element")
390 {audioElemCounts++;}
391 }
392 var node = document.createElement('div'); 391 var node = document.createElement('div');
393 node.setAttribute('class','head'); 392 node.setAttribute('class','head');
394 node.setAttribute('name','audio-element'); 393 node.setAttribute('name','audio-element');
395 var nodeTitle = document.createElement('span'); 394 var nodeTitle = document.createElement('span');
396 nodeTitle.textContent = 'Audio Element '+(audioElemCounts+1); 395 nodeTitle.textContent = 'Audio Element';
397 396
398 var attributes = document.createElement("div"); 397 var attributes = document.createElement("div");
399 attributes.setAttribute('class','attrib'); 398 attributes.setAttribute('class','attrib');
400 var id = attributePair("ID:","text",true); 399 var id = attributePair("ID:","text",true);
401 id[1].value = audioElemCounts;
402 var url = attributePair("URL:","text",true); 400 var url = attributePair("URL:","text",true);
403 id.forEach(function(item){attributes.appendChild(item);},false); 401 id.forEach(function(item){attributes.appendChild(item);},false);
404 url.forEach(function(item){attributes.appendChild(item);},false); 402 url.forEach(function(item){attributes.appendChild(item);},false);
405 403
406 node.appendChild(nodeTitle); 404 node.appendChild(nodeTitle);
422 420
423 var attributes = document.createElement('div'); 421 var attributes = document.createElement('div');
424 attributes.setAttribute('class','attrib'); 422 attributes.setAttribute('class','attrib');
425 var id = attributePair("ID:",'text',true); 423 var id = attributePair("ID:",'text',true);
426 var question = attributePair("Question:",'text',true); 424 var question = attributePair("Question:",'text',true);
425 question[1].style.width = "500px";
427 id.forEach(function(item){attributes.appendChild(item);},false); 426 id.forEach(function(item){attributes.appendChild(item);},false);
428 question.forEach(function(item){attributes.appendChild(item);},false); 427 question.forEach(function(item){attributes.appendChild(item);},false);
429 428
430 var removeButton = document.createElement("button"); 429 var removeButton = document.createElement("button");
431 removeButton.textContent = "Remove Comment Box"; 430 removeButton.textContent = "Remove Comment Box";
458 457
459 var file = e.dataTransfer.files[0]; 458 var file = e.dataTransfer.files[0];
460 459
461 // Uses HTML5 FileAPI - https://w3c.github.io/FileAPI/#filereader-interface 460 // Uses HTML5 FileAPI - https://w3c.github.io/FileAPI/#filereader-interface
462 var reader = new FileReader(); 461 var reader = new FileReader();
462 reader.onload = function() {
463 var parse = new DOMParser();
464 var xml = parse.parseFromString(reader.result,'text/xml');
465 importXML(xml);
466 };
463 reader.readAsText(file); 467 reader.readAsText(file);
464 var parse = new DOMParser(); 468
465 var xml = parse.parseFromString(reader.result,'text/xml'); 469 }
466 importXML(xml); 470 var g_XML;
467 }
468 471
469 function importXML(xml) { 472 function importXML(xml) {
470 console.log(xml); 473 g_XML = xml;
474
475 var root = xml.getElementsByTagName('BrowserEvalProjectDocument')[0];
476 var setup = xml.getElementsByTagName('setup')[0];
477 document.getElementById('interface').value = setup.getAttribute('interface');
478 document.getElementById('projectReturn').value = setup.getAttribute('projectReturn');
479 document.getElementById('randomisePageOrder').checked = setup.getAttribute('randomiseOrder');
480 document.getElementById('collectMetrics').checked = setup.getAttribute('collectMetrics');
481
482 var globalPreTest = setup.getElementsByTagName('PreTest')[0];
483 var globalPostTest = setup.getElementsByTagName('PostTest')[0];
484 for (var i=0; i<globalPreTest.childElementCount; i++) {
485 var child = globalPreTest.children[i];
486 var node;
487 if (child.nodeName == "question") {
488 node = questionNode();
489 var attribs = node.getElementsByClassName('attrib')[0].getElementsByTagName('input');
490 attribs[0].value = child.id;
491 attribs[1].value = child.textContent;
492 attribs[2].checked = child.getAttribute('mandatory');
493 } else if (child.nodeName == "statement") {
494 node = statementNode();
495 var attribs = node.getElementsByClassName('attrib')[0].getElementsByTagName('input');
496 attribs[0].value = child.textContent;
497 }
498 document.getElementById('globalPreTest').appendChild(node);
499 }
500
501 for (var i=0; i<globalPostTest.childElementCount; i++) {
502 var child = globalPostTest.children[i];
503 var node;
504 if (child.nodeName == "question") {
505 node = questionNode();
506 var attribs = node.getElementsByClassName('attrib')[0].getElementsByTagName('input');
507 attribs[0].value = child.id;
508 attribs[1].value = child.textContent;
509 attribs[2].checked = child.getAttribute('mandatory');
510 } else if (child.nodeName == "statement") {
511 node = statementNode();
512 var attribs = node.getElementsByClassName('attrib')[0].getElementsByTagName('input');
513 attribs[0].value = child.textContent;
514 }
515 document.getElementById('globalPostTest').appendChild(node);
516 }
517
518 var audioHolders = root.getElementsByTagName('audioHolder');
519 for (var i=0; i<audioHolders.length; i++) {
520 var audioHolderDOM = audioHolderNode();
521 var attribs = audioHolderDOM.getElementsByClassName('attrib')[0].getElementsByTagName('input');
522 attribs[0].value = audioHolders[i].id;
523 attribs[1].value = audioHolders[i].getAttribute('sampleRate');
524 attribs[2].value = audioHolders[i].getAttribute('hostURL');
525 attribs[3].checked = audioHolders[i].getAttribute('randomiseOrder');
526 attribs[4].value = audioHolders[i].getAttribute('repeatCount');
527 attribs[5].checked = audioHolders[i].getAttribute('loop');
528 attribs[6].checked = audioHolders[i].getAttribute('elementComments');
529
530 var PreTest = audioHolders[i].getElementsByTagName('PreTest');
531 var PostTest = audioHolders[i].getElementsByTagName('PostTest');
532 if (PreTest.length != 0) {
533 PreTest = PreTest[0];
534 for (var j=0; j<PreTest.childElementCount; j++) {
535 var child = PreTest.children[j];
536 var node;
537 if (child.nodeName == "question") {
538 node = questionNode();
539 var attribs = node.getElementsByClassName('attrib')[0].getElementsByTagName('input');
540 attribs[0].value = child.id;
541 attribs[1].value = child.textContent;
542 attribs[2].checked = child.getAttribute('mandatory');
543 } else if (child.nodeName == "statement") {
544 node = statementNode();
545 var attribs = node.getElementsByClassName('attrib')[0].getElementsByTagName('input');
546 attribs[0].value = child.textContent;
547 }
548 audioHolderDOM.children[2].appendChild(node);
549 }
550 }
551 if (PostTest.length != 0) {
552 PostTest = PostTest[0];
553 for (var j=0; j<PostTest.childElementCount; j++) {
554 var child = PostTest.children[j];
555 var node;
556 if (child.nodeName == "question") {
557 node = questionNode();
558 var attribs = node.getElementsByClassName('attrib')[0].getElementsByTagName('input');
559 attribs[0].value = child.id;
560 attribs[1].value = child.textContent;
561 attribs[2].checked = child.getAttribute('mandatory');
562 } else if (child.nodeName == "statement") {
563 node = statementNode();
564 var attribs = node.getElementsByClassName('attrib')[0].getElementsByTagName('input');
565 attribs[0].value = child.textContent;
566 }
567 audioHolderDOM.children[3].appendChild(node);
568 }
569 }
570
571 // Process audio-element
572 var audioElements = audioHolders[i].getElementsByTagName('audioElements');
573 for (var j=0; j<audioElements.length; j++) {
574 var node = audioElementNode();
575 var child = audioElements[j];
576 var attribs = node.getElementsByClassName('attrib')[0].getElementsByTagName('input');
577 attribs[0].value = child.id;
578 attribs[1].value = child.getAttribute('url');
579 audioHolderDOM.appendChild(node);
580 }
581
582 // Process comment-question
583 var commentQuestion = audioHolders[0].getElementsByTagName('CommentQuestion');
584 for (var j=0; j<commentQuestion.length; j++) {
585 var node = commentBox();
586 var child = commentQuestion[j];
587 var attribs = node.getElementsByClassName('attrib')[0].getElementsByTagName('input');
588 attribs[0].value = child.id;
589 attribs[1].value = child.textContent;
590 audioHolderDOM.appendChild(node);
591 }
592
593 document.getElementById('setup').appendChild(audioHolderDOM);
594 }
471 } 595 }
472 </script> 596 </script>
473 <style> 597 <style>
474 div { 598 div {
475 padding: 2px; 599 padding: 2px;