2 Copyright 2018 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
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 performAction(instance_name
, instance_id
) {
18 var url
= '/instances/ns/'+instance_id
+'/action';
19 $("#formActionNS").attr("action", url
);
20 $('#modal_instance_new_action').modal('show');
23 function exportMetricNs(instance_name
, instance_id
) {
24 var url
= '/instances/ns/'+instance_id
+'/monitoring/metric';
25 $("#formExportMetricNS").attr("action", url
);
26 $('#modal_instance_export_metric').modal('show');
29 function newAlarmNs(instance_name
, instance_id
) {
30 var url
= '/instances/ns/'+instance_id
+'/monitoring/alarm';
31 $("#formAlarmNS").attr("action", url
);
32 $('#modal_instance_new_alarm').modal('show');
35 function deleteNs(instance_name
, instance_id
, force
) {
36 var url
= '/instances/ns/'+instance_id
+'/delete';
37 bootbox
.confirm("Are you sure want to delete " + instance_name
+ "?", function (result
) {
40 url
= url
+ '?force=true';
41 var dialog
= bootbox
.dialog({
42 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
49 contentType
: "application/json;charset=utf-8",
50 success: function (result
) {
51 if (result
['error'] == true){
53 bootbox
.alert("An error occurred.");
60 error: function (error
) {
62 bootbox
.alert("An error occurred.");
69 var addFormGroup = function (event
) {
70 event
.preventDefault();
72 var $formGroup
= $(this).closest('.form-group');
73 var $formGroupClone
= $formGroup
.clone();
76 .toggleClass('btn-success btn-add btn-danger btn-remove')
79 $formGroupClone
.find('input').val('');
80 $formGroupClone
.insertAfter($formGroup
);
84 var removeFormGroup = function (event
) {
85 event
.preventDefault();
86 var $formGroup
= $(this).closest('.form-group');
90 function showInstanceDetails(type
, instance_id
) {
91 var url_info
= '/instances/'+type
+'/'+instance_id
;
92 var dialog
= bootbox
.dialog({
93 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
100 contentType
: "application/json;charset=utf-8",
101 success: function (result
) {
103 if (result
['data'] !== undefined) {
104 editorJSON
.setValue(JSON
.stringify(result
['data'], null, "\t"));
105 editorJSON
.setOption("autoRefresh", true);
106 dialog
.modal('hide');
107 $('#modal_show_instance').modal('show');
110 dialog
.modal('hide');
111 bootbox
.alert("An error occurred while retrieving the information.");
114 error: function (result
) {
115 dialog
.modal('hide');
116 bootbox
.alert("An error occurred while retrieving the information.");
123 $(document
).ready(function () {
124 var json_editor_settings
= {
126 showCursorWhenSelecting
: true,
131 gutters
: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
132 autoCloseBrackets
: true,
135 "F11": function (cm
) {
136 cm
.setOption("fullScreen", !cm
.getOption("fullScreen"));
138 "Esc": function (cm
) {
139 if (cm
.getOption("fullScreen")) cm
.setOption("fullScreen", false);
141 "Ctrl-Q": function (cm
) {
142 cm
.foldCode(cm
.getCursor());
148 var myJsonTextArea
= document
.getElementById("instance_view_json");
149 editorJSON
= CodeMirror(function (elt
) {
150 myJsonTextArea
.parentNode
.replaceChild(elt
, myJsonTextArea
);
151 }, json_editor_settings
);
154 $(document
).on('click', '.btn-add', addFormGroup
);
155 $(document
).on('click', '.btn-remove', removeFormGroup
);
157 $("#formActionNS").submit(function (event
) {
158 event
.preventDefault(); //prevent default action
159 var post_url
= $(this).attr("action"); //get form action url
160 var request_method
= $(this).attr("method"); //get form GET/POST method
161 var form_data
= new FormData(this); //Encode form elements for submission
162 console
.log(post_url
);
165 type
: request_method
,
168 "Accept": 'application/json'
172 }).done(function (response
, textStatus
, jqXHR
) {
173 $('#modal_instance_new_action').modal('hide');
176 message
: "Action received."
178 }).fail(function (result
) {
179 var data
= result
.responseJSON
;
180 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
181 var message
= data
.detail
? data
.detail
: 'No detail available.';
189 $("#formAlarmNS").submit(function (event
) {
190 event
.preventDefault(); //prevent default action
191 var post_url
= $(this).attr("action"); //get form action url
192 var request_method
= $(this).attr("method"); //get form GET/POST method
193 var form_data
= new FormData(this); //Encode form elements for submission
194 console
.log(post_url
);
197 type
: request_method
,
200 "Accept": 'application/json'
204 }).done(function (response
, textStatus
, jqXHR
) {
205 $('#modal_instance_new_action').modal('hide');
208 message
: "Alarm created."
210 }).fail(function (result
) {
211 var data
= result
.responseJSON
;
212 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
213 var message
= data
.detail
? data
.detail
: 'No detail available.';
221 $("#formExportMetricNS").submit(function (event
) {
222 event
.preventDefault(); //prevent default action
223 var post_url
= $(this).attr("action"); //get form action url
224 var request_method
= $(this).attr("method"); //get form GET/POST method
225 var form_data
= new FormData(this); //Encode form elements for submission
226 console
.log(post_url
);
229 type
: request_method
,
232 "Accept": 'application/json'
236 }).done(function (response
, textStatus
, jqXHR
) {
237 $('#modal_instance_new_action').modal('hide');
240 message
: "Metric exported."
242 }).fail(function (result
) {
243 var data
= result
.responseJSON
;
244 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
245 var message
= data
.detail
? data
.detail
: 'No detail available.';