comparison test_create/test_core.js @ 2855:6625f4ad24f4

Finished <survey> interpretation for test_creator.html
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Wed, 26 Apr 2017 17:43:52 +0100
parents f75db4482006
children 5591d01adf1c
comparison
equal deleted inserted replaced
2854:aed359997687 2855:6625f4ad24f4
1 /* globals angular, window, Promise, XMLHttpRequest, Specification */ 1 /* globals document, angular, window, Promise, XMLHttpRequest, Specification */
2 function get(url) { 2 function get(url) {
3 // Return a new promise. 3 // Return a new promise.
4 return new Promise(function (resolve, reject) { 4 return new Promise(function (resolve, reject) {
5 // Do the usual XHR stuff 5 // Do the usual XHR stuff
6 var req = new XMLHttpRequest(); 6 var req = new XMLHttpRequest();
125 var DOM = metricsNode.querySelector("[value=" + metric + "]"); 125 var DOM = metricsNode.querySelector("[value=" + metric + "]");
126 if (DOM) { 126 if (DOM) {
127 DOM.checked = true; 127 DOM.checked = true;
128 } 128 }
129 }); 129 });
130 }) 130 });
131 131
132 $s.enableMetric = function ($event) { 132 $s.enableMetric = function ($event) {
133 var metric = $event.currentTarget.value; 133 var metric = $event.currentTarget.value;
134 var index = specification.metrics.enabled.findIndex(function (a) { 134 var index = specification.metrics.enabled.findIndex(function (a) {
135 return a == metric; 135 return a == metric;
141 } else { 141 } else {
142 if (index >= 0) { 142 if (index >= 0) {
143 specification.metrics.enabled.splice(index, 1); 143 specification.metrics.enabled.splice(index, 1);
144 } 144 }
145 } 145 }
146 } 146 };
147 }]); 147 }]);
148 148
149 AngularInterface.controller("surveyOption", ['$scope', '$element', '$window', function ($s, $e, $w) { 149 AngularInterface.controller("surveyOption", ['$scope', '$element', '$window', function ($s, $e, $w) {
150 150
151 $s.removeOption = function (option) { 151 $s.removeOption = function (option) {
160 $s.addOption = function () { 160 $s.addOption = function () {
161 $s.opt.options.push({ 161 $s.opt.options.push({
162 name: "", 162 name: "",
163 text: "" 163 text: ""
164 }); 164 });
165 };
166 }]);
167
168 AngularInterface.controller("interfaceNode", ['$scope', '$element', '$window', function ($s, $e, $w) {
169 $s.$watch("interface.options.length", function () {
170 if (!$s.interface || !$s.interface.options) {
171 return;
172 }
173 var options = $e[0].querySelector(".interfaceOptions").querySelectorAll(".attribute");
174 options.forEach(function (option) {
175 var name = option.getAttribute("name");
176 var index = $s.interface.options.findIndex(function (io) {
177 return io.name == name;
178 });
179 option.querySelector("input").checked = (index >= 0);
180 if (name == "scalerange" && index >= 0) {
181 option.querySelector("[name=min]").value = $s.interface.options[index].min;
182 option.querySelector("[name=max]").value = $s.interface.options[index].max;
183 }
184 });
185 });
186 $s.enableInterfaceOption = function ($event) {
187 var name = $event.currentTarget.parentElement.getAttribute("name");
188 var type = $event.currentTarget.parentElement.getAttribute("type");
189 var index = $s.interface.options.findIndex(function (io) {
190 return io.name == name;
191 });
192 if (index == -1 && $event.currentTarget.checked) {
193 var obj = $s.interface.options.push({
194 name: name,
195 type: type
196 });
197 if (name == "scalerange") {
198 obj.min = $event.currentTarget.parentElement.querySelector("[name=min]").value;
199 obj.max = $event.currentTarget.parentElement.querySelector("[name=max]").value;
200 }
201 } else if (index >= 0 && !$event.currentTarget.checked) {
202 $s.interface.options.splice(index, 1);
203 }
165 } 204 }
166 }]); 205 }]);