nicholas@2851
|
1 /* globals 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@2851
|
56 }]);
|
nickjillings@1370
|
57
|
nicholas@2851
|
58 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) {
|
nicholas@2851
|
59 $s.state = 0;
|
nicholas@2851
|
60 $s.next = function () {
|
nicholas@2851
|
61 $s.state++;
|
nicholas@2851
|
62 if ($s.state > 1) {
|
nicholas@2851
|
63 $s.hidePopup();
|
nicholas@2851
|
64 }
|
nicholas@2851
|
65 };
|
nicholas@2851
|
66 $s.back = function () {
|
nicholas@2851
|
67 $s.state--;
|
nicholas@2851
|
68 };
|
nicholas@2851
|
69 $s.mouseover = function (name) {
|
nicholas@2851
|
70 var obj = $s.interfaces.find(function (i) {
|
nicholas@2851
|
71 return i.name == name;
|
nicholas@2851
|
72 });
|
nicholas@2851
|
73 if (obj) {
|
nicholas@2851
|
74 $s.description = obj.description.en;
|
nicholas@2851
|
75 }
|
nicholas@2851
|
76 };
|
nicholas@2851
|
77 $s.initialise = function (name) {
|
nicholas@2851
|
78 var obj = $s.interfaces.find(function (i) {
|
nicholas@2851
|
79 return i.name == name;
|
nicholas@2851
|
80 });
|
nicholas@2851
|
81 specification.interface = obj.interface;
|
nicholas@2851
|
82 };
|
nicholas@2851
|
83 // Get the test interface specifications
|
nicholas@2851
|
84 $s.interfaces = {};
|
nicholas@2851
|
85 $s.description = "";
|
nicholas@2851
|
86 var interfaceCollection = new Promise(function (resolve, reject) {
|
nicholas@2851
|
87 var xml = new XMLHttpRequest();
|
nicholas@2851
|
88 xml.open("GET", "test_create/interfaces/specifications.json");
|
nicholas@2851
|
89 xml.onload = function () {
|
nicholas@2851
|
90 if (xml.status === 200) {
|
nicholas@2851
|
91 resolve(xml.responseText);
|
nicholas@2851
|
92 return;
|
nicholas@2851
|
93 }
|
nicholas@2851
|
94 reject(xml.status);
|
nicholas@2851
|
95 };
|
nicholas@2851
|
96 xml.onerror = function () {
|
nicholas@2851
|
97 reject(new Error("Network Error"));
|
nicholas@2851
|
98 };
|
nicholas@2851
|
99 xml.send();
|
nicholas@2851
|
100 }).then(JSON.parse).then(function (data) {
|
nicholas@2851
|
101 $s.interfaces = data.interfaces;
|
nicholas@2851
|
102 $s.$apply();
|
nicholas@2851
|
103 });
|
nicholas@2851
|
104 }]);
|
nickjillings@1370
|
105
|
nicholas@2851
|
106 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {
|
nicholas@2851
|
107 function initialise() {
|
nicholas@2851
|
108 if ($s.globalSchema) {
|
nicholas@2851
|
109 $s.schema = $s.globalSchema.querySelector("[name=setup]");
|
nickjillings@1385
|
110 }
|
nickjillings@1370
|
111 }
|
nicholas@2851
|
112 $s.schema = undefined;
|
nicholas@2851
|
113 $s.attributes = [];
|
nicholas@2851
|
114 $s.model = specification;
|
nickjillings@1370
|
115
|
nicholas@2851
|
116 $s.$watch("globalSchema", initialise);
|
nicholas@2851
|
117 }]);
|