comparison test_create/test_create.html @ 1594:155019bf86b5

create_test: Added crude validation tool.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Tue, 02 Jun 2015 12:24:19 +0100
parents cd5e9144ecb7
children 82baf45866fc
comparison
equal deleted inserted replaced
1593:59a8370a2e97 1594:155019bf86b5
22 var setup = document.createElement('div'); 22 var setup = document.createElement('div');
23 setup.id = 'setupTagDiv'; 23 setup.id = 'setupTagDiv';
24 24
25 }; 25 };
26 26
27 function attributePair(string, type){ 27 function attributePair(string, type, mandatory){
28 var id = document.createElement("span"); 28 var id = document.createElement("span");
29 id.textContent = string; 29 id.textContent = string;
30 var input = document.createElement("input"); 30 var input = document.createElement("input");
31 input.type = type; 31 input.type = type;
32 if (type == 'text') {
33 if (mandatory == true) {
34 input.setAttribute('mandatory','true');
35 }
36 else {
37 input.setAttribute('mandatory','false');
38 }
39 }
32 return [id, input]; 40 return [id, input];
33 } 41 }
34 42
35 function removeNode(event) { 43 function removeNode(event) {
36 event.srcElement.parentElement.parentElement.removeChild(event.srcElement.parentElement); 44 event.srcElement.parentElement.parentElement.removeChild(event.srcElement.parentElement);
45 }
46
47 function buttonClickedValidate() {
48 var ready = validate();
49 if (ready == false) {
50 var errMsg = document.getElementById('errorMessage');
51 errMsg.textContent = "There were some errors with your XML. Any input boxes highlighted in red are invalid because they are empty. Please fill these in correctly. Any boxes which are yellow are not-invalid but will use the default value.";
52 errMsg.style.visibility = 'visible';
53 document.getElementById('createXML').disabled = true;
54
55 } else {
56 var errMsg = document.getElementById('errorMessage');
57 errMsg.textContent = "";
58 errMsg.style.visiblity = 'hidden';
59 document.getElementById('createXML').disabled = false;
60 }
61 }
62
63 function validate() {
64 var canExport = true;
65 // Checks if the XML can be created from the given entries
66 var inputs = document.getElementsByTagName('input');
67 for (var i=0; i<inputs.length; i++) {
68 if (inputs[i].type == 'text') {
69 if (inputs[i].value == "") {
70 var mandatory = inputs[i].getAttribute('mandatory');
71 if (mandatory == "true") {
72 errorInput(inputs[i]);
73 canExport = false;
74 } else {
75 warningInput(inputs[i]);
76 }
77 } else {
78 goodInput(inputs[i]);
79 }
80 }
81 }
82 return canExport;
83 };
84
85 function errorInput(node) {
86 node.style.backgroundColor = "#FF0000";
87 }
88
89 function warningInput(node) {
90 node.style.backgroundColor = "#FFFF00";
91 }
92
93 function goodInput(node) {
94 node.style.backgroundColor = "#FFFFFF";
37 } 95 }
38 96
39 function questionNode() { 97 function questionNode() {
40 var node = document.createElement("div"); 98 var node = document.createElement("div");
41 node.setAttribute('class','head'); 99 node.setAttribute('class','head');
42 node.setAttribute('name','question-node'); 100 node.setAttribute('name','question-node');
43 var nodeTitle = document.createElement("span"); 101 var nodeTitle = document.createElement("span");
44 nodeTitle.textContent = "Question"; 102 nodeTitle.textContent = "Question";
45 var attributes = document.createElement("div"); 103 var attributes = document.createElement("div");
46 attributes.setAttribute('class','attrib'); 104 attributes.setAttribute('class','attrib');
47 var id = attributePair("ID:","text"); 105 var id = attributePair("ID:","text", true);
48 var question = attributePair("Question:","text"); 106 var question = attributePair("Question:","text", false);
49 node.appendChild(nodeTitle); 107 node.appendChild(nodeTitle);
50 id.forEach(function(item){attributes.appendChild(item);},false); 108 id.forEach(function(item){attributes.appendChild(item);},false);
51 question.forEach(function(item){attributes.appendChild(item);},false); 109 question.forEach(function(item){attributes.appendChild(item);},false);
52 node.appendChild(attributes); 110 node.appendChild(attributes);
53 111
59 } 117 }
60 118
61 function statementNode() { 119 function statementNode() {
62 var node = document.createElement("div"); 120 var node = document.createElement("div");
63 node.setAttribute('class','head'); 121 node.setAttribute('class','head');
64 node.setAttribute('name','question-node'); 122 node.setAttribute('name','statement-node');
65 var nodeTitle = document.createElement("span"); 123 var nodeTitle = document.createElement("span");
66 nodeTitle.textContent = "Statement"; 124 nodeTitle.textContent = "Statement";
67 var attributes = document.createElement("div"); 125 var attributes = document.createElement("div");
68 attributes.setAttribute('class','attrib'); 126 attributes.setAttribute('class','attrib');
69 var statement = attributePair("Statement:","text"); 127 var statement = attributePair("Statement:","text",false);
70 node.appendChild(nodeTitle); 128 node.appendChild(nodeTitle);
71 statement.forEach(function(item){attributes.appendChild(item);},false); 129 statement.forEach(function(item){attributes.appendChild(item);},false);
72 node.appendChild(attributes); 130 node.appendChild(attributes);
73 131
74 var removeButton = document.createElement("button"); 132 var removeButton = document.createElement("button");
87 var nodeTitle = document.createElement("span"); 145 var nodeTitle = document.createElement("span");
88 nodeTitle.textContent = "Audio Holder "+(audioHolderCounts+1); 146 nodeTitle.textContent = "Audio Holder "+(audioHolderCounts+1);
89 147
90 var attributes = document.createElement("div"); 148 var attributes = document.createElement("div");
91 attributes.setAttribute('class','attrib'); 149 attributes.setAttribute('class','attrib');
92 var id = attributePair("ID:","text"); 150 var id = attributePair("ID:","text",true);
93 id[1].value=audioHolderCounts; 151 id[1].value=audioHolderCounts;
94 var hostURL = attributePair("Host URL:", "text"); 152 var hostURL = attributePair("Host URL:", "text",false);
95 var sampleRate = attributePair("Sample Rate:","text"); 153 var sampleRate = attributePair("Sample Rate:","text",false);
96 var randomiseOrder = attributePair("Randomise Element Order:","checkbox"); 154 var randomiseOrder = attributePair("Randomise Element Order:","checkbox");
97 var repeatCount = attributePair("Repeat Page Count:","number"); 155 var repeatCount = attributePair("Repeat Page Count:","number");
98 repeatCount[1].value = 0; 156 repeatCount[1].value = 0;
99 var loop = attributePair("Loop Element Playback","checkbox"); 157 var loop = attributePair("Loop Element Playback","checkbox");
100 var elementComments = attributePair("Enable Comment Boxes","checkbox"); 158 var elementComments = attributePair("Enable Comment Boxes","checkbox");
177 var nodeTitle = document.createElement('span'); 235 var nodeTitle = document.createElement('span');
178 nodeTitle.textContent = 'Audio Element '+(audioElemCounts+1); 236 nodeTitle.textContent = 'Audio Element '+(audioElemCounts+1);
179 237
180 var attributes = document.createElement("div"); 238 var attributes = document.createElement("div");
181 attributes.setAttribute('class','attrib'); 239 attributes.setAttribute('class','attrib');
182 var id = attributePair("ID:","text"); 240 var id = attributePair("ID:","text",true);
183 id[1].value = audioElemCounts; 241 id[1].value = audioElemCounts;
184 var url = attributePair("URL:","text"); 242 var url = attributePair("URL:","text",true);
185 id.forEach(function(item){attributes.appendChild(item);},false); 243 id.forEach(function(item){attributes.appendChild(item);},false);
186 url.forEach(function(item){attributes.appendChild(item);},false); 244 url.forEach(function(item){attributes.appendChild(item);},false);
187 245
188 node.appendChild(nodeTitle); 246 node.appendChild(nodeTitle);
189 node.appendChild(attributes); 247 node.appendChild(attributes);
202 var nodeTitle = document.createElement('h4'); 260 var nodeTitle = document.createElement('h4');
203 nodeTitle.textContent = "Comment Box"; 261 nodeTitle.textContent = "Comment Box";
204 262
205 var attributes = document.createElement('div'); 263 var attributes = document.createElement('div');
206 attributes.setAttribute('class','attrib'); 264 attributes.setAttribute('class','attrib');
207 var id = attributePair("ID:",'text'); 265 var id = attributePair("ID:",'text',true);
208 var question = attributePair("Question:",'text'); 266 var question = attributePair("Question:",'text',true);
209 id.forEach(function(item){attributes.appendChild(item);},false); 267 id.forEach(function(item){attributes.appendChild(item);},false);
210 question.forEach(function(item){attributes.appendChild(item);},false); 268 question.forEach(function(item){attributes.appendChild(item);},false);
211 269
212 var removeButton = document.createElement("button"); 270 var removeButton = document.createElement("button");
213 removeButton.textContent = "Remove Comment Box"; 271 removeButton.textContent = "Remove Comment Box";
242 300
243 </head> 301 </head>
244 302
245 <body> 303 <body>
246 <h1>Create Test Setup XML</h1> 304 <h1>Create Test Setup XML</h1>
305 <button id="validateXML" onclick="buttonClickedValidate();">Validate</button>
306 <button id="createXML" onclick="buttonClickedValidate();" disabled>Submit</button>
307 <span id="errorMessage" visibility="hidden"></span>
247 <div id="topLevelBody" align="left"> 308 <div id="topLevelBody" align="left">
248 <!-- Interface goes here --> 309 <!-- Interface goes here -->
249 <div name='test-setup'> 310 <div name='test-setup'>
250 <div id="setup" class="head"> 311 <div id="setup" class="head">
251 <h2>Setup Tag</h2> 312 <h2>Setup Tag</h2>
253 <span>Interface</span> 314 <span>Interface</span>
254 <select id="interface"> 315 <select id="interface">
255 <option value='APE'>APE</option> 316 <option value='APE'>APE</option>
256 </select> 317 </select>
257 <span>Project Return</span> 318 <span>Project Return</span>
258 <input type="text" id="projectReturn"> 319 <input type="text" id="projectReturn" mandatory="false">
259 <span>Randomise Test Page Order</span> 320 <span>Randomise Test Page Order</span>
260 <input id="randomisePageOrder" type="checkbox" value="false"> 321 <input id="randomisePageOrder" type="checkbox" value="false">
261 <span>Collect Session Metrics</span> 322 <span>Collect Session Metrics</span>
262 <input id="collectMetrics" type="checkbox"> 323 <input id="collectMetrics" type="checkbox">
263 </div> 324 </div>