Mercurial > hg > webaudioevaluationtool
comparison test_create/test_core.js @ 506:1dbc6d3e6fb5 Dev_main
Test Creator nearing completion. Some more GUI events needed. Generates valid XML, can create new or use old. Supports most features.
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Thu, 11 Feb 2016 14:07:24 +0000 |
parents | cf55f9ee9446 |
children | f4800ccc4d54 |
comparison
equal
deleted
inserted
replaced
505:cf55f9ee9446 | 506:1dbc6d3e6fb5 |
---|---|
221 var reader = new FileReader(); | 221 var reader = new FileReader(); |
222 reader.onload = function(decoded) { | 222 reader.onload = function(decoded) { |
223 var parse = new DOMParser(); | 223 var parse = new DOMParser(); |
224 specification.decode(parse.parseFromString(decoded.target.result,'text/xml')); | 224 specification.decode(parse.parseFromString(decoded.target.result,'text/xml')); |
225 popupObject.hide(); | 225 popupObject.hide(); |
226 popupObject.popupContent.innerHTML = null; | |
226 convert.convert(document.getElementById('content')); | 227 convert.convert(document.getElementById('content')); |
227 } | 228 } |
228 reader.readAsText(files); | 229 reader.readAsText(files); |
229 }); | 230 }); |
230 | 231 |
573 spnH.appendChild(span); | 574 spnH.appendChild(span); |
574 this.content.appendChild(spnH); | 575 this.content.appendChild(spnH); |
575 this.dynamic = document.createElement("div"); | 576 this.dynamic = document.createElement("div"); |
576 this.option = null; | 577 this.option = null; |
577 this.parent = null; | 578 this.parent = null; |
579 this.optionLists = []; | |
578 var select = document.createElement("select"); | 580 var select = document.createElement("select"); |
579 select.setAttribute("name","type"); | 581 select.setAttribute("name","type"); |
580 select.addEventListener("change",this,false); | 582 select.addEventListener("change",this,false); |
581 this.content.appendChild(select); | 583 this.content.appendChild(select); |
582 this.content.appendChild(this.dynamic); | 584 this.content.appendChild(this.dynamic); |
608 statementText.textContent = "Statement/Question"; | 610 statementText.textContent = "Statement/Question"; |
609 statementEntry.addEventListener("change",this,false); | 611 statementEntry.addEventListener("change",this,false); |
610 statementEntry.setAttribute("name","statement"); | 612 statementEntry.setAttribute("name","statement"); |
611 statementEntry.value = this.option.statement; | 613 statementEntry.value = this.option.statement; |
612 this.dynamic.appendChild(statement); | 614 this.dynamic.appendChild(statement); |
615 | |
616 var id = document.createElement("div"); | |
617 var idText = document.createElement("span"); | |
618 var idEntry = document.createElement("input"); | |
619 id.appendChild(idText); | |
620 id.appendChild(idEntry); | |
621 idText.textContent = "ID: "; | |
622 idEntry.addEventListener("change",this,false); | |
623 idEntry.setAttribute("name","id"); | |
624 idEntry.value = this.option.id; | |
625 | |
613 switch(this.option.type) | 626 switch(this.option.type) |
614 { | 627 { |
615 case "statement": | 628 case "statement": |
616 break; | 629 break; |
617 case "question": | 630 case "question": |
631 this.dynamic.appendChild(id); | |
618 var boxsizeSelect = document.createElement("select"); | 632 var boxsizeSelect = document.createElement("select"); |
619 var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("boxsize")[0].getAllElementsByTagName("xs:enumeration"); | 633 var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("boxsize")[0].getAllElementsByTagName("xs:enumeration"); |
620 for (var i=0; i<optionList.length; i++) | 634 for (var i=0; i<optionList.length; i++) |
621 { | 635 { |
622 var selectOption = document.createElement("option"); | 636 var selectOption = document.createElement("option"); |
647 mandatory.appendChild(mandatoryInput); | 661 mandatory.appendChild(mandatoryInput); |
648 mandatoryInput.type = "checkbox"; | 662 mandatoryInput.type = "checkbox"; |
649 if (this.option.mandatory) {mandatoryInput.checked = true;} else {mandatoryInput.checked = false;} | 663 if (this.option.mandatory) {mandatoryInput.checked = true;} else {mandatoryInput.checked = false;} |
650 mandatoryInput.setAttribute("name","mandatory"); | 664 mandatoryInput.setAttribute("name","mandatory"); |
651 mandatoryInput.addEventListener("change",this,false); | 665 mandatoryInput.addEventListener("change",this,false); |
666 this.dynamic.appendChild(mandatory); | |
667 break; | |
668 case "number": | |
669 this.dynamic.appendChild(id); | |
670 | |
671 var mandatory = document.createElement("div"); | |
672 var mandatoryInput = document.createElement("input"); | |
673 var mandatoryText = document.createElement("span"); | |
674 mandatoryText.textContent = "Mandatory: "; | |
652 mandatory.appendChild(mandatoryText); | 675 mandatory.appendChild(mandatoryText); |
653 mandatory.appendChild(mandatoryInput); | 676 mandatory.appendChild(mandatoryInput); |
677 mandatoryInput.type = "checkbox"; | |
678 if (this.option.mandatory) {mandatoryInput.checked = true;} else {mandatoryInput.checked = false;} | |
679 mandatoryInput.setAttribute("name","mandatory"); | |
680 mandatoryInput.addEventListener("change",this,false); | |
654 this.dynamic.appendChild(mandatory); | 681 this.dynamic.appendChild(mandatory); |
682 | |
683 var minimum = document.createElement("div"); | |
684 var minimumEntry = document.createElement("input"); | |
685 var minimumText = document.createElement("span"); | |
686 minimumText.textContent = "Minimum: "; | |
687 minimum.appendChild(minimumText); | |
688 minimum.appendChild(minimumEntry); | |
689 minimumEntry.type = "number"; | |
690 minimumEntry.setAttribute("name","min"); | |
691 minimumEntry.addEventListener("change",this,false); | |
692 minimumEntry.value = this.option.min; | |
693 this.dynamic.appendChild(minimum); | |
694 | |
695 var maximum = document.createElement("div"); | |
696 var maximumEntry = document.createElement("input"); | |
697 var maximumText = document.createElement("span"); | |
698 maximumText.textContent = "Maximum: "; | |
699 maximum.appendChild(maximumText); | |
700 maximum.appendChild(maximumEntry); | |
701 maximumEntry.type = "number"; | |
702 maximumEntry.setAttribute("name","max"); | |
703 maximumEntry.addEventListener("change",this,false); | |
704 maximumEntry.value = this.option.max; | |
705 this.dynamic.appendChild(maximum); | |
655 break; | 706 break; |
707 case "checkbox": | |
708 case "radio": | |
709 this.dynamic.appendChild(id); | |
710 var optionHolder = document.createElement("div"); | |
711 optionHolder.className = 'node'; | |
712 optionHolder.id = 'popup-option-holder'; | |
713 var optionObject = function(parent,option) { | |
714 this.rootDOM = document.createElement("div"); | |
715 this.rootDOM.className = "popup-option-entry"; | |
716 this.inputName = document.createElement("input"); | |
717 this.inputName.setAttribute("name","name"); | |
718 this.inputLabel = document.createElement("input"); | |
719 this.inputLabel.setAttribute("name","text"); | |
720 this.specification = option; | |
721 this.parent = parent; | |
722 this.handleEvent = function() | |
723 { | |
724 var target = event.currentTarget.getAttribute("name"); | |
725 eval("this.specification."+target+" = event.currentTarget.value"); | |
726 }; | |
727 | |
728 var nameText = document.createElement("span"); | |
729 nameText.textContent = "Name: "; | |
730 var labelText = document.createElement("span"); | |
731 labelText.textContent = "Label: "; | |
732 this.rootDOM.appendChild(nameText); | |
733 this.rootDOM.appendChild(this.inputName); | |
734 this.rootDOM.appendChild(labelText); | |
735 this.rootDOM.appendChild(this.inputLabel); | |
736 this.inputName.addEventListener("change",this,false); | |
737 this.inputLabel.addEventListener("change",this,false); | |
738 this.inputName.value = this.specification.name; | |
739 this.inputLabel.value = this.specification.text; | |
740 | |
741 this.deleteEntry = { | |
742 root: document.createElement("button"), | |
743 parent: this, | |
744 handleEvent: function() { | |
745 document.getElementById("popup-option-holder").removeChild(this.parent.rootDOM); | |
746 var index = this.parent.parent.option.options.findIndex(function(element,index,array){ | |
747 if (element == this.parent.specification) | |
748 return true; | |
749 else | |
750 return false; | |
751 },this); | |
752 var optionList = this.parent.parent.option.options; | |
753 if (index == optionList.length-1) { | |
754 optionList = optionList.slice(0,index); | |
755 } else { | |
756 optionList = optionList.slice(0,index).concat(optionList.slice(index+1)); | |
757 } | |
758 this.parent.parent.option.options = optionList; | |
759 } | |
760 }; | |
761 this.deleteEntry.root.textContent = "Delete Option"; | |
762 this.deleteEntry.root.addEventListener("click",this.deleteEntry,false); | |
763 this.rootDOM.appendChild(this.deleteEntry.root); | |
764 } | |
765 for (var i=0; i<this.option.options.length; i++) | |
766 { | |
767 var obj = new optionObject(this,this.option.options[i]); | |
768 this.optionLists.push(obj); | |
769 optionHolder.appendChild(obj.rootDOM); | |
770 } | |
771 this.dynamic.appendChild(optionHolder); | |
656 } | 772 } |
657 } | 773 } |
658 this.handleEvent = function() | 774 this.handleEvent = function() |
659 { | 775 { |
660 var name = event.currentTarget.getAttribute("name"); | 776 var name = event.currentTarget.getAttribute("name"); |
678 break; | 794 break; |
679 } | 795 } |
680 } | 796 } |
681 this.continue = function() | 797 this.continue = function() |
682 { | 798 { |
683 var newNode = new this.parent.surveyEntryNode(this.parent,this.option); | 799 if (this.parent.type == "surveyNode") |
684 this.parent.children.push(newNode); | 800 { |
685 this.parent.childrenDOM.appendChild(newNode.rootDOM); | 801 var newNode = new this.parent.surveyEntryNode(this.parent,this.option); |
802 this.parent.children.push(newNode); | |
803 this.parent.childrenDOM.appendChild(newNode.rootDOM); | |
804 } else if (this.parent.type == "surveyEntryNode") { | |
805 this.parent.build(); | |
806 } | |
686 popupObject.hide(); | 807 popupObject.hide(); |
687 } | 808 } |
688 } | 809 } |
689 } | 810 } |
690 } | 811 } |
700 this.pages = []; | 821 this.pages = []; |
701 | 822 |
702 // Self-contained generators | 823 // Self-contained generators |
703 this.createGeneralNodeDOM = function(name,id,parent) | 824 this.createGeneralNodeDOM = function(name,id,parent) |
704 { | 825 { |
826 this.type = name; | |
705 var root = document.createElement('div'); | 827 var root = document.createElement('div'); |
706 root.id = id; | 828 root.id = id; |
707 root.className = "node"; | 829 root.className = "node"; |
708 | 830 |
709 var titleDiv = document.createElement('div'); | 831 var titleDiv = document.createElement('div'); |
1005 } | 1127 } |
1006 } | 1128 } |
1007 | 1129 |
1008 this.interfaceNode = function(parent,rootObject) | 1130 this.interfaceNode = function(parent,rootObject) |
1009 { | 1131 { |
1132 this.type = "interfaceNode"; | |
1010 this.rootDOM; | 1133 this.rootDOM; |
1011 this.titleDOM; | 1134 this.titleDOM; |
1012 this.attributeDOM; | 1135 this.attributeDOM; |
1013 this.attributes = []; | 1136 this.attributes = []; |
1014 this.childrenDOM; | 1137 this.childrenDOM; |
1204 } | 1327 } |
1205 } | 1328 } |
1206 | 1329 |
1207 this.surveyNode = function(parent,rootObject,location) | 1330 this.surveyNode = function(parent,rootObject,location) |
1208 { | 1331 { |
1332 this.type = "surveyNode"; | |
1209 this.rootDOM = document.createElement("div"); | 1333 this.rootDOM = document.createElement("div"); |
1210 this.titleDOM = document.createElement("span"); | 1334 this.titleDOM = document.createElement("span"); |
1211 this.attributeDOM = document.createElement("div"); | 1335 this.attributeDOM = document.createElement("div"); |
1212 this.attributes = []; | 1336 this.attributes = []; |
1213 this.childrenDOM = document.createElement("div"); | 1337 this.childrenDOM = document.createElement("div"); |
1240 this.rootDOM.appendChild(this.childrenDOM); | 1364 this.rootDOM.appendChild(this.childrenDOM); |
1241 this.rootDOM.appendChild(this.buttonDOM); | 1365 this.rootDOM.appendChild(this.buttonDOM); |
1242 | 1366 |
1243 this.surveyEntryNode = function(parent,rootObject) | 1367 this.surveyEntryNode = function(parent,rootObject) |
1244 { | 1368 { |
1369 this.type = "surveyEntryNode"; | |
1245 this.rootDOM = document.createElement("div"); | 1370 this.rootDOM = document.createElement("div"); |
1246 this.titleDOM = document.createElement("span"); | 1371 this.titleDOM = document.createElement("span"); |
1247 this.attributeDOM = document.createElement("div"); | 1372 this.attributeDOM = document.createElement("div"); |
1248 this.attributes = []; | 1373 this.attributes = []; |
1249 this.childrenDOM = document.createElement("div"); | 1374 this.childrenDOM = document.createElement("div"); |
1251 this.buttonDOM = document.createElement("div"); | 1376 this.buttonDOM = document.createElement("div"); |
1252 this.parent = parent; | 1377 this.parent = parent; |
1253 this.specification = rootObject; | 1378 this.specification = rootObject; |
1254 this.schema = specification.schema.getAllElementsByName("surveyentry")[1]; | 1379 this.schema = specification.schema.getAllElementsByName("surveyentry")[1]; |
1255 | 1380 |
1256 this.rootDOM.id = id; | |
1257 this.rootDOM.className = "node"; | 1381 this.rootDOM.className = "node"; |
1258 this.rootDOM.style.minWidth = "50%"; | 1382 this.rootDOM.style.minWidth = "50%"; |
1259 | 1383 |
1260 var titleDiv = document.createElement('div'); | 1384 var titleDiv = document.createElement('div'); |
1261 titleDiv.className = "node-title"; | 1385 titleDiv.className = "node-title"; |
1269 this.rootDOM.appendChild(titleDiv); | 1393 this.rootDOM.appendChild(titleDiv); |
1270 this.rootDOM.appendChild(this.attributeDOM); | 1394 this.rootDOM.appendChild(this.attributeDOM); |
1271 this.rootDOM.appendChild(this.childrenDOM); | 1395 this.rootDOM.appendChild(this.childrenDOM); |
1272 this.rootDOM.appendChild(this.buttonDOM); | 1396 this.rootDOM.appendChild(this.buttonDOM); |
1273 | 1397 |
1274 var statement = {}; | 1398 this.build = function() |
1275 statement.rootDOM = document.createElement("div"); | 1399 { |
1276 statement.titleDOM = document.createElement("span"); | 1400 this.attributeDOM.innerHTML = null; |
1277 statement.titleDOM.textContent = "Statement/Question"; | 1401 this.childrenDOM.innerHTML = null; |
1278 statement.input = document.createElement("textarea"); | 1402 var statementRoot = document.createElement("div"); |
1279 statement.input.value = this.specification.statement; | 1403 var statement = document.createElement("span"); |
1280 statement.specification = this.specification; | 1404 statement.textContent = "Statement / Question: "+this.specification.statement; |
1281 statement.handleEvent = function() { | 1405 statementRoot.appendChild(statement); |
1282 this.specification.statement = this.input.value; | 1406 this.children.push(statementRoot); |
1283 } | 1407 this.childrenDOM.appendChild(statementRoot); |
1284 statement.input.addEventListener("change",statement,false); | 1408 switch(this.specification.type) |
1285 statement.rootDOM.appendChild(statement.titleDOM); | 1409 { |
1286 statement.rootDOM.appendChild(statement.input); | 1410 case "statement": |
1287 this.children.push(statement); | 1411 this.titleDOM.textContent = "Statement"; |
1288 this.childrenDOM.appendChild(statement.rootDOM); | 1412 break; |
1289 switch(this.specification.type) | 1413 case "question": |
1290 { | 1414 this.titleDOM.textContent = "Question"; |
1291 case "statement": | 1415 var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); |
1292 this.titleDOM.textContent = "Statement"; | 1416 var mandatory = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("mandatory")[0]); |
1293 this.rootDOM.removeChild(this.attributeDOM); | 1417 var boxsize = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("boxsize")[0]); |
1294 break; | 1418 this.attributeDOM.appendChild(id.holder); |
1295 case "question": | 1419 this.attributes.push(id); |
1296 this.titleDOM.textContent = "Question"; | 1420 this.attributeDOM.appendChild(mandatory.holder); |
1297 var id = convert.convertAttributeToDOM(this.specification.id,specification.schema.getAllElementsByName("id")[0]); | 1421 this.attributes.push(mandatory); |
1298 var mandatory = convert.convertAttributeToDOM(this.specification.mandatory,specification.schema.getAllElementsByName("mandatory")[0]); | 1422 this.attributeDOM.appendChild(boxsize.holder); |
1299 var boxsize = convert.convertAttributeToDOM(this.specification.mandatory,specification.schema.getAllElementsByName("boxsize")[0]); | 1423 this.attributes.push(boxsize); |
1300 this.attributeDOM.appendChild(id.holder); | 1424 break; |
1301 this.attributes.push(id); | 1425 case "number": |
1302 this.attributeDOM.appendChild(mandatory.holder); | 1426 this.titleDOM.textContent = "Number"; |
1303 this.attributes.push(mandatory); | 1427 var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); |
1304 this.attributeDOM.appendChild(boxsize.holder); | 1428 var mandatory = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("mandatory")[0]); |
1305 this.attributes.push(boxsize); | 1429 var min = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("min")[0]); |
1306 break; | 1430 var max = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("max")[0]); |
1307 case "checkbox": | 1431 this.attributeDOM.appendChild(id.holder); |
1308 this.titleDOM.textContent = "Checkbox"; | 1432 this.attributes.push(id); |
1309 var id = convert.convertAttributeToDOM(this.specification.id,specification.schema.getAllElementsByName("id")[0]); | 1433 this.attributeDOM.appendChild(min.holder); |
1310 this.attributeDOM.appendChild(id.holder); | 1434 this.attributes.push(min); |
1311 this.attributes.push(id); | 1435 this.attributeDOM.appendChild(max.holder); |
1312 case "radio": | 1436 this.attributes.push(max); |
1313 this.titleDOM.textContent = "Radio"; | 1437 break; |
1314 var id = convert.convertAttributeToDOM(this.specification.id,specification.schema.getAllElementsByName("id")[0]); | 1438 case "checkbox": |
1315 this.attributeDOM.appendChild(id.holder); | 1439 this.titleDOM.textContent = "Checkbox"; |
1316 this.attributes.push(id); | 1440 var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); |
1317 } | 1441 this.attributeDOM.appendChild(id.holder); |
1442 this.attributes.push(id); | |
1443 break; | |
1444 case "radio": | |
1445 this.titleDOM.textContent = "Radio"; | |
1446 var id = convert.convertAttributeToDOM(this.specification,specification.schema.getAllElementsByName("id")[0]); | |
1447 this.attributeDOM.appendChild(id.holder); | |
1448 this.attributes.push(id); | |
1449 break; | |
1450 } | |
1451 } | |
1452 this.build(); | |
1318 | 1453 |
1319 this.editNode = { | 1454 this.editNode = { |
1320 root: document.createElement("button"), | 1455 root: document.createElement("button"), |
1321 parent: this, | 1456 parent: this, |
1322 handleEvent: function() | 1457 handleEvent: function() |
1323 { | 1458 { |
1324 popupObject.show(); | 1459 popupObject.show(); |
1325 popupStateNodes.state[5].generate(this,this.parent); | 1460 popupStateNodes.state[5].generate(this.parent.specification,this.parent); |
1326 popupObject.postNode(popupStateNodes.state[5]); | 1461 popupObject.postNode(popupStateNodes.state[5]); |
1327 } | 1462 } |
1328 } | 1463 } |
1329 this.editNode.root.textContent = "Edit Entry"; | 1464 this.editNode.root.textContent = "Edit Entry"; |
1330 this.editNode.root.addEventListener("click",this.editNode,false); | 1465 this.editNode.root.addEventListener("click",this.editNode,false); |
1386 } | 1521 } |
1387 } | 1522 } |
1388 | 1523 |
1389 this.pageNode = function(parent,rootObject) | 1524 this.pageNode = function(parent,rootObject) |
1390 { | 1525 { |
1526 this.type = "pageNode"; | |
1391 this.rootDOM = document.createElement("div"); | 1527 this.rootDOM = document.createElement("div"); |
1392 this.titleDOM = document.createElement("span"); | 1528 this.titleDOM = document.createElement("span"); |
1393 this.attributeDOM = document.createElement("div"); | 1529 this.attributeDOM = document.createElement("div"); |
1394 this.attributes = []; | 1530 this.attributes = []; |
1395 this.childrenDOM = document.createElement("div"); | 1531 this.childrenDOM = document.createElement("div"); |
1463 | 1599 |
1464 this.interfaces = []; | 1600 this.interfaces = []; |
1465 | 1601 |
1466 this.audioElementNode = function(parent,rootObject) | 1602 this.audioElementNode = function(parent,rootObject) |
1467 { | 1603 { |
1604 this.type = "audioElementNode"; | |
1468 this.rootDOM = document.createElement("div"); | 1605 this.rootDOM = document.createElement("div"); |
1469 this.titleDOM = document.createElement("span"); | 1606 this.titleDOM = document.createElement("span"); |
1470 this.attributeDOM = document.createElement("div"); | 1607 this.attributeDOM = document.createElement("div"); |
1471 this.attributes = []; | 1608 this.attributes = []; |
1472 this.childrenDOM = document.createElement("div"); | 1609 this.childrenDOM = document.createElement("div"); |
1544 this.buttonDOM.appendChild(this.deleteNode.root); | 1681 this.buttonDOM.appendChild(this.deleteNode.root); |
1545 } | 1682 } |
1546 | 1683 |
1547 this.commentQuestionNode = function(parent,rootObject) | 1684 this.commentQuestionNode = function(parent,rootObject) |
1548 { | 1685 { |
1686 this.type = "commentQuestionNode"; | |
1549 this.rootDOM = document.createElement("div"); | 1687 this.rootDOM = document.createElement("div"); |
1550 this.titleDOM = document.createElement("span"); | 1688 this.titleDOM = document.createElement("span"); |
1551 this.attributeDOM = document.createElement("div"); | 1689 this.attributeDOM = document.createElement("div"); |
1552 this.attributes = []; | 1690 this.attributes = []; |
1553 this.childrenDOM = document.createElement("div"); | 1691 this.childrenDOM = document.createElement("div"); |