mark export works

This commit is contained in:
Dan Ballard 2015-05-15 07:26:50 -07:00
parent b7d5f08978
commit 98457565c9
3 changed files with 27 additions and 5 deletions

View File

@ -1,11 +1,11 @@
$(document).ready( function () {
$("#datepicker").datepicker();
$("confirm-export").confirm({
$(".confirm-export").confirm({
"text": "Mark current batch exported?",
"title": "Export confrimation",
confirm: function() {
alert('exported!');
window.location = "/export";
},
});
});

View File

@ -105,4 +105,15 @@ func Unexported(db *sql.DB) (map[int]*NewsContainer, error) {
func (this *NewsContainer) HeaderDepth(start int) int {
return start + this.Category.Depth()
}
// Mark the current batch (news.exported is null) as exported in this batch (exported = now())
func MarkExported(db *sql.DB) error {
now := time.Now()
_, err := db.Exec("UPDATE news SET exported=$1 WHERE exported is null", now)
if err != nil {
fmt.Println("DB errror: news.MarkExported():", err)
}
return err
}

View File

@ -219,8 +219,18 @@ func templateFormHandler(w http.ResponseWriter, r *http.Request, user *user.User
ShowTemplate("list", w, map[string]interface{}{"user": user, "flashes": flashes, "template": &templateBuf, "url": config.Url})
}
func templatePostHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
func exportHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
session, _ := store.Get(r, "c_user")
err := news.MarkExported(db)
if err != nil {
session.AddFlash("Error marking last batch of news exported", flash_err)
} else {
session.AddFlash("Last batch of news marked exported", flash_info)
}
session.Save(r, w)
http.Redirect(w, r, "/", http.StatusFound)
}
@ -235,7 +245,8 @@ func init_route_handlers() {
r.HandleFunc("/logout", userHandler(LogoutHandler))
r.HandleFunc("/add", getPostHandler(userHandler(addFormHandler), userHandler(addPostHandler)))
r.HandleFunc("/", getPostHandler(userHandler(templateFormHandler), userHandler(templatePostHandler)))
r.HandleFunc("/", userHandler(templateFormHandler))
r.HandleFunc("/export", userHandler(exportHandler))
http.Handle("/", r)