feat: edit printer (name, HA prefix, notes) via modal
Deploy via Portainer / deploy (push) Successful in 0s

This commit is contained in:
Jo
2026-07-07 12:06:01 +02:00
parent de9ecec6dc
commit 29af4b4917
2 changed files with 65 additions and 0 deletions
+13
View File
@@ -1347,6 +1347,19 @@ def delete_printer(id):
conn.commit(); conn.close()
return redirect(url_for('printers_page'))
@app.route('/printers/<int:id>/edit', methods=['POST'])
@login_required
def edit_printer(id):
name = request.form.get('name','').strip()
ha_prefix = request.form.get('ha_entity_prefix','').strip().lower()
notes = request.form.get('notes','').strip()
if name:
conn = get_db()
conn.execute('UPDATE printers SET name=?, ha_entity_prefix=?, notes=? WHERE id=?',
(name, ha_prefix, notes, id))
conn.commit(); conn.close()
return redirect(url_for('printers_page'))
@app.route('/working-schedule', methods=['GET','POST'])
def working_schedule():
if request.method == 'POST':
+52
View File
@@ -38,6 +38,10 @@
<td class="text-muted small">{{ p.notes or '—' }}</td>
<td>
<div class="d-flex gap-1">
<button class="btn btn-sm btn-outline-secondary py-0"
onclick="openEditModal({{ p.id }}, '{{ p.name|replace("'","\\'") }}', '{{ p.ha_entity_prefix or '' }}', '{{ p.notes|replace("'","\\'")|default('') }}')">
<i class="bi bi-pencil"></i>
</button>
<form method="POST" action="{{ url_for('toggle_printer', id=p.id) }}">
<button class="btn btn-sm {% if p.is_active %}btn-outline-warning{% else %}btn-outline-success{% endif %} py-0">
{% if p.is_active %}<i class="bi bi-pause"></i>{% else %}<i class="bi bi-play"></i>{% endif %}
@@ -93,4 +97,52 @@
</div>
</div>
</div>
<!-- Modal édition imprimante -->
<div class="modal fade" id="editPrinterModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="bi bi-pencil me-2"></i>Modifier l'imprimante</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form id="editPrinterForm" method="POST">
<div class="modal-body">
<div class="mb-3">
<label class="form-label fw-semibold">Nom</label>
<input type="text" name="name" id="editName" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label fw-semibold">Préfixe Home Assistant <span class="text-muted fw-normal small">(optionnel)</span></label>
<input type="text" name="ha_entity_prefix" id="editHaPrefix" class="form-control font-monospace"
placeholder="ex : patabambulab01">
<div class="form-text">Laisser vide pour désactiver la synchro HA.</div>
</div>
<div class="mb-3">
<label class="form-label fw-semibold">Notes</label>
<input type="text" name="notes" id="editNotes" class="form-control" placeholder="couleur, emplacement…">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Annuler</button>
<button type="submit" class="btn fw-bold" style="background:#ff6b35;color:#fff">
<i class="bi bi-save me-1"></i>Enregistrer
</button>
</div>
</form>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
function openEditModal(id, name, haPrefix, notes) {
document.getElementById('editPrinterForm').action = '/printers/' + id + '/edit';
document.getElementById('editName').value = name;
document.getElementById('editHaPrefix').value = haPrefix;
document.getElementById('editNotes').value = notes;
new bootstrap.Modal(document.getElementById('editPrinterModal')).show();
}
</script>
{% endblock %}