comparison test_create/test_core.js @ 2861:79258b2a8245

Completed file upload for test_create
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Thu, 27 Apr 2017 12:57:31 +0100
parents 65b8d9ad75cc
children b8795a6452f8
comparison
equal deleted inserted replaced
2860:65b8d9ad75cc 2861:79258b2a8245
1 /* globals document, angular, window, Promise, XMLHttpRequest, Specification */ 1 /* globals document, angular, window, Promise, XMLHttpRequest, Specification, XMLSerializer, Blob, DOMParser*/
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();
36 window.onload = function () { 36 window.onload = function () {
37 // Get the test interface specifications 37 // Get the test interface specifications
38 38
39 }; 39 };
40 40
41 function handleFiles(event) {
42 var s = angular.element(event.currentTarget).scope();
43 s.handleFiles(event);
44 s.$apply();
45 }
46
41 AngularInterface.controller("view", ['$scope', '$element', '$window', function ($s, $e, $w) { 47 AngularInterface.controller("view", ['$scope', '$element', '$window', function ($s, $e, $w) {
42 $s.popupVisible = true; 48 $s.popupVisible = true;
43 49
44 $s.showPopup = function () { 50 $s.showPopup = function () {
45 $s.popupVisible = true; 51 $s.popupVisible = true;
64 var bb = new Blob([s.serializeToString(doc)], { 70 var bb = new Blob([s.serializeToString(doc)], {
65 type: 'application/xml' 71 type: 'application/xml'
66 }); 72 });
67 var dnlk = window.URL.createObjectURL(bb); 73 var dnlk = window.URL.createObjectURL(bb);
68 window.location.href = dnlk; 74 window.location.href = dnlk;
69 } 75 };
70 }]); 76 }]);
71 77
72 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) { 78 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) {
73 $s.state = 0; 79 $s.state = 0;
74 $s.next = function () { 80 $s.next = function () {
75 $s.state++; 81 $s.state++;
76 if ($s.state > 1) { 82 if ($s.state > 1 || $s.file) {
77 $s.hidePopup(); 83 $s.hidePopup();
78 } 84 }
79 }; 85 };
80 $s.back = function () { 86 $s.back = function () {
81 $s.state--; 87 $s.state--;
94 }); 100 });
95 specification.interface = obj.interface; 101 specification.interface = obj.interface;
96 }; 102 };
97 // Get the test interface specifications 103 // Get the test interface specifications
98 $s.interfaces = {}; 104 $s.interfaces = {};
105 $s.file = undefined;
99 $s.description = ""; 106 $s.description = "";
100 var interfaceCollection = new Promise(function (resolve, reject) { 107 var interfaceCollection = new Promise(function (resolve, reject) {
101 var xml = new XMLHttpRequest(); 108 var xml = new XMLHttpRequest();
102 xml.open("GET", "test_create/interfaces/specifications.json"); 109 xml.open("GET", "test_create/interfaces/specifications.json");
103 xml.onload = function () { 110 xml.onload = function () {
113 xml.send(); 120 xml.send();
114 }).then(JSON.parse).then(function (data) { 121 }).then(JSON.parse).then(function (data) {
115 $s.interfaces = data.interfaces; 122 $s.interfaces = data.interfaces;
116 $s.$apply(); 123 $s.$apply();
117 }); 124 });
125
126 $s.handleFiles = function ($event) {
127 $s.file = $event.currentTarget.files[0];
128 var r = new FileReader();
129 r.onload = function () {
130 var p = new DOMParser();
131 specification.decode(p.parseFromString(r.result, "text/xml"));
132 $s.$apply();
133 }
134 r.readAsText($s.file);
135 };
118 }]); 136 }]);
119 137
120 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) { 138 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {
121 function initialise() { 139 function initialise() {
122 if ($s.globalSchema) { 140 if ($s.globalSchema) {