161cc51bcda803a1432ba6e7793968e260450a3d
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 deleteNs(url
) {
23 bootbox
.confirm("Are you sure want to delete?", function (result
) {
30 var addFormGroup = function (event
) {
31 event
.preventDefault();
33 var $formGroup
= $(this).closest('.form-group');
34 var $formGroupClone
= $formGroup
.clone();
37 .toggleClass('btn-success btn-add btn-danger btn-remove')
40 $formGroupClone
.find('input').val('');
41 $formGroupClone
.insertAfter($formGroup
);
45 var removeFormGroup = function (event
) {
46 event
.preventDefault();
47 var $formGroup
= $(this).closest('.form-group');
51 function showInstanceDetails(url_info
) {
52 var dialog
= bootbox
.dialog({
53 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
60 contentType
: "application/json;charset=utf-8",
61 success: function (result
) {
62 editorJSON
.setValue(JSON
.stringify(result
, null, "\t"));
63 editorJSON
.setOption("autoRefresh", true);
65 $('#modal_show_instance').modal('show');
67 error: function (result
) {
69 bootbox
.alert("An error occurred while retrieving the information for the NS");
76 $(document
).ready(function () {
77 var json_editor_settings
= {
79 showCursorWhenSelecting
: true,
84 gutters
: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
85 autoCloseBrackets
: true,
88 "F11": function (cm
) {
89 cm
.setOption("fullScreen", !cm
.getOption("fullScreen"));
91 "Esc": function (cm
) {
92 if (cm
.getOption("fullScreen")) cm
.setOption("fullScreen", false);
94 "Ctrl-Q": function (cm
) {
95 cm
.foldCode(cm
.getCursor());
101 var myJsonTextArea
= document
.getElementById("instance_view_json");
102 editorJSON
= CodeMirror(function (elt
) {
103 myJsonTextArea
.parentNode
.replaceChild(elt
, myJsonTextArea
);
104 }, json_editor_settings
);
107 $(document
).on('click', '.btn-add', addFormGroup
);
108 $(document
).on('click', '.btn-remove', removeFormGroup
);
110 $("#formActionNS").submit(function (event
) {
111 event
.preventDefault(); //prevent default action
112 var post_url
= $(this).attr("action"); //get form action url
113 var request_method
= $(this).attr("method"); //get form GET/POST method
114 var form_data
= new FormData(this); //Encode form elements for submission
115 console
.log(post_url
);
118 type
: request_method
,
121 "Accept": 'application/json'
125 }).done(function (response
,textStatus
, jqXHR
) {
126 $('#modal_instance_new_action').modal('hide');
127 }).fail(function(result
){
128 var data
= result
.responseJSON
;
129 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
130 var message
= data
.detail
? data
.detail
: 'No detail available.';