-
Notifications
You must be signed in to change notification settings - Fork 4
/
admin_teams.go
100 lines (96 loc) · 3.06 KB
/
admin_teams.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"fmt"
"net/http"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"github.com/gorilla/mux"
)
func handleAdminTeams(w http.ResponseWriter, req *http.Request, page *pageData) {
vars := mux.Vars(req)
page.SubTitle = "Teams"
teamId := vars["id"]
if teamId == "new" {
// Add a new team
switch vars["function"] {
case "save":
name := req.FormValue("teamname")
tm := NewTeam("")
tm.Name = name
if err := m.jam.AddTeam(tm); err != nil {
page.session.setFlashMessage("Error adding team: "+err.Error(), "error")
}
redirect("/admin/teams", w, req)
default:
page.SubTitle = "Add New Team"
page.show("admin-addteam.html", w)
}
} else if teamId != "" {
// Functions for existing team
tm, _ := m.jam.GetTeamById(teamId)
if tm != nil {
switch vars["function"] {
case "save":
tm.Name = req.FormValue("teamname")
page.session.setFlashMessage("Team Updated!", "success")
redirect("/admin/teams", w, req)
case "delete":
var err error
if err = m.jam.RemoveTeamById(teamId); err != nil {
page.session.setFlashMessage("Error removing team: "+err.Error(), "error")
} else {
page.session.setFlashMessage("Team "+tm.Name+" Removed", "success")
}
redirect("/admin/teams", w, req)
case "savemember":
mbrName := req.FormValue("newmembername")
mbr, err := NewTeamMember(tm.UUID, "")
if err == nil {
mbr.Name = mbrName
mbr.SlackId = req.FormValue("newmemberslackid")
mbr.Twitter = req.FormValue("newmembertwitter")
mbr.Email = req.FormValue("newmemberemail")
}
if err := tm.AddTeamMember(mbr); err != nil {
page.session.setFlashMessage("Error adding team member: "+err.Error(), "error")
} else {
page.session.setFlashMessage(mbrName+" added to team!", "success")
}
redirect("/admin/teams/"+teamId+"#members", w, req)
case "deletemember":
var err error
var mbr *TeamMember
if mbr, err = tm.GetTeamMemberById(req.FormValue("memberid")); err != nil {
fmt.Println("Error removing team member: " + err.Error())
page.session.setFlashMessage("Error deleting team member", "error")
redirect("/admin/teams/"+teamId+"#members", w, req)
}
if err = tm.RemoveTeamMemberById(mbr.UUID); err != nil {
fmt.Println("Error removing team member: " + err.Error())
page.session.setFlashMessage("Error deleting team member", "error")
} else {
page.session.setFlashMessage(mbr.Name+" deleted from team", "success")
}
redirect("/admin/teams/"+teamId+"#members", w, req)
default:
page.SubTitle = "Edit Team"
t, err := m.jam.GetTeamById(teamId)
if err != nil {
page.session.setFlashMessage("Error loading team: "+err.Error(), "error")
redirect("/admin/teams", w, req)
}
page.TemplateData = t
page.show("admin-editteam.html", w)
}
} else {
page.session.setFlashMessage("Couldn't find the requested team, please try again.", "error")
redirect("/admin/teams", w, req)
}
} else {
// Team List
page.TemplateData = m.jam
page.SubTitle = "Teams"
page.show("admin-teams.html", w)
}
}