2 Copyright 2019 EveryUP srl
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 {% extends
"descriptor_view_base.html" %}
19 {% load staticfiles %}
22 {% block title_header_big %}
24 Edit {{ descriptor_type|upper }} Descriptor
28 {% block left_sidebar %}
29 {% include 'osm/osm_project_left_sidebar.html' %}
32 {% block breadcrumb_body %}
34 {% if user.is_admin %}
35 <li><a href=
"{% url 'projects:projects_list' %}">Projects
</a></li>
37 <li><a href=
"#">Projects
</a></li>
39 <li><a href=
"{% url 'projects:open_project' %}">{{project_name}}
</a></li>
40 <li><a>{{descriptor_id}}
</a></li>
43 {% block tab_pane_button_list %}
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>
49 {% block nav_buttons_list %}
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>
52 <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>
57 {% block tab_pane_list %}
61 <div class=
"active tab-pane" id=
"yaml">
62 <textarea id=
"code_editor_yaml">
67 <div class=
"tab-pane" id=
"json">
68 <textarea id=
"code_editor_json">
74 {% block resource_block %}
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);
88 editorJSON.setValue(JSON.stringify({{descriptor_strings.descriptor_string_json | safe}}, null,
"\t"));
89 editorJSON.setOption(
"autoRefresh", true);
90 editorJSON.setSize(
"auto",
"auto");
92 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);
98 editorYaml.setSize(
"auto",
"auto");
102 function update(e, show_graph) {
103 var dialog = bootbox.dialog({
104 message: '
<div class=
"text-center"><i class=
"fa fa-spin fa-spinner"></i> Loading...
</div>',
108 var id = $('.nav-tabs .active').attr('id');
113 text = editorYaml.getValue();
117 text = editorJSON.getValue();
121 url:
"/projects/descriptors/{{descriptor_type}}/{{descriptor_id}}/",
125 'csrfmiddlewaretoken': '{{csrf_token}}',
129 success: function (result) {
133 dialog.modal('hide');
134 $(
"#success-alert").fadeTo(
2000,
500).slideDown(
500, function(){
135 setTimeout(function () {
136 $(
"#success-alert").slideUp(
500);
141 error: function (result) {
142 dialog.modal('hide');
143 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.';
159 {% include
"footer.html" %}