mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-24 08:46:24 -07:00
use template for board management page instead of several if/else blocks and "html +="
This commit is contained in:
parent
e32ded4907
commit
0f7e6b2696
5 changed files with 70 additions and 142 deletions
|
@ -1,3 +1,7 @@
|
|||
table#board-options, table#board-options th, td, tr {
|
||||
border: solid 1px;
|
||||
}
|
||||
|
||||
.loginbox {
|
||||
width:300px;
|
||||
height: 120px;
|
||||
|
|
|
@ -624,7 +624,6 @@ var manage_functions = map[string]ManageFunction{
|
|||
board_creation_status = err.Error()
|
||||
continue
|
||||
}
|
||||
//_, err := db.Prepare("INSERT INTO (" + generatePlaceholders(24, ", ") + ")")
|
||||
stmt, err := db.Prepare(
|
||||
"INSERT INTO `" + config.DBprefix + "boards` (`order`,`dir`,`type`,`upload_type`,`title`,`subtitle`," +
|
||||
"`description`,`section`,`max_image_size`,`max_pages`,`locale`,`default_style`,`locked`,`created_on`," +
|
||||
|
@ -743,92 +742,28 @@ var manage_functions = map[string]ManageFunction{
|
|||
}
|
||||
var board_dir string
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&board_dir)
|
||||
rows.Scan(&board_dir)
|
||||
html += "<option>" + board_dir + "</option>\n"
|
||||
}
|
||||
html += "</select> <input type=\"submit\" value=\"Edit\" /> <input type=\"submit\" value=\"Delete\" /></form><hr />"
|
||||
html += fmt.Sprintf("<h2>Create new board</h2>"+
|
||||
"<span id=\"board-creation-message\">%s</span><br />"+
|
||||
"<form action=\"/manage?action=boards\" method=\"POST\">"+
|
||||
"<input type=\"hidden\" name=\"do\" value=\"add\" />"+
|
||||
"Directory <input type=\"text\" name=\"dir\" value=\"%s\" /><br />"+
|
||||
"Order <input type=\"text\" name=\"order\" value=\"%d\" /><br />"+
|
||||
"Title <input type=\"text\" name=\"title\" value=\"%s\" /><br />"+
|
||||
"Subtitle <input type=\"text\" name=\"subtitle\" value=\"%s\" /><br />"+
|
||||
"Description <input type=\"text\" name=\"description\" value=\"%s\" /><br />"+
|
||||
"Section <select name=\"section\" selected=\"%d\">\n<option value=\"none\">Select section...</option>\n",
|
||||
board_creation_status, board.Dir, board.Order, board.Title, board.Subtitle, board.Description, board.Section)
|
||||
html += "</select> <input type=\"submit\" value=\"Edit\" /> <input type=\"submit\" value=\"Delete\" /></form><hr />" +
|
||||
"<h2>Create new board</h2>\n<span id=\"board-creation-message\">" + board_creation_status + "</span><br />"
|
||||
|
||||
rows, err = db.Query("SELECT `name` FROM `" + config.DBprefix + "sections` WHERE `hidden` = 0 ORDER BY `order`;")
|
||||
manageBoardsBuffer := bytes.NewBufferString("")
|
||||
all_sections, _ = getSectionArr("")
|
||||
if len(all_sections) == 0 {
|
||||
db.Exec("INSERT INTO `" + config.DBprefix + "sections` (`hidden`,`name`,`abbreviation`) VALUES(0,'Main','main')")
|
||||
}
|
||||
all_sections, _ = getSectionArr("")
|
||||
|
||||
err := renderTemplate(manage_boards_tmpl, "manage_boards", manageBoardsBuffer,
|
||||
&Wrapper{IName: "board", Data: []interface{}{board}},
|
||||
&Wrapper{IName: "section_arr", Data: all_sections},
|
||||
)
|
||||
if err != nil {
|
||||
html += err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
iter := 0
|
||||
var section_name string
|
||||
for rows.Next() {
|
||||
err = rows.Scan(§ion_name)
|
||||
html += "<option value=\"" + strconv.Itoa(iter) + "\">" + section_name + "</option>\n"
|
||||
iter += 1
|
||||
}
|
||||
html += "</select><br />Max image size: <input type=\"text\" name=\"maximagesize\" value=\"" + strconv.Itoa(board.MaxImageSize) + "\" /><br />Max pages: <input type=\"text\" name=\"maxpages\" value=\"" + strconv.Itoa(board.MaxPages) + "\" /><br />Default style</td><td><select name=\"defaultstyle\" selected=\"" + board.DefaultStyle + "\">"
|
||||
for _, style := range config.Styles_img {
|
||||
html += "<option value=\"" + style + "\">" + style + "</option>"
|
||||
}
|
||||
|
||||
html += "</select>Locked"
|
||||
if board.Locked {
|
||||
html += "<input type=\"checkbox\" name=\"locked\" checked/>"
|
||||
} else {
|
||||
html += "<input type=\"checkbox\" name=\"locked\" />"
|
||||
}
|
||||
|
||||
html += "<br />Forced anonymity"
|
||||
|
||||
if board.ForcedAnon {
|
||||
html += "<input type=\"checkbox\" name=\"forcedanon\" checked/>"
|
||||
} else {
|
||||
html += "<input type=\"checkbox\" name=\"forcedanon\" />"
|
||||
}
|
||||
|
||||
html += fmt.Sprintf("<br />Anonymous: <input type=\"text\" name=\"anonymous\" value=\"%s\" /><br />"+
|
||||
"Max age: <input type=\"text\" name=\"maxage\" value=\"%d\"/><br />"+
|
||||
"Bump limit: <input type=\"text\" name=\"autosageafter\" value=\"%d\"/><br />"+
|
||||
"No images after <input type=\"text\" name=\"noimagesafter\" value=\"%d\"/>px<br />"+
|
||||
"Max message length</td><td><input type=\"text\" name=\"maxmessagelength\" value=\"%d\"/><br />"+
|
||||
"Embeds allowed ", board.Anonymous, board.MaxAge, board.AutosageAfter, board.NoImagesAfter, board.MaxMessageLength)
|
||||
|
||||
if board.EmbedsAllowed {
|
||||
html += "<input type=\"checkbox\" name=\"embedsallowed\" checked/>"
|
||||
} else {
|
||||
html += "<input type=\"checkbox\" name=\"embedsallowed\" />"
|
||||
}
|
||||
|
||||
html += "<br />Redirect to thread</td><td>"
|
||||
if board.RedirectToThread {
|
||||
html += "<input type=\"checkbox\" name=\"redirecttothread\" checked/>"
|
||||
} else {
|
||||
html += "<input type=\"checkbox\" name=\"redirecttothread\" />"
|
||||
}
|
||||
|
||||
html += "<br />Require an uploaded file"
|
||||
|
||||
if board.RequireFile {
|
||||
html += "<input type=\"checkbox\" name=\"require_file\" checked/>"
|
||||
} else {
|
||||
html += "<input type=\"checkbox\" name=\"require_file\" />"
|
||||
}
|
||||
|
||||
html += "<br />Enable catalog"
|
||||
|
||||
if board.EnableCatalog {
|
||||
html += "<input type=\"checkbox\" name=\"enablecatalog\" checked />"
|
||||
} else {
|
||||
html += "<input type=\"checkbox\" name=\"enablecatalog\" />"
|
||||
}
|
||||
|
||||
html += "<br /><input type=\"submit\" /></form>"
|
||||
html += manageBoardsBuffer.String()
|
||||
return
|
||||
}
|
||||
resetBoardSectionArrays()
|
||||
|
|
|
@ -196,6 +196,9 @@ var (
|
|||
manage_header_tmpl_str string
|
||||
manage_header_tmpl *template.Template
|
||||
|
||||
manage_boards_tmpl_str string
|
||||
manage_boards_tmpl *template.Template
|
||||
|
||||
front_page_tmpl_str string
|
||||
front_page_tmpl *template.Template
|
||||
|
||||
|
@ -290,6 +293,21 @@ func initTemplates() {
|
|||
os.Exit(2)
|
||||
}
|
||||
|
||||
manage_boards_tmpl_bytes, err := ioutil.ReadFile(config.TemplateDir + "/manage_boards.html")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
manage_boards_tmpl_str = "{{$config := getInterface .Data 0}}" +
|
||||
"{{$board := getInterface (getInterface .Data 1).Data 0}}" +
|
||||
"{{$section_arr := (getInterface .Data 2).Data}}" +
|
||||
string(manage_boards_tmpl_bytes)
|
||||
|
||||
manage_boards_tmpl, tmpl_err = template.New("manage_boards_tmpl").Funcs(funcMap).Parse(manage_boards_tmpl_str)
|
||||
if tmpl_err != nil {
|
||||
fmt.Println("Failed loading template \"" + config.TemplateDir + "/manage_boards.html\": " + tmpl_err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
front_page_tmpl_bytes, err := ioutil.ReadFile(config.TemplateDir + "/front.html")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Gochan Manage Page - Boards</title>
|
||||
<script type="text/javascript" src="/javascript/jquery-1.10.2.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
var styles = [{{range $ii, $style := $config.Styles_img}}{{if gt $ii 0}}, {{end}}"{{$style}}"{{end}}];
|
||||
var webroot = "{{$config.SiteWebfolder}}";
|
||||
var thread_type = "board";
|
||||
</script>
|
||||
<script type="text/javascript" src="/javascript/gochan.js"></script>
|
||||
<script type="text/javascript" src="/javascript/manage.js"></script>
|
||||
<link rel="stylesheet" href="/css/global/img.css" />
|
||||
{{range $i, $style := $config.Styles_img}}
|
||||
<link rel="{{if isStyleNotDefault_img $style}}alternate {{end}}stylesheet" href="/css/{{$style}}/img.css" />{{end}}
|
||||
</head>
|
||||
<body>
|
||||
<h1>Manage boards</h1>
|
||||
<form action="/manage?action=boards" method="POST">
|
||||
<input type="hidden" name="do" value="existing" />
|
||||
<select name="boardselect">
|
||||
<option>Select board...</option>
|
||||
<option>test</option>
|
||||
</select>
|
||||
<input type="submit" value="Edit" /> <input type="submit" value="Delete" /> <input type="submit" value="Go To" />
|
||||
</form>
|
||||
<h2>Create new board</h2>
|
||||
<form action="/manage?action=boards" method="POST">
|
||||
<input type="hidden" name="do" value="add" />
|
||||
<table class="board-options">
|
||||
<tr><th class="option-column">Option</th><th class="value-column">Value</th></tr>
|
||||
<tr><td>Directory</td><td><input type="text" name="dir" value="" /></td></tr>
|
||||
<tr><td>Section</td><td><select name="section" selected="0">
|
||||
<option value="none">Select section...</option>
|
||||
</select></td></tr>
|
||||
|
||||
<tr><td>Order</td><td><input type="text" name="order" value="0" /></td></tr>
|
||||
<tr><td>Title</td><td><input type="text" name="title" value="" /></td></tr>
|
||||
<tr><td>Subtitle</td><td><input type="text" name="subtitle" value="" /></td></tr>
|
||||
<tr><td>Description</td><td><input type="text" name="description" value="" /></td></tr>
|
||||
<tr><td>Max image size</td><td><input type="text" name="maximagesize" value="4718592" /></td></tr>
|
||||
<tr><td>Max pages</td><td><input type="text" name="maxpages" value="11" /></td></tr>
|
||||
<tr><td>Default style</td><td><select name="defaultstyle" selected="">
|
||||
{{range $i, $style := $config.Styles_img}}
|
||||
<option value="{{$style}}">{{$style}}</option>{{end}}
|
||||
</select></td></tr>
|
||||
<tr><td>Locked</td><td><input type="checkbox" name="locked" /></td></tr>
|
||||
<tr><td>Forced anonymity</td><td><input type="checkbox" name="forcedanon" /></td></tr>
|
||||
<tr><td>Anonymous name</td><td><input type="text" name="anonymous" value="Anonymous" /></td></tr>
|
||||
<tr><td>Max age</td><td><input type="text" name="maxage" value="0"/></td></tr>
|
||||
<tr><td>Bump limit</td><td><input type="text" name="autosageafter" value="200"/></td></tr>
|
||||
<tr><td>No images after</td><td><input type="text" name="noimagesafter" value="0"/></td></tr>
|
||||
<tr><td>Max message length</td><td><input type="text" name="maxmessagelength" value="8192"/></td></tr>
|
||||
<tr><td>Embeds allowed</td><td><input type="checkbox" name="embedsallowed" /></td></tr>
|
||||
<tr><td>Redirect to thread</td><td><input type="checkbox" name="redirecttothread" checked/></td></tr>
|
||||
<tr><td>Require an uploaded file</td><td><input type="checkbox" name="require_file" /></td></tr>
|
||||
<tr><td>Enable catalog</td><td><input type="checkbox" name="enablecatalog" checked /></td></tr>
|
||||
</table>
|
||||
<input type="submit" /></form>
|
||||
</body>
|
||||
</html>
|
33
templates/manage_boards.html
Normal file
33
templates/manage_boards.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
<form action="/manage?action=boards" method="POST">
|
||||
<input type="hidden" name="do" value="add" />
|
||||
<table id="board-options">
|
||||
<tr><th class="option-column">Option</th><th class="value-column">Value</th></tr>
|
||||
<tr><td>Directory</td><td><input type="text" name="dir" value="" /></td></tr>
|
||||
<tr><td>Section</td><td><select name="section" selected="0">
|
||||
<option value="none">Select section...</option>
|
||||
{{range $_, $section := $section_arr}}
|
||||
<option value="{{$section.ID}}">{{$section.Name}}</option>{{end}}
|
||||
</select></td></tr>
|
||||
<tr><td>Order</td><td><input type="text" name="order" value="0" /></td></tr>
|
||||
<tr><td>Title</td><td><input type="text" name="title" value="" /></td></tr>
|
||||
<tr><td>Subtitle</td><td><input type="text" name="subtitle" value="" /></td></tr>
|
||||
<tr><td>Description</td><td><input type="text" name="description" value="" /></td></tr>
|
||||
<tr><td>Max image size</td><td><input type="text" name="maximagesize" value="4718592" /></td></tr>
|
||||
<tr><td>Max pages</td><td><input type="text" name="maxpages" value="11" /></td></tr>
|
||||
<tr><td>Default style</td><td><select name="defaultstyle" selected="">
|
||||
{{range $i, $style := $config.Styles_img}}
|
||||
<option value="{{$style}}">{{$style}}</option>{{end}}
|
||||
</select></td></tr>
|
||||
<tr><td>Locked</td><td><input type="checkbox" name="locked" {{if $board.Locked}}checked{{end}}/></td></tr>
|
||||
<tr><td>Forced anonymity</td><td><input type="checkbox" name="forcedanon" {{if $board.ForcedAnon}}checked{{end}}/></td></tr>
|
||||
<tr><td>Anonymous name</td><td><input type="text" name="anonymous" value="{{$board.Anonymous}}" /></td></tr>
|
||||
<tr><td>Max age</td><td><input type="text" name="maxage" value="{{$board.MaxAge}}"/></td></tr>
|
||||
<tr><td>Bump limit<sup title="After this many posts, the thread will stop being bumped when a new post is made. ">[?]</sup></td><td><input type="text" name="autosageafter" value="{{$board.AutosageAfter}}"/></td></tr>
|
||||
<tr><td>No images after</td><td><input type="text" name="noimagesafter" value="{{$board.NoImagesAfter}}"/></td></tr>
|
||||
<tr><td>Max message length</td><td><input type="text" name="maxmessagelength" value="{{$board.MaxMessageLength}}"/></td></tr>
|
||||
<tr><td>Embeds allowed</td><td><input type="checkbox" name="embedsallowed" {{if $board.EmbedsAllowed}}checked{{end}}/></td></tr>
|
||||
<tr><td>Redirect to thread<sup title="If checked, posts will redirect to the thread by default without requiring 'noko' in the email">[?]</sup></td><td><input type="checkbox" name="redirecttothread" {{if $board.RedirectToThread}}checked{{end}}/></td></tr>
|
||||
<tr><td>Require an uploaded file</td><td><input type="checkbox" name="require_file" {{if $board.RequireFile}}checked{{end}}/></td></tr>
|
||||
<tr><td>Enable catalog</td><td><input type="checkbox" name="enablecatalog" {{if $board.EnableCatalog}}checked{{end}}/></td></tr>
|
||||
</table>
|
||||
<input type="submit" /></form>
|
Loading…
Add table
Add a link
Reference in a new issue