0eebca619ba9f44ef40a1a312fd673fed655c8b5
[osm/LW-UI.git] / static / src / packagehandler / packages_list.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(package_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: '/packages/' + package_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 var data = result.responseJSON;
37 var title = "Error " + (data && data.code ? data.code : 'unknown');
38 var message = data && data.detail ? data.detail : 'No detail available.';
39 bootbox.alert({
40 title: title,
41 message: message
42 });
43 }
44 });
45 }
46 })
47 }
48
49 function clonePackage(package_type, package_id) {
50
51 bootbox.confirm("Are you sure want to clone?", function (result) {
52 if (result) {
53 var dialog = bootbox.dialog({
54 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
55 closeButton: true
56 });
57 $.ajax({
58 url: '/packages/' + package_type + '/' + package_id + '/clone',
59 type: 'GET',
60 dataType: "json",
61 contentType: "application/json;charset=utf-8",
62 success: function (result) {
63 dialog.modal('hide');
64 location.reload();
65 },
66 error: function (result) {
67 dialog.modal('hide');
68 var data = result.responseJSON;
69 var title = "Error " + (data && data.code ? data.code : 'unknown');
70 var message = data && data.detail ? data.detail : 'No detail available.';
71 bootbox.alert({
72 title: title,
73 message: message
74 });
75 }
76 });
77 }
78 })
79 }
80
81
82 function openPackageContentList(type, pkg_id) {
83 var dialog = bootbox.dialog({
84 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
85 closeButton: true
86 });
87 $.ajax({
88 url: '/packages/' + type + '/' + pkg_id + '/action/get_package_files_list',
89 type: 'GET',
90 dataType: "json",
91 contentType: "application/json;charset=utf-8",
92 success: function (result) {
93 //$('#modal_show_vim_body').empty();
94 dialog.modal('hide');
95 build_file_list("Files in " + pkg_id, result.files);
96 },
97 error: function (result) {
98 dialog.modal('hide');
99 bootbox.alert("An error occurred while retrieving the package content.");
100 }
101 });
102 }
103
104
105 function build_file_list(title, list) {
106 $('#files_list_tbody').find('tr:gt(0)').remove();
107 $('#files_list_tbody_title').text(title)
108 for (var i in list) {
109 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>'
110 $('#files_list_tbody').append(template)
111 }
112 $('#modal_files_list').modal('show');
113 }
114