Add "location" support (embed a tag with a Place object)

This commit is contained in:
Thomas Sileo
2019-10-27 19:05:42 +01:00
parent cf983ca9f3
commit e611d61739
4 changed files with 93 additions and 1 deletions

View File

@@ -49,6 +49,15 @@
<input type="text" name="file_description" placeholder="attachment description (optional)">
</p>
<p>
<input type="text" name="location_lat" id="location_lat" placeholder="latitude (optional)">
<input type="text" name="location_lng" id="location_lng" placeholder="longitude (optional)">
<a href="#" class="location_autofill">ask browser for location</a>
</p>
<p>
<input type="text" name="location_name" placeholder="location name (optional)">
</p>
{% if request.args.get("question") == "1" %}
<div style="margin-top:20px;">
<p>Open for: <select name="open_for">
@@ -114,4 +123,16 @@ var items = document.getElementsByClassName("ji")
for (var i = 0; i < items.length; i++) {
items[i].addEventListener('click', ji);
}
var askForLocation = function(ev) {
ev.preventDefault();
navigator.geolocation.getCurrentPosition(function(position) {
document.getElementById("location_lat").value = position.coords.latitude;
document.getElementById("location_lng").value = position.coords.longitude;
});
}
var items = document.getElementsByClassName("location_autofill")
for (var i = 0; i < items.length; i++) {
items[i].addEventListener('click', askForLocation);
}
</script>{% endblock %}

View File

@@ -208,6 +208,11 @@
{% else %}
{{ obj.content | clean | replace_custom_emojis(obj) | code_highlight | safe }}
{% endif %}
{% if obj | has_place %}
<p>Location: {{ obj | get_place | safe }}</p>
{% endif %}
</div>
{% if obj.attachment and obj | has_type('Note') %}