comparison core.js @ 1406:a2a0a3a6f36d

Specification Node is same across project.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Mon, 07 Dec 2015 09:47:26 +0000
parents 3b9f0bc523d6
children d2a83474a967
comparison
equal deleted inserted replaced
1405:a9f1b91b6335 1406:a2a0a3a6f36d
555 555
556 var parse = new DOMParser(); 556 var parse = new DOMParser();
557 projectXML = parse.parseFromString(response,'text/xml'); 557 projectXML = parse.parseFromString(response,'text/xml');
558 558
559 // Build the specification 559 // Build the specification
560 specification.decode(); 560 specification.decode(projectXML);
561 561
562 testState.stateMap.push(specification.preTest); 562 testState.stateMap.push(specification.preTest);
563 563
564 $(specification.audioHolders).each(function(index,elem){ 564 $(specification.audioHolders).each(function(index,elem){
565 testState.stateMap.push(elem); 565 testState.stateMap.push(elem);
1310 1310
1311 function Specification() { 1311 function Specification() {
1312 // Handles the decoding of the project specification XML into a simple JavaScript Object. 1312 // Handles the decoding of the project specification XML into a simple JavaScript Object.
1313 1313
1314 this.interfaceType = null; 1314 this.interfaceType = null;
1315 this.commonInterface = null; 1315 this.commonInterface = new function()
1316 {
1317 this.options = [];
1318 this.optionNode = function(input)
1319 {
1320 var name = input.getAttribute('name');
1321 this.type = name;
1322 if(this.type == "option")
1323 {
1324 this.name = input.id;
1325 } else if (this.type == "check")
1326 {
1327 this.check = input.id;
1328 }
1329 };
1330 };
1316 this.projectReturn = null; 1331 this.projectReturn = null;
1317 this.randomiseOrder = null; 1332 this.randomiseOrder = null;
1318 this.collectMetrics = null; 1333 this.collectMetrics = null;
1319 this.testPages = null; 1334 this.testPages = null;
1320 this.preTest = null;
1321 this.postTest = null;
1322 this.metrics =[];
1323
1324 this.audioHolders = []; 1335 this.audioHolders = [];
1325 1336 this.metrics = [];
1326 this.decode = function() { 1337
1338 this.decode = function(projectXML) {
1327 // projectXML - DOM Parsed document 1339 // projectXML - DOM Parsed document
1328 this.projectXML = projectXML.childNodes[0]; 1340 this.projectXML = projectXML.childNodes[0];
1329 var setupNode = projectXML.getElementsByTagName('setup')[0]; 1341 var setupNode = projectXML.getElementsByTagName('setup')[0];
1330 this.interfaceType = setupNode.getAttribute('interface'); 1342 this.interfaceType = setupNode.getAttribute('interface');
1331 this.projectReturn = setupNode.getAttribute('projectReturn'); 1343 this.projectReturn = setupNode.getAttribute('projectReturn');
1343 this.testPages = Number(this.testPages); 1355 this.testPages = Number(this.testPages);
1344 if (this.testPages == 0) {this.testPages = null;} 1356 if (this.testPages == 0) {this.testPages = null;}
1345 } 1357 }
1346 var metricCollection = setupNode.getElementsByTagName('Metric'); 1358 var metricCollection = setupNode.getElementsByTagName('Metric');
1347 1359
1348 this.preTest = new this.prepostNode('pretest',setupNode.getElementsByTagName('PreTest')); 1360 var setupPreTestNode = setupNode.getElementsByTagName('PreTest');
1349 this.postTest = new this.prepostNode('posttest',setupNode.getElementsByTagName('PostTest')); 1361 if (setupPreTestNode.length != 0)
1362 {
1363 setupPreTestNode = setupPreTestNode[0];
1364 this.preTest.construct(setupPreTestNode);
1365 }
1366
1367 var setupPostTestNode = setupNode.getElementsByTagName('PostTest');
1368 if (setupPostTestNode.length != 0)
1369 {
1370 setupPostTestNode = setupPostTestNode[0];
1371 this.postTest.construct(setupPostTestNode);
1372 }
1350 1373
1351 if (metricCollection.length > 0) { 1374 if (metricCollection.length > 0) {
1352 metricCollection = metricCollection[0].getElementsByTagName('metricEnable'); 1375 metricCollection = metricCollection[0].getElementsByTagName('metricEnable');
1353 for (var i=0; i<metricCollection.length; i++) { 1376 for (var i=0; i<metricCollection.length; i++) {
1354 this.metrics.push(new this.metricNode(metricCollection[i].textContent)); 1377 this.metrics.push(new this.metricNode(metricCollection[i].textContent));
1386 } else { 1409 } else {
1387 this.max = Number(this.max); 1410 this.max = Number(this.max);
1388 } 1411 }
1389 } 1412 }
1390 } else if (this.type == 'anchor' || this.type == 'reference') { 1413 } else if (this.type == 'anchor' || this.type == 'reference') {
1391 Console.log("WARNING: Anchor and Reference tags in the <interface> node are depricated"); 1414 this.value = Number(child.textContent);
1415 this.enforce = child.getAttribute('enforce');
1416 if (this.enforce == 'true') {this.enforce = true;}
1417 else {this.enforce = false;}
1392 } 1418 }
1393 }; 1419 };
1394 this.options = []; 1420 this.options = [];
1395 if (commonInterfaceNode != undefined) { 1421 if (commonInterfaceNode != undefined) {
1396 var child = commonInterfaceNode.firstElementChild; 1422 var child = commonInterfaceNode.firstElementChild;
1401 } 1427 }
1402 }; 1428 };
1403 1429
1404 var audioHolders = projectXML.getElementsByTagName('audioHolder'); 1430 var audioHolders = projectXML.getElementsByTagName('audioHolder');
1405 for (var i=0; i<audioHolders.length; i++) { 1431 for (var i=0; i<audioHolders.length; i++) {
1406 this.audioHolders.push(new this.audioHolderNode(this,audioHolders[i])); 1432 var node = new this.audioHolderNode(this);
1433 node.decode(this,audioHolders[i]);
1434 this.audioHolders.push(node);
1407 } 1435 }
1408 1436
1409 // New check if we need to randomise the test order 1437 // New check if we need to randomise the test order
1410 if (this.randomiseOrder) 1438 if (this.randomiseOrder)
1411 { 1439 {
1430 this.audioHolders.push(aH[i]); 1458 this.audioHolders.push(aH[i]);
1431 } 1459 }
1432 } 1460 }
1433 }; 1461 };
1434 1462
1435 this.prepostNode = function(type,Collection) { 1463 this.encode = function()
1464 {
1465 var root = document.implementation.createDocument(null,"BrowserEvalProjectDocument");
1466 // First get all the <setup> tag compiled
1467 var setupNode = root.createElement("setup");
1468 setupNode.setAttribute('interface',this.interfaceType);
1469 setupNode.setAttribute('projectReturn',this.projectReturn);
1470 setupNode.setAttribute('randomiseOrder',this.randomiseOrder);
1471 setupNode.setAttribute('collectMetrics',this.collectMetrics);
1472 setupNode.setAttribute('testPages',this.testPages);
1473
1474 var setupPreTest = root.createElement("PreTest");
1475 for (var i=0; i<this.preTest.options.length; i++)
1476 {
1477 setupPreTest.appendChild(this.preTest.options[i].exportXML(root));
1478 }
1479
1480 var setupPostTest = root.createElement("PostTest");
1481 for (var i=0; i<this.postTest.options.length; i++)
1482 {
1483 setupPostTest.appendChild(this.postTest.options[i].exportXML(root));
1484 }
1485
1486 setupNode.appendChild(setupPreTest);
1487 setupNode.appendChild(setupPostTest);
1488
1489 // <Metric> tag
1490 var Metric = root.createElement("Metric");
1491 for (var i=0; i<this.metrics.length; i++)
1492 {
1493 var metricEnable = root.createElement("metricEnable");
1494 metricEnable.textContent = this.metrics[i].enabled;
1495 Metric.appendChild(metricEnable);
1496 }
1497 setupNode.appendChild(Metric);
1498
1499 // <interface> tag
1500 var CommonInterface = root.createElement("interface");
1501 for (var i=0; i<this.commonInterface.options.length; i++)
1502 {
1503 var CIObj = this.commonInterface.options[i];
1504 var CINode = root.createElement(CIObj.type);
1505 if (CIObj.type == "check") {CINode.setAttribute("name",CIObj.check);}
1506 else {CINode.setAttribute("name",CIObj.name);}
1507 CommonInterface.appendChild(CINode);
1508 }
1509 setupNode.appendChild(CommonInterface);
1510
1511 root.getElementsByTagName("BrowserEvalProjectDocument")[0].appendChild(setupNode);
1512 // Time for the <audioHolder> tags
1513 for (var ahIndex = 0; ahIndex < this.audioHolders.length; ahIndex++)
1514 {
1515 var node = this.audioHolders[ahIndex].encode(root);
1516 root.getElementsByTagName("BrowserEvalProjectDocument")[0].appendChild(node);
1517 }
1518 return root;
1519 };
1520
1521 this.prepostNode = function(type) {
1436 this.type = type; 1522 this.type = type;
1437 this.options = []; 1523 this.options = [];
1438 1524
1439 this.OptionNode = function(child) { 1525 this.OptionNode = function() {
1440 1526
1441 this.childOption = function(element) { 1527 this.childOption = function() {
1442 this.type = 'option'; 1528 this.type = 'option';
1443 this.id = element.id; 1529 this.id = null;
1444 this.name = element.getAttribute('name'); 1530 this.name = undefined;
1445 this.text = element.textContent; 1531 this.text = null;
1446 }; 1532 };
1447 1533
1448 this.type = child.nodeName; 1534 this.type = undefined;
1449 if (child.nodeName == "question") { 1535 this.id = undefined;
1450 this.id = child.id; 1536 this.mandatory = undefined;
1451 this.mandatory; 1537 this.question = undefined;
1452 if (child.getAttribute('mandatory') == "true") {this.mandatory = true;} 1538 this.statement = undefined;
1453 else {this.mandatory = false;} 1539 this.boxsize = undefined;
1454 this.question = child.textContent; 1540 this.options = [];
1455 if (child.getAttribute('boxsize') == null) { 1541 this.min = undefined;
1456 this.boxsize = 'normal'; 1542 this.max = undefined;
1457 } else { 1543 this.step = undefined;
1458 this.boxsize = child.getAttribute('boxsize'); 1544
1459 } 1545 this.decode = function(child)
1460 } else if (child.nodeName == "statement") { 1546 {
1461 this.statement = child.textContent; 1547 this.type = child.nodeName;
1462 } else if (child.nodeName == "checkbox" || child.nodeName == "radio") { 1548 if (child.nodeName == "question") {
1463 var element = child.firstElementChild; 1549 this.id = child.id;
1464 this.id = child.id; 1550 this.mandatory;
1465 if (element == null) { 1551 if (child.getAttribute('mandatory') == "true") {this.mandatory = true;}
1466 console.log('Malformed' +child.nodeName+ 'entry'); 1552 else {this.mandatory = false;}
1467 this.statement = 'Malformed' +child.nodeName+ 'entry'; 1553 this.question = child.textContent;
1468 this.type = 'statement'; 1554 if (child.getAttribute('boxsize') == null) {
1469 } else { 1555 this.boxsize = 'normal';
1470 this.options = []; 1556 } else {
1471 while (element != null) { 1557 this.boxsize = child.getAttribute('boxsize');
1472 if (element.nodeName == 'statement' && this.statement == undefined){ 1558 }
1473 this.statement = element.textContent; 1559 } else if (child.nodeName == "statement") {
1474 } else if (element.nodeName == 'option') { 1560 this.statement = child.textContent;
1475 this.options.push(new this.childOption(element)); 1561 } else if (child.nodeName == "checkbox" || child.nodeName == "radio") {
1562 var element = child.firstElementChild;
1563 this.id = child.id;
1564 if (element == null) {
1565 console.log('Malformed' +child.nodeName+ 'entry');
1566 this.statement = 'Malformed' +child.nodeName+ 'entry';
1567 this.type = 'statement';
1568 } else {
1569 this.options = [];
1570 while (element != null) {
1571 if (element.nodeName == 'statement' && this.statement == undefined){
1572 this.statement = element.textContent;
1573 } else if (element.nodeName == 'option') {
1574 var node = new this.childOption();
1575 node.id = element.id;
1576 node.name = element.getAttribute('name');
1577 node.text = element.textContent;
1578 this.options.push(node);
1579 }
1580 element = element.nextElementSibling;
1476 } 1581 }
1477 element = element.nextElementSibling;
1478 } 1582 }
1479 } 1583 } else if (child.nodeName == "number") {
1480 } else if (child.nodeName == "number") { 1584 this.statement = child.textContent;
1481 this.statement = child.textContent; 1585 this.id = child.id;
1482 this.id = child.id; 1586 this.min = child.getAttribute('min');
1483 this.min = child.getAttribute('min'); 1587 this.max = child.getAttribute('max');
1484 this.max = child.getAttribute('max'); 1588 this.step = child.getAttribute('step');
1485 this.step = child.getAttribute('step'); 1589 }
1486 } 1590 };
1591
1592 this.exportXML = function(root)
1593 {
1594 var node = root.createElement(this.type);
1595 switch(this.type)
1596 {
1597 case "statement":
1598 node.textContent = this.statement;
1599 break;
1600 case "question":
1601 node.id = this.id;
1602 node.setAttribute("mandatory",this.mandatory);
1603 node.setAttribute("boxsize",this.boxsize);
1604 node.textContent = this.question;
1605 break;
1606 case "number":
1607 node.id = this.id;
1608 node.setAttribute("mandatory",this.mandatory);
1609 node.setAttribute("min", this.min);
1610 node.setAttribute("max", this.max);
1611 node.setAttribute("step", this.step);
1612 node.textContent = this.statement;
1613 break;
1614 case "checkbox":
1615 node.id = this.id;
1616 var statement = root.createElement("statement");
1617 statement.textContent = this.statement;
1618 node.appendChild(statement);
1619 for (var i=0; i<this.options.length; i++)
1620 {
1621 var option = this.options[i];
1622 var optionNode = root.createElement("option");
1623 optionNode.id = option.id;
1624 optionNode.textContent = option.text;
1625 node.appendChild(optionNode);
1626 }
1627 break;
1628 case "radio":
1629 node.id = this.id;
1630 var statement = root.createElement("statement");
1631 statement.textContent = this.statement;
1632 node.appendChild(statement);
1633 for (var i=0; i<this.options.length; i++)
1634 {
1635 var option = this.options[i];
1636 var optionNode = root.createElement("option");
1637 optionNode.setAttribute("name",option.name);
1638 optionNode.textContent = option.text;
1639 node.appendChild(optionNode);
1640 }
1641 break;
1642 }
1643 return node;
1644 };
1487 }; 1645 };
1488 1646 this.construct = function(Collection)
1489 // On construction: 1647 {
1490 if (Collection.length != 0) {
1491 Collection = Collection[0];
1492 if (Collection.childElementCount != 0) { 1648 if (Collection.childElementCount != 0) {
1493 var child = Collection.firstElementChild; 1649 var child = Collection.firstElementChild;
1494 this.options.push(new this.OptionNode(child)); 1650 var node = new this.OptionNode();
1651 node.decode(child);
1652 this.options.push(node);
1495 while (child.nextElementSibling != null) { 1653 while (child.nextElementSibling != null) {
1496 child = child.nextElementSibling; 1654 child = child.nextElementSibling;
1497 this.options.push(new this.OptionNode(child)); 1655 node = new this.OptionNode();
1498 } 1656 node.decode(child);
1499 } 1657 this.options.push(node);
1500 } 1658 }
1501 }; 1659 }
1660 };
1661 };
1662 this.preTest = new this.prepostNode("pretest");
1663 this.postTest = new this.prepostNode("posttest");
1502 1664
1503 this.metricNode = function(name) { 1665 this.metricNode = function(name) {
1504 this.enabled = name; 1666 this.enabled = name;
1505 }; 1667 };
1506 1668
1507 this.audioHolderNode = function(parent,xml) { 1669 this.audioHolderNode = function(parent) {
1508 this.type = 'audioHolder'; 1670 this.type = 'audioHolder';
1509 this.presentedId = parent.audioHolders.length; 1671 this.presentedId = undefined;
1510 this.interfaceNode = function(DOM) { 1672 this.id = undefined;
1511 var title = DOM.getElementsByTagName('title'); 1673 this.hostURL = undefined;
1512 if (title.length == 0) {this.title = null;} 1674 this.sampleRate = undefined;
1513 else {this.title = title[0].textContent;} 1675 this.randomiseOrder = undefined;
1514 this.options = parent.commonInterface.options; 1676 this.loop = undefined;
1515 var scale = DOM.getElementsByTagName('scale'); 1677 this.elementComments = undefined;
1678 this.outsideReference = null;
1679 this.preTest = new parent.prepostNode("pretest");
1680 this.postTest = new parent.prepostNode("pretest");
1681 this.interfaces = [];
1682 this.commentBoxPrefix = "Comment on track";
1683 this.audioElements = [];
1684 this.commentQuestions = [];
1685
1686 this.decode = function(parent,xml)
1687 {
1688 this.presentedId = parent.audioHolders.length;
1689 this.id = xml.id;
1690 this.hostURL = xml.getAttribute('hostURL');
1691 this.sampleRate = xml.getAttribute('sampleRate');
1692 if (xml.getAttribute('randomiseOrder') == "true") {this.randomiseOrder = true;}
1693 else {this.randomiseOrder = false;}
1694 this.repeatCount = xml.getAttribute('repeatCount');
1695 if (xml.getAttribute('loop') == 'true') {this.loop = true;}
1696 else {this.loop == false;}
1697 if (xml.getAttribute('elementComments') == "true") {this.elementComments = true;}
1698 else {this.elementComments = false;}
1699
1700 var setupPreTestNode = xml.getElementsByTagName('PreTest');
1701 if (setupPreTestNode.length != 0)
1702 {
1703 setupPreTestNode = setupPreTestNode[0];
1704 this.preTest.construct(setupPreTestNode);
1705 }
1706
1707 var setupPostTestNode = xml.getElementsByTagName('PostTest');
1708 if (setupPostTestNode.length != 0)
1709 {
1710 setupPostTestNode = setupPostTestNode[0];
1711 this.postTest.construct(setupPostTestNode);
1712 }
1713
1714 var interfaceDOM = xml.getElementsByTagName('interface');
1715 for (var i=0; i<interfaceDOM.length; i++) {
1716 var node = new this.interfaceNode();
1717 node.decode(interfaceDOM[i]);
1718 this.interfaces.push(node);
1719 }
1720 this.commentBoxPrefix = xml.getElementsByTagName('commentBoxPrefix');
1721 if (this.commentBoxPrefix.length != 0) {
1722 this.commentBoxPrefix = this.commentBoxPrefix[0].textContent;
1723 } else {
1724 this.commentBoxPrefix = "Comment on track";
1725 }
1726 var audioElementsDOM = xml.getElementsByTagName('audioElements');
1727 for (var i=0; i<audioElementsDOM.length; i++) {
1728 var node = new this.audioElementNode();
1729 node.decode(this,audioElementsDOM[i]);
1730 if (audioElementsDOM[i].getAttribute('type') == 'outsidereference') {
1731 if (this.outsideReference == null) {
1732 this.outsideReference = node;
1733 } else {
1734 console.log('Error only one audioelement can be of type outsidereference per audioholder');
1735 this.audioElements.push(node);
1736 console.log('Element id '+audioElementsDOM[i].id+' made into normal node');
1737 }
1738 } else {
1739 this.audioElements.push(node);
1740 }
1741 }
1742
1743 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
1744 for (var i=0; i<commentQuestionsDOM.length; i++) {
1745 var node = new this.commentQuestionNode();
1746 node.decode(commentQuestionsDOM[i]);
1747 this.commentQuestions.push(node);
1748 }
1749 };
1750
1751 this.encode = function(root)
1752 {
1753 var AHNode = root.createElement("audioHolder");
1754 AHNode.id = this.id;
1755 AHNode.setAttribute("hostURL",this.hostURL);
1756 AHNode.setAttribute("sampleRate",this.sampleRate);
1757 AHNode.setAttribute("randomiseOrder",this.randomiseOrder);
1758 AHNode.setAttribute("repeatCount",this.repeatCount);
1759 AHNode.setAttribute("loop",this.loop);
1760 AHNode.setAttribute("elementComments",this.elementComments);
1761
1762 for (var i=0; i<this.interfaces.length; i++)
1763 {
1764 AHNode.appendChild(this.interfaces[i].encode(root));
1765 }
1766
1767 for (var i=0; i<this.audioElements.length; i++) {
1768 AHNode.appendChild(this.audioElements[i].encode(root));
1769 }
1770 // Create <CommentQuestion>
1771 for (var i=0; i<this.commentQuestions.length; i++)
1772 {
1773 AHNode.appendChild(this.commentQuestions[i].exportXML(root));
1774 }
1775
1776 // Create <PreTest>
1777 var AHPreTest = root.createElement("PreTest");
1778 for (var i=0; i<this.preTest.options.length; i++)
1779 {
1780 AHPreTest.appendChild(this.preTest.options[i].exportXML(root));
1781 }
1782
1783 var AHPostTest = root.createElement("PostTest");
1784 for (var i=0; i<this.postTest.options.length; i++)
1785 {
1786 AHPostTest.appendChild(this.postTest.options[i].exportXML(root));
1787 }
1788 AHNode.appendChild(AHPreTest);
1789 AHNode.appendChild(AHPostTest);
1790 return AHNode;
1791 };
1792
1793 this.interfaceNode = function() {
1794 this.title = undefined;
1795 this.options = [];
1516 this.scale = []; 1796 this.scale = [];
1517 for (var i=0; i<scale.length; i++) { 1797 this.decode = function(DOM)
1518 var arr = [null, null]; 1798 {
1519 arr[0] = scale[i].getAttribute('position'); 1799 var title = DOM.getElementsByTagName('title');
1520 arr[1] = scale[i].textContent; 1800 if (title.length == 0) {this.title = null;}
1521 this.scale.push(arr); 1801 else {this.title = title[0].textContent;}
1522 } 1802 this.options = parent.commonInterface.options;
1803 var scale = DOM.getElementsByTagName('scale');
1804 this.scale = [];
1805 for (var i=0; i<scale.length; i++) {
1806 var arr = [null, null];
1807 arr[0] = scale[i].getAttribute('position');
1808 arr[1] = scale[i].textContent;
1809 this.scale.push(arr);
1810 }
1811 };
1812 this.encode = function(root)
1813 {
1814 var node = root.createElement("interface");
1815 if (this.title != undefined)
1816 {
1817 var title = root.createElement("title");
1818 title.textContent = this.title;
1819 node.appendChild(title);
1820 }
1821 for (var i=0; i<this.options.length; i++)
1822 {
1823 var optionNode = root.createElement(this.options[i].type);
1824 if (this.options[i].type == "option")
1825 {
1826 optionNode.setAttribute("name",this.options[i].name);
1827 } else if (this.options[i].type == "check") {
1828 optionNode.setAttribute("check",this.options[i].check);
1829 } else if (this.options[i].type == "scalerange") {
1830 optionNode.setAttribute("min",this.options[i].min*100);
1831 optionNode.setAttribute("max",this.options[i].max*100);
1832 }
1833 node.appendChild(optionNode);
1834 }
1835 for (var i=0; i<this.scale.length; i++) {
1836 var scale = root.createElement("scale");
1837 scale.setAttribute("position",this.scale[i][0]);
1838 scale.textContent = this.scale[i][1];
1839 node.appendChild(scale);
1840 }
1841 return node;
1842 };
1523 }; 1843 };
1524 1844
1525 this.audioElementNode = function(parent,xml) { 1845 this.audioElementNode = function() {
1526 this.url = xml.getAttribute('url'); 1846 this.url = null;
1527 this.id = xml.id; 1847 this.id = null;
1528 this.parent = parent; 1848 this.parent = null;
1529 this.type = xml.getAttribute('type'); 1849 this.type = "normal";
1530 if (this.type == null) {this.type = "normal";} 1850 this.marker = false;
1531 if (this.type == 'anchor') {this.anchor = true;} 1851 this.enforce = false;
1532 else {this.anchor = false;} 1852 this.decode = function(parent,xml)
1533 if (this.type == 'reference') {this.reference = true;} 1853 {
1534 else {this.reference = false;} 1854 this.url = xml.getAttribute('url');
1535 1855 this.id = xml.id;
1536 if (this.anchor == true || this.reference == true) 1856 this.parent = parent;
1537 { 1857 this.type = xml.getAttribute('type');
1538 this.marker = xml.getAttribute('marker'); 1858 if (this.type == null) {this.type = "normal";}
1539 if (this.marker != undefined) 1859 if (this.type == 'anchor') {this.anchor = true;}
1860 else {this.anchor = false;}
1861 if (this.type == 'reference') {this.reference = true;}
1862 else {this.reference = false;}
1863
1864 if (this.anchor == true || this.reference == true)
1540 { 1865 {
1541 this.marker = Number(this.marker); 1866 this.marker = xml.getAttribute('marker');
1542 if (isNaN(this.marker) == false) 1867 if (this.marker != undefined)
1543 { 1868 {
1544 if (this.marker > 1) 1869 this.marker = Number(this.marker);
1545 { this.marker /= 100.0;} 1870 if (isNaN(this.marker) == false)
1546 if (this.marker >= 0 && this.marker <= 1)
1547 { 1871 {
1548 this.enforce = true; 1872 if (this.marker > 1)
1549 return; 1873 { this.marker /= 100.0;}
1874 if (this.marker >= 0 && this.marker <= 1)
1875 {
1876 this.enforce = true;
1877 return;
1878 } else {
1879 console.log("ERROR - Marker of audioElement "+this.id+" is not between 0 and 1 (float) or 0 and 100 (integer)!");
1880 console.log("ERROR - Marker not enforced!");
1881 }
1550 } else { 1882 } else {
1551 console.log("ERROR - Marker of audioElement "+this.id+" is not between 0 and 1 (float) or 0 and 100 (integer)!"); 1883 console.log("ERROR - Marker of audioElement "+this.id+" is not a number!");
1552 console.log("ERROR - Marker not enforced!"); 1884 console.log("ERROR - Marker not enforced!");
1553 } 1885 }
1554 } else {
1555 console.log("ERROR - Marker of audioElement "+this.id+" is not a number!");
1556 console.log("ERROR - Marker not enforced!");
1557 } 1886 }
1558 } 1887 }
1559 } 1888 };
1560 this.marker = false; 1889 this.encode = function(root)
1561 this.enforce = false; 1890 {
1891 var AENode = root.createElement("audioElements");
1892 AENode.id = this.id;
1893 AENode.setAttribute("url",this.url);
1894 AENode.setAttribute("type",this.type);
1895 if (this.marker != false)
1896 {
1897 AENode.setAttribute("marker",this.marker*100);
1898 }
1899 return AENode;
1900 };
1562 }; 1901 };
1563 1902
1564 this.commentQuestionNode = function(xml) { 1903 this.commentQuestionNode = function(xml) {
1565 this.childOption = function(element) { 1904 this.id = null;
1905 this.type = undefined;
1906 this.question = undefined;
1907 this.options = [];
1908 this.statement = undefined;
1909
1910 this.childOption = function() {
1566 this.type = 'option'; 1911 this.type = 'option';
1567 this.name = element.getAttribute('name'); 1912 this.name = null;
1568 this.text = element.textContent; 1913 this.text = null;
1569 }; 1914 };
1570 this.id = xml.id; 1915 this.exportXML = function(root)
1571 if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;} 1916 {
1572 else {this.mandatory = false;} 1917 var CQNode = root.createElement("CommentQuestion");
1573 this.type = xml.getAttribute('type'); 1918 CQNode.id = this.id;
1574 if (this.type == undefined) {this.type = 'text';} 1919 CQNode.setAttribute("type",this.type);
1575 switch (this.type) { 1920 switch(this.type)
1576 case 'text': 1921 {
1577 this.question = xml.textContent; 1922 case "text":
1578 break; 1923 CQNode.textContent = this.question;
1579 case 'radio': 1924 break;
1580 var child = xml.firstElementChild; 1925 case "radio":
1581 this.options = []; 1926 var statement = root.createElement("statement");
1582 while (child != undefined) { 1927 statement.textContent = this.statement;
1583 if (child.nodeName == 'statement' && this.statement == undefined) { 1928 CQNode.appendChild(statement);
1584 this.statement = child.textContent; 1929 for (var i=0; i<this.options.length; i++)
1585 } else if (child.nodeName == 'option') { 1930 {
1586 this.options.push(new this.childOption(child)); 1931 var optionNode = root.createElement("option");
1932 optionNode.setAttribute("name",this.options[i].name);
1933 optionNode.textContent = this.options[i].text;
1934 CQNode.appendChild(optionNode);
1587 } 1935 }
1588 child = child.nextElementSibling; 1936 break;
1589 } 1937 case "checkbox":
1590 break; 1938 var statement = root.createElement("statement");
1591 case 'checkbox': 1939 statement.textContent = this.statement;
1592 var child = xml.firstElementChild; 1940 CQNode.appendChild(statement);
1593 this.options = []; 1941 for (var i=0; i<this.options.length; i++)
1594 while (child != undefined) { 1942 {
1595 if (child.nodeName == 'statement' && this.statement == undefined) { 1943 var optionNode = root.createElement("option");
1596 this.statement = child.textContent; 1944 optionNode.setAttribute("name",this.options[i].name);
1597 } else if (child.nodeName == 'option') { 1945 optionNode.textContent = this.options[i].text;
1598 this.options.push(new this.childOption(child)); 1946 CQNode.appendChild(optionNode);
1599 } 1947 }
1600 child = child.nextElementSibling; 1948 break;
1601 } 1949 }
1602 break; 1950 return CQNode;
1603 } 1951 };
1952 this.decode = function(xml) {
1953 this.id = xml.id;
1954 if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;}
1955 else {this.mandatory = false;}
1956 this.type = xml.getAttribute('type');
1957 if (this.type == undefined) {this.type = 'text';}
1958 switch (this.type) {
1959 case 'text':
1960 this.question = xml.textContent;
1961 break;
1962 case 'radio':
1963 var child = xml.firstElementChild;
1964 this.options = [];
1965 while (child != undefined) {
1966 if (child.nodeName == 'statement' && this.statement == undefined) {
1967 this.statement = child.textContent;
1968 } else if (child.nodeName == 'option') {
1969 var node = new this.childOption();
1970 node.name = child.getAttribute('name');
1971 node.text = child.textContent;
1972 this.options.push(node);
1973 }
1974 child = child.nextElementSibling;
1975 }
1976 break;
1977 case 'checkbox':
1978 var child = xml.firstElementChild;
1979 this.options = [];
1980 while (child != undefined) {
1981 if (child.nodeName == 'statement' && this.statement == undefined) {
1982 this.statement = child.textContent;
1983 } else if (child.nodeName == 'option') {
1984 var node = new this.childOption();
1985 node.name = child.getAttribute('name');
1986 node.text = child.textContent;
1987 this.options.push(node);
1988 }
1989 child = child.nextElementSibling;
1990 }
1991 break;
1992 }
1993 };
1604 }; 1994 };
1605
1606 this.id = xml.id;
1607 this.hostURL = xml.getAttribute('hostURL');
1608 this.sampleRate = xml.getAttribute('sampleRate');
1609 if (xml.getAttribute('randomiseOrder') == "true") {this.randomiseOrder = true;}
1610 else {this.randomiseOrder = false;}
1611 this.repeatCount = xml.getAttribute('repeatCount');
1612 if (xml.getAttribute('loop') == 'true') {this.loop = true;}
1613 else {this.loop == false;}
1614 if (xml.getAttribute('elementComments') == "true") {this.elementComments = true;}
1615 else {this.elementComments = false;}
1616
1617 this.preTest = new parent.prepostNode('pretest',xml.getElementsByTagName('PreTest'));
1618 this.postTest = new parent.prepostNode('posttest',xml.getElementsByTagName('PostTest'));
1619
1620 this.interfaces = [];
1621 var interfaceDOM = xml.getElementsByTagName('interface');
1622 for (var i=0; i<interfaceDOM.length; i++) {
1623 this.interfaces.push(new this.interfaceNode(interfaceDOM[i]));
1624 }
1625
1626 this.commentBoxPrefix = xml.getElementsByTagName('commentBoxPrefix');
1627 if (this.commentBoxPrefix.length != 0) {
1628 this.commentBoxPrefix = this.commentBoxPrefix[0].textContent;
1629 } else {
1630 this.commentBoxPrefix = "Comment on track";
1631 }
1632
1633 this.audioElements =[];
1634 var audioElementsDOM = xml.getElementsByTagName('audioElements');
1635 this.outsideReference = null;
1636 for (var i=0; i<audioElementsDOM.length; i++) {
1637 if (audioElementsDOM[i].getAttribute('type') == 'outsidereference') {
1638 if (this.outsideReference == null) {
1639 this.outsideReference = new this.audioElementNode(this,audioElementsDOM[i]);
1640 } else {
1641 console.log('Error only one audioelement can be of type outsidereference per audioholder');
1642 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i]));
1643 console.log('Element id '+audioElementsDOM[i].id+' made into normal node');
1644 }
1645 } else {
1646 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i]));
1647 }
1648 }
1649
1650 if (this.randomiseOrder) {
1651 this.audioElements = randomiseOrder(this.audioElements);
1652 }
1653
1654 this.commentQuestions = [];
1655 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
1656 for (var i=0; i<commentQuestionsDOM.length; i++) {
1657 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i]));
1658 }
1659 }; 1995 };
1660 } 1996 }
1661 1997
1662 function Interface(specificationObject) { 1998 function Interface(specificationObject) {
1663 // This handles the bindings between the interface and the audioEngineContext; 1999 // This handles the bindings between the interface and the audioEngineContext;
1664 this.specification = specificationObject; 2000 this.specification = specificationObject;
1665 this.insertPoint = document.getElementById("topLevelBody"); 2001 this.insertPoint = document.getElementById("topLevelBody");
1666 2002