blob: 446a7c5dc99111050b04434ad8d611ed2e5f1d76 [file] [log] [blame]
Tyler Scottcdfcde82015-09-14 16:13:29 -06001//Run when the document loads AND we have the config loaded.
2(function(){
3 "use strict";
4 var config;
5 Promise.all([
6 new Promise(function(resolve, reject){
7 $.ajax('config.json').done(function(data){
8 config = data;
9 resolve();
10 }).fail(function(){
11 console.error("Failed to get config.");
12 ga('send', 'event', 'error', 'config');
13 reject();
14 });
15 }),
16 new Promise(function(resolve, reject){
17 var timeout = setTimeout(function(){
18 console.error("Document never loaded? Something bad has happened!");
19 reject();
20 }, 10000);
21 $(function () {
22 clearTimeout(timeout);
23 resolve();
24 });
25 })
26 ]).then(function(){
27 new Atmos(config);
28 }, function(){
29 console.error("Failed to initialize!");
30 ga('send', 'event', 'error', 'init');
31 });
32})();
33
34var Atmos = (function(){
35 "use strict";
36
37 var closeButton = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
38
39 var guid = function(){
40 var d = new Date().getTime();
41 var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
42 var r = (d + Math.random()*16)%16 | 0;
43 d = Math.floor(d/16);
44 return (c=='x' ? r : (r&0x3|0x8)).toString(16);
45 });
46 return uuid;
47 }
48
49 /**
50 * Atmos
51 * @version 2.0
52 *
53 * Configures an Atmos object. This manages the atmos interface.
54 *
55 * @constructor
56 * @param {string} catalog - NDN path
57 * @param {Object} config - Object of configuration options for a Face.
58 */
59 var Atmos = function(config){
60
61 //Internal variables.
62 this.results = [];
63 this.resultCount = Infinity;
64 this.name = null;
65 this.page = 0;
66 this.resultsPerPage = 25;
67 this.retrievedSegments = 0;
68
69 //Config/init
70 this.config = config;
71
72 this.catalog = config['global']['catalogPrefix'];
73
74 this.face = new Face(config['global']['faceConfig']);
75
76 //Easy access dom variables
77 this.categories = $('#side-menu');
78 this.resultTable = $('#resultTable');
79 this.filters = $('#filters');
80 this.searchInput = $('#search');
81 this.searchBar = $('#searchBar');
82 this.searchButton = $('#searchButton');
83 this.resultMenu = $('.resultMenu');
84 this.alerts = $('#alerts');
85 this.requestForm = $('#requestForm');
86
87 var scope = this;
88
89 $('.requestSelectedButton').click(function(){
90 ga('send', 'event', 'button', 'click', 'request');
91 scope.request(scope.resultTable.find('.resultSelector:checked:not([disabled])').parent().parent());
92 });
93
94 this.filterSetup();
95
96 //Init autocomplete
97 this.searchInput.autoComplete(function(field, callback){
98 ga('send', 'event', 'search', 'autocomplete');
99 scope.autoComplete(field, function(list){
100 callback(list.map(function(element){
101 return field + element + "/";
102 }));
103 });
104 });
105
106 //Handle search
107 this.searchBar.submit(function(e){
108 ga('send', 'event', 'search', 'submit');
109 e.preventDefault();
110 if (scope.searchInput.val().length === 0){
111 if (!scope.searchBar.hasClass('has-error')){
112 scope.searchBar.addClass('has-error').append('<span class="help-block">Search path is required!</span>');
113 }
114 return;
115 } else {
116 scope.searchBar.removeClass('has-error').find('.help-block').fadeOut(function(){$(this).remove()});
117 }
118 scope.pathSearch();
119 });
120
121 this.searchButton.click(function(){
122 console.log("Search Button Pressed");
123 ga('send', 'event', 'button', 'click', 'search');
124 scope.search();
125 });
126
127 //Result navigation handlers
128 this.resultMenu.find('.next').click(function(){
129 ga('send', 'event', 'button', 'click', 'next');
130 if (!$(this).hasClass('disabled')){
131 scope.getResults(scope.page + 1);
132 }
133 });
134 this.resultMenu.find('.previous').click(function(){
135 ga('send', 'event', 'button', 'click', 'previous');
136 if (!$(this).hasClass('disabled')){
137 scope.getResults(scope.page - 1);
138 }
139 });
140
141 //Change the number of results per page handler
142 var rpps = $('.resultsPerPageSelector').click(function(){
143
144 var t = $(this);
145
146 if (t.hasClass('active')){
147 return;
148 }
149
150 rpps.find('.active').removeClass('active');
151 t.addClass('active');
152 scope.resultsPerPage = Number(t.text());
153 scope.getResults(0); //Force return to page 1;
154
155 });
156
157 //Init tree search
158 $('#treeSearch div').treeExplorer(function(path, callback){
159 console.log("Tree Explorer request", path);
160 ga('send', 'event', 'tree', 'request');
Tyler Scottb59e6de2015-09-18 14:46:30 -0600161 scope.autoComplete(path, function(data){
162 var list = data.next;
163 var last = (data.lastComponent === true);
Tyler Scottcdfcde82015-09-14 16:13:29 -0600164 console.log("Autocomplete response", list);
165 callback(list.map(function(element){
Tyler Scottb59e6de2015-09-18 14:46:30 -0600166 return (path == "/"?"/":"") + element + (!last?"/":"");
Tyler Scottcdfcde82015-09-14 16:13:29 -0600167 }));
168 })
169 });
170
Tyler Scottb59e6de2015-09-18 14:46:30 -0600171 $('#treeSearch').on('click', '.treeSearch', function(){
172 var t = $(this);
173
174 scope.clearResults();
175
176 var path = t.parent().parent().attr('id');
177
178 console.log("Stringing tree search:", path);
179
180 scope.query(scope.catalog, {'??': path},
181 function(interest, data){ //Success
182 console.log("Tree search response", interest, data);
183
184 scope.name = data.getContent().toString().replace(/[\n\0]+/g,'');
185
186 scope.getResults(0);
187 },
188 function(interest){ //Failure
189 console.warn("Request failed! Timeout", interest);
190 scope.createAlert("Request timed out.\""+ interest.getName().toUri() + "\" See console for details.");
191 });
192
193 });
194
Tyler Scottcdfcde82015-09-14 16:13:29 -0600195 this.setupRequestForm();
196
197 }
198
199 Atmos.prototype.clearResults = function(){
200 this.results = []; //Drop any old results.
201 this.retrievedSegments = 0;
202 this.resultCount = Infinity;
203 this.page = 0;
204 this.resultTable.empty();
205 }
206
207 Atmos.prototype.pathSearch = function(){
208 var value = this.searchInput.val();
209
210 this.clearResults();
211
212 var scope = this;
213
214 this.query(this.catalog, {"??": value},
215 function(interest, data){
216 console.log("Query response:", interest, data);
217
218 scope.name = data.getContent().toString().replace(/[\n\0]/g,"");
219
220 scope.getResults(0);
221
222 },
223 function(interest){
224 console.warn("Request failed! Timeout", interest);
225 scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
226 });
227
228 }
229
230 Atmos.prototype.search = function(){
231
232 var filters = this.getFilters();
233
234 console.log("Search started!", this.searchInput.val(), filters);
235
236 console.log("Initiating query");
237
238 this.clearResults();
239
240 var scope = this;
241
242 this.query(this.catalog, filters,
243 function(interest, data){ //Response function
244 console.log("Query Response:", interest, data);
245
246 scope.name = data.getContent().toString().replace(/[\n\0]/g,"");
247
248 scope.getResults(0);
249
250 }, function(interest){ //Timeout function
251 console.warn("Request failed! Timeout");
252 scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
253 });
254
255 }
256
257 Atmos.prototype.autoComplete = function(field, callback){
258
259 var scope = this;
260
261 this.query(this.catalog, {"?": field},
262 function(interest, data){
263
264 var name = new Name(data.getContent().toString().replace(/[\n\0]/g,""));
265
266 var interest = new Interest(name);
267 interest.setInterestLifetimeMilliseconds(5000);
268 interest.setMustBeFresh(true);
269
270 scope.face.expressInterest(interest,
271 function(interest, data){
272
273 if (data.getContent().length !== 0){
Tyler Scottb59e6de2015-09-18 14:46:30 -0600274 callback(JSON.parse(data.getContent().toString().replace(/[\n\0]/g, "")));
Tyler Scottcdfcde82015-09-14 16:13:29 -0600275 } else {
276 callback([]);
277 }
278
279 }, function(interest){
280 console.warn("Interest timed out!", interest);
281 scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
282 });
283
284 }, function(interest){
285 console.error("Request failed! Timeout", interest);
286 scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
287 });
288
289 }
290
291 Atmos.prototype.showResults = function(resultIndex) {
292
293 var results = this.results.slice(this.resultsPerPage * resultIndex, this.resultsPerPage * (resultIndex + 1));
294
295 var resultDOM = $(
296 results.reduce(function(prev, current){
297 prev.push('<tr><td><input class="resultSelector" type="checkbox"></td><td>');
298 prev.push(current);
299 prev.push('</td></tr>');
300 return prev;
301 }, ['<tr><th><input id="resultSelectAll" type="checkbox" title="Select All"> Select</th><th>Name</th></tr>']).join('')
302 );
303
304 resultDOM.find('#resultSelectAll').click(function(){
305 if ($(this).is(':checked')){
306 resultDOM.find('.resultSelector:not([disabled])').prop('checked', true);
307 } else {
308 resultDOM.find('.resultSelector:not([disabled])').prop('checked', false);
309 }
310 });
311
312 this.resultTable.hide().empty().append(resultDOM).slideDown('slow');
313
314 this.resultMenu.find('.pageNumber').text(resultIndex + 1);
315 this.resultMenu.find('.pageLength').text(this.resultsPerPage * resultIndex + results.length);
316
317 if (this.resultsPerPage * (resultIndex + 1) >= this.resultCount) {
318 this.resultMenu.find('.next').addClass('disabled');
319 } else if (resultIndex === 0){
320 this.resultMenu.find('.next').removeClass('disabled');
321 }
322
323 if (resultIndex === 0){
324 this.resultMenu.find('.previous').addClass('disabled');
325 } else if (resultIndex === 1) {
326 this.resultMenu.find('.previous').removeClass('disabled');
327 }
328
329 }
330
331 Atmos.prototype.getResults = function(index){
332
333 if ($('#results').hasClass('hidden')){
334 $('#results').removeClass('hidden').slideDown();
335 }
336
Tyler Scottb59e6de2015-09-18 14:46:30 -0600337 $.scrollTo("#results", 700);
338
Tyler Scottcdfcde82015-09-14 16:13:29 -0600339 if ((this.results.length === this.resultCount) || (this.resultsPerPage * (index + 1) < this.results.length)){
340 //console.log("We already have index", index);
341 this.page = index;
342 this.showResults(index);
343 return;
344 }
345
346 if (this.name === null) {
347 console.error("This shouldn't be reached! We are getting results before a search has occured!");
348 throw new Error("Illegal State");
349 }
350
351 var first = new Name(this.name).appendSegment(this.retrievedSegments++);
352
353 console.log("Requesting data index: (", this.retrievedSegments - 1, ") at ", first.toUri());
354
355 var scope = this;
356
357 var interest = new Interest(first)
358 interest.setInterestLifetimeMilliseconds(5000);
359 interest.setMustBeFresh(true);
360
361 this.face.expressInterest(interest,
362 function(interest, data){ //Response
363
364 if (data.getContent().length === 0){
365 scope.resultMenu.find('.totalResults').text(0);
366 scope.resultMenu.find('.pageNumber').text(0);
367 scope.resultMenu.find('.pageLength').text(0);
368 console.log("Empty response.");
369 return;
370 }
371
372 var content = JSON.parse(data.getContent().toString().replace(/[\n\0]/g,""));
373
374 if (!content.results){
375 scope.resultMenu.find('.totalResults').text(0);
376 scope.resultMenu.find('.pageNumber').text(0);
377 scope.resultMenu.find('.pageLength').text(0);
378 console.log("No results were found!");
379 return;
380 }
381
382 scope.results = scope.results.concat(content.results);
383
384 scope.resultCount = content.resultCount;
385
386 scope.resultMenu.find('.totalResults').text(scope.resultCount);
387
388 scope.page = index;
389
390 scope.getResults(index); //Keep calling this until we have enough data.
391
392 },
393 function(interest){ //Timeout
394 console.error("Failed to retrieve results: timeout", interest);
395 scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
396 }
397 );
398
399 }
400
401 Atmos.prototype.query = function(prefix, parameters, callback, timeout) {
402
403 var queryPrefix = new Name(prefix);
404 queryPrefix.append("query");
405
406 var jsonString = JSON.stringify(parameters);
407 queryPrefix.append(jsonString);
408
409 var queryInterest = new Interest(queryPrefix);
410 queryInterest.setInterestLifetimeMilliseconds(4000);
411 queryInterest.setMustBeFresh(true);
412
413 this.face.expressInterest(queryInterest, callback, timeout);
414
415 }
416
417 /**
418 * This function returns a map of all the categories active filters.
419 * @return {Object<string, string>}
420 */
421 Atmos.prototype.getFilters = function(){
422 var filters = this.filters.children().toArray().reduce(function(prev, current){
423 var data = $(current).text().split(/:/);
424 prev[data[0]] = data[1];
425 return prev;
426 }, {}); //Collect a map<category, filter>.
427 //TODO Make the return value map<category, Array<filter>>
428 return filters;
429 }
430
431 /**
432 * Creates a closable alert for the user.
433 *
434 * @param {string} message
435 * @param {string} type - Override the alert type.
436 */
437 Atmos.prototype.createAlert = function(message, type) {
438
439 var alert = $('<div class="alert"><div>');
440 alert.addClass(type?type:'alert-info');
441 alert.text(message);
442 alert.append(closeButton);
443
444 this.alerts.append(alert);
445 }
446
447 /**
448 * Requests all of the names represented by the buttons in the elements list.
449 *
450 * @param elements {Array<jQuery>} A list of the table row elements
451 */
452 Atmos.prototype.request = function(){
453
454 //Pseudo globals.
455 var keyChain;
456 var certificateName;
457 var keyAdded = false;
458
459 return function(elements){
460
461 var names = [];
462 var destination = $('#requestDest .active').text();
463 $(elements).find('>*:nth-child(2)').each(function(){
464 var name = $(this).text();
465 names.push(name);
466 });//.append('<span class="badge">Requested!</span>')
467 //Disabling the checkbox doesn't make sense anymore with the ability to request to multiple destinations.
468 //$(elements).find('.resultSelector').prop('disabled', true).prop('checked', false);
469
470 var scope = this;
471 this.requestForm.on('submit', function(e){ //This will be registered for the next submit from the form.
472 e.preventDefault();
473
474 //Form checking
475 var dest = scope.requestForm.find('#requestDest .active');
476 if (dest.length !== 1){
477 $('#requestForm').append($('<div class="alert alert-warning">A destination is required!' + closeButton + '<div>'));
478 return;
479 }
480
481 $('#request').modal('hide')//Initial params are ok. We can close the form.
482 .remove('.alert') //Remove any alerts
Tyler Scottb59e6de2015-09-18 14:46:30 -0600483
484 scope.cleanRequestForm();
Tyler Scottcdfcde82015-09-14 16:13:29 -0600485
486 $(this).off(e); //Don't fire this again, the request must be regenerated
487
488 //Key setup
489 if (!keyAdded){
490 if (!scope.config.retrieval.demoKey || !scope.config.retrieval.demoKey.pub || !scope.config.retrieval.demoKey.priv){
491 scope.createAlert("This host was not configured to handle retrieval! See console for details.", 'alert-danger');
492 console.error("Missing/invalid key! This must be configured in the config on the server.", scope.config.demoKey);
493 return;
494 }
495
496 //FIXME base64 may or may not exist in other browsers. Need a new polyfill.
497 var pub = new Buffer(base64.toByteArray(scope.config.retrieval.demoKey.pub)); //MUST be a Buffer (Buffer != Uint8Array)
498 var priv = new Buffer(base64.toByteArray(scope.config.retrieval.demoKey.priv));
499
500 var identityStorage = new MemoryIdentityStorage();
501 var privateKeyStorage = new MemoryPrivateKeyStorage();
502 keyChain = new KeyChain(new IdentityManager(identityStorage, privateKeyStorage),
503 new SelfVerifyPolicyManager(identityStorage));
504
505 var keyName = new Name("/retrieve/DSK-123");
506 certificateName = keyName.getSubName(0, keyName.size() - 1)
507 .append("KEY").append(keyName.get(-1))
508 .append("ID-CERT").append("0");
509
510 identityStorage.addKey(keyName, KeyType.RSA, new Blob(pub, false));
511 privateKeyStorage.setKeyPairForKeyName(keyName, KeyType.RSA, pub, priv);
512
513 scope.face.setCommandSigningInfo(keyChain, certificateName);
514
515 keyAdded = true;
516
517 }
518
519 //Retrieval
520 var retrievePrefix = new Name("/catalog/ui/" + guid());
521
522 //Due to a lack of success callback in the register prefix function, we have to pretend we
523 //know it succeeded with an arbitrary timeout.
524 var sendTimer = setTimeout(function(){
525 var prefix = new Name(dest.text());
526 prefix.append(retrievePrefix);
527 var interest = new Interest(prefix);
528 interest.setInterestLifetimeMilliseconds(3000);
529 scope.face.expressInterest(interest,
530 function(interest, data){ //Success
531 console.log("Request for", prefix.toUri(), "succeeded.", interest, data);
Tyler Scottb59e6de2015-09-18 14:46:30 -0600532 scope.createAlert("Data retrieval has initiated.", "alert-success");
Tyler Scottcdfcde82015-09-14 16:13:29 -0600533 }, function(interest){ //Failure
Tyler Scottb59e6de2015-09-18 14:46:30 -0600534 console.error("Request for", prefix.toUri(), "timed out.", interest);
535 scope.createAlert("Request for " + prefix.toUri() + " timed out. This means that the retrieve failed! See console for more details.");
Tyler Scottcdfcde82015-09-14 16:13:29 -0600536 }
537 );
Tyler Scottb59e6de2015-09-18 14:46:30 -0600538 }, 5000); //Wait 5 seconds
Tyler Scottcdfcde82015-09-14 16:13:29 -0600539
540 scope.face.registerPrefix(retrievePrefix,
541 function(prefix, interest, face, interestFilterId, filter){ //On Interest
542 //This function will exist until the page exits but will likely only be used once.
543
544 var data = new Data(interest.getName());
545 var content = JSON.stringify(names);
546 data.setContent(content);
547 keyChain.sign(data, certificateName);
548
549 try {
550 face.putData(data);
551 console.log("Responded for", interest.getName().toUri(), data);
Tyler Scottcdfcde82015-09-14 16:13:29 -0600552 } catch (e) {
553 console.error("Failed to respond to", interest.getName().toUri(), data);
554 scope.createAlert("Data retrieval failed.");
555 }
556
557 }, function(prefix){ //On fail
558 clearTimeout(sendTimer); //Cancel the earlier request timer
559 scope.createAlert("Failed to register the retrieval URI! See console for details.", "alert-danger");
560 console.error("Failed to register URI:", prefix.toUri(), prefix);
561
562 }
563 );
564
565 });
566 $('#request').modal(); //This forces the form to be the only option.
567
568 }
569 }();
570
571 Atmos.prototype.filterSetup = function() {
572 //Filter setup
573
574 var prefix = new Name(this.catalog).append("filters-initialization");
575
576 var scope = this;
577
578 this.getAll(prefix, function(data) { //Success
579 var raw = JSON.parse(data.replace(/[\n\0]/g, '')); //Remove null byte and parse
580
581 console.log("Filter categories:", raw);
582
583 $.each(raw, function(index, object){ //Unpack list of objects
584 $.each(object, function(category, searchOptions) { //Unpack category from object (We don't know what it is called)
585 //Create the category
586 var e = $('<li><a href="#">' + category.replace(/_/g, " ") + '</a><ul class="subnav nav nav-pills nav-stacked"></ul></li>');
587
588 var sub = e.find('ul.subnav');
589 $.each(searchOptions, function(index, name){
590 //Create the filter list inside the category
591 var item = $('<li><a href="#">' + name + '</a></li>');
592 sub.append(item);
593 item.click(function(){ //Click on the side menu filters
594 if (item.hasClass('active')){ //Does the filter already exist?
595 item.removeClass('active');
596 scope.filters.find(':contains(' + category + ':' + name + ')').remove();
597 } else { //Add a filter
598 item.addClass('active');
599 var filter = $('<span class="label label-default"></span>');
600 filter.text(category + ':' + name);
601
602 scope.filters.append(filter);
603
604 filter.click(function(){ //Click on a filter
605 filter.remove();
606 item.removeClass('active');
607 });
608 }
609
610 });
611 });
612
613 //Toggle the menus. (Only respond when the immediate tab is clicked.)
614 e.find('> a').click(function(){
615 scope.categories.find('.subnav').slideUp();
616 var t = $(this).siblings('.subnav');
617 if ( !t.is(':visible') ){ //If the sub menu is not visible
618 t.slideDown(function(){
619 t.triggerHandler('focus');
620 }); //Make it visible and look at it.
621 }
622 });
623
624 scope.categories.append(e);
625
626 });
627 });
628
629 }, function(interest){ //Timeout
630 scope.createAlert("Failed to initialize the filters!", "alert-danger");
631 console.error("Failed to initialize filters!", interest);
632 ga('send', 'event', 'error', 'filters');
633 });
634
635 }
636
637 /**
638 * This function retrieves all segments in order until it knows it has reached the last one.
639 * It then returns the final joined result.
640 */
641 Atmos.prototype.getAll = function(prefix, callback, timeout){
642
643 var scope = this;
644 var d = [];
645
646 var request = function(segment){
647
648 var name = new Name(prefix);
649 name.appendSegment(segment);
650
651 var interest = new Interest(name);
652 interest.setInterestLifetimeMilliseconds(1000);
653 interest.setMustBeFresh(true); //Is this needed?
654
655 scope.face.expressInterest(interest, handleData, timeout);
656
657 }
658
659
660 var handleData = function(interest, data){
661
662 d.push(data.getContent().toString());
663
664 if (interest.getName().get(-1).toSegment() == data.getMetaInfo().getFinalBlockId().toSegment()){
665 callback(d.join(""));
666 } else {
667 request(interest.getName().toSegment()++);
668 }
669
670 }
671
672 request(0);
673
674 }
675
Tyler Scottb59e6de2015-09-18 14:46:30 -0600676 Atmos.prototype.cleanRequestForm = function(){
677 $('#requestDest').prev().removeClass('btn-success').addClass('btn-default');
678 $('#requestDropText').text('Destination');
679 $('#requestDest .active').removeClass('active');
680 }
681
Tyler Scottcdfcde82015-09-14 16:13:29 -0600682 Atmos.prototype.setupRequestForm = function(){
Tyler Scottb59e6de2015-09-18 14:46:30 -0600683
684 var scope = this;
685
Tyler Scottcdfcde82015-09-14 16:13:29 -0600686 this.requestForm.find('#requestCancel').click(function(){
687 $('#request').unbind('submit') //Removes all event handlers.
688 .modal('hide'); //Hides the form.
Tyler Scottb59e6de2015-09-18 14:46:30 -0600689 scope.cleanRequestForm();
Tyler Scottcdfcde82015-09-14 16:13:29 -0600690 });
691
692 var dests = $(this.config['retrieval']['destinations'].reduce(function(prev, current){
693 prev.push('<li><a href="#">');
694 prev.push(current);
695 prev.push("</a></li>");
696 return prev;
697 }, []).join(""));
698
699 this.requestForm.find('#requestDest').append(dests)
700 .on('click', 'a', function(e){
701 $('#requestDest .active').removeClass('active');
Tyler Scottb59e6de2015-09-18 14:46:30 -0600702 var t = $(this);
703 t.parent().addClass('active');
704 $('#requestDropText').text(t.text());
705 $('#requestDest').prev().removeClass('btn-default').addClass('btn-success');
Tyler Scottcdfcde82015-09-14 16:13:29 -0600706 });
707
708 //This code will remain unused until users must use their own keys instead of the demo key.
709// var scope = this;
710
711// var warning = '<div class="alert alert-warning">' + closeButton + '<div>';
712
713// var handleFile = function(e){
714// var t = $(this);
715// if (e.target.files.length > 1){
716// var el = $(warning);
717// t.append(el.append("We are looking for a single file, we will try the first only!"));
718// } else if (e.target.files.length === 0) {
719// var el = $(warning.replace("alert-warning", "alert-danger"));
720// t.append(el.append("No file was supplied!"));
721// return;
722// }
723
724// var reader = new FileReader();
725// reader.onload = function(e){
726// var key;
727// try {
728// key = JSON.parse(e.target.result);
729// } catch (e) {
730// console.error("Could not parse the key! (", key, ")");
731// var el = $(warning.replace("alert-warning", "alert-danger"));
732// t.append(el.append("Failed to parse the key file, is it a valid json key?"));
733// }
734
735// if (!key.DEFAULT_RSA_PUBLIC_KEY_DER || !key.DEFAULT_RSA_PRIVATE_KEY_DER) {
736// console.warn("Invalid key", key);
737// var el = $(warning.replace("alert-warning", "alert-danger"));
738// t.append(el.append("Failed to parse the key file, it is missing required attributes."));
739// }
740
741
742// };
743
744// }
745
746// this.requestForm.find('#requestDrop').on('dragover', function(e){
747// e.dataTransfer.dropEffect = 'copy';
748// }).on('drop', handleFile);
749
750// this.requestForm.find('input[type=file]').change(handleFile);
751
752 }
753
754 return Atmos;
755
756})();