2 Copyright 2018 EveryUP srl
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
16 $(document
).ready(function () {
17 $("#formCreateNS").submit(function (event
) {
18 event
.preventDefault(); //prevent default action
19 var post_url
= $(this).attr("action"); //get form action url
20 var request_method
= $(this).attr("method"); //get form GET/POST method
21 var form_data
= new FormData(this); //Encode form elements for submission
27 "Accept": 'application/json'
31 }).done(function (response
, textStatus
, jqXHR
) {
32 window
.location
.href
= '/instances/ns/list/';
34 }).fail(function (result
) {
35 var data
= result
.responseJSON
;
36 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
37 var message
= data
.detail
? data
.detail
: 'No detail available.';
48 function deletePackage(package_type
, package_id
, package_name
) {
50 bootbox
.confirm("Are you sure want to delete " + package_name
+ "?", function (result
) {
52 var dialog
= bootbox
.dialog({
53 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
57 url
: '/packages/' + package_type
+ '/' + package_id
+ '/delete',
60 contentType
: "application/json;charset=utf-8",
61 success: function (result
) {
65 error: function (result
) {
67 var data
= result
.responseJSON
;
68 var title
= "Error " + (data
&& data
.code
? data
.code
: 'unknown');
69 var message
= data
&& data
.detail
? data
.detail
: 'No detail available.';
80 function clonePackage(package_type
, package_id
) {
82 bootbox
.confirm("Are you sure want to clone?", function (result
) {
84 var dialog
= bootbox
.dialog({
85 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
89 url
: '/packages/' + package_type
+ '/' + package_id
+ '/clone',
92 contentType
: "application/json;charset=utf-8",
93 success: function (result
) {
97 error: function (result
) {
99 var data
= result
.responseJSON
;
100 var title
= "Error " + (data
&& data
.code
? data
.code
: 'unknown');
101 var message
= data
&& data
.detail
? data
.detail
: 'No detail available.';
113 function openPackageContentList(type
, pkg_id
) {
114 var dialog
= bootbox
.dialog({
115 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
119 url
: '/packages/' + type
+ '/' + pkg_id
+ '/action/get_package_files_list',
122 contentType
: "application/json;charset=utf-8",
123 success: function (result
) {
124 //$('#modal_show_vim_body').empty();
125 dialog
.modal('hide');
126 build_file_list("Files in " + pkg_id
, result
.files
);
128 error: function (result
) {
129 dialog
.modal('hide');
130 bootbox
.alert("An error occurred while retrieving the package content.");
136 function build_file_list(title
, list
) {
137 $('#files_list_tbody').find('tr:gt(0)').remove();
138 $('#files_list_tbody_title').text(title
)
139 for (var i
in list
) {
140 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>'
141 $('#files_list_tbody').append(template
)
143 $('#modal_files_list').modal('show');