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 newAlarmNs(url
) {
29 $("#formAlarmNS").attr("action", url
);
30 $('#modal_instance_new_alarm').modal('show');
33 function deleteNs(url
, force
) {
34 bootbox
.confirm("Are you sure want to delete?", function (result
) {
37 url
= url
+ '?force=true';
43 var addFormGroup = function (event
) {
44 event
.preventDefault();
46 var $formGroup
= $(this).closest('.form-group');
47 var $formGroupClone
= $formGroup
.clone();
50 .toggleClass('btn-success btn-add btn-danger btn-remove')
53 $formGroupClone
.find('input').val('');
54 $formGroupClone
.insertAfter($formGroup
);
58 var removeFormGroup = function (event
) {
59 event
.preventDefault();
60 var $formGroup
= $(this).closest('.form-group');
64 function showInstanceDetails(url_info
) {
65 var dialog
= bootbox
.dialog({
66 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
73 contentType
: "application/json;charset=utf-8",
74 success: function (result
) {
75 editorJSON
.setValue(JSON
.stringify(result
, null, "\t"));
76 editorJSON
.setOption("autoRefresh", true);
78 $('#modal_show_instance').modal('show');
80 error: function (result
) {
82 bootbox
.alert("An error occurred while retrieving the information.");
89 $(document
).ready(function () {
90 var json_editor_settings
= {
92 showCursorWhenSelecting
: true,
97 gutters
: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
98 autoCloseBrackets
: true,
101 "F11": function (cm
) {
102 cm
.setOption("fullScreen", !cm
.getOption("fullScreen"));
104 "Esc": function (cm
) {
105 if (cm
.getOption("fullScreen")) cm
.setOption("fullScreen", false);
107 "Ctrl-Q": function (cm
) {
108 cm
.foldCode(cm
.getCursor());
114 var myJsonTextArea
= document
.getElementById("instance_view_json");
115 editorJSON
= CodeMirror(function (elt
) {
116 myJsonTextArea
.parentNode
.replaceChild(elt
, myJsonTextArea
);
117 }, json_editor_settings
);
120 $(document
).on('click', '.btn-add', addFormGroup
);
121 $(document
).on('click', '.btn-remove', removeFormGroup
);
123 $("#formActionNS").submit(function (event
) {
124 event
.preventDefault(); //prevent default action
125 var post_url
= $(this).attr("action"); //get form action url
126 var request_method
= $(this).attr("method"); //get form GET/POST method
127 var form_data
= new FormData(this); //Encode form elements for submission
128 console
.log(post_url
);
131 type
: request_method
,
134 "Accept": 'application/json'
138 }).done(function (response
,textStatus
, jqXHR
) {
139 $('#modal_instance_new_action').modal('hide');
142 message
: "Action received."
144 }).fail(function(result
){
145 var data
= result
.responseJSON
;
146 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
147 var message
= data
.detail
? data
.detail
: 'No detail available.';
155 $("#formAlarmNS").submit(function (event
) {
156 event
.preventDefault(); //prevent default action
157 var post_url
= $(this).attr("action"); //get form action url
158 var request_method
= $(this).attr("method"); //get form GET/POST method
159 var form_data
= new FormData(this); //Encode form elements for submission
160 console
.log(post_url
);
163 type
: request_method
,
166 "Accept": 'application/json'
170 }).done(function (response
,textStatus
, jqXHR
) {
171 $('#modal_instance_new_action').modal('hide');
174 message
: "Alarm created."
176 }).fail(function(result
){
177 var data
= result
.responseJSON
;
178 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
179 var message
= data
.detail
? data
.detail
: 'No detail available.';
187 $("#formExportMetricNS").submit(function (event
) {
188 event
.preventDefault(); //prevent default action
189 var post_url
= $(this).attr("action"); //get form action url
190 var request_method
= $(this).attr("method"); //get form GET/POST method
191 var form_data
= new FormData(this); //Encode form elements for submission
192 console
.log(post_url
);
195 type
: request_method
,
198 "Accept": 'application/json'
202 }).done(function (response
,textStatus
, jqXHR
) {
203 $('#modal_instance_new_action').modal('hide');
206 message
: "Metric exported."
208 }).fail(function(result
){
209 var data
= result
.responseJSON
;
210 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
211 var message
= data
.detail
? data
.detail
: 'No detail available.';