50600413d6bd0a8052c0593d543578cf9f722afb
[osm/LW-UI.git] / static / src / projecthandler / descriptorslist.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 deletePackage(descriptor_type, package_id, package_name) {
18
19 bootbox.confirm("Are you sure want to delete " + package_name + "?", function (result) {
20 if (result) {
21 var dialog = bootbox.dialog({
22 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
23 closeButton: true
24 });
25 $.ajax({
26 url: '/projects/descriptors/' + descriptor_type + '/' + package_id + '/delete',
27 type: 'GET',
28 dataType: "json",
29 contentType: "application/json;charset=utf-8",
30 success: function (result) {
31 dialog.modal('hide');
32 location.reload();
33 },
34 error: function (result) {
35 dialog.modal('hide');
36 bootbox.alert("An error occurred.");
37 }
38 });
39 }
40 })
41 }
42
43 function clonePackage(descriptor_type, package_id) {
44
45 bootbox.confirm("Are you sure want to clone?", function (result) {
46 if (result) {
47 var dialog = bootbox.dialog({
48 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
49 closeButton: true
50 });
51 $.ajax({
52 url: '/projects/descriptors/' + descriptor_type + '/' + package_id + '/clone',
53 type: 'GET',
54 dataType: "json",
55 contentType: "application/json;charset=utf-8",
56 success: function (result) {
57 dialog.modal('hide');
58 location.reload();
59 },
60 error: function (result) {
61 dialog.modal('hide');
62 bootbox.alert("An error occurred.");
63 }
64 });
65 }
66 })
67 }
68
69
70 function openPackageContentList(type, pkg_id) {
71 var dialog = bootbox.dialog({
72 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
73 closeButton: true
74 });
75 $.ajax({
76 url: '/projects/descriptors/' + type + '/' + pkg_id + '/action/get_package_files_list',
77 type: 'GET',
78 dataType: "json",
79 contentType: "application/json;charset=utf-8",
80 success: function (result) {
81 //$('#modal_show_vim_body').empty();
82 dialog.modal('hide');
83 build_file_list("Files in " + pkg_id, result.files);
84 },
85 error: function (result) {
86 dialog.modal('hide');
87 bootbox.alert("An error occurred while retrieving the package content.");
88 }
89 });
90 }
91
92
93 function build_file_list(title, list) {
94 $('#files_list_tbody').find('tr:gt(0)').remove();
95 $('#files_list_tbody_title').text(title)
96 for (var i in list) {
97 var template = '<tr><td>-</td><td>' + list[i] + '</td><td><button type="button" class="btn btn-default" onclick="" disabled><i class="fa fa-folder-open"></i></button></td></tr>'
98 $('#files_list_tbody').append(template)
99 }
100 $('#modal_files_list').modal('show');
101 }
102