blob: 0e1285dcd0483e2ac0da6c2248e753dda9cfe82a [file] [log] [blame]
lombardofr93770e22019-08-30 19:37:56 +02001<!--
2Copyright 2019 EveryUP srl
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15-->
16
lombardofr3218b2b2018-10-29 13:41:08 +010017{% extends "descriptor_view_base.html" %}
lombardoffb37bca2018-05-03 16:20:04 +020018
19{% load staticfiles %}
20
21
22{% block title_header_big %}
23{{ block.super }}
24Edit {{ descriptor_type|upper }} Descriptor
25{% endblock %}
26
27
28{% block left_sidebar %}
29{% include 'osm/osm_project_left_sidebar.html' %}
30{% endblock %}
31
32{% block breadcrumb_body %}
33{{ block.super }}
lombardofre5a130a2019-07-15 09:17:59 +020034{% if user.is_admin %}
35 <li><a href="{% url 'projects:projects_list' %}">Projects</a></li>
36{% else%}
37 <li><a href="#">Projects</a></li>
38{% endif %}
39<li><a href="{% url 'projects:open_project' %}">{{project_name}}</a></li>
lombardoffb37bca2018-05-03 16:20:04 +020040<li><a>{{descriptor_id}}</a></li>
41{% endblock %}
42
43{% block tab_pane_button_list %}
44{{ block.super }}
45<li class="active" id="yaml_li"><a href="#yaml" data-toggle="tab"><i class="fa fa-file-code-o"></i> YAML</a></li>
46<li id="json_li"><a href="#json" data-toggle="tab"><i class="fa fa-file-code-o"></i> JSON</a></li>
47{% endblock %}
48
49{% block nav_buttons_list %}
50 {{ block.super }}
51 <li class="pull-right"><button id="save" type="button" class="btn btn-block btn-primary btn-sm" onclick="update(this.id)" ><i class="fa fa-save"></i> Update</button></li>
lombardofr36e3ddd2018-11-30 10:15:11 +010052 <li class="pull-right"><button id="save_show_graph" type="button" class="btn btn-block btn-primary btn-sm" onclick="update(this.id, 'true')"><i class="fa fa-save"></i> Update and Show Graph</button></li>
53 <li class="pull-right"><button type="button" class="btn btn-block btn-primary btn-sm" onclick="goToGraph()"><i class="fa fa-sitemap"></i> Show Graph</button></li>
lombardofr1bd6a672018-09-13 11:51:01 +020054
lombardoffb37bca2018-05-03 16:20:04 +020055{% endblock %}
56
57{% block tab_pane_list %}
58{{ block.super }}
59
60<!-- /.tab-pane -->
61<div class="active tab-pane" id="yaml">
62 <textarea id="code_editor_yaml">
63 </textarea>
64</div>
65<!-- /.tab-pane-->
66
67<div class="tab-pane" id="json">
68 <textarea id="code_editor_json">
69 </textarea>
70</div>
71
72{% endblock %}
73
74{% block resource_block %}
75{{ block.super }}
76
77
78<script>
79 var editorJSON;
80 var editorYaml;
81
82 $(document).ready(function () {
83 //var cmjsoneditor = CodeMirror.fromTextArea(document.getElementById("code_editor"), json_editor_settings);
84 var myJsonTextArea = document.getElementById("code_editor_json");
85 editorJSON = CodeMirror(function (elt) {
86 myJsonTextArea.parentNode.replaceChild(elt, myJsonTextArea);
87 }, json_editor_settings);
lombardoffb37bca2018-05-03 16:20:04 +020088 editorJSON.setValue(JSON.stringify({{descriptor_strings.descriptor_string_json | safe}}, null, "\t"));
89 editorJSON.setOption("autoRefresh", true);
lombardofra74cd442018-08-23 09:24:32 +020090 editorJSON.setSize("auto", "auto");
91
lombardoffb37bca2018-05-03 16:20:04 +020092 var myYamlTextArea = document.getElementById("code_editor_yaml");
93 editorYaml = CodeMirror(function (elt) {
94 myYamlTextArea.parentNode.replaceChild(elt, myYamlTextArea);
95 }, yaml_editor_settings);
96 var des_strings = {{descriptor_strings | safe}};
97 editorYaml.setValue(des_strings.descriptor_string_yaml);
lombardofra74cd442018-08-23 09:24:32 +020098 editorYaml.setSize("auto", "auto");
lombardoffb37bca2018-05-03 16:20:04 +020099 });
100
101
lombardofr36e3ddd2018-11-30 10:15:11 +0100102 function update(e, show_graph) {
lombardoffb37bca2018-05-03 16:20:04 +0200103 var dialog = bootbox.dialog({
104 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
105 closeButton: false
106 });
107
108 var id = $('.nav-tabs .active').attr('id');
109 var type, text;
110 switch (id) {
111 case 'yaml_li':
112 type = 'yaml';
113 text = editorYaml.getValue();
114 break;
115 case 'json_li':
116 type = 'json';
117 text = editorJSON.getValue();
118 break;
119 }
120 $.ajax({
lombardofr99f922f2018-07-17 17:27:36 +0200121 url: "/projects/descriptors/{{descriptor_type}}/{{descriptor_id}}/",
lombardoffb37bca2018-05-03 16:20:04 +0200122 type: 'POST',
123 dataType: 'json',
124 data: {
125 'csrfmiddlewaretoken': '{{csrf_token}}',
126 'type': type,
127 'text': text
128 },
129 success: function (result) {
lombardofr36e3ddd2018-11-30 10:15:11 +0100130 if(show_graph){
131 goToGraph();
132 }
lombardoffb37bca2018-05-03 16:20:04 +0200133 dialog.modal('hide');
lombardofr1bd6a672018-09-13 11:51:01 +0200134 $("#success-alert").fadeTo(2000, 500).slideDown(500, function(){
135 setTimeout(function () {
136 $("#success-alert").slideUp(500);
137 }, 2000);
lombardoffb37bca2018-05-03 16:20:04 +0200138
lombardofr1bd6a672018-09-13 11:51:01 +0200139 });
lombardoffb37bca2018-05-03 16:20:04 +0200140 },
141 error: function (result) {
lombardoffb37bca2018-05-03 16:20:04 +0200142 dialog.modal('hide');
lombardofr36e3ddd2018-11-30 10:15:11 +0100143 var data = result.responseJSON;
144 var title = "Error " + (data && data.code ? data.code : 'unknown');
145 var message = data && data.detail ? data.detail : 'No detail available.';
146 bootbox.alert({
147 title: title,
148 message: message
149 });
lombardoffb37bca2018-05-03 16:20:04 +0200150 }
151 });
152 }
153
154</script>
155{% endblock %}
156
157
158{% block footer %}
lombardofr3218b2b2018-10-29 13:41:08 +0100159 {% include "footer.html" %}
lombardoffb37bca2018-05-03 16:20:04 +0200160{% endblock %}