refactor: update template to allow changing preference settings for gps.

This commit is contained in:
kdeterme 2026-08-05 15:44:39 +02:00
parent abfd9c3efd
commit 72ff9852bd
3 changed files with 119 additions and 32 deletions

View file

@ -7,6 +7,13 @@
let activeGpsLat = null;
let activeGpsLon = null;
const PROVIDER_NAMES = {
'google': 'Google Maps',
'waze': 'Waze',
'apple': 'Apple Maps',
'geo': 'App système par défaut'
};
/**
* Ouvre le modal de sélection GPS ou lance le GPS préféré s'il est enregistré.
* @param {number|string} lat Latitude
@ -53,9 +60,17 @@
}
}
const savedPrefInfo = document.getElementById('gpsSavedPrefInfo');
const savedPrefName = document.getElementById('gpsSavedPrefName');
const rememberCheckbox = document.getElementById('gpsRememberChoice');
if (rememberCheckbox) {
rememberCheckbox.checked = !!preferredProvider;
if (preferredProvider) {
if (savedPrefInfo) savedPrefInfo.classList.remove('d-none');
if (savedPrefName) savedPrefName.textContent = PROVIDER_NAMES[preferredProvider] || preferredProvider;
if (rememberCheckbox) rememberCheckbox.checked = true;
} else {
if (savedPrefInfo) savedPrefInfo.classList.add('d-none');
if (rememberCheckbox) rememberCheckbox.checked = false;
}
const bsModal = bootstrap.Modal.getOrCreateInstance(modalEl);
@ -118,8 +133,60 @@
*/
function resetGpsPreference() {
localStorage.removeItem('streetup_preferred_gps');
const rememberCheckbox = document.getElementById('gpsRememberChoice');
if (rememberCheckbox) rememberCheckbox.checked = false;
const savedPrefInfo = document.getElementById('gpsSavedPrefInfo');
if (savedPrefInfo) savedPrefInfo.classList.add('d-none');
}
/**
* Gestionnaire d'appui long (Long Press) sur les boutons GPS
*/
document.addEventListener('DOMContentLoaded', function() {
let longPressTimer = null;
document.addEventListener('touchstart', function(e) {
const target = e.target.closest('[onclick*="openGpsNavigation"]');
if (!target) return;
longPressTimer = setTimeout(function() {
// Déclencher le modal forcé lors de l'appui long
const onclickAttr = target.getAttribute('onclick');
const matches = onclickAttr ? onclickAttr.match(/openGpsNavigation\s*\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]*)['"])?/) : null;
if (matches) {
const lat = matches[1];
const lon = matches[2];
const label = matches[3] || '';
openGpsNavigation(lat, lon, label, true, e);
}
}, 500);
}, { passive: false });
document.addEventListener('touchend', function() {
if (longPressTimer) clearTimeout(longPressTimer);
});
document.addEventListener('touchmove', function() {
if (longPressTimer) clearTimeout(longPressTimer);
});
// Permettre également le clic droit (contextmenu) pour forcer le modal sur desktop/simulateur
document.addEventListener('contextmenu', function(e) {
const target = e.target.closest('[onclick*="openGpsNavigation"]');
if (target) {
const onclickAttr = target.getAttribute('onclick');
const matches = onclickAttr ? onclickAttr.match(/openGpsNavigation\s*\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]*)['"])?/) : null;
if (matches) {
const lat = matches[1];
const lon = matches[2];
const label = matches[3] || '';
openGpsNavigation(lat, lon, label, true, e);
}
}
});
});
// Exposer les fonctions globalement
window.openGpsNavigation = openGpsNavigation;
window.launchGpsProvider = launchGpsProvider;

View file

@ -12,6 +12,18 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{% translate 'Fermer' %}"></button>
</div>
<div class="modal-body pt-2 pb-3">
<!-- Info sur la préférence enregistrée si elle existe -->
<div id="gpsSavedPrefInfo" class="alert alert-light border py-1.5 px-2.5 small mb-3 d-none d-flex justify-content-between align-items-center rounded-3">
<span class="text-secondary small">
<i class="bi bi-check-circle-fill text-success me-1"></i>
{% translate "Favori :" %} <strong id="gpsSavedPrefName" class="text-dark"></strong>
</span>
<button type="button" class="btn btn-link text-danger p-0 ms-2 text-decoration-none small" onclick="resetGpsPreference()" title="{% translate 'Effacer mon choix automatique' %}">
<i class="bi bi-trash me-1"></i>{% translate "Effacer" %}
</button>
</div>
<p class="text-muted small mb-3" id="gpsModalDestinationLabel">
{% translate "Choisissez votre application de navigation :" %}
</p>

View file

