2 Copyright 2019 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.
17 function openModalRegisterK8s(args
) {
18 // load vim account list
19 select2_groups
= $('#k8sc_vim_account').select2({
20 placeholder
: 'Select VIM',
23 url
: args
.vim_list_url
,
25 processResults: function (data
) {
27 if (data
['datacenters']) {
28 for (d
in data
['datacenters']) {
29 var datacenter
= data
['datacenters'][d
];
30 vims
.push({ id
: datacenter
['_id'], text
: datacenter
['name'] })
42 $('#modal_new_k8sc').modal('show');
45 function showK8sc(k8sc_id
, k8sc_name
) {
46 var url_info
= '/k8scluster/' + k8sc_id
;
47 var dialog
= bootbox
.dialog({
48 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
55 contentType
: "application/json;charset=utf-8",
56 success: function (result
) {
58 if (result
['data'] !== undefined) {
59 editorJSON
.setValue(JSON
.stringify(result
['data'], null, "\t"));
60 editorJSON
.setOption("autoRefresh", true);
62 $('#modal_show_k8sc').modal('show');
66 bootbox
.alert("An error occurred while retrieving the information.");
69 error: function (result
) {
71 bootbox
.alert("An error occurred while retrieving the information.");
76 function deleteK8sc(k8sc_id
, k8sc_name
) {
77 var url
= "/k8scluster/"+k8sc_id
+"/delete";
78 bootbox
.confirm("Are you sure want to delete " + k8sc_name
+ "?", function (result
) {
80 var dialog
= bootbox
.dialog({
81 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
88 contentType
: "application/json;charset=utf-8",
89 success: function (result
) {
90 if (result
['error'] == true) {
92 bootbox
.alert("An error occurred.");
99 error: function (error
) {
100 dialog
.modal('hide');
101 bootbox
.alert("An error occurred.");
110 $(document
).ready(function () {
112 var json_editor_settings
= {
114 showCursorWhenSelecting
: true,
119 gutters
: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
120 autoCloseBrackets
: true,
123 "F11": function (cm
) {
124 cm
.setOption("fullScreen", !cm
.getOption("fullScreen"));
126 "Esc": function (cm
) {
127 if (cm
.getOption("fullScreen")) cm
.setOption("fullScreen", false);
129 "Ctrl-Q": function (cm
) {
130 cm
.foldCode(cm
.getCursor());
136 var myJsonTextArea
= document
.getElementById("k8sc_view_json");
137 editorJSON
= CodeMirror(function (elt
) {
138 myJsonTextArea
.parentNode
.replaceChild(elt
, myJsonTextArea
);
139 }, json_editor_settings
);
141 $("#formCreatek8sc").submit(function (event
) {
142 event
.preventDefault(); //prevent default action
143 var post_url
= $(this).attr("action"); //get form action url
144 var request_method
= $(this).attr("method"); //get form GET/POST method
145 var form_data
= new FormData(this); //Encode form elements for submission
148 type
: request_method
,
151 "Accept": 'application/json'
155 }).done(function (response
, textStatus
, jqXHR
) {
157 $('#modal_new_k8sc').modal('hide');
158 }).fail(function (result
) {
159 var data
= result
.responseJSON
;
160 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
161 var message
= data
.detail
? data
.detail
: 'No detail available.';