forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_lower_thirds.go
78 lines (72 loc) · 2.07 KB
/
setup_lower_thirds.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
// Copyright 2014 Team 254. All Rights Reserved.
// Author: [email protected] (Patrick Fairbank)
//
// Web routes for managing lower thirds.
package main
import (
"html/template"
"net/http"
"strconv"
)
// Shows the lower third configuration page.
func LowerThirdsGetHandler(w http.ResponseWriter, r *http.Request) {
template, err := template.ParseFiles("templates/setup_lower_thirds.html", "templates/base.html")
if err != nil {
handleWebErr(w, err)
return
}
lowerThirds, err := db.GetAllLowerThirds()
if err != nil {
handleWebErr(w, err)
return
}
data := struct {
*EventSettings
LowerThirds []LowerThird
}{eventSettings, lowerThirds}
err = template.ExecuteTemplate(w, "base", data)
if err != nil {
handleWebErr(w, err)
return
}
}
// Saves the new or modified lower third to the database and triggers showing it on the audience display.
func LowerThirdsPostHandler(w http.ResponseWriter, r *http.Request) {
lowerThirdId, _ := strconv.Atoi(r.PostFormValue("id"))
lowerThird, err := db.GetLowerThirdById(lowerThirdId)
if err != nil {
handleWebErr(w, err)
return
}
if r.PostFormValue("action") == "delete" {
err := db.DeleteLowerThird(lowerThird)
if err != nil {
handleWebErr(w, err)
return
}
} else {
// Save the lower third even if the show or hide buttons were clicked.
if lowerThird == nil {
lowerThird = &LowerThird{TopText: r.PostFormValue("topText"),
BottomText: r.PostFormValue("bottomText")}
err = db.CreateLowerThird(lowerThird)
} else {
lowerThird.TopText = r.PostFormValue("topText")
lowerThird.BottomText = r.PostFormValue("bottomText")
err = db.SaveLowerThird(lowerThird)
}
if err != nil {
handleWebErr(w, err)
return
}
if r.PostFormValue("action") == "show" {
mainArena.lowerThirdNotifier.Notify(lowerThird)
mainArena.audienceDisplayScreen = "lowerThird"
mainArena.audienceDisplayNotifier.Notify(nil)
} else if r.PostFormValue("action") == "hide" {
mainArena.audienceDisplayScreen = "blank"
mainArena.audienceDisplayNotifier.Notify(nil)
}
}
http.Redirect(w, r, "/setup/lower_thirds", 302)
}