diff --git a/js/funcs.js b/js/funcs.js index a3c2aae..fc56b0b 100644 --- a/js/funcs.js +++ b/js/funcs.js @@ -9,6 +9,8 @@ $(document).ready( function () { }, }); + + if( $('.addedLink').length > 0) { setTimeout(function (){ window.close(); @@ -28,7 +30,14 @@ $(document).ready( function () { $('.cat-delete').confirm({ text: "Are you sure you want to delete this category?", - title: "Confrimation required", + title: "Confirmation required", + confirmButton: "Yes", + cancelButton: "No", + }); + + $(".confirm-delete").confirm({ + "text": "Delete news item?", + "title": "Delete confirmation", confirmButton: "Yes", cancelButton: "No", }); diff --git a/route_handlers.go b/route_handlers.go index e89d1e6..7d75371 100644 --- a/route_handlers.go +++ b/route_handlers.go @@ -236,6 +236,24 @@ func addedHandler(w http.ResponseWriter, r *http.Request, user *user.User, sessi ShowTemplate("added", w, map[string]interface{}{"user": user, "flashes": flashes}) } +func deleteHandler(w http.ResponseWriter, r *http.Request, user *user.User, session *sessions.Session) { + id, idErr := strconv.Atoi(r.FormValue("id")) + + if idErr != nil { + session.AddFlash("Invalid news to delete", flash_err) + } else { + err := categories.Delete(db, id) + if err != nil { + session.AddFlash("Error commiting to Database", flash_err) + } else { + session.AddFlash("Deleted category", flash_info) + } + } + + session.Save(r, w) + http.Redirect(w, r, "/categories", http.StatusFound) +} + func categoriesFormHandler(w http.ResponseWriter, r *http.Request, user *user.User, session *sessions.Session) { flashes := GetFlashes(session) @@ -363,6 +381,7 @@ func init_route_handlers() { r.HandleFunc("/export", userHandler(templateFormHandler)) r.HandleFunc("/export-commit", userHandler(exportHandler)) r.HandleFunc("/added", userHandler(addedHandler)) + r.handleFunc("/delete", userHandler(deleteHandler)) r.HandleFunc("/categories", getPostHandler(userHandler(categoriesFormHandler), userHandler(categoriesPostHandler))) r.HandleFunc("/categories/change-parent", userHandler(categoryChangeParentHandler)) diff --git a/templates/pages/news.html b/templates/pages/news.html index a765f29..4e96e8e 100644 --- a/templates/pages/news.html +++ b/templates/pages/news.html @@ -33,7 +33,7 @@
{{end}}