nickjillings@1370
|
1 var interfaceSpecs;
|
nickjillings@1370
|
2 var xmlHttp;
|
nickjillings@1370
|
3 var popupObject;
|
nickjillings@1370
|
4 var popupStateNodes;
|
nickjillings@1370
|
5 var specification;
|
nickjillings@1370
|
6 var convert;
|
nickjillings@1370
|
7 var attributeText;
|
nicholas@2355
|
8 var page_lang = "en";
|
nickjillings@1370
|
9
|
nickjillings@1370
|
10 // Firefox does not have an XMLDocument.prototype.getElementsByName
|
nickjillings@1370
|
11 // and there is no searchAll style command, this custom function will
|
nickjillings@1370
|
12 // search all children recusrively for the name. Used for XSD where all
|
nickjillings@1370
|
13 // element nodes must have a name and therefore can pull the schema node
|
nicholas@2535
|
14 XMLDocument.prototype.getAllElementsByName = function (name) {
|
nickjillings@1370
|
15 name = String(name);
|
nickjillings@1370
|
16 var selected = this.documentElement.getAllElementsByName(name);
|
nickjillings@1370
|
17 return selected;
|
nickjillings@1370
|
18 }
|
nickjillings@1370
|
19
|
nicholas@2535
|
20 Element.prototype.getAllElementsByName = function (name) {
|
nickjillings@1370
|
21 name = String(name);
|
nickjillings@1370
|
22 var selected = [];
|
nickjillings@1370
|
23 var node = this.firstElementChild;
|
nicholas@2535
|
24 while (node != null) {
|
nicholas@2535
|
25 if (node.getAttribute('name') == name) {
|
nickjillings@1370
|
26 selected.push(node);
|
nickjillings@1370
|
27 }
|
nicholas@2535
|
28 if (node.childElementCount > 0) {
|
nickjillings@1370
|
29 selected = selected.concat(node.getAllElementsByName(name));
|
nickjillings@1370
|
30 }
|
nickjillings@1370
|
31 node = node.nextElementSibling;
|
nickjillings@1370
|
32 }
|
nickjillings@1370
|
33 return selected;
|
nickjillings@1370
|
34 }
|
nickjillings@1370
|
35
|
nicholas@2535
|
36 XMLDocument.prototype.getAllElementsByTagName = function (name) {
|
nickjillings@1370
|
37 name = String(name);
|
nickjillings@1370
|
38 var selected = this.documentElement.getAllElementsByTagName(name);
|
nickjillings@1370
|
39 return selected;
|
nickjillings@1370
|
40 }
|
nickjillings@1370
|
41
|
nicholas@2535
|
42 Element.prototype.getAllElementsByTagName = function (name) {
|
nickjillings@1370
|
43 name = String(name);
|
nickjillings@1370
|
44 var selected = [];
|
nickjillings@1370
|
45 var node = this.firstElementChild;
|
nicholas@2535
|
46 while (node != null) {
|
nicholas@2535
|
47 if (node.nodeName == name) {
|
nickjillings@1370
|
48 selected.push(node);
|
nickjillings@1370
|
49 }
|
nicholas@2535
|
50 if (node.childElementCount > 0) {
|
nickjillings@1370
|
51 selected = selected.concat(node.getAllElementsByTagName(name));
|
nickjillings@1370
|
52 }
|
nickjillings@1370
|
53 node = node.nextElementSibling;
|
nickjillings@1370
|
54 }
|
nickjillings@1370
|
55 return selected;
|
nickjillings@1370
|
56 }
|
nickjillings@1370
|
57
|
nickjillings@1370
|
58 // Firefox does not have an XMLDocument.prototype.getElementsByName
|
nickjillings@1370
|
59 if (typeof XMLDocument.prototype.getElementsByName != "function") {
|
nicholas@2535
|
60 XMLDocument.prototype.getElementsByName = function (name) {
|
nickjillings@1370
|
61 name = String(name);
|
nickjillings@1370
|
62 var node = this.documentElement.firstElementChild;
|
nickjillings@1370
|
63 var selected = [];
|
nicholas@2535
|
64 while (node != null) {
|
nicholas@2535
|
65 if (node.getAttribute('name') == name) {
|
nickjillings@1370
|
66 selected.push(node);
|
nickjillings@1370
|
67 }
|
nickjillings@1370
|
68 node = node.nextElementSibling;
|
nickjillings@1370
|
69 }
|
nickjillings@1370
|
70 return selected;
|
nickjillings@1370
|
71 }
|
nickjillings@1370
|
72 }
|
nickjillings@1370
|
73
|
nicholas@2535
|
74 window.onload = function () {
|
nickjillings@1370
|
75 specification = new Specification();
|
nickjillings@1370
|
76 convert = new SpecificationToHTML();
|
nickjillings@1370
|
77 xmlHttp = new XMLHttpRequest();
|
nicholas@2535
|
78 xmlHttp.open("GET", "test_create/interface-specs.xml", true);
|
nicholas@2535
|
79 xmlHttp.onload = function () {
|
nickjillings@1370
|
80 var parse = new DOMParser();
|
nicholas@2535
|
81 interfaceSpecs = parse.parseFromString(xmlHttp.response, 'text/xml');
|
nickjillings@1370
|
82 buildPage();
|
nickjillings@1370
|
83 popupObject.postNode(popupStateNodes.state[0])
|
nickjillings@1370
|
84 }
|
nickjillings@1370
|
85 xmlHttp.send();
|
nicholas@2535
|
86
|
nickjillings@1370
|
87 var xsdGet = new XMLHttpRequest();
|
nicholas@2535
|
88 xsdGet.open("GET", "xml/test-schema.xsd", true);
|
nicholas@2535
|
89 xsdGet.onload = function () {
|
nickjillings@1370
|
90 var parse = new DOMParser();
|
nicholas@2535
|
91 specification.schema = parse.parseFromString(xsdGet.response, 'text/xml');;
|
nickjillings@1370
|
92 }
|
nickjillings@1370
|
93 xsdGet.send();
|
nicholas@2535
|
94
|
nickjillings@1370
|
95 var jsonAttribute = new XMLHttpRequest();
|
nicholas@2535
|
96 jsonAttribute.open("GET", "test_create/attributes.json", true);
|
nicholas@2535
|
97 jsonAttribute.onload = function () {
|
nickjillings@1370
|
98 attributeText = JSON.parse(jsonAttribute.response)
|
nickjillings@1370
|
99 }
|
nickjillings@1370
|
100 jsonAttribute.send();
|
nickjillings@1370
|
101 }
|
nickjillings@1370
|
102
|
nicholas@2535
|
103 function buildPage() {
|
nicholas@2535
|
104 popupObject = new function () {
|
nickjillings@1370
|
105 this.object = document.getElementById("popupHolder");
|
nickjillings@1370
|
106 this.blanket = document.getElementById("blanket");
|
nickjillings@1370
|
107
|
nickjillings@1370
|
108 this.popupTitle = document.createElement("div");
|
nickjillings@1370
|
109 this.popupTitle.id = "popup-title-holder";
|
nickjillings@1370
|
110 this.popupTitle.align = "center";
|
nickjillings@1370
|
111 this.titleDOM = document.createElement("span");
|
nickjillings@1370
|
112 this.titleDOM.id = "popup-title";
|
nickjillings@1370
|
113 this.popupTitle.appendChild(this.titleDOM);
|
nickjillings@1370
|
114 this.object.appendChild(this.popupTitle);
|
nickjillings@1370
|
115
|
nickjillings@1370
|
116 this.popupContent = document.createElement("div");
|
nickjillings@1370
|
117 this.popupContent.id = "popup-content";
|
nickjillings@1370
|
118 this.object.appendChild(this.popupContent);
|
nicholas@2535
|
119
|
nickjillings@1370
|
120 this.proceedButton = document.createElement("button");
|
nickjillings@1370
|
121 this.proceedButton.id = "popup-proceed";
|
nickjillings@2108
|
122 this.proceedButton.className = "popup-button";
|
nickjillings@1370
|
123 this.proceedButton.textContent = "Next";
|
nicholas@2535
|
124 this.proceedButton.onclick = function () {
|
nickjillings@1370
|
125 popupObject.popupContent.innerHTML = null;
|
nicholas@2535
|
126 if (typeof popupObject.shownObject.continue == "function") {
|
nickjillings@2110
|
127 popupObject.shownObject.continue();
|
nickjillings@2110
|
128 } else {
|
nickjillings@2110
|
129 popupObject.hide();
|
nickjillings@2110
|
130 }
|
nickjillings@1370
|
131 };
|
nickjillings@1370
|
132 this.object.appendChild(this.proceedButton);
|
nicholas@2535
|
133
|
nickjillings@2108
|
134 this.backButton = document.createElement("button");
|
nickjillings@2108
|
135 this.backButton.id = "popup-back";
|
nickjillings@2108
|
136 this.backButton.className = "popup-button";
|
nickjillings@2108
|
137 this.backButton.textContent = "Back";
|
nicholas@2535
|
138 this.backButton.onclick = function () {
|
nickjillings@2108
|
139 popupObject.popupContent.innerHTML = null;
|
nickjillings@2108
|
140 popupObject.shownObject.back();
|
nickjillings@2108
|
141 };
|
nickjillings@2108
|
142 this.object.appendChild(this.backButton);
|
nicholas@2535
|
143
|
nickjillings@1370
|
144 this.shownObject;
|
nickjillings@1370
|
145
|
nicholas@2535
|
146 this.resize = function () {
|
nickjillings@1370
|
147 var w = window.innerWidth;
|
nickjillings@1370
|
148 var h = window.innerHeight;
|
nicholas@2535
|
149 this.object.style.left = Math.floor((w - 750) / 2) + 'px';
|
nicholas@2535
|
150 this.object.style.top = Math.floor((h - 500) / 2) + 'px';
|
nickjillings@1370
|
151 }
|
nickjillings@1370
|
152
|
nicholas@2535
|
153 this.show = function () {
|
nickjillings@1370
|
154 this.object.style.visibility = "visible";
|
nickjillings@1370
|
155 this.blanket.style.visibility = "visible";
|
nickjillings@2108
|
156 if (typeof this.shownObject.back == "function") {
|
nickjillings@2108
|
157 this.backButton.style.visibility = "visible";
|
nickjillings@2108
|
158 } else {
|
nickjillings@2108
|
159 this.backButton.style.visibility = "hidden";
|
nickjillings@2108
|
160 }
|
nickjillings@1370
|
161 }
|
nickjillings@1370
|
162
|
nicholas@2535
|
163 this.hide = function () {
|
nickjillings@1370
|
164 this.object.style.visibility = "hidden";
|
nickjillings@1370
|
165 this.blanket.style.visibility = "hidden";
|
nickjillings@2108
|
166 this.backButton.style.visibility = "hidden";
|
nickjillings@1370
|
167 }
|
nickjillings@1370
|
168
|
nicholas@2535
|
169 this.postNode = function (postObject) {
|
nickjillings@1370
|
170 //Passed object must have the following:
|
nickjillings@1370
|
171 // Title: text to show in the title
|
nickjillings@1370
|
172 // Content: HTML DOM to show on the page
|
nickjillings@1370
|
173 // On complete this HTML DOM is destroyed so make sure it is referenced elsewhere for processing
|
nickjillings@1370
|
174 this.titleDOM.textContent = postObject.title;
|
nickjillings@1370
|
175 this.popupContent.appendChild(postObject.content);
|
nickjillings@1370
|
176 this.shownObject = postObject;
|
nickjillings@2108
|
177 if (typeof this.shownObject.back == "function") {
|
nickjillings@2108
|
178 this.backButton.style.visibility = "visible";
|
nickjillings@2108
|
179 } else {
|
nickjillings@2108
|
180 this.backButton.style.visibility = "hidden";
|
nickjillings@2108
|
181 }
|
nickjillings@2110
|
182 if (typeof this.shownObject.continue == "function") {
|
nickjillings@2110
|
183 this.proceedButton.textContent = "Next";
|
nickjillings@2110
|
184 } else {
|
nickjillings@2110
|
185 this.proceedButton.textContent = "Finish";
|
nickjillings@2110
|
186 }
|
nickjillings@2108
|
187 this.show();
|
nickjillings@1370
|
188 }
|
nickjillings@1370
|
189
|
nickjillings@1370
|
190 this.resize();
|
nickjillings@1370
|
191 this.hide();
|
nickjillings@1370
|
192 };
|
nicholas@2535
|
193
|
nicholas@2535
|
194 popupStateNodes = new function () {
|
nickjillings@1370
|
195 // This defines the several popup states wanted
|
nickjillings@1370
|
196 this.state = [];
|
nicholas@2535
|
197 this.state[0] = new function () {
|
nickjillings@1370
|
198 this.title = "Welcome";
|
nickjillings@1370
|
199 this.content = document.createElement("div");
|
nickjillings@1370
|
200 this.content.id = "state-0";
|
nickjillings@1370
|
201 var span = document.createElement("span");
|
nickjillings@1370
|
202 span.textContent = "Welcome to the WAET test creator tool. This will allow you to create a new test from scratch to suit your testing needs. If you wish to update a test file, please drag and drop the XML document into the area below for processing, otherwise press 'Next' to start a new test. This tool generates files for the WAET 1.2.0 version."
|
nickjillings@1370
|
203 this.content.appendChild(span);
|
nickjillings@1370
|
204 this.dragArea = document.createElement("div");
|
nickjillings@1373
|
205 this.dragArea.className = "drag-area";
|
nickjillings@1373
|
206 this.dragArea.id = "project-drop";
|
nickjillings@1370
|
207 this.content.appendChild(this.dragArea);
|
nicholas@2535
|
208
|
nicholas@2535
|
209 this.dragArea.addEventListener('dragover', function (e) {
|
nickjillings@1373
|
210 e.stopPropagation();
|
nickjillings@1373
|
211 e.preventDefault();
|
nickjillings@1373
|
212 e.dataTransfer.dropEffect = 'copy';
|
nickjillings@1373
|
213 e.currentTarget.className = "drag-area drag-over";
|
nickjillings@1373
|
214 });
|
nicholas@2535
|
215
|
nicholas@2535
|
216 this.dragArea.addEventListener('dragexit', function (e) {
|
nickjillings@1373
|
217 e.stopPropagation();
|
nickjillings@1373
|
218 e.preventDefault();
|
nickjillings@1373
|
219 e.dataTransfer.dropEffect = 'copy';
|
nickjillings@1373
|
220 e.currentTarget.className = "drag-area";
|
nickjillings@1373
|
221 });
|
nicholas@2535
|
222
|
nicholas@2535
|
223 this.dragArea.addEventListener('drop', function (e) {
|
nickjillings@1373
|
224 e.stopPropagation();
|
nickjillings@1373
|
225 e.preventDefault();
|
nickjillings@1373
|
226 e.currentTarget.className = "drag-area drag-dropped";
|
nickjillings@1373
|
227 var files = e.dataTransfer.files[0];
|
nickjillings@1374
|
228 var reader = new FileReader();
|
nicholas@2535
|
229 reader.onload = function (decoded) {
|
nickjillings@1374
|
230 var parse = new DOMParser();
|
nicholas@2535
|
231 specification.decode(parse.parseFromString(decoded.target.result, 'text/xml'));
|
nickjillings@1374
|
232 popupObject.hide();
|
nickjillings@1375
|
233 popupObject.popupContent.innerHTML = null;
|
nickjillings@1374
|
234 convert.convert(document.getElementById('content'));
|
nickjillings@1374
|
235 }
|
nickjillings@1374
|
236 reader.readAsText(files);
|
nickjillings@1373
|
237 });
|
nickjillings@1370
|
238
|
nicholas@2535
|
239
|
nicholas@2535
|
240 this.continue = function () {
|
nickjillings@1370
|
241 popupObject.postNode(popupStateNodes.state[1]);
|
nickjillings@1370
|
242 }
|
nickjillings@1370
|
243 }
|
nicholas@2535
|
244 this.state[1] = new function () {
|
nickjillings@1370
|
245 this.title = "Select your interface";
|
nickjillings@1370
|
246 this.content = document.createElement("div");
|
nickjillings@1370
|
247 this.content.id = "state-1";
|
nickjillings@1370
|
248 var spnH = document.createElement('div');
|
nickjillings@1370
|
249 var span = document.createElement("span");
|
nickjillings@1370
|
250 span.textContent = "Please select your interface from the list shown below. This will define the various options which are available. This can later be changed.";
|
nickjillings@1370
|
251 spnH.appendChild(span);
|
nickjillings@1370
|
252 this.content.appendChild(spnH);
|
nickjillings@1370
|
253 this.select = document.createElement("select");
|
nicholas@2355
|
254 this.content.appendChild(this.select);
|
nicholas@2355
|
255 this.description = document.createElement("p");
|
nicholas@2355
|
256 this.content.appendChild(this.description);
|
nicholas@2390
|
257 this.testsXML = interfaceSpecs.getElementsByTagName('tests')[0].getElementsByTagName('test');
|
nicholas@2535
|
258 for (var i = 0; i < this.testsXML.length; i++) {
|
nickjillings@1370
|
259 var option = document.createElement('option');
|
nickjillings@1370
|
260 option.value = this.testsXML[i].getAttribute('name');
|
nickjillings@1370
|
261 option.textContent = this.testsXML[i].getAttribute('name');
|
nickjillings@1370
|
262 this.select.appendChild(option);
|
nickjillings@1370
|
263 }
|
nicholas@2535
|
264 this.handleEvent = function (event) {
|
nicholas@2355
|
265 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(this.select.value)[0];
|
nicholas@2355
|
266 var descriptors = testXML.getAllElementsByTagName("description");
|
nicholas@2355
|
267 this.description.textContent = "";
|
nicholas@2535
|
268 for (var i = 0; i < descriptors.length; i++) {
|
nicholas@2355
|
269 if (descriptors[i].getAttribute("lang") == page_lang) {
|
nicholas@2355
|
270 this.description.textContent = descriptors[i].textContent;
|
nicholas@2355
|
271 }
|
nicholas@2355
|
272 }
|
nicholas@2355
|
273 }
|
nicholas@2535
|
274 this.select.addEventListener("change", this);
|
nicholas@2355
|
275 this.handleEvent();
|
nicholas@2535
|
276 this.continue = function () {
|
nickjillings@1370
|
277 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(this.select.value)[0];
|
nickjillings@1370
|
278 specification.interface = testXML.getAttribute("interface");
|
nicholas@2535
|
279 if (specification.interfaces == null) {
|
nickjillings@2194
|
280 specification.interfaces = new specification.interfaceNode(specification);
|
nickjillings@2108
|
281 }
|
nicholas@2535
|
282 if (specification.metrics == null) {
|
nickjillings@2108
|
283 specification.metrics = new specification.metricNode();
|
nickjillings@2108
|
284 }
|
nickjillings@1370
|
285 popupStateNodes.state[2].generate();
|
nickjillings@1370
|
286 popupObject.postNode(popupStateNodes.state[2]);
|
nickjillings@1370
|
287 }
|
nicholas@2535
|
288 this.back = function () {
|
nickjillings@2108
|
289 popupObject.postNode(popupStateNodes.state[0]);
|
nickjillings@2108
|
290 }
|
nickjillings@1370
|
291 }
|
nicholas@2535
|
292 this.state[2] = new function () {
|
nickjillings@1370
|
293 this.title = "Test Checks & Restrictions";
|
nickjillings@1370
|
294 this.content = document.createElement("div");
|
nickjillings@1370
|
295 this.content.id = "state-1";
|
nickjillings@1370
|
296 var spnH = document.createElement('div');
|
nickjillings@1370
|
297 var span = document.createElement("span");
|
nickjillings@1370
|
298 span.textContent = "Select your test checks and restrictions. Greyed out items are fixed by the test/interface and cannot be changed";
|
nickjillings@1370
|
299 spnH.appendChild(span);
|
nickjillings@1370
|
300 this.content.appendChild(spnH);
|
nickjillings@1370
|
301 var holder = document.createElement("div");
|
nickjillings@1370
|
302 this.options = [];
|
nickjillings@1370
|
303 this.testXML = null;
|
nickjillings@1370
|
304 this.interfaceXML = null;
|
nickjillings@2108
|
305 this.dynamicContent = document.createElement("div");
|
nickjillings@2108
|
306 this.content.appendChild(this.dynamicContent);
|
nicholas@2535
|
307 this.generate = function () {
|
nickjillings@2108
|
308 this.options = [];
|
nickjillings@2108
|
309 this.dynamicContent.innerHTML = null;
|
nickjillings@1370
|
310 var interfaceName = popupStateNodes.state[1].select.value;
|
nickjillings@1370
|
311 this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("checks")[0];
|
nickjillings@1370
|
312 this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
|
nickjillings@1370
|
313 this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("checks")[0];
|
nickjillings@1370
|
314 this.testXML = this.testXML.getAllElementsByTagName("checks");
|
nicholas@2390
|
315 var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry');
|
nicholas@2535
|
316 for (var i = 0; i < interfaceXMLChildren.length; i++) {
|
nicholas@2390
|
317 var interfaceNode = interfaceXMLChildren[i];
|
nickjillings@1370
|
318 var checkName = interfaceNode.getAttribute('name');
|
nickjillings@1370
|
319 var testNode
|
nicholas@2535
|
320 if (this.testXML.length > 0) {
|
nickjillings@1370
|
321 testNode = this.testXML[0].getAllElementsByName(checkName);
|
nicholas@2535
|
322 if (testNode.length != 0) {
|
nicholas@2535
|
323 testNode = testNode[0];
|
nicholas@2535
|
324 } else {
|
nicholas@2535
|
325 testNode = undefined;
|
nicholas@2535
|
326 }
|
nickjillings@1370
|
327 } else {
|
nickjillings@1370
|
328 testNode = undefined;
|
nickjillings@1370
|
329 }
|
nickjillings@2108
|
330 var obj = {
|
nickjillings@2108
|
331 root: document.createElement("div"),
|
nickjillings@2109
|
332 text: document.createElement("label"),
|
nickjillings@2108
|
333 input: document.createElement("input"),
|
nickjillings@2108
|
334 parent: this,
|
nickjillings@2108
|
335 name: checkName,
|
nicholas@2535
|
336 handleEvent: function (event) {
|
nickjillings@2108
|
337 if (this.input.checked) {
|
nickjillings@2108
|
338 // Add to specification.interfaces.option
|
nicholas@2535
|
339 var included = specification.interfaces.options.find(function (element, index, array) {
|
nicholas@2535
|
340 if (element.name == this.name) {
|
nicholas@2535
|
341 return true;
|
nicholas@2535
|
342 } else {
|
nicholas@2535
|
343 return false;
|
nicholas@2535
|
344 }
|
nicholas@2535
|
345 }, this);
|
nickjillings@2108
|
346 if (included == null) {
|
nicholas@2535
|
347 specification.interfaces.options.push({
|
nicholas@2535
|
348 type: "check",
|
nicholas@2535
|
349 name: this.name
|
nicholas@2535
|
350 });
|
nickjillings@2108
|
351 }
|
nickjillings@2108
|
352 } else {
|
nickjillings@2108
|
353 // Remove from specification.interfaces.option
|
nicholas@2535
|
354 var position = specification.interfaces.options.findIndex(function (element, index, array) {
|
nicholas@2535
|
355 if (element.name == this.name) {
|
nicholas@2535
|
356 return true;
|
nicholas@2535
|
357 } else {
|
nicholas@2535
|
358 return false;
|
nicholas@2535
|
359 }
|
nicholas@2535
|
360 }, this);
|
nickjillings@2108
|
361 if (position >= 0) {
|
nicholas@2535
|
362 specification.interfaces.options.splice(position, 1);
|
nickjillings@2108
|
363 }
|
nickjillings@2108
|
364 }
|
nickjillings@2108
|
365 }
|
nickjillings@1370
|
366 }
|
nicholas@2535
|
367
|
nicholas@2535
|
368 obj.input.addEventListener("click", obj);
|
nickjillings@2108
|
369 obj.root.className = "popup-checkbox";
|
nickjillings@2108
|
370 obj.input.type = "checkbox";
|
nicholas@2535
|
371 obj.input.setAttribute('id', checkName);
|
nicholas@2535
|
372 obj.text.setAttribute("for", checkName);
|
nickjillings@2108
|
373 obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent;
|
nickjillings@2108
|
374 obj.root.appendChild(obj.input);
|
nickjillings@2108
|
375 obj.root.appendChild(obj.text);
|
nicholas@2535
|
376 if (testNode != undefined) {
|
nicholas@2535
|
377 if (testNode.getAttribute('default') == 'on') {
|
nickjillings@2108
|
378 obj.input.checked = true;
|
nickjillings@1370
|
379 }
|
nicholas@2535
|
380 if (testNode.getAttribute('support') == "none") {
|
nickjillings@2108
|
381 obj.input.disabled = true;
|
nickjillings@2108
|
382 obj.input.checked = false;
|
nickjillings@2108
|
383 obj.root.className = "popup-checkbox disabled";
|
nicholas@2535
|
384 } else if (interfaceNode.getAttribute('support') == "mandatory") {
|
nickjillings@2108
|
385 obj.input.disabled = true;
|
nickjillings@2108
|
386 obj.input.checked = true;
|
nickjillings@2108
|
387 obj.root.className = "popup-checkbox disabled";
|
nickjillings@2108
|
388 }
|
nickjillings@2108
|
389 } else {
|
nicholas@2535
|
390 if (interfaceNode.getAttribute('default') == 'on') {
|
nickjillings@2108
|
391 obj.input.checked = true;
|
nickjillings@2108
|
392 }
|
nicholas@2535
|
393 if (interfaceNode.getAttribute('support') == "none") {
|
nickjillings@2108
|
394 obj.input.disabled = true;
|
nickjillings@2108
|
395 obj.input.checked = false;
|
nickjillings@2108
|
396 obj.root.className = "popup-checkbox disabled";
|
nicholas@2535
|
397 } else if (interfaceNode.getAttribute('support') == "mandatory") {
|
nickjillings@2108
|
398 obj.input.disabled = true;
|
nickjillings@2108
|
399 obj.input.checked = true;
|
nickjillings@2108
|
400 obj.root.className = "popup-checkbox disabled";
|
nickjillings@1370
|
401 }
|
nickjillings@1370
|
402 }
|
nicholas@2535
|
403 var included = specification.interfaces.options.find(function (element, index, array) {
|
nicholas@2535
|
404 if (element.name == this.name) {
|
nicholas@2535
|
405 return true;
|
nicholas@2535
|
406 } else {
|
nicholas@2535
|
407 return false;
|
nicholas@2535
|
408 }
|
nicholas@2535
|
409 }, obj);
|
nickjillings@2108
|
410 if (included != undefined) {
|
nickjillings@2108
|
411 obj.input.checked = true;
|
nickjillings@2108
|
412 }
|
nickjillings@2108
|
413 obj.handleEvent();
|
nickjillings@2108
|
414 this.options.push(obj);
|
nickjillings@2108
|
415 this.dynamicContent.appendChild(obj.root);
|
nickjillings@1370
|
416 }
|
nickjillings@1370
|
417 }
|
nicholas@2535
|
418 this.continue = function () {
|
nickjillings@1370
|
419 popupStateNodes.state[3].generate();
|
nickjillings@1370
|
420 popupObject.postNode(popupStateNodes.state[3]);
|
nickjillings@1370
|
421 }
|
nicholas@2535
|
422 this.back = function () {
|
nickjillings@2108
|
423 popupObject.postNode(popupStateNodes.state[1]);
|
nickjillings@2108
|
424 }
|
nickjillings@1370
|
425 }
|
nicholas@2535
|
426 this.state[3] = new function () {
|
nickjillings@1370
|
427 this.title = "Test Metrics";
|
nickjillings@1370
|
428 this.content = document.createElement("div");
|
nickjillings@1370
|
429 this.content.id = "state-1";
|
nickjillings@1370
|
430 var spnH = document.createElement('div');
|
nickjillings@1370
|
431 var span = document.createElement("span");
|
nickjillings@1370
|
432 span.textContent = "Select which data points to include in the exported results XML. Some of this is required for certain post script analysis. See the documentation for further details";
|
nickjillings@1370
|
433 spnH.appendChild(span);
|
nickjillings@1370
|
434 this.content.appendChild(spnH);
|
nickjillings@1370
|
435 this.options = [];
|
nickjillings@1370
|
436 this.checkText;
|
nickjillings@1370
|
437 this.testXML;
|
nickjillings@1370
|
438 this.interfaceXML;
|
nickjillings@2108
|
439 this.dynamicContent = document.createElement("div");
|
nickjillings@2108
|
440 this.content.appendChild(this.dynamicContent);
|
nicholas@2535
|
441 this.generate = function () {
|
nickjillings@2108
|
442 this.options = [];
|
nickjillings@2108
|
443 this.dynamicContent.innerHTML = null;
|
nickjillings@1370
|
444 var interfaceName = popupStateNodes.state[1].select.value;
|
nickjillings@1370
|
445 this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("metrics")[0];
|
nickjillings@1370
|
446 this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
|
nickjillings@1370
|
447 this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("metrics")[0];
|
nickjillings@1370
|
448 this.testXML = this.testXML.getAllElementsByTagName("metrics");
|
nicholas@2390
|
449 var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry');
|
nicholas@2535
|
450 for (var i = 0; i < interfaceXMLChildren.length; i++) {
|
nicholas@2390
|
451 var interfaceNode = interfaceXMLChildren[i];
|
nickjillings@1370
|
452 var checkName = interfaceNode.getAttribute('name');
|
nickjillings@1370
|
453 var testNode
|
nicholas@2535
|
454 if (this.testXML.length > 0) {
|
nickjillings@1370
|
455 testNode = this.testXML[0].getAllElementsByName(checkName);
|
nicholas@2535
|
456 if (testNode.length != 0) {
|
nicholas@2535
|
457 testNode = testNode[0];
|
nicholas@2535
|
458 } else {
|
nicholas@2535
|
459 testNode = undefined;
|
nicholas@2535
|
460 }
|
nickjillings@1370
|
461 } else {
|
nickjillings@1370
|
462 testNode = undefined;
|
nickjillings@1370
|
463 }
|
nickjillings@2108
|
464 var obj = {
|
nickjillings@2108
|
465 root: document.createElement("div"),
|
nickjillings@2109
|
466 text: document.createElement("label"),
|
nickjillings@2108
|
467 input: document.createElement("input"),
|
nickjillings@2108
|
468 parent: this,
|
nickjillings@2108
|
469 name: checkName,
|
nicholas@2535
|
470 handleEvent: function (event) {
|
nickjillings@2108
|
471 if (this.input.checked) {
|
nickjillings@2108
|
472 // Add to specification.interfaces.option
|
nicholas@2535
|
473 var included = specification.metrics.enabled.find(function (element, index, array) {
|
nicholas@2535
|
474 if (element == this.name) {
|
nicholas@2535
|
475 return true;
|
nicholas@2535
|
476 } else {
|
nicholas@2535
|
477 return false;
|
nicholas@2535
|
478 }
|
nicholas@2535
|
479 }, this);
|
nickjillings@2108
|
480 if (included == null) {
|
nickjillings@2108
|
481 specification.metrics.enabled.push(this.name);
|
nickjillings@2108
|
482 }
|
nickjillings@2108
|
483 } else {
|
nickjillings@2108
|
484 // Remove from specification.interfaces.option
|
nicholas@2535
|
485 var position = specification.metrics.enabled.findIndex(function (element, index, array) {
|
nicholas@2535
|
486 if (element == this.name) {
|
nicholas@2535
|
487 return true;
|
nicholas@2535
|
488 } else {
|
nicholas@2535
|
489 return false;
|
nicholas@2535
|
490 }
|
nicholas@2535
|
491 }, this);
|
nickjillings@2108
|
492 if (position >= 0) {
|
nicholas@2535
|
493 specification.metrics.enabled.splice(position, 1);
|
nickjillings@2108
|
494 }
|
nickjillings@2108
|
495 }
|
nickjillings@2108
|
496 }
|
nickjillings@1370
|
497 }
|
nicholas@2535
|
498
|
nicholas@2535
|
499 obj.input.addEventListener("click", obj);
|
nickjillings@2108
|
500 obj.root.className = "popup-checkbox";
|
nickjillings@2108
|
501 obj.input.type = "checkbox";
|
nicholas@2535
|
502 obj.input.setAttribute('id', checkName);
|
nicholas@2535
|
503 obj.text.setAttribute("for", checkName);
|
nickjillings@2108
|
504 obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent;
|
nickjillings@2108
|
505 obj.root.appendChild(obj.input);
|
nickjillings@2108
|
506 obj.root.appendChild(obj.text);
|
nicholas@2535
|
507 if (testNode != undefined) {
|
nicholas@2535
|
508 if (testNode.getAttribute('default') == 'on') {
|
nickjillings@2108
|
509 obj.input.checked = true;
|
nickjillings@1370
|
510 }
|
nicholas@2535
|
511 if (testNode.getAttribute('support') == "none") {
|
nickjillings@2108
|
512 obj.input.disabled = true;
|
nickjillings@2108
|
513 obj.input.checked = false;
|
nickjillings@2108
|
514 obj.root.className = "popup-checkbox disabled";
|
nicholas@2535
|
515 } else if (interfaceNode.getAttribute('support') == "mandatory") {
|
nickjillings@2108
|
516 obj.input.disabled = true;
|
nickjillings@2108
|
517 obj.input.checked = true;
|
nickjillings@2108
|
518 obj.root.className = "popup-checkbox disabled";
|
nickjillings@2108
|
519 }
|
nickjillings@2108
|
520 } else {
|
nicholas@2535
|
521 if (interfaceNode.getAttribute('default') == 'on') {
|
nickjillings@2108
|
522 obj.input.checked = true;
|
nickjillings@2108
|
523 }
|
nicholas@2535
|
524 if (interfaceNode.getAttribute('support') == "none") {
|
nickjillings@2108
|
525 obj.input.disabled = true;
|
nickjillings@2108
|
526 obj.input.checked = false;
|
nickjillings@2108
|
527 obj.root.className = "popup-checkbox disabled";
|
nicholas@2535
|
528 } else if (interfaceNode.getAttribute('support') == "mandatory") {
|
nickjillings@2108
|
529 obj.input.disabled = true;
|
nickjillings@2108
|
530 obj.input.checked = true;
|
nickjillings@2108
|
531 obj.root.className = "popup-checkbox disabled";
|
nickjillings@1370
|
532 }
|
nickjillings@1370
|
533 }
|
nicholas@2535
|
534 var included = specification.metrics.enabled.find(function (element, index, array) {
|
nicholas@2535
|
535 if (element == this.name) {
|
nicholas@2535
|
536 return true;
|
nicholas@2535
|
537 } else {
|
nicholas@2535
|
538 return false;
|
nicholas@2535
|
539 }
|
nicholas@2535
|
540 }, obj);
|
nickjillings@2108
|
541 obj.handleEvent();
|
nickjillings@2108
|
542 if (included != undefined) {
|
nickjillings@2108
|
543 obj.input.checked = true;
|
nickjillings@2108
|
544 }
|
nickjillings@2108
|
545 this.options.push(obj);
|
nickjillings@2108
|
546 this.dynamicContent.appendChild(obj.root);
|
nickjillings@1370
|
547 }
|
nickjillings@1370
|
548 }
|
nicholas@2535
|
549 this.continue = function () {
|
nickjillings@1370
|
550 popupStateNodes.state[4].generate();
|
nickjillings@1370
|
551 popupObject.postNode(popupStateNodes.state[4]);
|
nickjillings@1370
|
552 }
|
nicholas@2535
|
553 this.back = function () {
|
nickjillings@2108
|
554 popupObject.postNode(popupStateNodes.state[2]);
|
nickjillings@2108
|
555 }
|
nickjillings@1370
|
556 }
|
nicholas@2535
|
557 this.state[4] = new function () {
|
nickjillings@1370
|
558 this.title = "Test Visuals";
|
nickjillings@1370
|
559 this.content = document.createElement("div");
|
nickjillings@1370
|
560 this.content.id = "state-1";
|
nickjillings@1370
|
561 var spnH = document.createElement('div');
|
nickjillings@1370
|
562 var span = document.createElement("span");
|
nickjillings@1370
|
563 span.textContent = "You can display extra visual content with your interface for the test user to interact with. Select from the available options below. Greyed out options are unavailable for your selected interface";
|
nickjillings@1370
|
564 spnH.appendChild(span);
|
nickjillings@1370
|
565 this.content.appendChild(spnH);
|
nickjillings@1370
|
566 this.options = [];
|
nickjillings@1370
|
567 this.checkText;
|
nickjillings@1370
|
568 this.testXML;
|
nickjillings@1370
|
569 this.interfaceXML;
|
nickjillings@2108
|
570 this.dynamicContent = document.createElement("div");
|
nickjillings@2108
|
571 this.content.appendChild(this.dynamicContent);
|
nicholas@2535
|
572 this.generate = function () {
|
nickjillings@2108
|
573 this.options = [];
|
nickjillings@2108
|
574 this.dynamicContent.innerHTML = null;
|
nickjillings@1370
|
575 var interfaceName = popupStateNodes.state[1].select.value;
|
nickjillings@1370
|
576 this.checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("show")[0];
|
nickjillings@1370
|
577 this.testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
|
nickjillings@1370
|
578 this.interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(this.testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0];
|
nickjillings@2108
|
579 this.testXML = this.testXML.getAllElementsByTagName("show");
|
nicholas@2390
|
580 var interfaceXMLChildren = this.interfaceXML.getElementsByTagName('entry');
|
nicholas@2535
|
581 for (var i = 0; i < interfaceXMLChildren.length; i++) {
|
nicholas@2390
|
582 var interfaceNode = interfaceXMLChildren[i];
|
nickjillings@1370
|
583 var checkName = interfaceNode.getAttribute('name');
|
nickjillings@1370
|
584 var testNode
|
nicholas@2535
|
585 if (this.testXML.length > 0) {
|
nickjillings@1370
|
586 testNode = this.testXML[0].getAllElementsByName(checkName);
|
nicholas@2535
|
587 if (testNode.length != 0) {
|
nicholas@2535
|
588 testNode = testNode[0];
|
nicholas@2535
|
589 } else {
|
nicholas@2535
|
590 testNode = undefined;
|
nicholas@2535
|
591 }
|
nickjillings@1370
|
592 } else {
|
nickjillings@1370
|
593 testNode = undefined;
|
nickjillings@1370
|
594 }
|
nickjillings@2108
|
595 var obj = {
|
nickjillings@2108
|
596 root: document.createElement("div"),
|
nickjillings@2109
|
597 text: document.createElement("label"),
|
nickjillings@2108
|
598 input: document.createElement("input"),
|
nickjillings@2108
|
599 parent: this,
|
nickjillings@2108
|
600 name: checkName,
|
nicholas@2535
|
601 handleEvent: function (event) {
|
nickjillings@2108
|
602 if (this.input.checked) {
|
nickjillings@2108
|
603 // Add to specification.interfaces.option
|
nicholas@2535
|
604 var included = specification.interfaces.options.find(function (element, index, array) {
|
nicholas@2535
|
605 if (element.name == this.name) {
|
nicholas@2535
|
606 return true;
|
nicholas@2535
|
607 } else {
|
nicholas@2535
|
608 return false;
|
nicholas@2535
|
609 }
|
nicholas@2535
|
610 }, this);
|
nickjillings@2108
|
611 if (included == null) {
|
nicholas@2535
|
612 specification.interfaces.options.push({
|
nicholas@2535
|
613 type: "show",
|
nicholas@2535
|
614 name: this.name
|
nicholas@2535
|
615 });
|
nickjillings@2108
|
616 }
|
nickjillings@2108
|
617 } else {
|
nickjillings@2108
|
618 // Remove from specification.interfaces.option
|
nicholas@2535
|
619 var position = specification.interfaces.options.findIndex(function (element, index, array) {
|
nicholas@2535
|
620 if (element.name == this.name) {
|
nicholas@2535
|
621 return true;
|
nicholas@2535
|
622 } else {
|
nicholas@2535
|
623 return false;
|
nicholas@2535
|
624 }
|
nicholas@2535
|
625 }, this);
|
nickjillings@2108
|
626 if (position >= 0) {
|
nicholas@2535
|
627 specification.interfaces.options.splice(position, 1);
|
nickjillings@2108
|
628 }
|
nickjillings@2108
|
629 }
|
nickjillings@2108
|
630 }
|
nickjillings@1370
|
631 }
|
nicholas@2535
|
632
|
nicholas@2535
|
633 obj.input.addEventListener("click", obj);
|
nickjillings@2108
|
634 obj.root.className = "popup-checkbox";
|
nickjillings@2108
|
635 obj.input.type = "checkbox";
|
nicholas@2535
|
636 obj.input.setAttribute('id', checkName);
|
nicholas@2535
|
637 obj.text.setAttribute("for", checkName);
|
nickjillings@2108
|
638 obj.text.textContent = this.checkText.getAllElementsByName(checkName)[0].textContent;
|
nickjillings@2108
|
639 obj.root.appendChild(obj.input);
|
nickjillings@2108
|
640 obj.root.appendChild(obj.text);
|
nicholas@2535
|
641 if (testNode != undefined) {
|
nicholas@2535
|
642 if (testNode.getAttribute('default') == 'on') {
|
nickjillings@2108
|
643 obj.input.checked = true;
|
nickjillings@1370
|
644 }
|
nicholas@2535
|
645 if (testNode.getAttribute('support') == "none") {
|
nickjillings@2108
|
646 obj.input.disabled = true;
|
nickjillings@2108
|
647 obj.input.checked = false;
|
nickjillings@2108
|
648 obj.root.className = "popup-checkbox disabled";
|
nicholas@2535
|
649 } else if (interfaceNode.getAttribute('support') == "mandatory") {
|
nickjillings@2108
|
650 obj.input.disabled = true;
|
nickjillings@2108
|
651 obj.input.checked = true;
|
nickjillings@2108
|
652 obj.root.className = "popup-checkbox disabled";
|
nickjillings@2108
|
653 }
|
nickjillings@2108
|
654 } else {
|
nicholas@2535
|
655 if (interfaceNode.getAttribute('default') == 'on') {
|
nickjillings@2108
|
656 obj.input.checked = true;
|
nickjillings@2108
|
657 }
|
nicholas@2535
|
658 if (interfaceNode.getAttribute('support') == "none") {
|
nickjillings@2108
|
659 obj.input.disabled = true;
|
nickjillings@2108
|
660 obj.input.checked = false;
|
nickjillings@2108
|
661 obj.root.className = "popup-checkbox disabled";
|
nicholas@2535
|
662 } else if (interfaceNode.getAttribute('support') == "mandatory") {
|
nickjillings@2108
|
663 obj.input.disabled = true;
|
nickjillings@2108
|
664 obj.input.checked = true;
|
nickjillings@2108
|
665 obj.root.className = "popup-checkbox disabled";
|
nickjillings@1370
|
666 }
|
nickjillings@1370
|
667 }
|
nicholas@2535
|
668 var included = specification.interfaces.options.find(function (element, index, array) {
|
nicholas@2535
|
669 if (element.name == this.name) {
|
nicholas@2535
|
670 return true;
|
nicholas@2535
|
671 } else {
|
nicholas@2535
|
672 return false;
|
nicholas@2535
|
673 }
|
nicholas@2535
|
674 }, obj);
|
nickjillings@2108
|
675 if (included != undefined) {
|
nickjillings@2108
|
676 obj.input.checked = true;
|
nickjillings@2108
|
677 }
|
nickjillings@2108
|
678 obj.handleEvent();
|
nickjillings@2108
|
679 this.options.push(obj);
|
nickjillings@2108
|
680 this.dynamicContent.appendChild(obj.root);
|
nickjillings@1370
|
681 }
|
nickjillings@1370
|
682 }
|
nicholas@2535
|
683 this.continue = function () {
|
nickjillings@1370
|
684 popupObject.hide();
|
nickjillings@1370
|
685 convert.convert(document.getElementById('content'));
|
nickjillings@1370
|
686 }
|
nicholas@2535
|
687 this.back = function () {
|
nickjillings@2108
|
688 popupObject.postNode(popupStateNodes.state[3]);
|
nickjillings@2108
|
689 }
|
nickjillings@1370
|
690 }
|
nicholas@2535
|
691 this.state[5] = new function () {
|
nickjillings@1370
|
692 this.title = "Add/Edit Survey Element";
|
nickjillings@1370
|
693 this.content = document.createElement("div");
|
nickjillings@1370
|
694 this.content.id = "state-1";
|
nickjillings@1370
|
695 var spnH = document.createElement('div');
|
nickjillings@1370
|
696 var span = document.createElement("span");
|
nickjillings@1370
|
697 span.textContent = "You can configure your survey element here. Press 'Continue' to complete your changes.";
|
nickjillings@1370
|
698 spnH.appendChild(span);
|
nickjillings@1370
|
699 this.content.appendChild(spnH);
|
nickjillings@1370
|
700 this.dynamic = document.createElement("div");
|
nickjillings@1370
|
701 this.option = null;
|
nickjillings@1370
|
702 this.parent = null;
|
nickjillings@1375
|
703 this.optionLists = [];
|
nickjillings@2158
|
704 this.select = document.createElement("select");
|
nicholas@2535
|
705 this.select.setAttribute("name", "type");
|
nicholas@2535
|
706 this.select.addEventListener("change", this, false);
|
nickjillings@2158
|
707 this.content.appendChild(this.select);
|
nickjillings@1370
|
708 this.content.appendChild(this.dynamic);
|
nicholas@2535
|
709 this.generate = function (option, parent) {
|
nickjillings@1370
|
710 this.option = option;
|
nickjillings@1370
|
711 this.parent = parent;
|
nickjillings@2158
|
712 if (this.select.childElementCount == 0) {
|
nickjillings@2158
|
713 var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("type")[0].getAllElementsByTagName("xs:enumeration");
|
nicholas@2535
|
714 for (var i = 0; i < optionList.length; i++) {
|
nickjillings@2158
|
715 var selectOption = document.createElement("option");
|
nickjillings@2158
|
716 selectOption.value = optionList[i].getAttribute("value");
|
nickjillings@2158
|
717 selectOption.textContent = selectOption.value;
|
nickjillings@2158
|
718 this.select.appendChild(selectOption);
|
nickjillings@2158
|
719 }
|
nickjillings@1370
|
720 }
|
nicholas@2535
|
721 if (this.option.type != undefined) {
|
nickjillings@2158
|
722 this.select.value = this.option.type
|
nickjillings@1370
|
723 } else {
|
nickjillings@2158
|
724 this.select.value = "statement";
|
nickjillings@1370
|
725 this.option.type = "statement";
|
nickjillings@1370
|
726 }
|
nicholas@2535
|
727
|
nickjillings@1370
|
728 this.dynamic.innerHTML = null;
|
nickjillings@1370
|
729 var statement = document.createElement("div");
|
nickjillings@1370
|
730 var statementText = document.createElement("span");
|
nickjillings@2159
|
731 var statementEntry = document.createElement("input");
|
nickjillings@1370
|
732 statement.appendChild(statementText);
|
nickjillings@1370
|
733 statement.appendChild(statementEntry);
|
nickjillings@2159
|
734 statement.className = "survey-entry-attribute";
|
nickjillings@1370
|
735 statementText.textContent = "Statement/Question";
|
nickjillings@2159
|
736 statementEntry.style.width = "500px";
|
nicholas@2535
|
737 statementEntry.addEventListener("change", this, false);
|
nicholas@2535
|
738 statementEntry.setAttribute("name", "statement");
|
nickjillings@1370
|
739 statementEntry.value = this.option.statement;
|
nickjillings@1370
|
740 this.dynamic.appendChild(statement);
|
nicholas@2535
|
741
|
nickjillings@1375
|
742 var id = document.createElement("div");
|
nickjillings@1375
|
743 var idText = document.createElement("span");
|
nickjillings@1375
|
744 var idEntry = document.createElement("input");
|
nickjillings@1375
|
745 id.appendChild(idText);
|
nickjillings@1375
|
746 id.appendChild(idEntry);
|
nickjillings@2159
|
747 id.className = "survey-entry-attribute";
|
nickjillings@1375
|
748 idText.textContent = "ID: ";
|
nicholas@2535
|
749 idEntry.addEventListener("change", this, false);
|
nicholas@2535
|
750 idEntry.setAttribute("name", "id");
|
nickjillings@1375
|
751 idEntry.value = this.option.id;
|
nicholas@2535
|
752
|
nickjillings@2158
|
753 this.dynamic.appendChild(id);
|
nicholas@2535
|
754
|
nicholas@2535
|
755 switch (this.option.type) {
|
nickjillings@1370
|
756 case "statement":
|
nickjillings@1370
|
757 break;
|
nickjillings@1370
|
758 case "question":
|
nickjillings@1370
|
759 var boxsizeSelect = document.createElement("select");
|
nickjillings@1370
|
760 var optionList = specification.schema.getAllElementsByName("survey")[0].getAllElementsByName("boxsize")[0].getAllElementsByTagName("xs:enumeration");
|
nicholas@2535
|
761 for (var i = 0; i < optionList.length; i++) {
|
nickjillings@1370
|
762 var selectOption = document.createElement("option");
|
nickjillings@1370
|
763 selectOption.value = optionList[i].getAttribute("value");
|
nickjillings@1370
|
764 selectOption.textContent = selectOption.value;
|
nickjillings@1370
|
765 boxsizeSelect.appendChild(selectOption);
|
nickjillings@1370
|
766 }
|
nicholas@2535
|
767 if (this.option.boxsize != undefined) {
|
nickjillings@1370
|
768 boxsizeSelect.value = this.option.boxsize;
|
nickjillings@1370
|
769 } else {
|
nickjillings@1370
|
770 boxsizeSelect.value = "normal";
|
nickjillings@1370
|
771 this.option.boxsize = "normal";
|
nickjillings@1370
|
772 }
|
nicholas@2535
|
773 boxsizeSelect.setAttribute("name", "boxsize");
|
nicholas@2535
|
774 boxsizeSelect.addEventListener("change", this, false);
|
nickjillings@1370
|
775 var boxsize = document.createElement("div");
|
nickjillings@1370
|
776 var boxsizeText = document.createElement("span");
|
nickjillings@1370
|
777 boxsizeText.textContent = "Entry Size: ";
|
nickjillings@1370
|
778 boxsize.appendChild(boxsizeText);
|
nickjillings@1370
|
779 boxsize.appendChild(boxsizeSelect);
|
nickjillings@2159
|
780 boxsize.className = "survey-entry-attribute";
|
nickjillings@1370
|
781 this.dynamic.appendChild(boxsize);
|
nicholas@2535
|
782
|
nickjillings@1370
|
783 var mandatory = document.createElement("div");
|
nickjillings@1370
|
784 var mandatoryInput = document.createElement("input");
|
nickjillings@1370
|
785 var mandatoryText = document.createElement("span");
|
nickjillings@1370
|
786 mandatoryText.textContent = "Mandatory: ";
|
nickjillings@1370
|
787 mandatory.appendChild(mandatoryText);
|
nickjillings@1370
|
788 mandatory.appendChild(mandatoryInput);
|
nickjillings@2159
|
789 mandatory.className = "survey-entry-attribute";
|
nickjillings@1370
|
790 mandatoryInput.type = "checkbox";
|
nicholas@2535
|
791 if (this.option.mandatory) {
|
nicholas@2535
|
792 mandatoryInput.checked = true;
|
nicholas@2535
|
793 } else {
|
nicholas@2535
|
794 mandatoryInput.checked = false;
|
nicholas@2535
|
795 }
|
nicholas@2535
|
796 mandatoryInput.setAttribute("name", "mandatory");
|
nicholas@2535
|
797 mandatoryInput.addEventListener("change", this, false);
|
nickjillings@1375
|
798 this.dynamic.appendChild(mandatory);
|
nickjillings@1375
|
799 break;
|
nickjillings@1375
|
800 case "number":
|
nickjillings@1375
|
801 this.dynamic.appendChild(id);
|
nicholas@2535
|
802
|
nickjillings@1375
|
803 var mandatory = document.createElement("div");
|
nickjillings@1375
|
804 var mandatoryInput = document.createElement("input");
|
nickjillings@1375
|
805 var mandatoryText = document.createElement("span");
|
nickjillings@1375
|
806 mandatoryText.textContent = "Mandatory: ";
|
nickjillings@1370
|
807 mandatory.appendChild(mandatoryText);
|
nickjillings@1370
|
808 mandatory.appendChild(mandatoryInput);
|
nickjillings@2159
|
809 mandatory.className = "survey-entry-attribute";
|
nickjillings@1375
|
810 mandatoryInput.type = "checkbox";
|
nicholas@2535
|
811 if (this.option.mandatory) {
|
nicholas@2535
|
812 mandatoryInput.checked = true;
|
nicholas@2535
|
813 } else {
|
nicholas@2535
|
814 mandatoryInput.checked = false;
|
nicholas@2535
|
815 }
|
nicholas@2535
|
816 mandatoryInput.setAttribute("name", "mandatory");
|
nicholas@2535
|
817 mandatoryInput.addEventListener("change", this, false);
|
nickjillings@1370
|
818 this.dynamic.appendChild(mandatory);
|
nicholas@2535
|
819
|
nickjillings@1375
|
820 var minimum = document.createElement("div");
|
nickjillings@1375
|
821 var minimumEntry = document.createElement("input");
|
nickjillings@1375
|
822 var minimumText = document.createElement("span");
|
nickjillings@1375
|
823 minimumText.textContent = "Minimum: ";
|
nickjillings@1375
|
824 minimum.appendChild(minimumText);
|
nickjillings@1375
|
825 minimum.appendChild(minimumEntry);
|
nickjillings@2159
|
826 minimum.className = "survey-entry-attribute";
|
nickjillings@1375
|
827 minimumEntry.type = "number";
|
nicholas@2535
|
828 minimumEntry.setAttribute("name", "min");
|
nicholas@2535
|
829 minimumEntry.addEventListener("change", this, false);
|
nickjillings@1375
|
830 minimumEntry.value = this.option.min;
|
nickjillings@1375
|
831 this.dynamic.appendChild(minimum);
|
nicholas@2535
|
832
|
nickjillings@1375
|
833 var maximum = document.createElement("div");
|
nickjillings@1375
|
834 var maximumEntry = document.createElement("input");
|
nickjillings@1375
|
835 var maximumText = document.createElement("span");
|
nickjillings@1375
|
836 maximumText.textContent = "Maximum: ";
|
nickjillings@1375
|
837 maximum.appendChild(maximumText);
|
nickjillings@1375
|
838 maximum.appendChild(maximumEntry);
|
nickjillings@2159
|
839 maximum.className = "survey-entry-attribute";
|
nickjillings@1375
|
840 maximumEntry.type = "number";
|
nicholas@2535
|
841 maximumEntry.setAttribute("name", "max");
|
nicholas@2535
|
842 maximumEntry.addEventListener("change", this, false);
|
nickjillings@1375
|
843 maximumEntry.value = this.option.max;
|
nickjillings@1375
|
844 this.dynamic.appendChild(maximum);
|
nickjillings@1370
|
845 break;
|
nickjillings@1375
|
846 case "checkbox":
|
nickjillings@1375
|
847 case "radio":
|
nickjillings@1375
|
848 this.dynamic.appendChild(id);
|
nickjillings@1375
|
849 var optionHolder = document.createElement("div");
|
nickjillings@1375
|
850 optionHolder.className = 'node';
|
nickjillings@1375
|
851 optionHolder.id = 'popup-option-holder';
|
nicholas@2535
|
852 var optionObject = function (parent, option) {
|
nickjillings@1375
|
853 this.rootDOM = document.createElement("div");
|
nickjillings@1375
|
854 this.rootDOM.className = "popup-option-entry";
|
nickjillings@1375
|
855 this.inputName = document.createElement("input");
|
nicholas@2535
|
856 this.inputName.setAttribute("name", "name");
|
nickjillings@1375
|
857 this.inputLabel = document.createElement("input");
|
nicholas@2535
|
858 this.inputLabel.setAttribute("name", "text");
|
nickjillings@1375
|
859 this.specification = option;
|
nickjillings@1375
|
860 this.parent = parent;
|
nicholas@2535
|
861 this.handleEvent = function () {
|
nickjillings@1375
|
862 var target = event.currentTarget.getAttribute("name");
|
nicholas@2535
|
863 eval("this.specification." + target + " = event.currentTarget.value");
|
nickjillings@1375
|
864 };
|
nicholas@2535
|
865
|
nickjillings@1375
|
866 var nameText = document.createElement("span");
|
nickjillings@1375
|
867 nameText.textContent = "Name: ";
|
nickjillings@1375
|
868 var labelText = document.createElement("span");
|
nickjillings@1375
|
869 labelText.textContent = "Label: ";
|
nickjillings@1375
|
870 this.rootDOM.appendChild(nameText);
|
nickjillings@1375
|
871 this.rootDOM.appendChild(this.inputName);
|
nickjillings@1375
|
872 this.rootDOM.appendChild(labelText);
|
nickjillings@1375
|
873 this.rootDOM.appendChild(this.inputLabel);
|
nicholas@2535
|
874 this.inputName.addEventListener("change", this, false);
|
nicholas@2535
|
875 this.inputLabel.addEventListener("change", this, false);
|
nickjillings@1375
|
876 this.inputName.value = this.specification.name;
|
nickjillings@1375
|
877 this.inputLabel.value = this.specification.text;
|
nickjillings@2180
|
878 this.inputLabel.style.width = "350px";
|
nicholas@2535
|
879
|
nickjillings@1375
|
880 this.deleteEntry = {
|
nickjillings@1375
|
881 root: document.createElement("button"),
|
nickjillings@1375
|
882 parent: this,
|
nicholas@2535
|
883 handleEvent: function () {
|
nickjillings@1375
|
884 document.getElementById("popup-option-holder").removeChild(this.parent.rootDOM);
|
nicholas@2535
|
885 var index = this.parent.parent.option.options.findIndex(function (element, index, array) {
|
nickjillings@1375
|
886 if (element == this.parent.specification)
|
nickjillings@1375
|
887 return true;
|
nickjillings@1375
|
888 else
|
nickjillings@1375
|
889 return false;
|
nicholas@2535
|
890 }, this);
|
nickjillings@1375
|
891 var optionList = this.parent.parent.option.options;
|
nicholas@2535
|
892 if (index == optionList.length - 1) {
|
nicholas@2535
|
893 optionList = optionList.slice(0, index);
|
nickjillings@1375
|
894 } else {
|
nicholas@2535
|
895 optionList = optionList.slice(0, index).concat(optionList.slice(index + 1));
|
nickjillings@1375
|
896 }
|
nickjillings@1375
|
897 this.parent.parent.option.options = optionList;
|
nickjillings@1375
|
898 }
|
nickjillings@1375
|
899 };
|
nickjillings@1375
|
900 this.deleteEntry.root.textContent = "Delete Option";
|
nicholas@2535
|
901 this.deleteEntry.root.addEventListener("click", this.deleteEntry, false);
|
nickjillings@1375
|
902 this.rootDOM.appendChild(this.deleteEntry.root);
|
nickjillings@1375
|
903 }
|
nickjillings@2158
|
904 this.addEntry = {
|
nickjillings@2158
|
905 parent: this,
|
nickjillings@2158
|
906 root: document.createElement("button"),
|
nicholas@2535
|
907 handleEvent: function () {
|
nicholas@2535
|
908 var node = {
|
nicholas@2535
|
909 name: "name",
|
nicholas@2535
|
910 text: "text"
|
nicholas@2535
|
911 };
|
nickjillings@2158
|
912 var optionsList = this.parent.option.options;
|
nickjillings@2158
|
913 optionsList.push(node);
|
nicholas@2535
|
914 var obj = new optionObject(this.parent, optionsList[optionsList.length - 1]);
|
nickjillings@2158
|
915 this.parent.optionLists.push(obj);
|
nickjillings@2158
|
916 document.getElementById("popup-option-holder").appendChild(obj.rootDOM);
|
nickjillings@2158
|
917 }
|
nickjillings@2158
|
918 }
|
nickjillings@2158
|
919 this.addEntry.root.textContent = "Add Option";
|
nicholas@2535
|
920 this.addEntry.root.addEventListener("click", this.addEntry);
|
nickjillings@2158
|
921 this.dynamic.appendChild(this.addEntry.root);
|
nicholas@2535
|
922 for (var i = 0; i < this.option.options.length; i++) {
|
nicholas@2535
|
923 var obj = new optionObject(this, this.option.options[i]);
|
nickjillings@1375
|
924 this.optionLists.push(obj);
|
nickjillings@1375
|
925 optionHolder.appendChild(obj.rootDOM);
|
nickjillings@1375
|
926 }
|
nickjillings@1375
|
927 this.dynamic.appendChild(optionHolder);
|
nickjillings@1370
|
928 }
|
nickjillings@1370
|
929 }
|
nicholas@2535
|
930 this.handleEvent = function () {
|
nickjillings@1370
|
931 var name = event.currentTarget.getAttribute("name");
|
nickjillings@2159
|
932 var nodeName = event.currentTarget.nodeName;
|
nickjillings@2159
|
933 if (name == "type" && nodeName == "SELECT") {
|
nickjillings@2159
|
934 // If type has changed, we may need to rebuild the entire state node
|
nicholas@2535
|
935 if (event.currentTarget.value != this.option.name) {
|
nickjillings@2159
|
936 this.option.type = event.currentTarget.value;
|
nicholas@2535
|
937 this.generate(this.option, this.parent);
|
nickjillings@2159
|
938 }
|
nickjillings@2159
|
939 return;
|
nickjillings@2159
|
940 }
|
nicholas@2535
|
941 switch (event.currentTarget.getAttribute("type")) {
|
nickjillings@2159
|
942 case "checkbox":
|
nicholas@2535
|
943 eval("this.option." + name + " = event.currentTarget.checked");
|
nickjillings@1370
|
944 break;
|
nickjillings@2159
|
945 default:
|
nicholas@2535
|
946 eval("this.option." + name + " = event.currentTarget.value");
|
nickjillings@1370
|
947 break;
|
nickjillings@1370
|
948 }
|
nickjillings@1370
|
949 }
|
nicholas@2535
|
950 this.continue = function () {
|
nicholas@2535
|
951 if (this.parent.type == "surveyNode") {
|
nicholas@2535
|
952 var newNode = new this.parent.surveyEntryNode(this.parent, this.option);
|
nickjillings@1375
|
953 this.parent.children.push(newNode);
|
nickjillings@1375
|
954 this.parent.childrenDOM.appendChild(newNode.rootDOM);
|
nickjillings@1375
|
955 } else if (this.parent.type == "surveyEntryNode") {
|
nickjillings@1375
|
956 this.parent.build();
|
nickjillings@1375
|
957 }
|
nickjillings@1370
|
958 popupObject.hide();
|
nickjillings@1370
|
959 }
|
nickjillings@1370
|
960 }
|
nicholas@2535
|
961 this.state[6] = new function () {
|
nickjillings@1385
|
962 this.title = "Edit Scale Markers";
|
nickjillings@1385
|
963 this.content = document.createElement("div");
|
nickjillings@1385
|
964 this.content.id = "state-6";
|
nickjillings@1385
|
965 var spnH = document.createElement('div');
|
nickjillings@1385
|
966 var span = document.createElement("span");
|
nickjillings@1385
|
967 span.textContent = "You can edit your scale markers here for the selected interface.";
|
nickjillings@1385
|
968 spnH.appendChild(span);
|
nickjillings@1385
|
969 this.scaleRoot;
|
nickjillings@1385
|
970 this.parent;
|
nicholas@2535
|
971 this.markerNodes = [];
|
nickjillings@1385
|
972 this.preset = {
|
nickjillings@1385
|
973 input: document.createElement("select"),
|
nickjillings@1385
|
974 parent: this,
|
nicholas@2535
|
975 handleEvent: function (event) {
|
nickjillings@1385
|
976 this.parent.scaleRoot.scales = [];
|
nickjillings@1385
|
977 var protoScale = interfaceSpecs.getAllElementsByTagName('scaledefinitions')[0].getAllElementsByName(event.currentTarget.value)[0];
|
nicholas@2390
|
978 var protoMarkers = protoScale.getElementsByTagName("scale");
|
nicholas@2535
|
979 for (var i = 0; i < protoMarkers.length; i++) {
|
nickjillings@1385
|
980 var marker = {
|
nickjillings@1385
|
981 position: protoMarkers[i].getAttribute("position"),
|
nickjillings@1385
|
982 text: protoMarkers[i].textContent
|
nickjillings@1385
|
983 }
|
nickjillings@1385
|
984 this.parent.scaleRoot.scales.push(marker);
|
nickjillings@1385
|
985 }
|
nickjillings@1385
|
986 this.parent.buildMarkerList();
|
nickjillings@1385
|
987 }
|
nickjillings@1385
|
988 }
|
nicholas@2535
|
989 this.preset.input.addEventListener("change", this.preset);
|
nickjillings@1385
|
990 this.content.appendChild(this.preset.input);
|
nickjillings@1385
|
991 var optionHolder = document.createElement("div");
|
nickjillings@1385
|
992 optionHolder.className = 'node';
|
nickjillings@1385
|
993 optionHolder.id = 'popup-option-holder';
|
nickjillings@1385
|
994 this.content.appendChild(optionHolder);
|
nicholas@2535
|
995 this.generate = function (scaleRoot, parent) {
|
nickjillings@1385
|
996 this.scaleRoot = scaleRoot;
|
nickjillings@1385
|
997 this.parent = parent;
|
nicholas@2535
|
998
|
nickjillings@1385
|
999 // Generate Pre-Set dropdown
|
nicholas@2390
|
1000 var protoScales = interfaceSpecs.getAllElementsByTagName('scaledefinitions')[0].getElementsByTagName("scale");
|
nickjillings@1385
|
1001 this.preset.input.innerHTML = "";
|
nicholas@2535
|
1002
|
nicholas@2535
|
1003 for (var i = 0; i < protoScales.length; i++) {
|
nickjillings@1385
|
1004 var selectOption = document.createElement("option");
|
nickjillings@1385
|
1005 var scaleName = protoScales[i].getAttribute("name");
|
nicholas@2535
|
1006 selectOption.setAttribute("name", scaleName);
|
nickjillings@1385
|
1007 selectOption.textContent = scaleName;
|
nickjillings@1385
|
1008 this.preset.input.appendChild(selectOption);
|
nickjillings@1385
|
1009 }
|
nicholas@2535
|
1010
|
nickjillings@2115
|
1011 this.addMarker = {
|
nickjillings@2115
|
1012 root: document.createElement("button"),
|
nickjillings@2115
|
1013 parent: this,
|
nicholas@2535
|
1014 handleEvent: function () {
|
nickjillings@2115
|
1015 var marker = {
|
nickjillings@2115
|
1016 position: 0,
|
nickjillings@2115
|
1017 text: "text"
|
nickjillings@2115
|
1018 };
|
nickjillings@2115
|
1019 this.parent.scaleRoot.scales.push(marker);
|
nicholas@2535
|
1020 var markerNode = new this.parent.buildMarkerNode(this.parent, marker);
|
nickjillings@2115
|
1021 document.getElementById("popup-option-holder").appendChild(markerNode.root);
|
nickjillings@2115
|
1022 this.parent.markerNodes.push(markerNode);
|
nickjillings@2115
|
1023 }
|
nickjillings@2115
|
1024 };
|
nickjillings@2115
|
1025 this.addMarker.root.textContent = "Add Marker";
|
nicholas@2535
|
1026 this.addMarker.root.addEventListener("click", this.addMarker);
|
nickjillings@2115
|
1027 this.content.appendChild(this.addMarker.root);
|
nicholas@2535
|
1028
|
nickjillings@1385
|
1029 // Create Marker List
|
nickjillings@1385
|
1030 this.buildMarkerList();
|
nickjillings@1385
|
1031 }
|
nicholas@2535
|
1032 this.buildMarkerList = function () {
|
nickjillings@1385
|
1033 var markerInject = document.getElementById("popup-option-holder");
|
nickjillings@1385
|
1034 markerInject.innerHTML = "";
|
nickjillings@1385
|
1035 this.markerNodes = [];
|
nicholas@2535
|
1036 for (var i = 0; i < this.scaleRoot.scales.length; i++) {
|
nicholas@2535
|
1037 var markerNode = new this.buildMarkerNode(this, this.scaleRoot.scales[i]);
|
nickjillings@1385
|
1038 markerInject.appendChild(markerNode.root);
|
nickjillings@1385
|
1039 this.markerNodes.push(markerNode);
|
nicholas@2535
|
1040
|
nickjillings@1385
|
1041 }
|
nickjillings@1385
|
1042 }
|
nicholas@2535
|
1043
|
nicholas@2535
|
1044 this.buildMarkerNode = function (parent, specification) {
|
nickjillings@2115
|
1045 this.root = document.createElement("div");
|
nickjillings@2115
|
1046 this.root.className = "popup-option-entry";
|
nickjillings@2115
|
1047 this.positionInput = document.createElement("input");
|
nickjillings@2115
|
1048 this.positionInput.min = 0;
|
nickjillings@2115
|
1049 this.positionInput.max = 100;
|
nickjillings@2115
|
1050 this.positionInput.value = specification.position;
|
nicholas@2535
|
1051 this.positionInput.setAttribute("name", "position");
|
nickjillings@2115
|
1052 this.textInput = document.createElement("input");
|
nicholas@2535
|
1053 this.textInput.setAttribute("name", "text");
|
nickjillings@2180
|
1054 this.textInput.style.width = "300px";
|
nickjillings@2115
|
1055 this.textInput.value = specification.text;
|
nickjillings@2115
|
1056 this.specification = specification;
|
nickjillings@2115
|
1057 this.parent = parent;
|
nicholas@2535
|
1058 this.handleEvent = function (event) {
|
nicholas@2535
|
1059 switch (event.currentTarget.getAttribute("name")) {
|
nickjillings@2115
|
1060 case "position":
|
nickjillings@2115
|
1061 this.specification.position = Number(event.currentTarget.value);
|
nickjillings@2115
|
1062 break;
|
nickjillings@2115
|
1063 case "text":
|
nickjillings@2115
|
1064 this.specification.text = event.currentTarget.value;
|
nickjillings@2115
|
1065 break;
|
nickjillings@2115
|
1066 }
|
nickjillings@2115
|
1067 }
|
nicholas@2535
|
1068 this.positionInput.addEventListener("change", this, false);
|
nicholas@2535
|
1069 this.textInput.addEventListener("change", this, false);
|
nickjillings@2115
|
1070
|
nickjillings@2115
|
1071 var posText = document.createElement("span");
|
nickjillings@2115
|
1072 posText.textContent = "Position: ";
|
nickjillings@2115
|
1073 var textText = document.createElement("span");
|
nickjillings@2115
|
1074 textText.textContent = "Text: ";
|
nickjillings@2115
|
1075 this.root.appendChild(posText);
|
nickjillings@2115
|
1076 this.root.appendChild(this.positionInput);
|
nickjillings@2115
|
1077 this.root.appendChild(textText);
|
nickjillings@2115
|
1078 this.root.appendChild(this.textInput);
|
nickjillings@2115
|
1079
|
nickjillings@2115
|
1080 this.deleteMarker = {
|
nickjillings@2115
|
1081 root: document.createElement("button"),
|
nickjillings@2115
|
1082 parent: this,
|
nicholas@2535
|
1083 handleEvent: function () {
|
nicholas@2535
|
1084 var index = this.parent.parent.scaleRoot.scales.findIndex(function (element, index, array) {
|
nicholas@2535
|
1085 if (element == this) {
|
nicholas@2535
|
1086 return true;
|
nicholas@2535
|
1087 } else {
|
nicholas@2535
|
1088 return false;
|
nicholas@2535
|
1089 }
|
nicholas@2535
|
1090 }, this.parent.specification)
|
nickjillings@2115
|
1091 if (index >= 0) {
|
nicholas@2535
|
1092 this.parent.parent.scaleRoot.scales.splice(index, 1);
|
nickjillings@2115
|
1093 }
|
nickjillings@2115
|
1094 document.getElementById("popup-option-holder").removeChild(this.parent.root);
|
nickjillings@2115
|
1095 }
|
nickjillings@2115
|
1096 }
|
nicholas@2535
|
1097 this.deleteMarker.root.addEventListener("click", this.deleteMarker);
|
nickjillings@2115
|
1098 this.deleteMarker.root.textContent = "Delete Marker"
|
nickjillings@2115
|
1099 this.root.appendChild(this.deleteMarker.root);
|
nickjillings@2115
|
1100 }
|
nickjillings@1385
|
1101 }
|
nickjillings@1370
|
1102 }
|
nickjillings@1370
|
1103 }
|
nickjillings@1370
|
1104
|
nicholas@2535
|
1105 function SpecificationToHTML() {
|
nickjillings@1370
|
1106 // This takes the specification node and converts it to an on-page HTML object
|
nickjillings@1370
|
1107 // Each Specification Node is given its own JS object which listens to the XSD for instant verification
|
nickjillings@1370
|
1108 // Once generated, it directly binds into the specification object to update with changes
|
nickjillings@1370
|
1109 // Fixed DOM entries
|
nickjillings@1370
|
1110 this.injectDOM;
|
nickjillings@1370
|
1111 this.setupDOM;
|
nickjillings@1370
|
1112 this.pages = [];
|
nicholas@2535
|
1113
|
nickjillings@1370
|
1114 // Self-contained generators
|
nicholas@2535
|
1115 this.createGeneralNodeDOM = function (name, id, parent) {
|
nickjillings@1375
|
1116 this.type = name;
|
nickjillings@1370
|
1117 var root = document.createElement('div');
|
nickjillings@1370
|
1118 root.id = id;
|
nickjillings@1370
|
1119 root.className = "node";
|
nickjillings@1370
|
1120
|
nickjillings@1370
|
1121 var titleDiv = document.createElement('div');
|
nickjillings@1370
|
1122 titleDiv.className = "node-title";
|
nickjillings@1370
|
1123 var title = document.createElement('span');
|
nickjillings@1370
|
1124 title.className = "node-title";
|
nickjillings@1370
|
1125 title.textContent = name;
|
nickjillings@1370
|
1126 titleDiv.appendChild(title);
|
nickjillings@1370
|
1127
|
nickjillings@1370
|
1128 var attributeDiv = document.createElement('div');
|
nickjillings@1370
|
1129 attributeDiv.className = "node-attributes";
|
nickjillings@1370
|
1130
|
nickjillings@1370
|
1131 var childrenDiv = document.createElement('div');
|
nickjillings@1370
|
1132 childrenDiv.className = "node-children";
|
nickjillings@1370
|
1133
|
nickjillings@1370
|
1134 var buttonsDiv = document.createElement('div');
|
nickjillings@1370
|
1135 buttonsDiv.className = "node-buttons";
|
nickjillings@1370
|
1136
|
nickjillings@1370
|
1137 root.appendChild(titleDiv);
|
nickjillings@1370
|
1138 root.appendChild(attributeDiv);
|
nickjillings@1370
|
1139 root.appendChild(childrenDiv);
|
nickjillings@1370
|
1140 root.appendChild(buttonsDiv);
|
nickjillings@1370
|
1141
|
nickjillings@1370
|
1142 var obj = {
|
nickjillings@1370
|
1143 rootDOM: root,
|
nickjillings@1370
|
1144 titleDOM: title,
|
nickjillings@1370
|
1145 attributeDOM: attributeDiv,
|
nickjillings@1370
|
1146 attributes: [],
|
nickjillings@1370
|
1147 childrenDOM: childrenDiv,
|
nickjillings@1370
|
1148 children: [],
|
nickjillings@1370
|
1149 buttonDOM: buttonsDiv,
|
nickjillings@1370
|
1150 parent: parent
|
nickjillings@1370
|
1151 }
|
nickjillings@1370
|
1152 return obj;
|
nickjillings@1370
|
1153 }
|
nicholas@2535
|
1154
|
nicholas@2535
|
1155 this.convertAttributeToDOM = function (node, schema) {
|
nickjillings@1370
|
1156 // This takes an attribute schema node and returns an object with the input node and any bindings
|
nicholas@2535
|
1157 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) {
|
nicholas@2535
|
1158 schema = specification.schema.getAllElementsByName(schema.getAttribute('ref'))[0];
|
nicholas@2535
|
1159 }
|
nicholas@2535
|
1160 var obj = new function () {
|
nickjillings@1370
|
1161 this.input;
|
nickjillings@1370
|
1162 this.name;
|
nickjillings@1370
|
1163 this.owner;
|
nickjillings@1370
|
1164 this.holder;
|
nicholas@2535
|
1165
|
nickjillings@1370
|
1166 this.name = schema.getAttribute('name');
|
nickjillings@1370
|
1167 this.default = schema.getAttribute('default');
|
nickjillings@1370
|
1168 this.dataType = schema.getAttribute('type');
|
nickjillings@2158
|
1169 if (this.dataType == undefined) {
|
nickjillings@2158
|
1170 if (schema.childElementCount > 0) {
|
nicholas@2390
|
1171 if (schema.firstElementChild.nodeName == "xs:simpleType") {
|
nickjillings@2158
|
1172 this.dataType = schema.getAllElementsByTagName("xs:restriction")[0].getAttribute("base");
|
nickjillings@2158
|
1173 }
|
nickjillings@2158
|
1174 }
|
nickjillings@2158
|
1175 }
|
nicholas@2535
|
1176 if (typeof this.dataType == "string") {
|
nicholas@2535
|
1177 this.dataType = this.dataType.substr(3);
|
nicholas@2535
|
1178 } else {
|
nicholas@2535
|
1179 this.dataType = "string";
|
nicholas@2535
|
1180 }
|
nickjillings@1370
|
1181 var minVar = undefined;
|
nickjillings@1370
|
1182 var maxVar = undefined;
|
nicholas@2535
|
1183 switch (this.dataType) {
|
nickjillings@1370
|
1184 case "negativeInteger":
|
nickjillings@1370
|
1185 maxVar = -1;
|
nickjillings@1370
|
1186 break;
|
nickjillings@1370
|
1187 case "positiveInteger":
|
nickjillings@1370
|
1188 minVar = 1;
|
nickjillings@1370
|
1189 break;
|
nickjillings@1370
|
1190 case "nonNegativeInteger":
|
nickjillings@1370
|
1191 minVar = 0;
|
nickjillings@1370
|
1192 break;
|
nickjillings@1370
|
1193 case "nonPositiveInteger":
|
nickjillings@1370
|
1194 maxVar = 0;
|
nickjillings@1370
|
1195 break;
|
nickjillings@1370
|
1196 case "byte":
|
nickjillings@1370
|
1197 minVar = 0;
|
nickjillings@1370
|
1198 maxVar = 256;
|
nickjillings@1370
|
1199 break;
|
nickjillings@1370
|
1200 case "short":
|
nickjillings@1370
|
1201 minVar = 0;
|
nickjillings@1370
|
1202 maxVar = 65536;
|
nickjillings@1370
|
1203 break;
|
nickjillings@1370
|
1204 default:
|
nickjillings@1370
|
1205 break;
|
nickjillings@1370
|
1206 }
|
nicholas@2535
|
1207
|
nickjillings@2174
|
1208 this.enumeration = schema.getAllElementsByTagName("xs:enumeration");
|
nickjillings@2174
|
1209 if (this.enumeration.length == 0) {
|
nickjillings@2174
|
1210 this.input = document.createElement('input');
|
nicholas@2535
|
1211 switch (this.dataType) {
|
nickjillings@2174
|
1212 case "boolean":
|
nickjillings@2174
|
1213 this.input.type = "checkbox";
|
nickjillings@2174
|
1214 break;
|
nickjillings@2174
|
1215 case "negativeInteger":
|
nickjillings@2174
|
1216 case "positiveInteger":
|
nickjillings@2174
|
1217 case "nonNegativeInteger":
|
nickjillings@2174
|
1218 case "nonPositiveInteger":
|
nickjillings@2174
|
1219 case "integer":
|
nickjillings@2174
|
1220 case "short":
|
nickjillings@2174
|
1221 case "byte":
|
nickjillings@2174
|
1222 this.input.step = 1;
|
nickjillings@2174
|
1223 case "decimal":
|
nickjillings@2174
|
1224 this.input.type = "number";
|
nickjillings@2174
|
1225 this.input.min = minVar;
|
nickjillings@2174
|
1226 this.input.max = maxVar;
|
nickjillings@2174
|
1227 break;
|
nickjillings@2174
|
1228 default:
|
nickjillings@2174
|
1229 break;
|
nickjillings@2174
|
1230 }
|
nickjillings@2174
|
1231 } else {
|
nickjillings@2174
|
1232 this.input = document.createElement("select");
|
nicholas@2535
|
1233 for (var i = 0; i < this.enumeration.length; i++) {
|
nickjillings@2174
|
1234 var option = document.createElement("option");
|
nickjillings@2174
|
1235 var value = this.enumeration[i].getAttribute("value");
|
nicholas@2535
|
1236 option.setAttribute("value", value);
|
nickjillings@2174
|
1237 option.textContent = value;
|
nickjillings@2174
|
1238 this.input.appendChild(option);
|
nickjillings@2174
|
1239 }
|
nickjillings@1370
|
1240 }
|
nickjillings@1370
|
1241 var value;
|
nicholas@2535
|
1242 eval("value = node." + this.name)
|
nicholas@2535
|
1243 if (this.default != undefined && value == undefined) {
|
nickjillings@2174
|
1244 value = this.default;
|
nickjillings@2174
|
1245 }
|
nickjillings@2174
|
1246 if (this.input.type == "checkbox") {
|
nicholas@2535
|
1247 if (value == "true" || value == "True") {
|
nicholas@2535
|
1248 this.input.checked = false;
|
nicholas@2535
|
1249 } else {
|
nicholas@2535
|
1250 this.input.checked = false;
|
nicholas@2535
|
1251 }
|
nickjillings@2174
|
1252 } else {
|
nickjillings@1370
|
1253 this.input.value = value;
|
nickjillings@1370
|
1254 }
|
nicholas@2535
|
1255 this.handleEvent = function (event) {
|
nickjillings@1370
|
1256 var value;
|
nicholas@2535
|
1257 if (this.input.nodeName == "INPUT") {
|
nicholas@2535
|
1258 switch (this.input.type) {
|
nickjillings@2174
|
1259 case "checkbox":
|
nickjillings@2174
|
1260 value = event.currentTarget.checked;
|
nickjillings@2174
|
1261 break;
|
nickjillings@2174
|
1262 case "number":
|
n@2423
|
1263 if (event.currentTarget.value != "") {
|
n@2423
|
1264 value = Number(event.currentTarget.value);
|
n@2423
|
1265 } else {
|
n@2423
|
1266 value = undefined;
|
n@2423
|
1267 }
|
nickjillings@2174
|
1268 break;
|
nickjillings@2174
|
1269 default:
|
n@2423
|
1270 if (event.currentTarget.value != "") {
|
n@2423
|
1271 value = event.currentTarget.value;
|
n@2423
|
1272 } else {
|
n@2423
|
1273 value = undefined;
|
n@2423
|
1274 }
|
nicholas@2535
|
1275 break;
|
nickjillings@2174
|
1276 }
|
nickjillings@2174
|
1277 } else if (this.input.nodeName == "SELECT") {
|
nickjillings@2174
|
1278 value = event.currentTarget.value;
|
nickjillings@1370
|
1279 }
|
nicholas@2535
|
1280 eval("this.owner." + this.name + " = value");
|
nickjillings@1370
|
1281 }
|
nickjillings@1370
|
1282 this.holder = document.createElement('div');
|
nickjillings@1370
|
1283 this.holder.className = "attribute";
|
nicholas@2535
|
1284 this.holder.setAttribute('name', this.name);
|
nickjillings@1370
|
1285 var text = document.createElement('span');
|
nicholas@2535
|
1286 eval("text.textContent = attributeText." + this.name + "+': '");
|
nickjillings@1370
|
1287 this.holder.appendChild(text);
|
nickjillings@1370
|
1288 this.holder.appendChild(this.input);
|
nickjillings@1370
|
1289 this.owner = node;
|
nicholas@2535
|
1290 this.input.addEventListener("change", this, false);
|
nickjillings@1370
|
1291 }
|
nicholas@2535
|
1292 if (obj.attribute != null) {
|
nickjillings@1370
|
1293 obj.input.value = obj.attribute;
|
nickjillings@1370
|
1294 }
|
nickjillings@1370
|
1295 return obj;
|
nickjillings@1370
|
1296 }
|
nicholas@2535
|
1297
|
nicholas@2535
|
1298 this.convert = function (root) {
|
nickjillings@1370
|
1299 //Performs the actual conversion using the given root DOM as the root
|
nickjillings@1370
|
1300 this.injectDOM = root;
|
nicholas@2535
|
1301
|
nickjillings@1373
|
1302 // Build the export button
|
nickjillings@1373
|
1303 var exportButton = document.createElement("button");
|
nickjillings@1373
|
1304 exportButton.textContent = "Export to XML";
|
nicholas@2535
|
1305 exportButton.onclick = function () {
|
nickjillings@1373
|
1306 var doc = specification.encode();
|
nickjillings@1373
|
1307 var obj = {};
|
nickjillings@1373
|
1308 obj.title = "Export";
|
nickjillings@1373
|
1309 obj.content = document.createElement("div");
|
nickjillings@1373
|
1310 obj.content.id = "finish";
|
nickjillings@1373
|
1311 var span = document.createElement("span");
|
n@2405
|
1312 span.textContent = "Your XML document is linked below. On most browsers, simply right click on the link and select 'Save As'. Or clicking on the link may download the file directly."
|
n@2405
|
1313 obj.content.appendChild(span);
|
n@2405
|
1314 span = document.createElement("p");
|
n@2405
|
1315 span.textContent = "NOTE FOR SAFARI! You cannot right click on the below link and save it as a file, Safari does not like that at all. Instead click on it to open the XML, the Press Cmd+S to open the save dialogue. Make sure you have 'save as Page Source' selected on the bottom of the window. Currently Safari has no plans to support the HTML 'download' attribute which causes this problem";
|
nickjillings@1373
|
1316 obj.content.appendChild(span);
|
nickjillings@1373
|
1317 var link = document.createElement("div");
|
n@2412
|
1318 link.appendChild(doc.firstChild);
|
nickjillings@1373
|
1319 var file = [link.innerHTML];
|
nicholas@2535
|
1320 var bb = new Blob(file, {
|
nicholas@2535
|
1321 type: 'application/xml'
|
nicholas@2535
|
1322 });
|
nickjillings@1373
|
1323 var dnlk = window.URL.createObjectURL(bb);
|
nickjillings@1373
|
1324 var a = document.createElement("a");
|
nickjillings@1373
|
1325 a.hidden = '';
|
nickjillings@1373
|
1326 a.href = dnlk;
|
nickjillings@1373
|
1327 a.download = "project-specification.xml";
|
nickjillings@1373
|
1328 a.textContent = "Save File";
|
nickjillings@1373
|
1329 obj.content.appendChild(a);
|
nickjillings@1373
|
1330 popupObject.show();
|
nickjillings@1373
|
1331 popupObject.postNode(obj);
|
nickjillings@1373
|
1332 }
|
nickjillings@1373
|
1333 this.injectDOM.appendChild(exportButton);
|
nicholas@2535
|
1334
|
nickjillings@1370
|
1335 // First perform the setupNode;
|
nickjillings@1370
|
1336 var setupSchema = specification.schema.getAllElementsByName('setup')[0];
|
nicholas@2535
|
1337 this.setupDOM = new this.createGeneralNodeDOM('Global Configuration', 'setup', null);
|
nickjillings@1370
|
1338 this.injectDOM.appendChild(this.setupDOM.rootDOM);
|
nickjillings@1370
|
1339 var setupAttributes = setupSchema.getAllElementsByTagName('xs:attribute');
|
nicholas@2535
|
1340 for (var i = 0; i < setupAttributes.length; i++) {
|
nickjillings@1370
|
1341 var attributeName = setupAttributes[i].getAttribute('name');
|
nicholas@2535
|
1342 var attrObject = this.convertAttributeToDOM(specification, setupAttributes[i]);
|
nickjillings@1370
|
1343 this.setupDOM.attributeDOM.appendChild(attrObject.holder);
|
nickjillings@1370
|
1344 this.setupDOM.attributes.push(attrObject);
|
nickjillings@1370
|
1345 }
|
nicholas@2535
|
1346
|
nickjillings@2179
|
1347 // Build the exit Text node
|
nicholas@2535
|
1348 var exitText = new this.createGeneralNodeDOM("Exit Text", "exit-test", this.setupDOM);
|
nickjillings@2179
|
1349 exitText.rootDOM.removeChild(exitText.attributeDOM);
|
nickjillings@2179
|
1350 this.setupDOM.children.push(exitText);
|
nickjillings@2179
|
1351 this.setupDOM.childrenDOM.appendChild(exitText.rootDOM);
|
nickjillings@2179
|
1352 var obj = {
|
nickjillings@2179
|
1353 rootDOM: document.createElement("div"),
|
nickjillings@2179
|
1354 labelDOM: document.createElement("label"),
|
nickjillings@2179
|
1355 inputDOM: document.createElement("textarea"),
|
nickjillings@2179
|
1356 parent: exitText,
|
nickjillings@2179
|
1357 specification: specification,
|
nicholas@2535
|
1358 handleEvent: function (event) {
|
nickjillings@2179
|
1359 this.specification.exitText = this.inputDOM.value;
|
nickjillings@2179
|
1360 }
|
nickjillings@2179
|
1361 }
|
b@2367
|
1362 var exitWarning = document.createElement("div");
|
b@2367
|
1363 obj.rootDOM.appendChild(exitWarning);
|
b@2367
|
1364 exitWarning.textContent = "Only visible when the above 'On complete redirect URL' field is empty.";
|
nickjillings@2179
|
1365 obj.rootDOM.appendChild(obj.labelDOM);
|
nickjillings@2179
|
1366 obj.rootDOM.appendChild(obj.inputDOM);
|
nickjillings@2179
|
1367 obj.labelDOM.textContent = "Text: ";
|
nickjillings@2179
|
1368 obj.inputDOM.value = obj.specification.exitText;
|
nicholas@2535
|
1369 obj.inputDOM.addEventListener("change", obj);
|
nickjillings@2179
|
1370 exitText.children.push(obj);
|
nickjillings@2179
|
1371 exitText.childrenDOM.appendChild(obj.rootDOM);
|
nicholas@2535
|
1372
|
nickjillings@1370
|
1373 // Now we must build the interface Node
|
nicholas@2535
|
1374 this.interfaceDOM = new this.interfaceNode(this, specification.interfaces);
|
nicholas@2535
|
1375 this.interfaceDOM.build("Interface", "setup-interface", this.setupDOM.rootDOM);
|
nicholas@2535
|
1376
|
nickjillings@1370
|
1377 // Now build the Metrics selection node
|
nicholas@2535
|
1378 var metric = this.createGeneralNodeDOM("Session Metrics", "setup-metric", this.setupDOM);
|
nickjillings@1370
|
1379 metric.rootDOM.removeChild(metric.attributeDOM);
|
nickjillings@1370
|
1380 this.setupDOM.children.push(metric);
|
nickjillings@1370
|
1381 this.setupDOM.childrenDOM.appendChild(metric.rootDOM);
|
nickjillings@1370
|
1382 var interfaceName = popupStateNodes.state[1].select.value;
|
nickjillings@1370
|
1383 var checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("metrics")[0];
|
nickjillings@1370
|
1384 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
|
nickjillings@1370
|
1385 var interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("metrics")[0];
|
nickjillings@1370
|
1386 testXML = testXML.getAllElementsByTagName("metrics");
|
nicholas@2390
|
1387 var interfaceXMLChild = interfaceXML.firstElementChild;
|
nicholas@2535
|
1388 while (interfaceXMLChild) {
|
nickjillings@1370
|
1389 var obj = {
|
nickjillings@1370
|
1390 input: document.createElement('input'),
|
nickjillings@1370
|
1391 root: document.createElement('div'),
|
nickjillings@1370
|
1392 text: document.createElement('span'),
|
nickjillings@1370
|
1393 specification: specification.metrics.enabled,
|
nicholas@2390
|
1394 name: interfaceXMLChild.getAttribute("name"),
|
nicholas@2535
|
1395 handleEvent: function () {
|
nicholas@2535
|
1396 for (var i = 0; i < this.specification.length; i++) {
|
nicholas@2535
|
1397 if (this.specification[i] == this.name) {
|
nickjillings@1370
|
1398 var options = this.specification;
|
nickjillings@1370
|
1399 if (this.input.checked == false) {
|
nicholas@2535
|
1400 if (i == options.length) {
|
nicholas@2535
|
1401 options = options.slice(0, i);
|
nicholas@2535
|
1402 } else {
|
nicholas@2535
|
1403 options = options.slice(0, i).concat(options.slice(i + 1));
|
nickjillings@1370
|
1404 }
|
nickjillings@1370
|
1405 } else {
|
nickjillings@1370
|
1406 return;
|
nickjillings@1370
|
1407 }
|
nickjillings@1370
|
1408 this.specification = options;
|
nickjillings@1370
|
1409 break;
|
nickjillings@1370
|
1410 }
|
nickjillings@1370
|
1411 }
|
nickjillings@1370
|
1412 if (this.input.checked) {
|
nickjillings@1370
|
1413 this.specification.push(this.name);
|
nickjillings@1370
|
1414 }
|
nickjillings@1370
|
1415 }
|
nickjillings@1370
|
1416 };
|
nickjillings@1370
|
1417 obj.root.className = "attribute";
|
nickjillings@1370
|
1418 obj.input.type = "checkbox";
|
nickjillings@1370
|
1419 obj.root.appendChild(obj.text);
|
nickjillings@1370
|
1420 obj.root.appendChild(obj.input);
|
nicholas@2390
|
1421 obj.text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
|
nickjillings@1370
|
1422 metric.children.push(obj);
|
nickjillings@1370
|
1423 metric.childrenDOM.appendChild(obj.root);
|
nicholas@2535
|
1424 for (var j = 0; j < specification.metrics.enabled.length; j++) {
|
nicholas@2535
|
1425 if (specification.metrics.enabled[j] == obj.name) {
|
nickjillings@1370
|
1426 obj.input.checked = true;
|
nickjillings@1370
|
1427 break;
|
nickjillings@1370
|
1428 }
|
nickjillings@1370
|
1429 }
|
nicholas@2390
|
1430 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
|
nickjillings@1370
|
1431 }
|
nicholas@2535
|
1432
|
nickjillings@1370
|
1433 // Now both before and after surveys
|
nicholas@2535
|
1434 if (specification.preTest == undefined) {
|
nickjillings@2194
|
1435 specification.preTest = new specification.surveyNode(specification);
|
nickjillings@1370
|
1436 specification.preTest.location = "pre";
|
nickjillings@1370
|
1437 }
|
nicholas@2535
|
1438 if (specification.postTest == undefined) {
|
nickjillings@2194
|
1439 specification.postTest = new specification.surveyNode(specification);
|
nickjillings@1370
|
1440 specification.postTest.location = "post";
|
nickjillings@1370
|
1441 }
|
nicholas@2535
|
1442 var surveyBefore = new this.surveyNode(this, specification.preTest, "Pre");
|
nicholas@2535
|
1443 var surveyAfter = new this.surveyNode(this, specification.postTest, "Post");
|
nickjillings@1370
|
1444 this.setupDOM.children.push(surveyBefore);
|
nickjillings@1370
|
1445 this.setupDOM.children.push(surveyAfter);
|
nickjillings@1370
|
1446 this.setupDOM.childrenDOM.appendChild(surveyBefore.rootDOM);
|
nickjillings@1370
|
1447 this.setupDOM.childrenDOM.appendChild(surveyAfter.rootDOM);
|
nicholas@2535
|
1448
|
nickjillings@1370
|
1449 // Add in the page creator button
|
nickjillings@1370
|
1450 this.addPage = {
|
nickjillings@1370
|
1451 root: document.createElement("button"),
|
nickjillings@1370
|
1452 parent: this,
|
nicholas@2535
|
1453 handleEvent: function () {
|
nickjillings@2194
|
1454 var pageObj = new specification.page(specification);
|
nickjillings@1370
|
1455 specification.pages.push(pageObj);
|
nicholas@2535
|
1456 var newPage = new this.parent.pageNode(this.parent, pageObj);
|
nicholas@2315
|
1457 document.getElementById("page-holder").appendChild(newPage.rootDOM);
|
nickjillings@1370
|
1458 this.parent.pages.push(newPage);
|
nickjillings@1370
|
1459 }
|
nickjillings@1370
|
1460 }
|
nickjillings@1370
|
1461 this.addPage.root.textContent = "Add Page";
|
nicholas@2315
|
1462 this.addPage.root.id = "new-page-button";
|
nicholas@2315
|
1463 this.addPage.root.style.float = "left";
|
nicholas@2535
|
1464 this.addPage.root.addEventListener("click", this.addPage, false);
|
nicholas@2535
|
1465
|
nicholas@2315
|
1466 var pageHolder = document.createElement("div");
|
nicholas@2535
|
1467 pageHolder.id = "page-holder";
|
nicholas@2315
|
1468 this.injectDOM.appendChild(pageHolder);
|
nicholas@2535
|
1469
|
nickjillings@1374
|
1470 // Build each page
|
nicholas@2535
|
1471 for (var page of specification.pages) {
|
nicholas@2535
|
1472 var newPage = new this.pageNode(this, page);
|
nicholas@2315
|
1473 pageHolder.appendChild(newPage.rootDOM);
|
nickjillings@1374
|
1474 this.pages.push(newPage);
|
nickjillings@1374
|
1475 }
|
nicholas@2535
|
1476
|
nicholas@2315
|
1477 this.injectDOM.appendChild(this.addPage.root);
|
nickjillings@1370
|
1478 }
|
nicholas@2535
|
1479
|
nicholas@2535
|
1480 this.interfaceNode = function (parent, rootObject) {
|
nickjillings@1375
|
1481 this.type = "interfaceNode";
|
nickjillings@1370
|
1482 this.rootDOM;
|
nickjillings@1370
|
1483 this.titleDOM;
|
nickjillings@1370
|
1484 this.attributeDOM;
|
nickjillings@1370
|
1485 this.attributes = [];
|
nickjillings@1370
|
1486 this.childrenDOM;
|
nickjillings@1370
|
1487 this.children = [];
|
nickjillings@1370
|
1488 this.buttonDOM;
|
nickjillings@1370
|
1489 this.parent = parent;
|
nickjillings@1370
|
1490 this.HTMLPoint;
|
nickjillings@1370
|
1491 this.specification = rootObject;
|
nickjillings@1370
|
1492 this.schema = specification.schema.getAllElementsByName("interface")[1];
|
nicholas@2535
|
1493
|
nicholas@2535
|
1494 this.createIOasAttr = function (name, specification, parent, type) {
|
nickjillings@1370
|
1495 this.root = document.createElement('div');
|
nickjillings@1370
|
1496 this.input = document.createElement("input");
|
nickjillings@1370
|
1497 this.name = name;
|
nickjillings@1370
|
1498 this.type = type;
|
nickjillings@1370
|
1499 this.parent = parent;
|
nickjillings@1370
|
1500 this.specification = specification;
|
nicholas@2535
|
1501 this.handleEvent = function (event) {
|
nicholas@2535
|
1502 for (var i = 0; i < this.specification.options.length; i++) {
|
nicholas@2535
|
1503 if (this.specification.options[i].name == this.name) {
|
nickjillings@1370
|
1504 var options = this.specification.options;
|
nickjillings@1370
|
1505 if (this.input.checked == false) {
|
nicholas@2535
|
1506 if (i == options.length) {
|
nicholas@2535
|
1507 options = options.slice(0, i);
|
nicholas@2535
|
1508 } else {
|
nicholas@2535
|
1509 options = options.slice(0, i).concat(options.slice(i + 1));
|
nickjillings@1370
|
1510 }
|
nickjillings@1370
|
1511 } else {
|
nickjillings@1370
|
1512 return;
|
nickjillings@1370
|
1513 }
|
nickjillings@1370
|
1514 this.specification.options = options;
|
nickjillings@1370
|
1515 break;
|
nickjillings@1370
|
1516 }
|
nickjillings@1370
|
1517 }
|
nickjillings@1370
|
1518 if (this.input.checked) {
|
nickjillings@1370
|
1519 var obj = {
|
nickjillings@1370
|
1520 name: this.name,
|
nickjillings@1370
|
1521 type: this.type
|
nickjillings@1370
|
1522 };
|
nickjillings@1370
|
1523 this.specification.options.push(obj);
|
nickjillings@1370
|
1524 }
|
nicholas@2535
|
1525 if (this.parent.HTMLPoint.id == "setup") {
|
nickjillings@1370
|
1526 // We've changed a global setting, must update all child 'interfaces' and disable them
|
nicholas@2535
|
1527 for (pages of convert.pages) {
|
nicholas@2535
|
1528 for (interface of pages.interfaces) {
|
nicholas@2535
|
1529 if (this.type == "check") {
|
nicholas@2535
|
1530 for (node of interface.children[0].attributes) {
|
nickjillings@1370
|
1531 if (node.name == this.name) {
|
nickjillings@1370
|
1532 if (this.input.checked) {
|
nickjillings@1370
|
1533 node.input.disabled = true;
|
nickjillings@1370
|
1534 node.input.checked = false;
|
nickjillings@1370
|
1535 } else {
|
nickjillings@1370
|
1536 node.input.disabled = false;
|
nickjillings@1370
|
1537 }
|
nickjillings@1370
|
1538 break;
|
nickjillings@1370
|
1539 }
|
nickjillings@1370
|
1540 }
|
nicholas@2535
|
1541 } else if (this.type == "show") {
|
nicholas@2535
|
1542 for (node of interface.children[1].attributes) {
|
nickjillings@1370
|
1543 if (node.name == this.name) {
|
nickjillings@1370
|
1544 if (this.input.checked) {
|
nickjillings@1370
|
1545 node.input.disabled = true;
|
nickjillings@1370
|
1546 } else {
|
nickjillings@1370
|
1547 node.input.disabled = false;
|
nickjillings@1370
|
1548 }
|
nickjillings@1370
|
1549 break;
|
nickjillings@1370
|
1550 }
|
nickjillings@1370
|
1551 }
|
nickjillings@1370
|
1552 }
|
nickjillings@1370
|
1553 }
|
nickjillings@1370
|
1554 }
|
nickjillings@1370
|
1555 }
|
nickjillings@1370
|
1556 };
|
nicholas@2535
|
1557 this.findIndex = function (element, index, array) {
|
nickjillings@1370
|
1558 if (element.name == this.name)
|
nickjillings@1370
|
1559 return true;
|
nickjillings@1370
|
1560 else
|
nickjillings@1370
|
1561 return false;
|
nickjillings@1370
|
1562 };
|
nicholas@2535
|
1563 this.findNode = function (element, index, array) {
|
nickjillings@1370
|
1564 if (element.name == this.name)
|
nickjillings@1370
|
1565 return true;
|
nickjillings@1370
|
1566 else
|
nickjillings@1370
|
1567 return false;
|
nickjillings@1370
|
1568 };
|
nickjillings@1370
|
1569 this.input.type = "checkbox";
|
nicholas@2535
|
1570 this.input.setAttribute("name", name);
|
nicholas@2535
|
1571 this.input.addEventListener("change", this, false);
|
nickjillings@1370
|
1572 this.root.appendChild(this.input);
|
nickjillings@1370
|
1573 this.root.className = "attribute";
|
nickjillings@1370
|
1574 return this;
|
nickjillings@1370
|
1575 }
|
nicholas@2535
|
1576
|
nicholas@2535
|
1577 this.build = function (name, id, parent) {
|
nicholas@2535
|
1578 var obj = this.parent.createGeneralNodeDOM(name, id, parent);
|
nicholas@2535
|
1579
|
nickjillings@1370
|
1580 this.rootDOM = obj.rootDOM;
|
nickjillings@1370
|
1581 this.titleDOM = obj.titleDOM;
|
nickjillings@1370
|
1582 this.attributeDOM = obj.attributeDOM;
|
nickjillings@1370
|
1583 this.childrenDOM = obj.childrenDOM;
|
nickjillings@1370
|
1584 this.buttonDOM = obj.buttonsDOM;
|
nickjillings@1370
|
1585 this.HTMLPoint = parent;
|
nickjillings@1370
|
1586 this.rootDOM.removeChild(this.attributeDOM);
|
nicholas@2243
|
1587 if (parent.id != "setup") {
|
nicholas@2243
|
1588 // Put in the <title> node:
|
nicholas@2243
|
1589 this.titleNode = {
|
nicholas@2243
|
1590 root: document.createElement("div"),
|
nicholas@2243
|
1591 label: document.createElement("span"),
|
nicholas@2243
|
1592 input: document.createElement("input"),
|
nicholas@2243
|
1593 parent: this,
|
nicholas@2535
|
1594 handleEvent: function (event) {
|
nicholas@2243
|
1595 this.parent.specification.title = event.currentTarget.value;
|
nicholas@2243
|
1596 }
|
nicholas@2243
|
1597 }
|
nicholas@2243
|
1598 this.titleNode.label.textContent = "Axis Title:";
|
nicholas@2243
|
1599 this.titleNode.root.className = "node-children";
|
nicholas@2243
|
1600 this.titleNode.root.appendChild(this.titleNode.label);
|
nicholas@2243
|
1601 this.titleNode.root.appendChild(this.titleNode.input);
|
nicholas@2535
|
1602 this.titleNode.input.addEventListener("change", this.titleNode, false);
|
nicholas@2243
|
1603 this.titleNode.input.value = this.specification.title;
|
nicholas@2243
|
1604 this.children.push(this.titleNode);
|
nicholas@2243
|
1605 this.childrenDOM.appendChild(this.titleNode.root);
|
nicholas@2243
|
1606 }
|
nicholas@2535
|
1607
|
nickjillings@1370
|
1608 // Put in the check / show options as individual children
|
nicholas@2535
|
1609 var checks = this.parent.createGeneralNodeDOM("Checks", "setup-interface-checks", this);
|
nickjillings@1370
|
1610
|
nickjillings@1370
|
1611 var interfaceName = popupStateNodes.state[1].select.value;
|
nickjillings@1370
|
1612 var checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("checks")[0];
|
nickjillings@1370
|
1613 var testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
|
nickjillings@1370
|
1614 var interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("checks")[0];
|
nickjillings@1370
|
1615 testXML = testXML.getAllElementsByTagName("checks");
|
nicholas@2390
|
1616 var interfaceXMLChild = interfaceXML.firstElementChild;
|
nicholas@2535
|
1617 while (interfaceXMLChild) {
|
nicholas@2535
|
1618 var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"), this.specification, this, "check");
|
nicholas@2535
|
1619 for (var option of this.specification.options) {
|
nicholas@2535
|
1620 if (option.name == obj.name) {
|
nickjillings@1370
|
1621 obj.input.checked = true;
|
nickjillings@1370
|
1622 break;
|
nickjillings@1370
|
1623 }
|
nickjillings@1370
|
1624 }
|
nickjillings@1370
|
1625 if (parent.id != "setup") {
|
nicholas@2535
|
1626 var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode, obj);
|
nickjillings@1381
|
1627 if (node != undefined) {
|
nickjillings@1381
|
1628 if (node.input.checked) {
|
nickjillings@1381
|
1629 obj.input.checked = false;
|
nickjillings@1381
|
1630 obj.input.disabled = true;
|
nickjillings@1381
|
1631 }
|
nickjillings@1370
|
1632 }
|
nickjillings@1370
|
1633 }
|
nickjillings@1370
|
1634 var text = document.createElement('span');
|
nicholas@2390
|
1635 text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
|
nickjillings@1370
|
1636 obj.root.appendChild(text);
|
nickjillings@1370
|
1637 checks.attributeDOM.appendChild(obj.root);
|
nickjillings@1370
|
1638 checks.attributes.push(obj);
|
nicholas@2390
|
1639 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
|
nickjillings@1370
|
1640 }
|
nickjillings@1370
|
1641 this.children.push(checks);
|
nickjillings@1370
|
1642 this.childrenDOM.appendChild(checks.rootDOM);
|
nickjillings@1370
|
1643
|
nicholas@2535
|
1644 var show = this.parent.createGeneralNodeDOM("Show", "setup-interface-show", this);
|
nickjillings@1370
|
1645 interfaceName = popupStateNodes.state[1].select.value;
|
nickjillings@1370
|
1646 checkText = interfaceSpecs.getElementsByTagName("global")[0].getAllElementsByTagName("show")[0];
|
nickjillings@1370
|
1647 testXML = interfaceSpecs.getElementsByTagName("tests")[0].getAllElementsByName(interfaceName)[0];
|
nickjillings@1370
|
1648 interfaceXML = interfaceSpecs.getAllElementsByTagName("interfaces")[0].getAllElementsByName(testXML.getAttribute("interface"))[0].getAllElementsByTagName("show")[0];
|
nickjillings@1370
|
1649 testXML = testXML.getAllElementsByTagName("show");
|
nicholas@2390
|
1650 interfaceXMLChild = interfaceXML.firstElementChild;
|
nicholas@2535
|
1651 while (interfaceXMLChild) {
|
nicholas@2535
|
1652 var obj = new this.createIOasAttr(interfaceXMLChild.getAttribute("name"), this.specification, this, "show");
|
nicholas@2535
|
1653 for (var option of this.specification.options) {
|
nicholas@2535
|
1654 if (option.name == obj.name) {
|
nickjillings@1370
|
1655 obj.input.checked = true;
|
nickjillings@1370
|
1656 break;
|
nickjillings@1370
|
1657 }
|
nickjillings@1370
|
1658 }
|
nickjillings@1370
|
1659 if (parent.id != "setup") {
|
nicholas@2535
|
1660 var node = convert.interfaceDOM.children[0].attributes.find(obj.findNode, obj);
|
nickjillings@1381
|
1661 if (node != undefined) {
|
nickjillings@1381
|
1662 if (node.input.checked) {
|
nickjillings@1381
|
1663 obj.input.checked = false;
|
nickjillings@1381
|
1664 obj.input.disabled = true;
|
nickjillings@1381
|
1665 }
|
nickjillings@1370
|
1666 }
|
nickjillings@1370
|
1667 }
|
nickjillings@1370
|
1668 var text = document.createElement('span');
|
nicholas@2390
|
1669 text.textContent = checkText.getAllElementsByName(interfaceXMLChild.getAttribute("name"))[0].textContent;
|
nickjillings@1370
|
1670 obj.root.appendChild(text);
|
nickjillings@1370
|
1671 show.attributeDOM.appendChild(obj.root);
|
nickjillings@1370
|
1672 show.attributes.push(obj);
|
nicholas@2390
|
1673 interfaceXMLChild = interfaceXMLChild.nextElementSibling;
|
nickjillings@1370
|
1674 }
|
nickjillings@1370
|
1675 this.children.push(show);
|
nickjillings@1370
|
1676 this.childrenDOM.appendChild(show.rootDOM);
|
nicholas@2535
|
1677
|
nicholas@2535
|
1678 if (parent.id == "setup") {} else {
|
nicholas@2535
|
1679 var nameAttr = this.parent.convertAttributeToDOM(this, specification.schema.getAllElementsByName("name")[0]);
|
nickjillings@1370
|
1680 this.attributeDOM.appendChild(nameAttr.holder);
|
nickjillings@1370
|
1681 this.attributes.push(nameAttr);
|
nicholas@2535
|
1682 var scales = new this.scalesNode(this, this.specification);
|
nickjillings@1385
|
1683 this.children.push(scales);
|
nickjillings@1385
|
1684 this.childrenDOM.appendChild(scales.rootDOM);
|
nickjillings@1370
|
1685 }
|
nicholas@2535
|
1686 if (parent != undefined) {
|
nickjillings@1370
|
1687 parent.appendChild(this.rootDOM);
|
nickjillings@1370
|
1688 }
|
nickjillings@1370
|
1689 }
|
nicholas@2535
|
1690
|
nicholas@2535
|
1691 this.scalesNode = function (parent, rootObject) {
|
nickjillings@1385
|
1692 this.type = "scalesNode";
|
nickjillings@1385
|
1693 this.rootDOM = document.createElement("div");
|
nickjillings@1385
|
1694 this.titleDOM = document.createElement("span");
|
nickjillings@1385
|
1695 this.attributeDOM = document.createElement("div");
|
nickjillings@1385
|
1696 this.attributes = [];
|
nickjillings@1385
|
1697 this.childrenDOM = document.createElement("div");
|
nickjillings@1385
|
1698 this.children = [];
|
nickjillings@1385
|
1699 this.buttonDOM = document.createElement("div");
|
nickjillings@1385
|
1700 this.parent = parent;
|
nickjillings@1385
|
1701 this.specification = rootObject;
|
nickjillings@1385
|
1702 this.schema = specification.schema.getAllElementsByName("page")[0];
|
nickjillings@1385
|
1703 this.rootDOM.className = "node";
|
nickjillings@1385
|
1704
|
nickjillings@1385
|
1705 var titleDiv = document.createElement('div');
|
nickjillings@1385
|
1706 titleDiv.className = "node-title";
|
nickjillings@1385
|
1707 this.titleDOM.className = "node-title";
|
nickjillings@1385
|
1708 this.titleDOM.textContent = "Interface Scales";
|
nickjillings@1385
|
1709 titleDiv.appendChild(this.titleDOM);
|
nickjillings@1385
|
1710
|
nickjillings@1385
|
1711 this.attributeDOM.className = "node-attributes";
|
nickjillings@1385
|
1712 this.childrenDOM.className = "node-children";
|
nickjillings@1385
|
1713 this.buttonDOM.className = "node-buttons";
|
nickjillings@1385
|
1714
|
nickjillings@1385
|
1715 this.rootDOM.appendChild(titleDiv);
|
nickjillings@1385
|
1716 this.rootDOM.appendChild(this.attributeDOM);
|
nickjillings@1385
|
1717 this.rootDOM.appendChild(this.childrenDOM);
|
nickjillings@1385
|
1718 this.rootDOM.appendChild(this.buttonDOM);
|
nicholas@2535
|
1719
|
nickjillings@1385
|
1720 this.editButton = {
|
nickjillings@1385
|
1721 button: document.createElement("button"),
|
nickjillings@1385
|
1722 parent: this,
|
nicholas@2535
|
1723 handleEvent: function (event) {
|
nickjillings@1385
|
1724 popupObject.show();
|
nickjillings@1385
|
1725 popupObject.postNode(popupStateNodes.state[6]);
|
nicholas@2535
|
1726 popupStateNodes.state[6].generate(this.parent.specification, this.parent);
|
nickjillings@1385
|
1727 }
|
nickjillings@1385
|
1728 };
|
nickjillings@1385
|
1729 this.editButton.button.textContent = "Edit Scales/Markers";
|
nicholas@2535
|
1730 this.editButton.button.addEventListener("click", this.editButton, false);
|
nickjillings@1385
|
1731 this.buttonDOM.appendChild(this.editButton.button);
|
nickjillings@1385
|
1732 }
|
nickjillings@1370
|
1733 }
|
nicholas@2535
|
1734
|
nicholas@2535
|
1735 this.surveyNode = function (parent, rootObject, location) {
|
nickjillings@1375
|
1736 this.type = "surveyNode";
|
nickjillings@1370
|
1737 this.rootDOM = document.createElement("div");
|
nickjillings@1370
|
1738 this.titleDOM = document.createElement("span");
|
nickjillings@1370
|
1739 this.attributeDOM = document.createElement("div");
|
nickjillings@1370
|
1740 this.attributes = [];
|
nickjillings@1370
|
1741 this.childrenDOM = document.createElement("div");
|
nickjillings@1370
|
1742 this.children = [];
|
nickjillings@1370
|
1743 this.buttonDOM = document.createElement("div");
|
nickjillings@1370
|
1744 this.parent = parent;
|
nickjillings@1370
|
1745 this.specification = rootObject;
|
nickjillings@1370
|
1746 this.schema = specification.schema.getAllElementsByName("survey")[1];
|
nickjillings@1370
|
1747 this.rootDOM.className = "node";
|
nickjillings@1370
|
1748
|
nickjillings@1370
|
1749 var titleDiv = document.createElement('div');
|
nickjillings@1370
|
1750 titleDiv.className = "node-title";
|
nickjillings@1370
|
1751 this.titleDOM.className = "node-title";
|
nickjillings@1370
|
1752 this.titleDOM.textContent = "Survey";
|
nickjillings@1370
|
1753 titleDiv.appendChild(this.titleDOM);
|
nicholas@2535
|
1754
|
nickjillings@1370
|
1755 this.attributeDOM.className = "node-attributes";
|
nickjillings@1370
|
1756 var locationAttr = document.createElement("span");
|
nickjillings@1370
|
1757 this.attributeDOM.appendChild(locationAttr);
|
nickjillings@1370
|
1758 if (location == "Pre" || location == "pre") {
|
nickjillings@1370
|
1759 locationAttr.textContent = "Location: Before";
|
nickjillings@1370
|
1760 } else {
|
nickjillings@1370
|
1761 locationAttr.textContent = "Location: After";
|
nickjillings@1370
|
1762 }
|
nickjillings@1370
|
1763 this.childrenDOM.className = "node-children";
|
nickjillings@1370
|
1764 this.buttonDOM.className = "node-buttons";
|
nickjillings@1370
|
1765
|
nickjillings@1370
|
1766 this.rootDOM.appendChild(titleDiv);
|
nickjillings@1370
|
1767 this.rootDOM.appendChild(this.attributeDOM);
|
nickjillings@1370
|
1768 this.rootDOM.appendChild(this.childrenDOM);
|
nickjillings@1370
|
1769 this.rootDOM.appendChild(this.buttonDOM);
|
nicholas@2535
|
1770
|
nicholas@2535
|
1771 this.surveyEntryNode = function (parent, rootObject) {
|
nickjillings@1375
|
1772 this.type = "surveyEntryNode";
|
nickjillings@1370
|
1773 this.rootDOM = document.createElement("div");
|
nickjillings@1370
|
1774 this.titleDOM = document.createElement("span");
|
nickjillings@1370
|
1775 this.attributeDOM = document.createElement("div");
|
nickjillings@1370
|
1776 this.attributes = [];
|
nickjillings@1370
|
1777 this.childrenDOM = document.createElement("div");
|
nickjillings@1370
|
1778 this.children = [];
|
nickjillings@1370
|
1779 this.buttonDOM = document.createElement("div");
|
nickjillings@1370
|
1780 this.parent = parent;
|
nickjillings@1370
|
1781 this.specification = rootObject;
|
nickjillings@1370
|
1782 this.schema = specification.schema.getAllElementsByName("surveyentry")[1];
|
nickjillings@1370
|
1783
|
nickjillings@1370
|
1784 this.rootDOM.className = "node";
|
nickjillings@1370
|
1785 this.rootDOM.style.minWidth = "50%";
|
nickjillings@1370
|
1786
|
nickjillings@1370
|
1787 var titleDiv = document.createElement('div');
|
nickjillings@1370
|
1788 titleDiv.className = "node-title";
|
nickjillings@1370
|
1789 this.titleDOM.className = "node-title";
|
nickjillings@1370
|
1790 titleDiv.appendChild(this.titleDOM);
|
nickjillings@1370
|
1791
|
nickjillings@1370
|
1792 this.attributeDOM.className = "node-attributes";
|
nickjillings@1370
|
1793 this.childrenDOM.className = "node-children";
|
nickjillings@1370
|
1794 this.buttonDOM.className = "node-buttons";
|
nickjillings@1370
|
1795
|
nickjillings@1370
|
1796 this.rootDOM.appendChild(titleDiv);
|
nickjillings@1370
|
1797 this.rootDOM.appendChild(this.attributeDOM);
|
nickjillings@1370
|
1798 this.rootDOM.appendChild(this.childrenDOM);
|
nickjillings@1370
|
1799 this.rootDOM.appendChild(this.buttonDOM);
|
nicholas@2535
|
1800
|
nicholas@2535
|
1801 this.build = function () {
|
nickjillings@1375
|
1802 this.attributeDOM.innerHTML = null;
|
nickjillings@1375
|
1803 this.childrenDOM.innerHTML = null;
|
nickjillings@1375
|
1804 var statementRoot = document.createElement("div");
|
nickjillings@1375
|
1805 var statement = document.createElement("span");
|
nicholas@2535
|
1806 statement.textContent = "Statement / Question: " + this.specification.statement;
|
nickjillings@1375
|
1807 statementRoot.appendChild(statement);
|
nickjillings@1375
|
1808 this.children.push(statementRoot);
|
nickjillings@1375
|
1809 this.childrenDOM.appendChild(statementRoot);
|
nicholas@2535
|
1810 switch (this.specification.type) {
|
nickjillings@1375
|
1811 case "statement":
|
nickjillings@1375
|
1812 this.titleDOM.textContent = "Statement";
|
nickjillings@1375
|
1813 break;
|
nickjillings@1375
|
1814 case "question":
|
nickjillings@1375
|
1815 this.titleDOM.textContent = "Question";
|
nicholas@2535
|
1816 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
|
nicholas@2535
|
1817 var mandatory = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("mandatory")[0]);
|
nicholas@2535
|
1818 var boxsize = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("boxsize")[0]);
|
nickjillings@1375
|
1819 this.attributeDOM.appendChild(id.holder);
|
nickjillings@1375
|
1820 this.attributes.push(id);
|
nickjillings@1375
|
1821 this.attributeDOM.appendChild(mandatory.holder);
|
nickjillings@1375
|
1822 this.attributes.push(mandatory);
|
nickjillings@1375
|
1823 this.attributeDOM.appendChild(boxsize.holder);
|
nickjillings@1375
|
1824 this.attributes.push(boxsize);
|
nickjillings@1375
|
1825 break;
|
nickjillings@1375
|
1826 case "number":
|
nickjillings@1375
|
1827 this.titleDOM.textContent = "Number";
|
nicholas@2535
|
1828 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
|
nicholas@2535
|
1829 var mandatory = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("mandatory")[0]);
|
nicholas@2535
|
1830 var min = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("min")[0]);
|
nicholas@2535
|
1831 var max = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("max")[0]);
|
nickjillings@1375
|
1832 this.attributeDOM.appendChild(id.holder);
|
nickjillings@1375
|
1833 this.attributes.push(id);
|
nickjillings@1375
|
1834 this.attributeDOM.appendChild(min.holder);
|
nickjillings@1375
|
1835 this.attributes.push(min);
|
nickjillings@1375
|
1836 this.attributeDOM.appendChild(max.holder);
|
nickjillings@1375
|
1837 this.attributes.push(max);
|
nickjillings@1375
|
1838 break;
|
nickjillings@1375
|
1839 case "checkbox":
|
nickjillings@1375
|
1840 this.titleDOM.textContent = "Checkbox";
|
nicholas@2535
|
1841 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
|
nickjillings@1375
|
1842 this.attributeDOM.appendChild(id.holder);
|
nickjillings@1375
|
1843 this.attributes.push(id);
|
nickjillings@1375
|
1844 break;
|
nickjillings@1375
|
1845 case "radio":
|
nickjillings@1375
|
1846 this.titleDOM.textContent = "Radio";
|
nicholas@2535
|
1847 var id = convert.convertAttributeToDOM(this.specification, specification.schema.getAllElementsByName("id")[0]);
|
nickjillings@1375
|
1848 this.attributeDOM.appendChild(id.holder);
|
nickjillings@1375
|
1849 this.attributes.push(id);
|
nickjillings@1375
|
1850 break;
|
nickjillings@1375
|
1851 }
|
nickjillings@1370
|
1852 }
|
nickjillings@1375
|
1853 this.build();
|
nicholas@2535
|
1854
|
nickjillings@1370
|
1855 this.editNode = {
|
nickjillings@1370
|
1856 root: document.createElement("button"),
|
nickjillings@1370
|
1857 parent: this,
|
nicholas@2535
|
1858 handleEvent: function () {
|
nickjillings@1370
|
1859 popupObject.show();
|
nicholas@2535
|
1860 popupStateNodes.state[5].generate(this.parent.specification, this.parent);
|
nickjillings@1370
|
1861 popupObject.postNode(popupStateNodes.state[5]);
|
nickjillings@1370
|
1862 }
|
nickjillings@1370
|
1863 }
|
nickjillings@1370
|
1864 this.editNode.root.textContent = "Edit Entry";
|
nicholas@2535
|
1865 this.editNode.root.addEventListener("click", this.editNode, false);
|
nickjillings@1370
|
1866 this.buttonDOM.appendChild(this.editNode.root);
|
nicholas@2535
|
1867
|
nickjillings@1370
|
1868 this.deleteNode = {
|
nickjillings@1370
|
1869 root: document.createElement("button"),
|
nickjillings@1370
|
1870 parent: this,
|
nicholas@2535
|
1871 handleEvent: function () {
|
nickjillings@1370
|
1872 var optionList = this.parent.parent.specification.options;
|
nickjillings@1370
|
1873 var childList = this.parent.parent.children;
|
nicholas@2535
|
1874 for (var i = 0; i < this.parent.parent.specification.options.length; i++) {
|
nickjillings@1370
|
1875 var option = this.parent.parent.specification.options[i];
|
nicholas@2535
|
1876 if (option == this.parent.specification) {
|
nickjillings@1370
|
1877 this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM);
|
nicholas@2535
|
1878 if (i == this.parent.parent.specification.options.length - 1) {
|
nicholas@2535
|
1879 optionList = optionList.slice(0, i);
|
nicholas@2535
|
1880 childList = childList.slice(0, i);
|
nicholas@2535
|
1881 } else {
|
nicholas@2535
|
1882 optionList = optionList.slice(0, i).concat(optionList.slice(i + 1));
|
nicholas@2535
|
1883 childList = childList.slice(0, i).concat(childList.slice(i + 1));
|
nickjillings@1370
|
1884 }
|
nickjillings@1370
|
1885 this.parent.parent.specification.options = optionList;
|
nickjillings@1370
|
1886 this.parent.parent.children = childList;
|
nickjillings@1370
|
1887 }
|
nickjillings@1370
|
1888 }
|
nickjillings@1370
|
1889 }
|
nickjillings@1370
|
1890 }
|
nickjillings@1370
|
1891 this.deleteNode.root.textContent = "Delete Entry";
|
nicholas@2535
|
1892 this.deleteNode.root.addEventListener("click", this.deleteNode, false);
|
nickjillings@1370
|
1893 this.buttonDOM.appendChild(this.deleteNode.root);
|
nicholas@2535
|
1894
|
nicholas@2535
|
1895 this.moveToPosition = function (new_index) {
|
nicholas@2535
|
1896 new_index = Math.min(new_index, this.parent.children.length);
|
nicholas@2535
|
1897 var curr_index = this.parent.children.findIndex(function (elem) {
|
nicholas@2535
|
1898 if (elem == this) {
|
nicholas@2535
|
1899 return true;
|
nicholas@2535
|
1900 } else {
|
nicholas@2535
|
1901 return false;
|
nicholas@2535
|
1902 }
|
nicholas@2535
|
1903 }, this);
|
n@2416
|
1904 // Split at the current location to remove the node and shift all the children up
|
nicholas@2535
|
1905 var tail = this.parent.children.splice(curr_index + 1);
|
n@2416
|
1906 this.parent.children.pop();
|
n@2416
|
1907 this.parent.children = this.parent.children.concat(tail);
|
nicholas@2535
|
1908
|
n@2416
|
1909 //Split at the new location and insert the node
|
n@2416
|
1910 tail = this.parent.children.splice(new_index);
|
n@2416
|
1911 this.parent.children.push(this);
|
n@2416
|
1912 this.parent.children = this.parent.children.concat(tail);
|
nicholas@2535
|
1913
|
n@2416
|
1914 // Re-build the specification
|
n@2416
|
1915 this.parent.specification.options = [];
|
n@2416
|
1916 this.parent.childrenDOM.innerHTML = "";
|
n@2416
|
1917 for (var obj of this.parent.children) {
|
n@2416
|
1918 this.parent.specification.options.push(obj.specification);
|
n@2416
|
1919 this.parent.childrenDOM.appendChild(obj.rootDOM);
|
n@2416
|
1920 }
|
nicholas@2535
|
1921 this.parent.children.forEach(function (obj, index) {
|
n@2420
|
1922 obj.moveButtons.disable(index);
|
n@2420
|
1923 });
|
n@2414
|
1924 }
|
nicholas@2535
|
1925
|
n@2420
|
1926 this.moveButtons = {
|
n@2420
|
1927 root_up: document.createElement("button"),
|
n@2420
|
1928 root_down: document.createElement("button"),
|
n@2420
|
1929 parent: this,
|
nicholas@2535
|
1930 handleEvent: function (event) {
|
n@2420
|
1931 var index = this.parent.parent.children.indexOf(this.parent);
|
n@2420
|
1932 if (event.currentTarget.getAttribute("direction") == "up") {
|
nicholas@2535
|
1933 index = Math.max(index - 1, 0);
|
n@2420
|
1934 } else if (event.currentTarget.getAttribute("direction") == "down") {
|
nicholas@2535
|
1935 index = Math.min(index + 1, this.parent.parent.children.length - 1);
|
n@2420
|
1936 }
|
n@2420
|
1937 this.parent.moveToPosition(index);
|
n@2420
|
1938 this.disable(index);
|
n@2420
|
1939 },
|
nicholas@2535
|
1940 disable: function (index) {
|
n@2420
|
1941 if (index == 0) {
|
n@2420
|
1942 this.root_up.disabled = true;
|
n@2420
|
1943 } else {
|
n@2420
|
1944 this.root_up.disabled = false;
|
n@2420
|
1945 }
|
nicholas@2535
|
1946 if (index == this.parent.parent.children.length - 1) {
|
n@2420
|
1947 this.root_down.disabled = true;
|
n@2420
|
1948 } else {
|
n@2420
|
1949 this.root_down.disabled = false;
|
n@2420
|
1950 }
|
n@2420
|
1951 }
|
n@2420
|
1952 }
|
nicholas@2535
|
1953 this.moveButtons.root_up.setAttribute("direction", "up");
|
nicholas@2535
|
1954 this.moveButtons.root_down.setAttribute("direction", "down");
|
nicholas@2535
|
1955 this.moveButtons.root_up.addEventListener("click", this.moveButtons, false);
|
nicholas@2535
|
1956 this.moveButtons.root_down.addEventListener("click", this.moveButtons, false);
|
n@2420
|
1957 this.moveButtons.root_up.textContent = "Move Up";
|
n@2420
|
1958 this.moveButtons.root_down.textContent = "Move Down";
|
n@2420
|
1959 this.buttonDOM.appendChild(this.moveButtons.root_up);
|
n@2420
|
1960 this.buttonDOM.appendChild(this.moveButtons.root_down);
|
nickjillings@1370
|
1961 }
|
nickjillings@1370
|
1962 this.addNode = {
|
nickjillings@1370
|
1963 root: document.createElement("button"),
|
nickjillings@1370
|
1964 parent: this,
|
nicholas@2535
|
1965 handleEvent: function () {
|
nickjillings@2194
|
1966 var newNode = new this.parent.specification.OptionNode(this.parent.specification);
|
nickjillings@1370
|
1967 this.parent.specification.options.push(newNode);
|
nickjillings@1370
|
1968 popupObject.show();
|
nicholas@2535
|
1969 popupStateNodes.state[5].generate(newNode, this.parent);
|
nickjillings@1370
|
1970 popupObject.postNode(popupStateNodes.state[5]);
|
nickjillings@1370
|
1971 }
|
nickjillings@1370
|
1972 }
|
nickjillings@1370
|
1973 this.addNode.root.textContent = "Add Survey Entry";
|
nicholas@2535
|
1974 this.addNode.root.addEventListener("click", this.addNode, false);
|
nickjillings@1370
|
1975 this.buttonDOM.appendChild(this.addNode.root);
|
nicholas@2535
|
1976
|
nicholas@2535
|
1977 for (var option of this.specification.options) {
|
nicholas@2535
|
1978 var newNode = new this.surveyEntryNode(this, option);
|
nickjillings@1370
|
1979 this.children.push(newNode);
|
nickjillings@1370
|
1980 this.childrenDOM.appendChild(newNode.rootDOM);
|
nickjillings@1370
|
1981 }
|
nicholas@2535
|
1982
|
nicholas@2535
|
1983 this.children.forEach(function (obj, index) {
|
n@2420
|
1984 obj.moveButtons.disable(index);
|
n@2420
|
1985 });
|
nickjillings@1370
|
1986 }
|
nicholas@2535
|
1987
|
nicholas@2535
|
1988 this.pageNode = function (parent, rootObject) {
|
nickjillings@1375
|
1989 this.type = "pageNode";
|
nickjillings@1370
|
1990 this.rootDOM = document.createElement("div");
|
nickjillings@1370
|
1991 this.titleDOM = document.createElement("span");
|
nickjillings@1370
|
1992 this.attributeDOM = document.createElement("div");
|
nickjillings@1370
|
1993 this.attributes = [];
|
nickjillings@1370
|
1994 this.childrenDOM = document.createElement("div");
|
nickjillings@1370
|
1995 this.children = [];
|
nickjillings@1370
|
1996 this.buttonDOM = document.createElement("div");
|
nickjillings@1370
|
1997 this.parent = parent;
|
nickjillings@1370
|
1998 this.specification = rootObject;
|
nickjillings@1370
|
1999 this.schema = specification.schema.getAllElementsByName("page")[0];
|
nickjillings@1370
|
2000 this.rootDOM.className = "node";
|
nickjillings@1370
|
2001
|
nickjillings@1370
|
2002 var titleDiv = document.createElement('div');
|
nickjillings@1370
|
2003 titleDiv.className = "node-title";
|
nickjillings@1370
|
2004 this.titleDOM.className = "node-title";
|
nickjillings@1370
|
2005 this.titleDOM.textContent = "Test Page";
|
nickjillings@1370
|
2006 titleDiv.appendChild(this.titleDOM);
|
nicholas@2535
|
2007
|
nickjillings@1370
|
2008 this.attributeDOM.className = "node-attributes";
|
nickjillings@1370
|
2009 this.childrenDOM.className = "node-children";
|
nickjillings@1370
|
2010 this.buttonDOM.className = "node-buttons";
|
nickjillings@1370
|
2011
|
nickjillings@1370
|
2012 this.rootDOM.appendChild(titleDiv);
|
nickjillings@1370
|
2013 this.rootDOM.appendChild(this.attributeDOM);
|
nickjillings@1370
|
2014 this.rootDOM.appendChild(this.childrenDOM);
|
nickjillings@1370
|
2015 this.rootDOM.appendChild(this.buttonDOM);
|
nicholas@2535
|
2016
|
nickjillings@1370
|
2017 // Do the comment prefix node
|
nicholas@2535
|
2018 var cpn = this.parent.createGeneralNodeDOM("Comment Prefix", "" + this.specification.id + "-commentprefix", this.parent);
|
nickjillings@1370
|
2019 cpn.rootDOM.removeChild(cpn.attributeDOM);
|
nickjillings@1370
|
2020 var obj = {
|
nickjillings@1370
|
2021 root: document.createElement("div"),
|
nickjillings@1370
|
2022 input: document.createElement("input"),
|
nickjillings@1370
|
2023 parent: this,
|
nicholas@2535
|
2024 handleEvent: function () {
|
nickjillings@1370
|
2025 this.parent.specification.commentBoxPrefix = event.currentTarget.value;
|
nickjillings@1370
|
2026 }
|
nickjillings@1370
|
2027 }
|
nickjillings@1370
|
2028 cpn.children.push(obj);
|
nickjillings@1370
|
2029 cpn.childrenDOM.appendChild(obj.root);
|
nickjillings@1370
|
2030 obj.root.appendChild(obj.input);
|
nicholas@2535
|
2031 obj.input.addEventListener("change", obj, false);
|
nickjillings@1370
|
2032 obj.input.value = this.specification.commentBoxPrefix;
|
nickjillings@1370
|
2033 this.childrenDOM.appendChild(cpn.rootDOM);
|
nickjillings@1370
|
2034 this.children.push(cpn);
|
nicholas@2535
|
2035
|
nickjillings@1370
|
2036 // Now both before and after surveys
|
nicholas@2535
|
2037 if (this.specification.preTest == undefined) {
|
nickjillings@2194
|
2038 this.specification.preTest = new specification.surveyNode(specification);
|
nickjillings@1370
|
2039 this.specification.preTest.location = "pre";
|
nickjillings@1370
|
2040 }
|
nicholas@2535
|
2041 if (this.specification.postTest == undefined) {
|
nickjillings@2194
|
2042 this.specification.postTest = new specification.surveyNode(specification);
|
nickjillings@1370
|
2043 this.specification.postTest.location = "post";
|
nickjillings@1370
|
2044 }
|
nicholas@2535
|
2045 var surveyBefore = new this.parent.surveyNode(this, this.specification.preTest, "Pre");
|
nicholas@2535
|
2046 var surveyAfter = new this.parent.surveyNode(this, this.specification.postTest, "Post");
|
nickjillings@1370
|
2047 this.children.push(surveyBefore);
|
nickjillings@1370
|
2048 this.children.push(surveyAfter);
|
nickjillings@1370
|
2049 this.childrenDOM.appendChild(surveyBefore.rootDOM);
|
nickjillings@1370
|
2050 this.childrenDOM.appendChild(surveyAfter.rootDOM);
|
nicholas@2535
|
2051
|
nickjillings@1370
|
2052 // Build the attributes
|
nickjillings@1370
|
2053 var attributeList = this.schema.getAllElementsByTagName("xs:attribute");
|
nicholas@2535
|
2054 for (var i = 0; i < attributeList.length; i++) {
|
nickjillings@1370
|
2055 var attributeName = attributeList[i].getAttribute('name');
|
nicholas@2535
|
2056 var attrObject = this.parent.convertAttributeToDOM(rootObject, attributeList[i]);
|
nickjillings@1370
|
2057 this.attributeDOM.appendChild(attrObject.holder);
|
nickjillings@1370
|
2058 this.attributes.push(attrObject);
|
nickjillings@1370
|
2059 }
|
nicholas@2535
|
2060
|
nickjillings@1370
|
2061 this.interfaces = [];
|
nicholas@2535
|
2062
|
nicholas@2535
|
2063 this.getAudioElements = function () {
|
n@2421
|
2064 var array = [];
|
nicholas@2535
|
2065 for (var i = 0; i < this.children.length; i++) {
|
n@2421
|
2066 if (this.children[i].type == "audioElementNode") {
|
n@2421
|
2067 array[array.length] = this.children[i];
|
n@2421
|
2068 }
|
n@2421
|
2069 }
|
n@2421
|
2070 return array;
|
n@2421
|
2071 }
|
nicholas@2535
|
2072
|
nicholas@2535
|
2073 this.redrawChildren = function () {
|
n@2421
|
2074 this.childrenDOM.innerHTML = "";
|
nicholas@2535
|
2075 for (var child of this.children) {
|
n@2421
|
2076 this.childrenDOM.appendChild(child.rootDOM);
|
n@2421
|
2077 }
|
n@2421
|
2078 }
|
nicholas@2535
|
2079
|
nicholas@2535
|
2080 this.audioElementNode = function (parent, rootObject) {
|
nickjillings@1375
|
2081 this.type = "audioElementNode";
|
nickjillings@1370
|
2082 this.rootDOM = document.createElement("div");
|
nickjillings@1370
|
2083 this.titleDOM = document.createElement("span");
|
nickjillings@1370
|
2084 this.attributeDOM = document.createElement("div");
|
nickjillings@1370
|
2085 this.attributes = [];
|
nickjillings@1370
|
2086 this.childrenDOM = document.createElement("div");
|
nickjillings@1370
|
2087 this.children = [];
|
nickjillings@1370
|
2088 this.buttonDOM = document.createElement("div");
|
nickjillings@1370
|
2089 this.parent = parent;
|
nickjillings@1370
|
2090 this.specification = rootObject;
|
nickjillings@1370
|
2091 this.schema = specification.schema.getAllElementsByName("audioelement")[0];
|
nickjillings@1370
|
2092 this.rootDOM.className = "node";
|
nickjillings@1370
|
2093
|
nickjillings@1370
|
2094 var titleDiv = document.createElement('div');
|
nickjillings@1370
|
2095 titleDiv.className = "node-title";
|
nickjillings@1370
|
2096 this.titleDOM.className = "node-title";
|
nickjillings@1370
|
2097 this.titleDOM.textContent = "Audio Element";
|
nickjillings@1370
|
2098 titleDiv.appendChild(this.titleDOM);
|
nickjillings@1370
|
2099
|
nickjillings@1370
|
2100 this.attributeDOM.className = "node-attributes";
|
nickjillings@1370
|
2101 this.childrenDOM.className = "node-children";
|
nickjillings@1370
|
2102 this.buttonDOM.className = "node-buttons";
|
nickjillings@1370
|
2103
|
nickjillings@1370
|
2104 this.rootDOM.appendChild(titleDiv);
|
nickjillings@1370
|
2105 this.rootDOM.appendChild(this.attributeDOM);
|
nickjillings@1370
|
2106 this.rootDOM.appendChild(this.childrenDOM);
|
nickjillings@1370
|
2107 this.rootDOM.appendChild(this.buttonDOM);
|
nicholas@2535
|
2108
|
nickjillings@1370
|
2109 // Build the attributes
|
nickjillings@1370
|
2110 var attributeList = this.schema.getAllElementsByTagName("xs:attribute");
|
nicholas@2535
|
2111 for (var i = 0; i < attributeList.length; i++) {
|
nickjillings@1370
|
2112 var attributeName = attributeList[i].getAttribute('name');
|
nicholas@2535
|
2113 var attrObject = this.parent.parent.convertAttributeToDOM(rootObject, attributeList[i]);
|
nickjillings@1370
|
2114 this.attributeDOM.appendChild(attrObject.holder);
|
nickjillings@1370
|
2115 this.attributes.push(attrObject);
|
nickjillings@1370
|
2116 }
|
nicholas@2535
|
2117
|
nickjillings@1370
|
2118 this.deleteNode = {
|
nickjillings@1370
|
2119 root: document.createElement("button"),
|
nickjillings@1370
|
2120 parent: this,
|
nicholas@2535
|
2121 handleEvent: function () {
|
nicholas@2535
|
2122 var i = this.parent.parent.specification.audioElements.findIndex(this.findNode, this);
|
nickjillings@1370
|
2123 if (i >= 0) {
|
nickjillings@1370
|
2124 var aeList = this.parent.parent.specification.audioElements;
|
nicholas@2535
|
2125 if (i < aeList.length - 1) {
|
nicholas@2535
|
2126 aeList = aeList.slice(0, i).concat(aeList.slice(i + 1));
|
nickjillings@1370
|
2127 } else {
|
nicholas@2535
|
2128 aeList = aeList.slice(0, i);
|
nickjillings@1370
|
2129 }
|
nickjillings@1370
|
2130 }
|
nicholas@2535
|
2131 i = this.parent.parent.children.findIndex(function (element, index, array) {
|
nickjillings@1370
|
2132 if (element == this.parent)
|
nickjillings@1370
|
2133 return true;
|
nickjillings@1370
|
2134 else
|
nickjillings@1370
|
2135 return false;
|
nicholas@2535
|
2136 }, this);
|
nickjillings@1370
|
2137 if (i >= 0) {
|
nickjillings@1370
|
2138 var childList = this.parent.children;
|
nicholas@2535
|
2139 if (i < aeList.length - 1) {
|
nicholas@2535
|
2140 childList = childList.slice(0, i).concat(childList.slice(i + 1));
|
nickjillings@1370
|
2141 } else {
|
nicholas@2535
|
2142 childList = childList.slice(0, i);
|
nickjillings@1370
|
2143 }
|
nickjillings@1370
|
2144 this.parent.parent.childrenDOM.removeChild(this.parent.rootDOM);
|
nickjillings@1370
|
2145 }
|
nickjillings@1370
|
2146 },
|
nicholas@2535
|
2147 findNode: function (element, index, array) {
|
nickjillings@1370
|
2148 if (element == this.parent.specification)
|
nickjillings@1370
|
2149 return true;
|
nickjillings@1370
|
2150 else
|
nickjillings@1370
|
2151 return false;
|
nickjillings@1370
|
2152 }
|
nickjillings@1370
|
2153 }
|
nickjillings@1370
|
2154 this.deleteNode.root.textContent = "Delete Entry";
|
nicholas@2535
|
2155 this.deleteNode.root.addEventListener("click", this.deleteNode, false);
|
nickjillings@1370
|
2156 this.buttonDOM.appendChild(this.deleteNode.root);
|
nicholas@2535
|
2157
|
n@2421
|
2158 this.moveButtons = {
|
n@2421
|
2159 root_up: document.createElement("button"),
|
n@2421
|
2160 root_down: document.createElement("button"),
|
n@2421
|
2161 parent: this,
|
nicholas@2535
|
2162 handleEvent: function (event) {
|
n@2421
|
2163 var index = this.parent.parent.getAudioElements().indexOf(this.parent);
|
n@2421
|
2164 if (event.currentTarget.getAttribute("direction") == "up") {
|
nicholas@2535
|
2165 index = Math.max(index - 1, 0);
|
n@2421
|
2166 } else if (event.currentTarget.getAttribute("direction") == "down") {
|
nicholas@2535
|
2167 index = Math.min(index + 1, this.parent.parent.getAudioElements().length - 1);
|
n@2421
|
2168 }
|
n@2421
|
2169 this.parent.moveToPosition(index);
|
n@2421
|
2170 this.disable(index);
|
n@2421
|
2171 },
|
nicholas@2535
|
2172 disable: function (index) {
|
n@2421
|
2173 if (index == 0) {
|
n@2421
|
2174 this.root_up.disabled = true;
|
n@2421
|
2175 } else {
|
n@2421
|
2176 this.root_up.disabled = false;
|
n@2421
|
2177 }
|
nicholas@2535
|
2178 if (index == this.parent.parent.getAudioElements().length - 1) {
|
n@2421
|
2179 this.root_down.disabled = true;
|
n@2421
|
2180 } else {
|
n@2421
|
2181 this.root_down.disabled = false;
|
n@2421
|
2182 }
|
n@2421
|
2183 }
|
n@2421
|
2184 }
|
nicholas@2535
|
2185 this.moveButtons.root_up.setAttribute("direction", "up");
|
nicholas@2535
|
2186 this.moveButtons.root_down.setAttribute("direction", "down");
|
nicholas@2535
|
2187 this.moveButtons.root_up.addEventListener("click", this.moveButtons, false);
|
nicholas@2535
|
2188 this.moveButtons.root_down.addEventListener("click", this.moveButtons, false);
|
n@2421
|
2189 this.moveButtons.root_up.textContent = "Move Up";
|
n@2421
|
2190 this.moveButtons.root_down.textContent = "Move Down";
|
n@2421
|
2191 this.buttonDOM.appendChild(this.moveButtons.root_up);
|
n@2421
|
2192 this.buttonDOM.appendChild(this.moveButtons.root_down);
|
nicholas@2535
|
2193
|
nicholas@2535
|
2194 this.moveToPosition = function (new_index) {
|
nicholas@2535
|
2195
|
n@2421
|
2196 // Get the zero-th Object
|
n@2421
|
2197 var zero_object = this.parent.getAudioElements()[0];
|
n@2421
|
2198 var parent_children_root_index = this.parent.children.indexOf(zero_object);
|
n@2421
|
2199 // splice out the array for processing
|
n@2421
|
2200 var process_array = this.parent.children.splice(parent_children_root_index);
|
nicholas@2535
|
2201
|
nicholas@2535
|
2202
|
n@2421
|
2203 new_index = Math.min(new_index, process_array.length);
|
nicholas@2535
|
2204 var curr_index = process_array.findIndex(function (elem) {
|
nicholas@2535
|
2205 if (elem == this) {
|
nicholas@2535
|
2206 return true;
|
nicholas@2535
|
2207 } else {
|
nicholas@2535
|
2208 return false;
|
nicholas@2535
|
2209 }
|
nicholas@2535
|
2210 }, this);
|
nicholas@2535
|
2211
|
n@2421
|
2212 // Split at the current location to remove the node and shift all the children up
|
nicholas@2535
|
2213 var tail = process_array.splice(curr_index + 1);
|
n@2421
|
2214 process_array.pop();
|
n@2421
|
2215 process_array = process_array.concat(tail);
|
nicholas@2535
|
2216
|
n@2421
|
2217 //Split at the new location and insert the node
|
n@2421
|
2218 tail = process_array.splice(new_index);
|
n@2421
|
2219 process_array.push(this);
|
n@2421
|
2220 process_array = process_array.concat(tail);
|
nicholas@2535
|
2221
|
n@2421
|
2222 // Re-attach to the parent.children
|
n@2421
|
2223 this.parent.children = this.parent.children.concat(process_array);
|
nicholas@2535
|
2224
|
n@2421
|
2225 // Re-build the specification
|
n@2421
|
2226 this.parent.specification.audioElements = [];
|
n@2421
|
2227 for (var obj of process_array) {
|
n@2421
|
2228 this.parent.specification.audioElements.push(obj.specification);
|
n@2421
|
2229 }
|
n@2421
|
2230 this.parent.redrawChildren();
|
nicholas@2535
|
2231
|
nicholas@2535
|
2232 process_array.forEach(function (obj, index) {
|
n@2421
|
2233 obj.moveButtons.disable(index);
|
n@2421
|
2234 });
|
nicholas@2535
|
2235
|
n@2421
|
2236 }
|
nickjillings@1370
|
2237 }
|
nicholas@2535
|
2238
|
nicholas@2535
|
2239 this.commentQuestionNode = function (parent, rootObject) {
|
nickjillings@1375
|
2240 this.type = "commentQuestionNode";
|
nickjillings@1370
|
2241 this.rootDOM = document.createElement("div");
|
nickjillings@1370
|
2242 this.titleDOM = document.createElement("span");
|
nickjillings@1370
|
2243 this.attributeDOM = document.createElement("div");
|
nickjillings@1370
|
2244 this.attributes = [];
|
nickjillings@1370
|
2245 this.childrenDOM = document.createElement("div");
|
nickjillings@1370
|
2246 this.children = [];
|
nickjillings@1370
|
2247 this.buttonDOM = document.createElement("div");
|
nickjillings@1370
|
2248 this.parent = parent;
|
nickjillings@1370
|
2249 this.specification = rootObject;
|
nickjillings@1370
|
2250 this.schema = specification.schema.getAllElementsByName("page")[0];
|
n@2421
|
2251 this.rootDOM.className = "node audio-element";
|
nickjillings@1370
|
2252
|
nickjillings@1370
|
2253 var titleDiv = document.createElement('div');
|
nickjillings@1370
|
2254 titleDiv.className = "node-title";
|
nickjillings@1370
|
2255 this.titleDOM.className = "node-title";
|
nickjillings@1370
|
2256 this.titleDOM.textContent = "Test Page";
|
nickjillings@1370
|
2257 titleDiv.appendChild(this.titleDOM);
|
nickjillings@1370
|
2258
|
nickjillings@1370
|
2259 this.attributeDOM.className = "node-attributes";
|
nickjillings@1370
|
2260 this.childrenDOM.className = "node-children";
|
nickjillings@1370
|
2261 this.buttonDOM.className = "node-buttons";
|
nickjillings@1370
|
2262
|
nickjillings@1370
|
2263 this.rootDOM.appendChild(titleDiv);
|
nickjillings@1370
|
2264 this.rootDOM.appendChild(this.attributeDOM);
|
nickjillings@1370
|
2265 this.rootDOM.appendChild(this.childrenDOM);
|
nickjillings@1370
|
2266 this.rootDOM.appendChild(this.buttonDOM);
|
nicholas@2535
|
2267
|
nickjillings@1370
|
2268 }
|
nicholas@2535
|
2269
|
nickjillings@1374
|
2270 // Build the components
|
nickjillings@1310
|
2271 if (this.specification.interfaces.length == 0) {
|
nickjillings@2194
|
2272 this.specification.interfaces.push(new specification.interfaceNode(specification));
|
nickjillings@1310
|
2273 }
|
nicholas@2535
|
2274 for (var interfaceObj of this.specification.interfaces) {
|
nicholas@2535
|
2275 var newInterface = new this.parent.interfaceNode(this.parent, interfaceObj);
|
nicholas@2535
|
2276 newInterface.build("Interface", "" + this.specification.id + "-interface", this.childrenDOM);
|
nickjillings@1381
|
2277 this.children.push(newInterface);
|
nickjillings@1381
|
2278 this.interfaces.push(newInterface);
|
nickjillings@1381
|
2279 }
|
nicholas@2535
|
2280
|
nicholas@2535
|
2281 for (var elements of this.specification.audioElements) {
|
nicholas@2535
|
2282 var audioElementDOM = new this.audioElementNode(this, elements);
|
nickjillings@1374
|
2283 this.children.push(audioElementDOM);
|
nickjillings@1374
|
2284 this.childrenDOM.appendChild(audioElementDOM.rootDOM);
|
nickjillings@1374
|
2285 }
|
nicholas@2535
|
2286
|
nicholas@2535
|
2287 this.getAudioElements().forEach(function (elem) {
|
n@2421
|
2288 elem.moveButtons.disable();
|
n@2421
|
2289 });
|
nicholas@2535
|
2290
|
nickjillings@1370
|
2291 this.addInterface = {
|
nickjillings@1370
|
2292 root: document.createElement("button"),
|
nickjillings@1370
|
2293 parent: this,
|
nicholas@2535
|
2294 handleEvent: function () {
|
nickjillings@2194
|
2295 var InterfaceObj = new specification.interfaceNode(specification);
|
nicholas@2535
|
2296 var newInterface = new this.parent.parent.interfaceNode(this.parent.parent, InterfaceObj);
|
nicholas@2535
|
2297 newInterface.build("Interface", "" + this.parent.specification.id + "-interface", this.parent.childrenDOM);
|
nickjillings@1370
|
2298 this.parent.children.push(newInterface);
|
nickjillings@1370
|
2299 this.parent.specification.interfaces.push(InterfaceObj);
|
nickjillings@1370
|
2300 this.parent.interfaces.push(newInterface);
|
nickjillings@1370
|
2301 }
|
nickjillings@1370
|
2302 }
|
nickjillings@1370
|
2303 this.addInterface.root.textContent = "Add Interface";
|
nicholas@2535
|
2304 this.addInterface.root.addEventListener("click", this.addInterface, false);
|
nickjillings@1370
|
2305 this.buttonDOM.appendChild(this.addInterface.root);
|
nicholas@2535
|
2306
|
nickjillings@1370
|
2307 this.addAudioElement = {
|
nickjillings@1370
|
2308 root: document.createElement("button"),
|
nickjillings@1370
|
2309 parent: this,
|
nicholas@2535
|
2310 handleEvent: function () {
|
nickjillings@2194
|
2311 var audioElementObject = new this.parent.specification.audioElementNode(specification);
|
nicholas@2535
|
2312 var audioElementDOM = new this.parent.audioElementNode(this.parent, audioElementObject);
|
nickjillings@1370
|
2313 this.parent.specification.audioElements.push(audioElementObject);
|
nickjillings@1370
|
2314 this.parent.children.push(audioElementDOM);
|
nickjillings@1370
|
2315 this.parent.childrenDOM.appendChild(audioElementDOM.rootDOM);
|
nickjillings@1370
|
2316 }
|
nickjillings@1370
|
2317 }
|
nickjillings@1370
|
2318 this.addAudioElement.root.textContent = "Add Audio Element";
|
nicholas@2535
|
2319 this.addAudioElement.root.addEventListener("click", this.addAudioElement, false);
|
nickjillings@1370
|
2320 this.buttonDOM.appendChild(this.addAudioElement.root);
|
nickjillings@1370
|
2321 }
|
nicholas@2535
|
2322 }
|