automatic reload on lists; new django decorator for ajax request
[osm/LW-UI.git] / static / src / instancehandler / instance_operations_list.js
1 /*
2 Copyright 2018 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
3
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
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
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.
15 */
16
17
18 function showOperationDetails(instance_id, operation_id) {
19 var url_info = '/instances/ns/'+instance_id+'/operation/' + operation_id;
20 var dialog = bootbox.dialog({
21 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
22 closeButton: true
23 });
24 $.ajax({
25 url: url_info,
26 type: 'GET',
27 dataType: "json",
28 contentType: "application/json;charset=utf-8",
29 success: function (result) {
30 editorJSON.setValue(JSON.stringify(result, null, "\t"));
31 editorJSON.setOption("autoRefresh", true);
32 dialog.modal('hide');
33 $('#modal_show_operation').modal('show');
34 },
35 error: function (result) {
36 dialog.modal('hide');
37 bootbox.alert("An error occurred while retrieving the information for the NS");
38 }
39 });
40 }
41
42 var editorJSON;
43
44 $(document).ready(function () {
45 var json_editor_settings = {
46 mode: "javascript",
47 showCursorWhenSelecting: true,
48 autofocus: true,
49 lineNumbers: true,
50 lineWrapping: true,
51 foldGutter: true,
52 gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
53 autoCloseBrackets: true,
54 matchBrackets: true,
55 extraKeys: {
56 "F11": function (cm) {
57 cm.setOption("fullScreen", !cm.getOption("fullScreen"));
58 },
59 "Esc": function (cm) {
60 if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
61 },
62 "Ctrl-Q": function (cm) {
63 cm.foldCode(cm.getCursor());
64 }
65 },
66 theme: "neat",
67 keyMap: "sublime"
68 };
69 var myJsonTextArea = document.getElementById("operation_view_json");
70 editorJSON = CodeMirror(function (elt) {
71 myJsonTextArea.parentNode.replaceChild(elt, myJsonTextArea);
72 }, json_editor_settings);
73
74
75 });