comparison test_create/test_create.html @ 839:07b89feada77

test_create: Exports to XML with instructions.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Thu, 03 Dec 2015 16:58:56 +0000
parents 0920172d9478
children c17f3713fe56
comparison
equal deleted inserted replaced
838:0920172d9478 839:07b89feada77
1702 this.audioHolders.push(aH[i]); 1702 this.audioHolders.push(aH[i]);
1703 } 1703 }
1704 } 1704 }
1705 }; 1705 };
1706 1706
1707 this.encode = function()
1708 {
1709 var root = document.createElement("BrowserEvalProjectDocument");
1710 // First get all the <setup> tag compiled
1711 var setupNode = document.createElement("setup");
1712 setupNode.setAttribute('interface',this.interfaceType);
1713 setupNode.setAttribute('projectReturn',this.projectReturn);
1714 setupNode.setAttribute('randomiseOrder',this.randomiseOrder);
1715 setupNode.setAttribute('collectMetrics',this.collectMetrics);
1716 setupNode.setAttribute('testPages',this.testPages);
1717
1718 var setupPreTest = document.createElement("PreTest");
1719 for (var i=0; i<this.preTest.options.length; i++)
1720 {
1721 setupPreTest.appendChild(this.preTest.options.exportXML());
1722 }
1723
1724 var setupPostTest = document.createElement("PostTest");
1725 for (var i=0; i<this.preTest.options.length; i++)
1726 {
1727 setupPostTest.appendChild(this.postTest.options.exportXML());
1728 }
1729
1730 setupNode.appendChild(setupPreTest);
1731 setupNode.appendChild(setupPostTest);
1732
1733 // <Metric> tag
1734 var Metric = document.createElement("Metric");
1735 for (var i=0; i<this.metrics.length; i++)
1736 {
1737 var metricEnable = document.createElement("metricEnable");
1738 metricEnable.textContent = this.metrics[i].enabled;
1739 Metric.appendChild(metricEnable);
1740 }
1741 setupNode.appendChild(Metric);
1742
1743 // <interface> tag
1744 var CommonInterface = document.createElement("interface");
1745 for (var i=0; i<this.commonInterface.options.length; i++)
1746 {
1747 var CIObj = this.commonInterface.options[i];
1748 var CINode = document.createElement(CIObj.type);
1749 if (CIObj.type == "check") {CINode.setAttribute("name",CIObj.check);}
1750 else {CINode.setAttribute("name",CIObj.name);}
1751 CommonInterface.appendChild(CINode);
1752 }
1753 setupNode.appendChild(CommonInterface);
1754
1755 root.appendChild(setupNode);
1756 // Time for the <audioHolder> tags
1757 for (var ahIndex = 0; ahIndex < this.audioHolders.length; ahIndex++)
1758 {
1759 var AHObj = this.audioHolders[ahIndex];
1760 var AHNode = document.createElement("audioHolder");
1761 AHNode.id = AHObj.id;
1762 AHNode.setAttribute("hostURL",AHObj.hostURL);
1763 AHNode.setAttribute("sampleRate",AHObj.samplerate);
1764 AHNode.setAttribute("randomiseOrder",AHObj.randomiseOrder);
1765 AHNode.setAttribute("repeatCount",AHObj.repeatCount);
1766 AHNode.setAttribute("loop",AHObj.loop);
1767 AHNode.setAttribute("elementComments",AHObj.elementComments);
1768
1769 // Create <interface> tag
1770 for (var i=0; i<AHObj.interfaces.length; i++)
1771 {
1772 var AHObjInterface = AHObj.interfaces[i];
1773 var AHinterface = document.createElement("interface");
1774 if (AHObjInterface.title != undefined)
1775 {
1776 var title = document.createElement("title");
1777 title.textContent = AHObjInterface.title;
1778 AHinterface.appendChild(title);
1779 }
1780 for (var j=0; j<AHObjInterface.options.length; j++)
1781 {
1782 var CIObj = AHObjInterface.options[j];
1783 var CINode = document.createElement(CIObj.type);
1784 if (CIObj.type == "check") {CINode.setAttribute("name",CIObj.check);}
1785 else {CINode.setAttribute("name",CIObj.name);}
1786 AHinterface.appendChild(CINode);
1787 }
1788 if (AHObjInterface.scale != undefined)
1789 {
1790 for (var j=0; j<AHObjInterface.scale.length; j++)
1791 {
1792 var CIObj = AHObjInterface.scale[j];
1793 var CINode = document.createElement("scale");
1794 CINode.setAttribute("position",CIObj[0]);
1795 CINode.textContent = CIObj[1];
1796 AHinterface.appendChild(CINode);
1797 }
1798 }
1799 AHNode.appendChild(AHinterface);
1800 }
1801
1802 // Create <audioElements>
1803 for (var aeIndex = 0; aeIndex < AHObj.audioElements.length; aeIndex++)
1804 {
1805 var AEObj = AHObj.audioElements[aeIndex];
1806 var AENode = document.createElement("audioElements");
1807 AENode.id = AEObj.id;
1808 AENode.setAttribute("url",AEObj.url);
1809 AENode.setAttribute("type",AEObj.type);
1810 if (AEObj.marker != undefined && AEObj.enforce)
1811 {
1812 AENode.setAttribute("marker",AEObj.marker*100);
1813 }
1814 AHNode.appendChild(AENode);
1815 }
1816
1817 // Create <CommentQuestion>
1818 for (var i=0; i<AHObj.commentQuestions.length; i++)
1819 {
1820 AHNode.appendChild(AHObj.commentQuestions[i].exportXML());
1821 }
1822
1823 // Create <PreTest>
1824 var AHPreTest = document.createElement("PreTest");
1825 for (var i=0; i<AHObj.preTest.options.length; i++)
1826 {
1827 AHPreTest.appendChild(AHObj.preTest.options.exportXML());
1828 }
1829
1830 var AHPostTest = document.createElement("PostTest");
1831 for (var i=0; i<AHObj.preTest.options.length; i++)
1832 {
1833 AHPostTest.appendChild(AHObj.postTest.options.exportXML());
1834 }
1835 AHNode.appendChild(AHPreTest);
1836 AHNode.appendChild(AHPostTest);
1837 root.appendChild(AHNode);
1838 }
1839 return root;
1840 };
1841
1707 this.prepostNode = function(type) { 1842 this.prepostNode = function(type) {
1708 this.type = type; 1843 this.type = type;
1709 this.options = []; 1844 this.options = [];
1710 1845
1711 this.OptionNode = function() { 1846 this.OptionNode = function() {
1726 this.options = []; 1861 this.options = [];
1727 this.min = undefined; 1862 this.min = undefined;
1728 this.max = undefined; 1863 this.max = undefined;
1729 this.step = undefined; 1864 this.step = undefined;
1730 1865
1866 this.exportXML = function()
1867 {
1868 var node = document.createElement(this.type);
1869 switch(this.type)
1870 {
1871 case "statement":
1872 node.textContent = this.statement;
1873 break;
1874 case "question":
1875 node.id = this.id;
1876 node.setAttribute("mandatory",this.mandatory);
1877 node.setAttribute("boxsize",this.boxsize);
1878 node.textContent = this.question;
1879 break;
1880 case "number":
1881 node.id = this.id;
1882 node.setAttribute("mandatory",this.mandatory);
1883 node.setAttribute("min"), this.min;
1884 node.setAttribute("max"), this.max;
1885 node.setAttribute("step"), this.step;
1886 break;
1887 case "checkbox":
1888 node.id = this.id;
1889 var statement = document.createElement("statement");
1890 statement.textContent = this.statement;
1891 node.appendChild(statement);
1892 for (var i=0; i<this.options.length; i++)
1893 {
1894 var option = this.option[i];
1895 var optionNode = document.createElement("option");
1896 optionNode.id = option.id;
1897 optionNode.textContent = option.text;
1898 node.appendChild(option);
1899 }
1900 break;
1901 case "radio":
1902 node.id = this.id;
1903 var statement = document.createElement("statement");
1904 statement.textContent = this.statement;
1905 node.appendChild(statement);
1906 for (var i=0; i<this.options.length; i++)
1907 {
1908 var option = this.option[i];
1909 var optionNode = document.createElement("option");
1910 optionNode.setAttribute("name") = option.name;
1911 optionNode.textContent = option.text;
1912 node.appendChild(option);
1913 }
1914 break;
1915 }
1916 return node;
1917 };
1731 }; 1918 };
1732 }; 1919 };
1733 1920
1734 this.metricNode = function(name) { 1921 this.metricNode = function(name) {
1735 this.enabled = name; 1922 this.enabled = name;
1774 1961
1775 this.marker = undefined; 1962 this.marker = undefined;
1776 }; 1963 };
1777 1964
1778 this.commentQuestionNode = function(xml) { 1965 this.commentQuestionNode = function(xml) {
1966 this.exportXML = function()
1967 {
1968 var CQNode = document.createElement("CommentQuestion");
1969 CQNode.id = this.id;
1970 CQNode.setAttribute("type",this.type);
1971 switch(this.type)
1972 {
1973 case "text":
1974 CQNode.textContent = this.question;
1975 break;
1976 case "radio" || "checkbox":
1977 var statement = document.createElement("statement");
1978 statement.textContent = this.statement;
1979 CQNode.appendChild(statement);
1980 for (var i=0; i<this.options.length; i++)
1981 {
1982 var optionNode = document.createElement("option");
1983 optionNode.setAttribute("name",this.options[i].name);
1984 optionNode.textContent = this.options[i].text;
1985 CQNode.appendChild(optionNode);
1986 }
1987 break;
1988 }
1989 return CQNode;
1990 };
1779 this.childOption = function(element) { 1991 this.childOption = function(element) {
1780 this.type = 'option'; 1992 this.type = 'option';
1781 this.name = element.getAttribute('name'); 1993 this.name = element.getAttribute('name');
1782 this.text = element.textContent; 1994 this.text = element.textContent;
1783 }; 1995 };
2392 break; 2604 break;
2393 } 2605 }
2394 return holder; 2606 return holder;
2395 } 2607 }
2396 } 2608 }
2609 function exportToXML()
2610 {
2611 var xmlDoc = specificationNode.encode();
2612 var parent = document.createElement("div");
2613 parent.appendChild(xmlDoc);
2614 var file = [parent.innerHTML];
2615 var bb = new Blob(file,{type : 'application/xml'});
2616 var dnlk = window.URL.createObjectURL(bb);
2617 var a = document.createElement("a");
2618 a.hidden = '';
2619 a.href = dnlk;
2620 a.download = "save.xml";
2621 a.textContent = "Save File";
2622
2623 popupInstance.showPopup();
2624 popupInstance.popupBody.innerHTML = null;
2625 var body = document.createElement("span");
2626 body.textContent = "Right click and save the file using the link below. Place this file in your WAET directory as 'project.xml' in the example_eval/ directory. Place your media files in the location specified by the Host URL entries. If you wish to review this XML or edit it, refresh this tool and drag your XML document into the page on the welcome screen.";
2627 popupInstance.popupBody.appendChild(body);
2628 popupInstance.popupBody.appendChild(a);
2629 popupInstance.popupTitle.innerHTML = "<span>Thank You</span>";
2630 }
2397 </script> 2631 </script>
2398 <style> 2632 <style>
2399 div.popup { 2633 div.popup {
2400 width: 500px; 2634 width: 500px;
2401 position: absolute; 2635 position: absolute;