deactivate nodes without sending a request

This commit is contained in:
Laura Klünder 2017-07-27 12:22:42 +02:00
parent 684450424a
commit 301a08b3db
3 changed files with 22 additions and 1 deletions

View file

@ -201,6 +201,8 @@ editor = {
editor._last_graph_path = null;
}
editor._deactivate_graph_node_on_click = (content.find('[data-deactivate-node-on-click]').length > 0);
var geometry_url = content.find('[data-geometry-url]');
var $body = $('body');
if (geometry_url.length) {
@ -292,6 +294,7 @@ editor = {
_active_graph_node: null,
_active_graph_node_space_transfer: null,
_active_graph_node_html: null,
_deactivate_graph_node_on_click: false,
init_geometries: function () {
// init geometries and edit listeners
editor._highlight_layer = L.layerGroup().addTo(editor.map);
@ -496,6 +499,7 @@ editor = {
},
pointToLayer: editor._point_to_layer
}).getLayers()[0].addTo(editor._highlight_layer);
node_layer.node_layer = layer;
node_layer.on('mouseover', editor._hover_graph_item)
.on('mouseout', editor._unhover_graph_item)
.on('click', editor._click_graph_node);
@ -616,6 +620,21 @@ editor = {
_click_graph_node: function(e) {
// click callback for a graph node
if (editor._loading_geometry) return;
if (editor._deactivate_graph_node_on_click && editor._active_graph_node === e.target.feature.properties.id) {
e.target.node_layer.setStyle({
stroke: false
});
e.target.setStyle({
opacity: 0,
});
var sidebar = $('#sidebar');
sidebar.find('[data-active-node]').remove();
sidebar.find('#id_active_node').val('');
editor._active_graph_node = null;
editor._active_graph_node_space_transfer = null;
editor._active_graph_node_html = null;
return;
}
$('#id_clicked_node').val(e.target.feature.properties.id).closest('form').submit();
editor.map.doubleClickZoom.disable();
},

View file

@ -40,7 +40,7 @@
<div data-active-node class="well well-sm"></div>
{% endif %}
<form action="{{ request.path }}" method="post" data-graph-editing="{{ graph_editing }}" data-nozoom>
<form action="{{ request.path }}" method="post" data-graph-editing="{{ graph_editing }}"{% if deactivate_node_on_click %} data-deactivate-node-on-click{% endif %} data-nozoom>
{% csrf_token %}
<h4>{% trans 'Default node properties' %}</h4>

View file

@ -501,6 +501,8 @@ def graph_edit(request, level=None, space=None):
'edge_settings_form': edge_settings_form,
'graph_action_form': graph_action_form,
'graph_editing': graph_editing,
'deactivate_node_on_click': graph_editing_settings['node_click'] in ('deactivate', 'toggle',
'connect_or_toggle'),
})
return render(request, 'editor/graph.html', ctx)