@ -471,7 +471,7 @@
</div>
{% endif %}
<div class="d-flex justify-content-between align-items-center mb-2">
<div class="d-flex justify-content-between align-items-center mb-2 flex-wrap gap-2">
<div class="code d-flex align-items-center gap-2">
<span><i class="bi bi-tools"></i> {{ intervention.code }}</span>
<button id="subscription-btn"
@ -484,20 +484,38 @@
<span id="subscription-text">{% if is_subscribed %}{% translate "Suivi" %}{% else %}{% translate "Suivre" %}{% endif %}</span>
</button>
</div>
<div class="text-end">
{% if intervention.contract and intervention.contract.uses_intervention_manager %}
<div class="text-muted small mb-1">
<i class="bi bi-person-badge me-1"></i>{% translate "Gestionnaire :" %}
{% if intervention.intervention_manager %}
{{ intervention.intervention_manager.get_full_name|default:intervention.intervention_manager.username }}
{% else %}
{% translate "Aucun" %}
{% endif %}
<div class="text-end d-flex align-items-center gap-2">
{% if intervention.lat and intervention.lon %}
<div class="btn-group shadow-sm rounded-pill" role="group" aria-label="{% translate 'Navigation GPS' %}">
<button type="button"
class="btn btn-outline-primary btn-sm rounded-start-pill fw-semibold px-2.5 py-1 d-inline-flex align-items-center gap-1.5"
onclick="openGpsNavigation('{{ intervention.lat|stringformat:'f' }}', '{{ intervention.lon|stringformat:'f' }}', '{{ intervention.code|escapejs }}', false, event)">
<i class="bi bi-sign-turn-right-fill text-primary"></i>
<span>{% translate "Itinéraire GPS" %}</span>
</button>
<button type="button"
class="btn btn-outline-primary btn-sm rounded-end-pill px-2 py-1"
onclick="openGpsNavigation('{{ intervention.lat|stringformat:'f' }}', '{{ intervention.lon|stringformat:'f' }}', '{{ intervention.code|escapejs }}', true, event)"
title="{% translate "Changer d'application GPS" %}">
<i class="bi bi-gear-fill small"></i>
</button>
</div>
{% endif %}
{% if intervention.assigned_member %}
<div class="text-muted small"><i class="bi bi-person-fill me-1"></i>{{ intervention.assigned_member.name }}</div>
{% endif %}
<div>
{% if intervention.contract and intervention.contract.uses_intervention_manager %}
<div class="text-muted small mb-1">
<i class="bi bi-person-badge me-1"></i>{% translate "Gestionnaire :" %}
{% if intervention.intervention_manager %}
{{ intervention.intervention_manager.get_full_name|default:intervention.intervention_manager.username }}
{% else %}
{% translate "Aucun" %}
{% endif %}
</div>
{% endif %}
{% if intervention.assigned_member %}
<div class="text-muted small"><i class="bi bi-person-fill me-1"></i>{{ intervention.assigned_member.name }}</div>
{% endif %}
</div>
</div>
</div>
<div class="code mb-3">{{ intervention.title }}</div>
@ -506,23 +524,13 @@
<p class="mb-1 text-muted">
<i class="bi bi-calendar-event"></i> {{ intervention.planned_begin_time|date:"d/m/Y H:i"|default:"/" }}
</p>
<p class="mb-3 text-muted d-flex justify-content-between align-items-center flex-wrap gap-2">
<span>
<i class="bi bi-gear
{% if intervention.maintain_type == 'corrective' %}text-danger
{% elif intervention.maintain_type == 'preventive' %}text-warning
{% elif intervention.maintain_type == 'ameliorative' %}text-success
{% endif %}"
></i> {{ intervention.get_maintain_type_display }}
</span>
{% if intervention.lat and intervention.lon %}
<button type="button"
class="btn btn-outline-primary btn-sm rounded-pill fw-semibold px-3 py-1 d-inline-flex align-items-center gap-1.5 shadow-sm"
onclick="openGpsNavigation('{{ intervention.lat|stringformat:'f' }}', '{{ intervention.lon|stringformat:'f' }}', '{{ intervention.code|escapejs }}', false, event)">
<i class="bi bi-sign-turn-right-fill text-primary"></i>
<span>{% translate "Itinéraire GPS" %}</span>
</button>
{% endif %}
<p class="mb-3 text-muted">
<i class="bi bi-gear
{% if intervention.maintain_type == 'corrective' %}text-danger
{% elif intervention.maintain_type == 'preventive' %}text-warning
{% elif intervention.maintain_type == 'ameliorative' %}text-success
{% endif %}"
></i> {{ intervention.get_maintain_type_display }}
</p>
{% include "interventions/includes/_operation_comment_modal.html" %}