Aufgaben-Templates löschbar machen

This commit is contained in:
Kai
2026-02-17 17:33:38 +01:00
parent aa0475c151
commit 4d9b3a2997
3 changed files with 44 additions and 0 deletions

View File

@@ -498,6 +498,27 @@ func (a *App) handleCreateTaskTemplate(w http.ResponseWriter, r *http.Request) {
redirectWithMessage(w, r, "/planning", "info", "Template gespeichert") redirectWithMessage(w, r, "/planning", "info", "Template gespeichert")
} }
func (a *App) handleDeleteTaskTemplate(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
if err := r.ParseForm(); err != nil {
redirectWithMessage(w, r, "/planning", "error", "Form ungültig")
return
}
id := mustInt64(r.FormValue("id"), 0)
if id <= 0 {
redirectWithMessage(w, r, "/planning", "error", "Template-ID ungültig")
return
}
if _, err := a.db.Exec(`DELETE FROM custom_task_templates WHERE id=?`, id); err != nil {
redirectWithMessage(w, r, "/planning", "error", "Template konnte nicht gelöscht werden")
return
}
redirectWithMessage(w, r, "/planning", "info", "Template gelöscht")
}
func (a *App) handleCreateCustomTask(w http.ResponseWriter, r *http.Request) { func (a *App) handleCreateCustomTask(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost { if r.Method != http.MethodPost {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed) http.Error(w, "method not allowed", http.StatusMethodNotAllowed)

View File

@@ -69,6 +69,7 @@ func main() {
mux.HandleFunc("/crop-steps/create", app.handleCreateCropStep) mux.HandleFunc("/crop-steps/create", app.handleCreateCropStep)
mux.HandleFunc("/crop-steps/delete", app.handleDeleteCropStep) mux.HandleFunc("/crop-steps/delete", app.handleDeleteCropStep)
mux.HandleFunc("/task-templates/create", app.handleCreateTaskTemplate) mux.HandleFunc("/task-templates/create", app.handleCreateTaskTemplate)
mux.HandleFunc("/task-templates/delete", app.handleDeleteTaskTemplate)
mux.HandleFunc("/custom-tasks/create", app.handleCreateCustomTask) mux.HandleFunc("/custom-tasks/create", app.handleCreateCustomTask)
mux.HandleFunc("/custom-tasks/delete", app.handleDeleteCustomTask) mux.HandleFunc("/custom-tasks/delete", app.handleDeleteCustomTask)

View File

@@ -69,6 +69,28 @@
</label> </label>
<button type="submit">Template speichern</button> <button type="submit">Template speichern</button>
</form> </form>
<div class="table-wrap mt">
<table>
<thead><tr><th>Template</th><th>Aktion</th></tr></thead>
<tbody>
{{if .TaskTemplates}}
{{range .TaskTemplates}}
<tr>
<td>{{.Title}}</td>
<td>
<form method="post" action="/task-templates/delete">
<input type="hidden" name="id" value="{{.ID}}">
<button type="submit" class="btn-small danger" onclick="return confirm('Template wirklich löschen?')">Löschen</button>
</form>
</td>
</tr>
{{end}}
{{else}}
<tr><td colspan="2">Keine Templates vorhanden.</td></tr>
{{end}}
</tbody>
</table>
</div>
</section> </section>
<section class="card"> <section class="card">