mock out delete news

This commit is contained in:
Dan Ballard 2015-09-03 07:16:16 -07:00
parent fddf4b5045
commit f9ab27e32a
3 changed files with 30 additions and 2 deletions

View File

@ -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",
});

View File

@ -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))

View File

@ -33,7 +33,7 @@
<div class="row">
<div class="col-xs-2">&nbsp;</div>
<div class="col-xs-8">{{truncate .post.Notes 500}}</div>
<div class="col-xs-2"><a class="delete" href="/delete/{{.post.Id}}">Delete</a></div>
<div class="col-xs-2"><a class="confirm-delete" href="/delete?id={{.post.Id}}">Delete</a></div>
</div>
</div>
{{end}}