7c52fe7245de17f485bfa90d61daf39fb2cea752
[osm/LW-UI.git] / static / src / netslicehandler / templates_list.js
1 /*
2 Copyright 2019 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 $(document).ready(function () {
18 $("#formCreateNSI").submit(function (event) {
19 event.preventDefault(); //prevent default action
20 var post_url = $(this).attr("action"); //get form action url
21 var request_method = $(this).attr("method"); //get form GET/POST method
22 var form_data = new FormData(this); //Encode form elements for submission
23 $.ajax({
24 url: post_url,
25 type: request_method,
26 data: form_data,
27 headers: {
28 "Accept": 'application/json'
29 },
30 contentType: false,
31 processData: false
32 }).done(function (response, textStatus, jqXHR) {
33 window.location.href = '/instances/nsi/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.';
38 bootbox.alert({
39 title: title,
40 message: message
41 });
42 });
43 });
44 });
45
46 function deleteTemplate(template_name, template_id) {
47 var url = '/netslices/templates/'+template_id+'/delete';
48 bootbox.confirm("Are you sure want to delete " + template_name + "?", function (result) {
49 if (result) {
50 var dialog = bootbox.dialog({
51 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
52 closeButton: true
53 });
54 $.ajax({
55 url: url,
56 type: 'GET',
57 dataType: "json",
58 contentType: "application/json;charset=utf-8",
59 success: function (result) {
60 if (result['error'] == true){
61 dialog.modal('hide');
62 bootbox.alert("An error occurred.");
63 }
64 else {
65 dialog.modal('hide');
66 location.reload();
67 }
68 },
69 error: function (error) {
70 dialog.modal('hide');
71 bootbox.alert("An error occurred.");
72 }
73 });
74 }
75 })
76 }
77
78 function showNstDetails(template_id) {
79 var url_info = '/netslices/templates/'+template_id+'/details';
80 var dialog = bootbox.dialog({
81 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
82 closeButton: true
83 });
84 $.ajax({
85 url: url_info,
86 type: 'GET',
87 dataType: "json",
88 contentType: "application/json;charset=utf-8",
89 success: function (result) {
90 console.log(result)
91 if (result['data'] !== undefined) {
92 editorJSON.setValue(JSON.stringify(result['data'], null, "\t"));
93 editorJSON.setOption("autoRefresh", true);
94 dialog.modal('hide');
95 $('#modal_show_nst').modal('show');
96 }
97 else {
98 dialog.modal('hide');
99 bootbox.alert("An error occurred while retrieving the information.");
100 }
101 },
102 error: function (result) {
103 dialog.modal('hide');
104 bootbox.alert("An error occurred while retrieving the information.");
105 }
106 });
107 }