Aufgaben-Templates löschbar machen
This commit is contained in:
@@ -498,6 +498,27 @@ func (a *App) handleCreateTaskTemplate(w http.ResponseWriter, r *http.Request) {
|
||||
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) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
|
||||
@@ -69,6 +69,7 @@ func main() {
|
||||
mux.HandleFunc("/crop-steps/create", app.handleCreateCropStep)
|
||||
mux.HandleFunc("/crop-steps/delete", app.handleDeleteCropStep)
|
||||
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/delete", app.handleDeleteCustomTask)
|
||||
|
||||
|
||||
@@ -69,6 +69,28 @@
|
||||
</label>
|
||||
<button type="submit">Template speichern</button>
|
||||
</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 class="card">
|
||||
|
||||
Reference in New Issue
Block a user