nicholas@2855
|
1 /* globals document, angular, window, Promise, XMLHttpRequest, Specification */
|
nicholas@2851
|
2 function get(url) {
|
nicholas@2851
|
3 // Return a new promise.
|
nicholas@2851
|
4 return new Promise(function (resolve, reject) {
|
nicholas@2851
|
5 // Do the usual XHR stuff
|
nicholas@2851
|
6 var req = new XMLHttpRequest();
|
nicholas@2851
|
7 req.open('GET', url);
|
nickjillings@1370
|
8
|
nicholas@2851
|
9 req.onload = function () {
|
nicholas@2851
|
10 // This is called even on 404 etc
|
nicholas@2851
|
11 // so check the status
|
nicholas@2851
|
12 if (req.status == 200) {
|
nicholas@2851
|
13 // Resolve the promise with the response text
|
nicholas@2851
|
14 resolve(req.response);
|
nicholas@2851
|
15 } else {
|
nicholas@2851
|
16 // Otherwise reject with the status text
|
nicholas@2851
|
17 // which will hopefully be a meaningful error
|
nicholas@2851
|
18 reject(Error(req.statusText));
|
nicholas@2851
|
19 }
|
nicholas@2851
|
20 };
|
nicholas@2851
|
21
|
nicholas@2851
|
22 // Handle network errors
|
nicholas@2851
|
23 req.onerror = function () {
|
nicholas@2851
|
24 reject(Error("Network Error"));
|
nicholas@2851
|
25 };
|
nicholas@2851
|
26
|
nicholas@2851
|
27 // Make the request
|
nicholas@2851
|
28 req.send();
|
nicholas@2851
|
29 });
|
nickjillings@1370
|
30 }
|
nickjillings@1370
|
31
|
nicholas@2851
|
32 var AngularInterface = angular.module("creator", []);
|
nickjillings@1370
|
33
|
nicholas@2851
|
34 var specification = new Specification();
|
nickjillings@1370
|
35
|
nicholas@2535
|
36 window.onload = function () {
|
nicholas@2851
|
37 // Get the test interface specifications
|
nicholas@2535
|
38
|
nicholas@2851
|
39 };
|
nicholas@2535
|
40
|
nicholas@2851
|
41 AngularInterface.controller("view", ['$scope', '$element', '$window', function ($s, $e, $w) {
|
nicholas@2851
|
42 $s.popupVisible = true;
|
nickjillings@1370
|
43
|
nicholas@2851
|
44 $s.showPopup = function () {
|
nicholas@2851
|
45 $s.popupVisible = true;
|
nicholas@2851
|
46 };
|
nicholas@2851
|
47 $s.hidePopup = function () {
|
nicholas@2851
|
48 $s.popupVisible = false;
|
nicholas@2851
|
49 };
|
nicholas@2851
|
50 $s.globalSchema = undefined;
|
nicholas@2851
|
51 get("xml/test-schema.xsd").then(function (text) {
|
nicholas@2851
|
52 specification.processSchema(text);
|
nicholas@2851
|
53 $s.globalSchema = specification.getSchema();
|
nicholas@2851
|
54 });
|
nicholas@2851
|
55 $s.specification = specification;
|
nicholas@2857
|
56
|
nicholas@2857
|
57 $s.addPage = function () {
|
nicholas@2857
|
58 $s.specification.createNewPage();
|
nicholas@2859
|
59 };
|
nicholas@2860
|
60
|
nicholas@2860
|
61 $s.exportXML = function () {
|
nicholas@2860
|
62 var s = new XMLSerializer();
|
nicholas@2860
|
63 var doc = specification.encode();
|
nicholas@2860
|
64 var bb = new Blob([s.serializeToString(doc)], {
|
nicholas@2860
|
65 type: 'application/xml'
|
nicholas@2860
|
66 });
|
nicholas@2860
|
67 var dnlk = window.URL.createObjectURL(bb);
|
nicholas@2860
|
68 window.location.href = dnlk;
|
nicholas@2860
|
69 }
|
nicholas@2851
|
70 }]);
|
nickjillings@1370
|
71
|
nicholas@2851
|
72 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) {
|
nicholas@2851
|
73 $s.state = 0;
|
nicholas@2851
|
74 $s.next = function () {
|
nicholas@2851
|
75 $s.state++;
|
nicholas@2851
|
76 if ($s.state > 1) {
|
nicholas@2851
|
77 $s.hidePopup();
|
nicholas@2851
|
78 }
|
nicholas@2851
|
79 };
|
nicholas@2851
|
80 $s.back = function () {
|
nicholas@2851
|
81 $s.state--;
|
nicholas@2851
|
82 };
|
nicholas@2851
|
83 $s.mouseover = function (name) {
|
nicholas@2851
|
84 var obj = $s.interfaces.find(function (i) {
|
nicholas@2851
|
85 return i.name == name;
|
nicholas@2851
|
86 });
|
nicholas@2851
|
87 if (obj) {
|
nicholas@2851
|
88 $s.description = obj.description.en;
|
nicholas@2851
|
89 }
|
nicholas@2851
|
90 };
|
nicholas@2851
|
91 $s.initialise = function (name) {
|
nicholas@2851
|
92 var obj = $s.interfaces.find(function (i) {
|
nicholas@2851
|
93 return i.name == name;
|
nicholas@2851
|
94 });
|
nicholas@2851
|
95 specification.interface = obj.interface;
|
nicholas@2851
|
96 };
|
nicholas@2851
|
97 // Get the test interface specifications
|
nicholas@2851
|
98 $s.interfaces = {};
|
nicholas@2851
|
99 $s.description = "";
|
nicholas@2851
|
100 var interfaceCollection = new Promise(function (resolve, reject) {
|
nicholas@2851
|
101 var xml = new XMLHttpRequest();
|
nicholas@2851
|
102 xml.open("GET", "test_create/interfaces/specifications.json");
|
nicholas@2851
|
103 xml.onload = function () {
|
nicholas@2851
|
104 if (xml.status === 200) {
|
nicholas@2851
|
105 resolve(xml.responseText);
|
nicholas@2851
|
106 return;
|
nicholas@2851
|
107 }
|
nicholas@2851
|
108 reject(xml.status);
|
nicholas@2851
|
109 };
|
nicholas@2851
|
110 xml.onerror = function () {
|
nicholas@2851
|
111 reject(new Error("Network Error"));
|
nicholas@2851
|
112 };
|
nicholas@2851
|
113 xml.send();
|
nicholas@2851
|
114 }).then(JSON.parse).then(function (data) {
|
nicholas@2851
|
115 $s.interfaces = data.interfaces;
|
nicholas@2851
|
116 $s.$apply();
|
nicholas@2851
|
117 });
|
nicholas@2851
|
118 }]);
|
nickjillings@1370
|
119
|
nicholas@2851
|
120 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {
|
nicholas@2851
|
121 function initialise() {
|
nicholas@2851
|
122 if ($s.globalSchema) {
|
nicholas@2851
|
123 $s.schema = $s.globalSchema.querySelector("[name=setup]");
|
nickjillings@1385
|
124 }
|
nickjillings@1370
|
125 }
|
nicholas@2851
|
126 $s.schema = undefined;
|
nicholas@2851
|
127 $s.attributes = [];
|
nickjillings@1370
|
128
|
nicholas@2851
|
129 $s.$watch("globalSchema", initialise);
|
nicholas@2853
|
130 $s.$watch("specification.metrics.enabled.length", function () {
|
nicholas@2853
|
131 var metricsNode = document.getElementById("metricsNode");
|
nicholas@2853
|
132 if (!$s.specification.metrics) {
|
nicholas@2853
|
133 return;
|
nicholas@2853
|
134 }
|
nicholas@2853
|
135 metricsNode.querySelectorAll("input").forEach(function (DOM) {
|
nicholas@2853
|
136 DOM.checked = false;
|
nicholas@2853
|
137 });
|
nicholas@2853
|
138 $s.specification.metrics.enabled.forEach(function (metric) {
|
nicholas@2853
|
139 var DOM = metricsNode.querySelector("[value=" + metric + "]");
|
nicholas@2853
|
140 if (DOM) {
|
nicholas@2853
|
141 DOM.checked = true;
|
nicholas@2853
|
142 }
|
nicholas@2853
|
143 });
|
nicholas@2855
|
144 });
|
nicholas@2853
|
145
|
nicholas@2853
|
146 $s.enableMetric = function ($event) {
|
nicholas@2853
|
147 var metric = $event.currentTarget.value;
|
nicholas@2853
|
148 var index = specification.metrics.enabled.findIndex(function (a) {
|
nicholas@2853
|
149 return a == metric;
|
nicholas@2853
|
150 });
|
nicholas@2853
|
151 if ($event.currentTarget.checked) {
|
nicholas@2853
|
152 if (index == -1) {
|
nicholas@2853
|
153 specification.metrics.enabled.push(metric);
|
nicholas@2853
|
154 }
|
nicholas@2853
|
155 } else {
|
nicholas@2853
|
156 if (index >= 0) {
|
nicholas@2853
|
157 specification.metrics.enabled.splice(index, 1);
|
nicholas@2853
|
158 }
|
nicholas@2853
|
159 }
|
nicholas@2855
|
160 };
|
nicholas@2851
|
161 }]);
|
nicholas@2853
|
162
|
nicholas@2858
|
163 AngularInterface.controller("survey", ['$scope', '$element', '$window', function ($s, $e, $w) {
|
nicholas@2858
|
164 $s.addSurveyEntry = function () {
|
nicholas@2858
|
165 $s.survey.addOption();
|
nicholas@2858
|
166 };
|
nicholas@2858
|
167 $s.removeSurveyEntry = function (entry) {
|
nicholas@2858
|
168 var index = $s.survey.options.findIndex(function (a) {
|
nicholas@2858
|
169 return a == entry;
|
nicholas@2858
|
170 });
|
nicholas@2858
|
171 if (index === -1) {
|
nicholas@2858
|
172 throw ("Invalid Entry");
|
nicholas@2858
|
173 }
|
nicholas@2858
|
174 $s.survey.options.splice(index, 1);
|
nicholas@2858
|
175 };
|
nicholas@2858
|
176 }]);
|
nicholas@2858
|
177
|
nicholas@2853
|
178 AngularInterface.controller("surveyOption", ['$scope', '$element', '$window', function ($s, $e, $w) {
|
nicholas@2853
|
179
|
nicholas@2853
|
180 $s.removeOption = function (option) {
|
nicholas@2853
|
181 var index = $s.opt.options.findIndex(function (a) {
|
nicholas@2853
|
182 return a == option;
|
nicholas@2853
|
183 });
|
nicholas@2853
|
184 if (index === -1) {
|
nicholas@2853
|
185 throw ("Invalid option");
|
nicholas@2853
|
186 }
|
nicholas@2853
|
187 $s.opt.options.splice(index, 1);
|
nicholas@2853
|
188 };
|
nicholas@2853
|
189 $s.addOption = function () {
|
nicholas@2853
|
190 $s.opt.options.push({
|
nicholas@2853
|
191 name: "",
|
nicholas@2853
|
192 text: ""
|
nicholas@2853
|
193 });
|
nicholas@2855
|
194 };
|
nicholas@2857
|
195
|
nicholas@2857
|
196 $s.addCondition = function () {
|
nicholas@2857
|
197 $s.opt.conditions.push({
|
nicholas@2857
|
198 check: "equals",
|
nicholas@2857
|
199 value: "",
|
nicholas@2857
|
200 jumpToOnPass: undefined,
|
nicholas@2857
|
201 jumpToOnFail: undefined
|
nicholas@2857
|
202 });
|
nicholas@2857
|
203 };
|
nicholas@2857
|
204
|
nicholas@2857
|
205 $s.removeCondition = function (condition) {
|
nicholas@2857
|
206 var index = $s.opt.conditions.findIndex(function (c) {
|
nicholas@2857
|
207 return c == condition;
|
nicholas@2857
|
208 });
|
nicholas@2857
|
209 if (index === -1) {
|
nicholas@2857
|
210 throw ("Invalid Condition");
|
nicholas@2857
|
211 }
|
nicholas@2857
|
212 $s.opt.conditions.splice(index, 1);
|
nicholas@2857
|
213 };
|
nicholas@2855
|
214 }]);
|
nicholas@2855
|
215
|
nicholas@2855
|
216 AngularInterface.controller("interfaceNode", ['$scope', '$element', '$window', function ($s, $e, $w) {
|
nicholas@2855
|
217 $s.$watch("interface.options.length", function () {
|
nicholas@2855
|
218 if (!$s.interface || !$s.interface.options) {
|
nicholas@2855
|
219 return;
|
nicholas@2855
|
220 }
|
nicholas@2855
|
221 var options = $e[0].querySelector(".interfaceOptions").querySelectorAll(".attribute");
|
nicholas@2855
|
222 options.forEach(function (option) {
|
nicholas@2855
|
223 var name = option.getAttribute("name");
|
nicholas@2855
|
224 var index = $s.interface.options.findIndex(function (io) {
|
nicholas@2855
|
225 return io.name == name;
|
nicholas@2855
|
226 });
|
nicholas@2855
|
227 option.querySelector("input").checked = (index >= 0);
|
nicholas@2855
|
228 if (name == "scalerange" && index >= 0) {
|
nicholas@2855
|
229 option.querySelector("[name=min]").value = $s.interface.options[index].min;
|
nicholas@2855
|
230 option.querySelector("[name=max]").value = $s.interface.options[index].max;
|
nicholas@2855
|
231 }
|
nicholas@2855
|
232 });
|
nicholas@2855
|
233 });
|
nicholas@2855
|
234 $s.enableInterfaceOption = function ($event) {
|
nicholas@2855
|
235 var name = $event.currentTarget.parentElement.getAttribute("name");
|
nicholas@2855
|
236 var type = $event.currentTarget.parentElement.getAttribute("type");
|
nicholas@2855
|
237 var index = $s.interface.options.findIndex(function (io) {
|
nicholas@2855
|
238 return io.name == name;
|
nicholas@2855
|
239 });
|
nicholas@2855
|
240 if (index == -1 && $event.currentTarget.checked) {
|
nicholas@2855
|
241 var obj = $s.interface.options.push({
|
nicholas@2855
|
242 name: name,
|
nicholas@2855
|
243 type: type
|
nicholas@2855
|
244 });
|
nicholas@2855
|
245 if (name == "scalerange") {
|
nicholas@2855
|
246 obj.min = $event.currentTarget.parentElement.querySelector("[name=min]").value;
|
nicholas@2855
|
247 obj.max = $event.currentTarget.parentElement.querySelector("[name=max]").value;
|
nicholas@2855
|
248 }
|
nicholas@2855
|
249 } else if (index >= 0 && !$event.currentTarget.checked) {
|
nicholas@2855
|
250 $s.interface.options.splice(index, 1);
|
nicholas@2855
|
251 }
|
nicholas@2857
|
252 };
|
nicholas@2857
|
253 $s.removeScale = function (scale) {
|
nicholas@2857
|
254 var index = $s.interface.scales.findIndex(function (s) {
|
nicholas@2857
|
255 return s == scale;
|
nicholas@2857
|
256 });
|
nicholas@2857
|
257 if (index >= 0) {
|
nicholas@2857
|
258 $s.interface.scales.splice(index, 1);
|
nicholas@2857
|
259 }
|
nicholas@2857
|
260 };
|
nicholas@2857
|
261 $s.addScale = function () {
|
nicholas@2857
|
262 $s.interface.scales.push({
|
nicholas@2857
|
263 position: undefined,
|
nicholas@2857
|
264 text: undefined
|
nicholas@2857
|
265 });
|
nicholas@2857
|
266 };
|
nicholas@2853
|
267 }]);
|
nicholas@2859
|
268 AngularInterface.controller("page", ['$scope', '$element', '$window', function ($s, $e, $w) {
|
nicholas@2859
|
269 $s.addInterface = function () {
|
nicholas@2859
|
270 $s.page.addInterface();
|
nicholas@2859
|
271 };
|
nicholas@2859
|
272 $s.removeInterface = function (node) {
|
nicholas@2859
|
273 var index = $s.page.interfaces.findIndex(function (a) {
|
nicholas@2859
|
274 return a == node;
|
nicholas@2859
|
275 });
|
nicholas@2859
|
276 if (index === -1) {
|
nicholas@2859
|
277 throw ("Invalid node");
|
nicholas@2859
|
278 }
|
nicholas@2859
|
279 $s.page.interfaces.splice(index, 1);
|
nicholas@2859
|
280 };
|
nicholas@2859
|
281
|
nicholas@2859
|
282 $s.addCommentQuestion = function () {
|
nicholas@2859
|
283 $s.page.addCommentQuestion();
|
nicholas@2859
|
284 };
|
nicholas@2859
|
285 $s.removeCommentQuestion = function (node) {
|
nicholas@2859
|
286 var index = $s.page.commentQuestions.findIndex(function (a) {
|
nicholas@2859
|
287 return a == node;
|
nicholas@2859
|
288 });
|
nicholas@2859
|
289 if (index === -1) {
|
nicholas@2859
|
290 throw ("Invalid node");
|
nicholas@2859
|
291 }
|
nicholas@2859
|
292 $s.page.commentQuestions.splice(index, 1);
|
nicholas@2859
|
293 };
|
nicholas@2859
|
294 $s.addAudioElement = function () {
|
nicholas@2859
|
295 $s.page.addAudioElement();
|
nicholas@2859
|
296 };
|
nicholas@2859
|
297 $s.removeAudioElement = function (element) {
|
nicholas@2859
|
298 var index = $s.page.audioElements.findIndex(function (a) {
|
nicholas@2859
|
299 return a == element;
|
nicholas@2859
|
300 });
|
nicholas@2859
|
301 if (index === -1) {
|
nicholas@2859
|
302 throw ("Invalid node");
|
nicholas@2859
|
303 }
|
nicholas@2859
|
304 $s.page.audioElements.splice(index, 1);
|
nicholas@2859
|
305 };
|
nicholas@2859
|
306 }]);
|