1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-03 23:56:22 -07:00

Add stuff to be able to create a board section from the web interface

This commit is contained in:
Eggbertx 2022-08-07 22:32:37 -07:00
parent 8e3a7c493a
commit dc6cac7213
3 changed files with 44 additions and 20 deletions

View file

@ -304,9 +304,9 @@ func GetOrCreateDefaultSectionID() (sectionID int, err error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
board := BoardSection{Name: "Main", Abbreviation: "Main", Hidden: false, ListOrder: ID} section := BoardSection{Name: "Main", Abbreviation: "Main", Hidden: false, ListOrder: ID}
err = CreateSection(&board) err = CreateSection(&section)
return board.ID, err return section.ID, err
} }
if err != nil { if err != nil {
return 0, err //other error return 0, err //other error

View file

@ -562,9 +562,32 @@ var actions = []Action{
Permissions: AdminPerms, Permissions: AdminPerms,
JSONoutput: NoJSON, JSONoutput: NoJSON,
Callback: func(writer http.ResponseWriter, request *http.Request, wantsJSON bool) (output interface{}, err error) { Callback: func(writer http.ResponseWriter, request *http.Request, wantsJSON bool) (output interface{}, err error) {
sections, err := gcsql.GetAllSections() if request.PostForm.Get("create_section_btn") != "" {
if err != nil { // user is creating a new board section
return "", err sName := request.PostForm.Get("newname")
sAbbr := request.PostForm.Get("newabbr")
sHidden := request.PostForm.Get("newhidden")
sPosition, err := strconv.Atoi(request.PostForm.Get("newposition"))
if sName == "" || sAbbr == "" || sHidden == "" || err != nil {
return "", &ErrStaffAction{
ErrorField: "formerror",
Action: "boardsections",
Message: "Missing section title, abbreviation, or hidden status data, or invalid position",
}
}
if err = gcsql.CreateSection(&gcsql.BoardSection{
Name: sName,
Abbreviation: sAbbr,
Hidden: sHidden == "on",
ListOrder: sPosition,
}); err != nil {
return "", &ErrStaffAction{
ErrorField: "db",
Action: "boardsections",
Message: err.Error(),
}
}
gcsql.ResetBoardSectionArrays()
} }
for i, input := range request.Form { for i, input := range request.Form {
@ -574,7 +597,7 @@ var actions = []Action{
if err = serverutil.MinifyTemplate(gctemplates.ManageSections, map[string]interface{}{ if err = serverutil.MinifyTemplate(gctemplates.ManageSections, map[string]interface{}{
"webroot": config.GetSystemCriticalConfig().WebRoot, "webroot": config.GetSystemCriticalConfig().WebRoot,
"site_config": config.GetSiteConfig(), "site_config": config.GetSiteConfig(),
"sections": sections, "sections": gcsql.AllSections,
}, pageBuffer, "text/html"); err != nil { }, pageBuffer, "text/html"); err != nil {
return "", err return "", err
} }

View file

@ -1,9 +1,10 @@
<form action="{{.webroot}}manage?action=boardsections" method="POST"> <form action="{{.webroot}}manage?action=boardsections" method="POST">
<h2>New section</h2> <h2>New section</h2>
<table> <table>
<tr><td>Name:</td><td><input type="text" name="newname" id="newname"></td></tr> <tr><td>Name:</td><td><input type="text" name="newname"></td></tr>
<tr><td>Abbreviation:</td><td><input type="text" name="newabbr" id="newabbr"></td></tr> <tr><td>Abbreviation:</td><td><input type="text" name="newabbr"></td></tr>
<tr><td>Hidden:</td><td><input type="checkbox" name="newhidden" id="newhidden"></td></tr> <tr><td>List order</td><td><input type="number" name="newposition" value="0"/></td></tr>
<tr><td>Hidden:</td><td><input type="checkbox" name="newhidden"></td></tr>
</table> </table>
<input type="submit" name="create_section_btn" value="Create section"> <input type="submit" name="create_section_btn" value="Create section">
</form> </form>