blob: d18be5b1d90dbee50ba312b7f618fd249cebdd0b [file] [log] [blame]
lombardofr1e320062018-10-30 22:16:25 +01001/*
2 Copyright 2018 EveryUP srl
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
lombardof9b8155e2018-06-03 18:04:42 +020017var dropZone = document.getElementById('drop-zone');
18dropZone.ondrop = function (e) {
19 e.preventDefault();
20 this.className = 'upload-drop-zone';
21 create(e.dataTransfer.files, true);
22};
23
24dropZone.ondragover = function () {
25 this.className = 'upload-drop-zone drop';
26 return false;
27};
28
29dropZone.ondragleave = function () {
30 this.className = 'upload-drop-zone';
31 return false;
32};
33
34
35function create(fs, dropzone) {
36 var id = $('.nav-tabs .active').attr('id');
37 if (dropzone) id = 'file_li';
38 var type, text;
39 var data = new FormData();
40 switch (id) {
41
42 case 'file_li':
43 type = 'file';
44
45 var files = dropzone ? fs : document.getElementById('js-upload-files').files;
46 if (!files || !files.length) {
47 files = document.getElementById('drop-zone').files;
48 if (!files || !files.length) {
49 alert("Select a file");
50 return
51 }
52 }
53 console.log(files[0])
54 var patt1 = /\.([0-9a-z]+)(?:[\?#]|$)/i;
55 console.log(files[0].name.match(patt1));
56 var extension = files[0].name.substr(files[0].name.lastIndexOf('.') + 1);
57 console.log(extension);
58 if (!(extension == 'gz' )) {
59 alert("The file must be .tar.gz");
60 return
61 }
62
63 data.append('file', files[0]);
64 break;
65 }
66 data.append('csrfmiddlewaretoken', csrf_token);
67 data.append('type', type);
68 data.append('text', text);
69 data.append('id', '{{descriptor_id}}');
70 console.log(text);
lombardofrfbd4aef2018-10-06 14:11:43 +020071 var dialog = bootbox.dialog({
72 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Onboarding...</div>',
73 closeButton: true
74 });
lombardof9b8155e2018-06-03 18:04:42 +020075 $.ajax({
lombardof20d05502018-06-07 15:50:03 +020076 url: new_desc_url,
lombardof9b8155e2018-06-03 18:04:42 +020077 type: 'POST',
78 data: data,
79 cache: false,
80 contentType: false,
81 processData: false,
82 success: function (result) {
lombardofrfbd4aef2018-10-06 14:11:43 +020083 dialog.modal('hide');
84 refreshTable();
lombardof9b8155e2018-06-03 18:04:42 +020085 },
86 error: function (result) {
lombardofrfbd4aef2018-10-06 14:11:43 +020087 dialog.modal('hide');
lombardof9b8155e2018-06-03 18:04:42 +020088 showAlert(result);
89 }
90 });
91}