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(url
) {
18 $("#formActionNS").attr("action", url
);
19 $('#modal_instance_new_action').modal('show');
22 function exportMetricNs(url
) {
24 $("#formExportMetricNS").attr("action", url
);
25 $('#modal_instance_export_metric').modal('show');
28 function showInstanceTopology(url
) {
29 window
.location
.href
= url
;
32 function newAlarmNs(url
) {
33 $("#formAlarmNS").attr("action", url
);
34 $('#modal_instance_new_alarm').modal('show');
37 function deleteNs(url
, force
) {
38 bootbox
.confirm("Are you sure want to delete?", function (result
) {
41 url
= url
+ '?force=true';
47 var addFormGroup = function (event
) {
48 event
.preventDefault();
50 var $formGroup
= $(this).closest('.form-group');
51 var $formGroupClone
= $formGroup
.clone();
54 .toggleClass('btn-success btn-add btn-danger btn-remove')
57 $formGroupClone
.find('input').val('');
58 $formGroupClone
.insertAfter($formGroup
);
62 var removeFormGroup = function (event
) {
63 event
.preventDefault();
64 var $formGroup
= $(this).closest('.form-group');
68 function showInstanceDetails(url_info
) {
69 var dialog
= bootbox
.dialog({
70 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
77 contentType
: "application/json;charset=utf-8",
78 success: function (result
) {
80 if(result
['data'] !== undefined) {
81 editorJSON
.setValue(JSON
.stringify(result
['data'], null, "\t"));
82 editorJSON
.setOption("autoRefresh", true);
84 $('#modal_show_instance').modal('show');
88 bootbox
.alert("An error occurred while retrieving the information.");
91 error: function (result
) {
93 bootbox
.alert("An error occurred while retrieving the information.");
100 $(document
).ready(function () {
101 var json_editor_settings
= {
103 showCursorWhenSelecting
: true,
108 gutters
: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
109 autoCloseBrackets
: true,
112 "F11": function (cm
) {
113 cm
.setOption("fullScreen", !cm
.getOption("fullScreen"));
115 "Esc": function (cm
) {
116 if (cm
.getOption("fullScreen")) cm
.setOption("fullScreen", false);
118 "Ctrl-Q": function (cm
) {
119 cm
.foldCode(cm
.getCursor());
125 var myJsonTextArea
= document
.getElementById("instance_view_json");
126 editorJSON
= CodeMirror(function (elt
) {
127 myJsonTextArea
.parentNode
.replaceChild(elt
, myJsonTextArea
);
128 }, json_editor_settings
);
131 $(document
).on('click', '.btn-add', addFormGroup
);
132 $(document
).on('click', '.btn-remove', removeFormGroup
);
134 $("#formActionNS").submit(function (event
) {
135 event
.preventDefault(); //prevent default action
136 var post_url
= $(this).attr("action"); //get form action url
137 var request_method
= $(this).attr("method"); //get form GET/POST method
138 var form_data
= new FormData(this); //Encode form elements for submission
139 console
.log(post_url
);
142 type
: request_method
,
145 "Accept": 'application/json'
149 }).done(function (response
,textStatus
, jqXHR
) {
150 $('#modal_instance_new_action').modal('hide');
153 message
: "Action received."
155 }).fail(function(result
){
156 var data
= result
.responseJSON
;
157 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
158 var message
= data
.detail
? data
.detail
: 'No detail available.';
166 $("#formAlarmNS").submit(function (event
) {
167 event
.preventDefault(); //prevent default action
168 var post_url
= $(this).attr("action"); //get form action url
169 var request_method
= $(this).attr("method"); //get form GET/POST method
170 var form_data
= new FormData(this); //Encode form elements for submission
171 console
.log(post_url
);
174 type
: request_method
,
177 "Accept": 'application/json'
181 }).done(function (response
,textStatus
, jqXHR
) {
182 $('#modal_instance_new_action').modal('hide');
185 message
: "Alarm created."
187 }).fail(function(result
){
188 var data
= result
.responseJSON
;
189 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
190 var message
= data
.detail
? data
.detail
: 'No detail available.';
198 $("#formExportMetricNS").submit(function (event
) {
199 event
.preventDefault(); //prevent default action
200 var post_url
= $(this).attr("action"); //get form action url
201 var request_method
= $(this).attr("method"); //get form GET/POST method
202 var form_data
= new FormData(this); //Encode form elements for submission
203 console
.log(post_url
);
206 type
: request_method
,
209 "Accept": 'application/json'
213 }).done(function (response
,textStatus
, jqXHR
) {
214 $('#modal_instance_new_action').modal('hide');
217 message
: "Metric exported."
219 }).fail(function(result
){
220 var data
= result
.responseJSON
;
221 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
222 var message
= data
.detail
? data
.detail
: 'No detail available.';