Make requests to create stairs

This commit is contained in:
Fabio Giovanazzi 2025-08-02 11:00:11 +02:00
parent e893e53151
commit e1fe06a1b1
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23
3 changed files with 51 additions and 16 deletions

View file

@ -501,6 +501,10 @@ editor = {
// listener for form submits in the sidebar.
e.preventDefault();
if (editor._loading_geometry || $(this).is('.creation-lock') || $(this).is('.scan-lock')) return;
if (editor._staircase_layer) {
editor._staircase_submit($(this))
return
}
var data = $(this).serialize();
var btn = $(this).data('btn');
if (btn !== undefined && btn !== null) {
@ -1906,12 +1910,12 @@ editor = {
},
_destroy_staircase_editing: function() {
if (editor._staircase_layer !== null) {
if (editor._staircase_layer) {
editor.map.removeLayer(editor._staircase_layer)
editor._staircase_layer = null
}
editor.map.off('editable:editing', editor._update_staircase_preview)
if (editor._current_editing_shape !== null) {
if (editor._current_editing_shape && editor._current_editing_shape.editor) {
editor._current_editing_shape.editor.cancelDrawing()
editor._current_editing_shape.remove()
editor._current_editing_shape = null
@ -1989,29 +1993,59 @@ editor = {
return lines
},
_update_staircase_preview: function(e = null) {
if (editor._current_editing_shape === null) {
return
_get_staircase_lines: function() {
if (!editor._current_editing_shape || !editor._current_editing_shape._parts) {
return []
}
points = editor._current_editing_shape._parts[0] || []
editor._staircase_layer.clearLayers()
//console.log(points)
if (points.length < 3) {
return
return []
}
xs = points.map(p => p.x)
ys = points.map(p => p.y)
lines = editor._transform_for_staircase(xs, ys, editor._staircase_steps_count)
lines = lines.map(l => [
editor.map.layerPointToLatLng([l.p1.x, l.p1.y]),
editor.map.layerPointToLatLng([l.p2.x, l.p2.y]),
])
return lines
},
_update_staircase_preview: function(e = null) {
if (editor._staircase_layer) {
editor._staircase_layer.clearLayers()
}
lines = editor._get_staircase_lines()
lines.forEach(l => {
L.polyline(
[
editor.map.layerPointToLatLng([l.p1.x, l.p1.y]),
editor.map.layerPointToLatLng([l.p2.x, l.p2.y]),
],
{color: "red"}
).addTo(editor._staircase_layer);
L.polyline(l, {color: "red"}).addTo(editor._staircase_layer);
})
},
_staircase_submit: function(form) {
csrfmiddlewaretoken = form.find('input[name=csrfmiddlewaretoken]').attr('value')
import_tag = form.find('input[name=import_tag]').val()
space = form.attr('space')
lines = editor._get_staircase_lines()
console.log("hereeeeeee", csrfmiddlewaretoken, import_tag, space, lines)
Promise.all(lines.map(l =>
fetch("/editor/spaces/" + space + "/stairs/create", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
},
body: "csrfmiddlewaretoken=" + encodeURIComponent(csrfmiddlewaretoken) +
"&geometry=" + encodeURIComponent(JSON.stringify({
type: "LineString",
coordinates: [[l[0]["lng"], l[0]["lat"]], [l[1]["lng"], l[1]["lat"]]]
})) +
"&import_tag=" + encodeURIComponent(import_tag)
})
)).then(() => {
form.remove()
window.location.href = "/editor/spaces/" + space + "/stairs"
})
}
};

View file

@ -8,7 +8,7 @@
</h3>
{% bootstrap_messages %}
<form {% if nozoom %}data-nozoom {% endif %}data-onbeforeunload data-new="staircase" data-geomtype="polygon" {% if access_restriction_select %} data-access-restriction-select{% endif %}>
<form space="{{ space }}" {% if nozoom %}data-nozoom {% endif %}data-onbeforeunload data-new="staircase" data-geomtype="polygon" {% if access_restriction_select %} data-access-restriction-select{% endif %}>
{% csrf_token %}
{% bootstrap_form form %}
<div class="form-group">

View file

@ -412,6 +412,7 @@ def edit(request, pk=None, model=None, level=None, space=None, on_top_of=None, e
})
if request.path.endswith("staircase"):
ctx["space"] = space_id
return render(request, 'editor/create_staircase.html', ctx)
else:
return render(request, 'editor/edit.html', ctx)