comparison test_create/test_create.html @ 1755:186651a48582

Create_test: Submit button exposes completed XML file.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 03 Jun 2015 12:15:14 +0100
parents bd697e53d942
children e103d40537b5
comparison
equal deleted inserted replaced
1754:bd697e53d942 1755:186651a48582
61 } 61 }
62 62
63 function buttonClickedSubmit() { 63 function buttonClickedSubmit() {
64 var ready = validate(); 64 var ready = validate();
65 if (ready == true) { 65 if (ready == true) {
66 var xmlDoc = document.createElement('BrowserEvalProjectDocument'); 66 var xmlDoc = buildXML();
67 var setup = document.createElement('setup'); 67 var inject = document.getElementById('errorMessage');
68 setup.setAttribute('interface',document.getElementById('interface').value); 68 createProjectSave(xmlDoc, inject);
69 if (document.getElementById('projectReturn').value == "") { 69 }
70 setup.setAttribute('projectReturn',"null"); 70 }
71 } else { 71
72 setup.setAttribute('projectReturn',document.getElementById('projectReturn').value); 72 function createProjectSave(xmlDoc, injectPoint) {
73 } 73 var parent = document.createElement("div");
74 setup.setAttribute('randomiseOrder',document.getElementById('randomisePageOrder').checked); 74 parent.appendChild(xmlDoc);
75 setup.setAttribute('collectMetrics',document.getElementById('collectMetrics').checked); 75 var file = [parent.innerHTML];
76 var bb = new Blob(file,{type : 'application/xml'});
77 var dnlk = window.URL.createObjectURL(bb);
78 var a = document.createElement("a");
79 a.hidden = '';
80 a.href = dnlk;
81 a.download = "save.xml";
82 a.textContent = "Save File";
83 injectPoint.appendChild(a);
84 }
85
86 function buildXML() {
87 var xmlDoc = document.createElement('BrowserEvalProjectDocument');
88 var setup = document.createElement('setup');
89 setup.setAttribute('interface',document.getElementById('interface').value);
90 if (document.getElementById('projectReturn').value == "") {
91 setup.setAttribute('projectReturn',"null");
92 } else {
93 setup.setAttribute('projectReturn',document.getElementById('projectReturn').value);
94 }
95 setup.setAttribute('randomiseOrder',document.getElementById('randomisePageOrder').checked);
96 setup.setAttribute('collectMetrics',document.getElementById('collectMetrics').checked);
97
98 var globalPreTest = document.createElement('preTest');
99 var options = document.getElementById('globalPreTest').getElementsByClassName('head');
100 constructPrePost(globalPreTest, options);
101
102 var globalPostTest = document.createElement('postTest');
103 options = document.getElementById('globalPostTest').getElementsByClassName('head');
104 constructPrePost(globalPostTest, options);
105
106 var globalMetrics = document.createElement('metric');
107 options = document.getElementById('globalMetric').getElementsByClassName('attrib')[0].getElementsByTagName('input');
108 for (var i=0; i<options.length; i++) {
109 if (options[i].checked) {
110 var metric = document.createElement('metricEnable');
111 metric.textContent = options[i].id;
112 globalMetrics.appendChild(metric);
113 }
114 }
115 setup.appendChild(globalPreTest);
116 setup.appendChild(globalPostTest);
117 setup.appendChild(globalMetrics);
118 xmlDoc.appendChild(setup);
119
120 var audioHolders = document.getElementsByName('audio-holder');
121 for (var i=0; i<audioHolders.length; i++) {
122 var audioHolder = document.createElement('audioHolder');
123 var audioHolderDOM = audioHolders[i];
124 var attribs = audioHolderDOM.getElementsByClassName('attrib')[0].getElementsByTagName('input');
125 audioHolder.id = attribs[0].value;
126 if (attribs[1].value != "") {audioHolder.setAttribute('sampleRate',attribs[1].value);}
127 if (attribs[2].value != "") {audioHolder.setAttribute('hostURL',attribs[2].value);}
128 audioHolder.setAttribute('randomiseOrder',attribs[3].checked);
129 audioHolder.setAttribute('repeatCount',attribs[4].checked);
130 audioHolder.setAttribute('loop',attribs[5].checked);
131 audioHolder.setAttribute('elementComments',attribs[6].checked);
76 132
77 var globalPreTest = document.createElement('preTest'); 133 // Audio-Holder PreTests
78 var options = document.getElementById('globalPreTest').getElementsByClassName('head'); 134 var audioHolderPreTest = document.createElement('preTest');
79 constructPrePost(globalPreTest, options); 135 var audioHolderPostTest = document.createElement('postTest');
136 options = audioHolderDOM.childNodes[2].getElementsByClassName('head');
137 constructPrePost(audioHolderPreTest, options);
138 options = audioHolderDOM.childNodes[3].getElementsByClassName('head');
139 constructPrePost(audioHolderPostTest, options);
80 140
81 var globalPostTest = document.createElement('postTest'); 141 audioHolder.appendChild(audioHolderPreTest);
82 options = document.getElementById('globalPostTest').getElementsByClassName('head'); 142 audioHolder.appendChild(audioHolderPostTest);
83 constructPrePost(globalPostTest, options);
84 143
85 var globalMetrics = document.createElement('metric'); 144 // audio-Elements
86 options = document.getElementById('globalMetric').getElementsByClassName('attrib')[0].getElementsByTagName('input'); 145 var audioElementsDOM = [];
87 for (var i=0; i<options.length; i++) { 146 var commentQuestionDOM = [];
88 if (options[i].checked) { 147 for (var j=0; j<audioHolderDOM.childElementCount; j++) {
89 var metric = document.createElement('metricEnable'); 148 var child = audioHolderDOM.childNodes[j];
90 metric.textContent = options[i].id; 149 var name = child.getAttribute('name');
91 globalMetrics.appendChild(metric); 150 if (name == 'audio-element') {audioElementsDOM.push(child);}
92 } 151 else if (name == 'comment-question') {commentQuestionDOM.push(child);}
93 } 152 }
94 setup.appendChild(globalPreTest);
95 setup.appendChild(globalPostTest);
96 setup.appendChild(globalMetrics);
97 xmlDoc.appendChild(setup);
98 153
99 var audioHolders = document.getElementsByName('audio-holder'); 154 for (var j=0; j<audioElementsDOM.length; j++) {
100 for (var i=0; i<audioHolders.length; i++) { 155 var audioElement = document.createElement('audioElement');
101 var audioHolder = document.createElement('audioHolder'); 156 attribs = audioElementsDOM[j].getElementsByClassName('attrib')[0].getElementsByTagName('input');
102 var audioHolderDOM = audioHolders[i]; 157 audioElement.id = attribs[0].value;
103 var attribs = audioHolderDOM.getElementsByClassName('attrib')[0].getElementsByTagName('input'); 158 audioElement.setAttribute('url',attribs[1].value);
104 audioHolder.id = attribs[0].value; 159 audioHolder.appendChild(audioElement);
105 if (attribs[1].value != "") {audioHolder.setAttribute('sampleRate',attribs[1].value);} 160 }
106 if (attribs[2].value != "") {audioHolder.setAttribute('hostURL',attribs[2].value);} 161
107 audioHolder.setAttribute('randomiseOrder',attribs[3].checked); 162 for (var j=0; j<commentQuestionDOM.length; j++) {
108 audioHolder.setAttribute('repeatCount',attribs[4].checked); 163 var commentQuestion = document.createElement('commentQuestion');
109 audioHolder.setAttribute('loop',attribs[5].checked); 164 attribs = commentQuestionDOM[j].getElementsByClassName('attrib')[0].getElementsByTagName('input');
110 audioHolder.setAttribute('elementComments',attribs[6].checked); 165 commentQuestion.id = attribs[0].value;
111 166 commentQuestion.textContent = attribs[1].value;
112 // Audio-Holder PreTests 167 audioHolder.appendChild(commentQuestion);
113 var audioHolderPreTest = document.createElement('preTest'); 168 }
114 var audioHolderPostTest = document.createElement('postTest'); 169 xmlDoc.appendChild(audioHolder);
115 options = audioHolderDOM.childNodes[2].getElementsByClassName('head'); 170 }
116 constructPrePost(audioHolderPreTest, options); 171 return xmlDoc;
117 options = audioHolderDOM.childNodes[3].getElementsByClassName('head');
118 constructPrePost(audioHolderPostTest, options);
119
120 audioHolder.appendChild(audioHolderPreTest);
121 audioHolder.appendChild(audioHolderPostTest);
122
123 // audio-Elements
124 var audioElementsDOM = [];
125 var commentQuestionDOM = [];
126 for (var j=0; j<audioHolderDOM.childElementCount; j++) {
127 var child = audioHolderDOM.childNodes[j];
128 var name = child.getAttribute('name');
129 if (name == 'audio-element') {audioElementsDOM.push(child);}
130 else if (name == 'comment-question') {commentQuestionDOM.push(child);}
131 }
132
133 for (var j=0; j<audioElementsDOM.length; j++) {
134 var audioElement = document.createElement('audioElement');
135 attribs = audioElementsDOM[j].getElementsByClassName('attrib')[0].getElementsByTagName('input');
136 audioElement.id = attribs[0].value;
137 audioElement.setAttribute('url',attribs[1].value);
138 audioHolder.appendChild(audioElement);
139 }
140
141 for (var j=0; j<commentQuestionDOM.length; j++) {
142 var commentQuestion = document.createElement('commentQuestion');
143 attribs = commentQuestionDOM[j].getElementsByClassName('attrib')[0].getElementsByTagName('input');
144 commentQuestion.id = attribs[0].value;
145 commentQuestion.textContent = attribs[1].value;
146 audioHolder.appendChild(commentQuestion);
147 }
148 xmlDoc.appendChild(audioHolder);
149 }
150 return xmlDoc;
151 }
152 } 172 }
153 173
154 function constructPrePost(parent, options) { 174 function constructPrePost(parent, options) {
155 for (var i=0; i<options.length; i++) { 175 for (var i=0; i<options.length; i++) {
156 var elem = options[i]; 176 var elem = options[i];
435 </head> 455 </head>
436 456
437 <body> 457 <body>
438 <h1>Create Test Setup XML</h1> 458 <h1>Create Test Setup XML</h1>
439 <button id="validateXML" onclick="buttonClickedValidate();">Validate</button> 459 <button id="validateXML" onclick="buttonClickedValidate();">Validate</button>
440 <button id="createXML" onclick="buttonClickedValidate();" disabled>Submit</button> 460 <button id="createXML" onclick="buttonClickedSubmit();" disabled>Submit</button>
441 <span id="errorMessage" visibility="hidden"></span> 461 <span id="errorMessage" visibility="hidden"></span>
442 <div id="topLevelBody" align="left"> 462 <div id="topLevelBody" align="left">
443 <!-- Interface goes here --> 463 <!-- Interface goes here -->
444 <div name='test-setup'> 464 <div name='test-setup'>
445 <div id="setup" class="head"> 465 <div id="setup" class="head">