Network Slice Templates
[osm/LW-UI.git] / static / src / packagehandler / onboard_package.js
1 /*
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
17 function create(fs, dropzone) {
18 var id = $('.nav-tabs .active').attr('id');
19 if (dropzone) id = 'file_li';
20 var type, text;
21 var data = new FormData();
22 switch (id) {
23
24 case 'file_li':
25 type = 'file';
26
27 var files = dropzone ? fs : document.getElementById('js-upload-files').files;
28 if (!files || !files.length) {
29 files = document.getElementById('drop-zone').files;
30 if (!files || !files.length) {
31 alert("Select a file");
32 return
33 }
34 }
35 console.log(files[0])
36 var patt1 = /\.([0-9a-z]+)(?:[\?#]|$)/i;
37 console.log(files[0].name.match(patt1));
38 var extension = files[0].name.substr(files[0].name.lastIndexOf('.') + 1);
39 console.log(extension);
40 if (!(extension == 'gz' )) {
41 alert("The file must be .tar.gz");
42 return
43 }
44
45 data.append('file', files[0]);
46 break;
47 }
48 data.append('csrfmiddlewaretoken', csrf_token);
49 data.append('type', type);
50 data.append('text', text);
51 data.append('id', '{{descriptor_id}}');
52 console.log(text);
53 var dialog = bootbox.dialog({
54 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Onboarding...</div>',
55 closeButton: true
56 });
57 $.ajax({
58 url: new_desc_url,
59 type: 'POST',
60 data: data,
61 cache: false,
62 contentType: false,
63 processData: false,
64 success: function (result) {
65 dialog.modal('hide');
66 refreshTable();
67 },
68 error: function (result) {
69 dialog.modal('hide');
70 showAlert(result);
71 }
72 });
73 }