k8sClusters; k8sRepos
[osm/LW-UI.git] / static / src / k8srepohandler / k8srepos_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 function openModalRegisterK8sr(args) {
18 $('#modal_new_k8sr').modal('show');
19 }
20
21 function showK8sr(k8sr_id, k8sr_name) {
22 var url_info = '/k8srepo/' + k8sr_id;
23 var dialog = bootbox.dialog({
24 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
25 closeButton: true
26 });
27 $.ajax({
28 url: url_info,
29 type: 'GET',
30 dataType: "json",
31 contentType: "application/json;charset=utf-8",
32 success: function (result) {
33
34 if (result['data'] !== undefined) {
35 editorJSON.setValue(JSON.stringify(result['data'], null, "\t"));
36 editorJSON.setOption("autoRefresh", true);
37 dialog.modal('hide');
38 $('#modal_show_k8sr').modal('show');
39 }
40 else {
41 dialog.modal('hide');
42 bootbox.alert("An error occurred while retrieving the information.");
43 }
44 },
45 error: function (result) {
46 dialog.modal('hide');
47 bootbox.alert("An error occurred while retrieving the information.");
48 }
49 });
50 }
51
52 function deleteK8sc(k8sr_id, k8sr_name) {
53 var url = "/k8srepo/"+k8sr_id+"/delete";
54 bootbox.confirm("Are you sure want to delete " + k8sr_name + "?", function (result) {
55 if (result) {
56 var dialog = bootbox.dialog({
57 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
58 closeButton: true
59 });
60 $.ajax({
61 url: url,
62 type: 'GET',
63 dataType: "json",
64 contentType: "application/json;charset=utf-8",
65 success: function (result) {
66 if (result['error'] == true) {
67 dialog.modal('hide');
68 bootbox.alert("An error occurred.");
69 }
70 else {
71 table.ajax.reload();
72 dialog.modal('hide');
73 }
74 },
75 error: function (error) {
76 dialog.modal('hide');
77 bootbox.alert("An error occurred.");
78 }
79 });
80 }
81 })
82 }
83
84
85 var editorJSON;
86
87 $(document).ready(function () {
88
89 var json_editor_settings = {
90 mode: "javascript",
91 showCursorWhenSelecting: true,
92 autofocus: true,
93 lineNumbers: true,
94 lineWrapping: true,
95 foldGutter: true,
96 gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
97 autoCloseBrackets: true,
98 matchBrackets: true,
99 extraKeys: {
100 "F11": function (cm) {
101 cm.setOption("fullScreen", !cm.getOption("fullScreen"));
102 },
103 "Esc": function (cm) {
104 if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
105 },
106 "Ctrl-Q": function (cm) {
107 cm.foldCode(cm.getCursor());
108 }
109 },
110 theme: "neat",
111 keyMap: "sublime"
112 };
113 var myJsonTextArea = document.getElementById("k8sr_view_json");
114 editorJSON = CodeMirror(function (elt) {
115 myJsonTextArea.parentNode.replaceChild(elt, myJsonTextArea);
116 }, json_editor_settings);
117
118 $("#formCreatek8sr").submit(function (event) {
119 event.preventDefault(); //prevent default action
120 var post_url = $(this).attr("action"); //get form action url
121 var request_method = $(this).attr("method"); //get form GET/POST method
122 var form_data = new FormData(this); //Encode form elements for submission
123 $.ajax({
124 url: post_url,
125 type: request_method,
126 data: form_data,
127 headers: {
128 "Accept": 'application/json'
129 },
130 contentType: false,
131 processData: false
132 }).done(function (response, textStatus, jqXHR) {
133 table.ajax.reload();
134 $('#modal_new_k8sr').modal('hide');
135 }).fail(function (result) {
136 var data = result.responseJSON;
137 var title = "Error " + (data.code ? data.code : 'unknown');
138 var message = data.detail ? data.detail : 'No detail available.';
139 bootbox.alert({
140 title: title,
141 message: message
142 });
143 });
144 });
145
146 });