forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_sponsor_slides.go
81 lines (74 loc) · 2.04 KB
/
setup_sponsor_slides.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2014 Team 254. All Rights Reserved.
// Author: [email protected] (Nick Eyre)
//
// Web routes for managing sponsor slides.
package main
import (
"html/template"
"net/http"
"strconv"
)
// Shows the sponsor slides configuration page.
func SponsorSlidesGetHandler(w http.ResponseWriter, r *http.Request) {
if !UserIsAdmin(w, r) {
return
}
template, err := template.ParseFiles("templates/setup_sponsor_slides.html", "templates/base.html")
if err != nil {
handleWebErr(w, err)
return
}
sponsorSlides, err := db.GetAllSponsorSlides()
if err != nil {
handleWebErr(w, err)
return
}
data := struct {
*EventSettings
SponsorSlides []SponsorSlide
}{eventSettings, sponsorSlides}
err = template.ExecuteTemplate(w, "base", data)
if err != nil {
handleWebErr(w, err)
return
}
}
// Saves the new or modified sponsor slides to the database.
func SponsorSlidesPostHandler(w http.ResponseWriter, r *http.Request) {
if !UserIsAdmin(w, r) {
return
}
sponsorSlideId, _ := strconv.Atoi(r.PostFormValue("id"))
sponsorSlide, err := db.GetSponsorSlideById(sponsorSlideId)
if err != nil {
handleWebErr(w, err)
return
}
if r.PostFormValue("action") == "delete" {
err := db.DeleteSponsorSlide(sponsorSlide)
if err != nil {
handleWebErr(w, err)
return
}
} else {
displayTimeSec, _ := strconv.Atoi(r.PostFormValue("displayTimeSec"))
if sponsorSlide == nil {
sponsorSlide = &SponsorSlide{Subtitle: r.PostFormValue("subtitle"),
Line1: r.PostFormValue("line1"), Line2: r.PostFormValue("line2"),
Image: r.PostFormValue("image"), DisplayTimeSec: displayTimeSec}
err = db.CreateSponsorSlide(sponsorSlide)
} else {
sponsorSlide.Subtitle = r.PostFormValue("subtitle")
sponsorSlide.Line1 = r.PostFormValue("line1")
sponsorSlide.Line2 = r.PostFormValue("line2")
sponsorSlide.Image = r.PostFormValue("image")
sponsorSlide.DisplayTimeSec = displayTimeSec
err = db.SaveSponsorSlide(sponsorSlide)
}
if err != nil {
handleWebErr(w, err)
return
}
}
http.Redirect(w, r, "/setup/sponsor_slides", 302)
}