Fixed the buttons and some bugs.

This commit is contained in:
dom96 2012-05-16 17:53:22 +01:00
commit 645ad91a0c
2 changed files with 18 additions and 18 deletions

View file

@ -115,13 +115,14 @@
# #
# #
#proc genFormPost(c: var TForumData, action: string, #proc genFormPost(c: var TForumData, action: string,
# isEdit: bool, title, content: string): string = # topText, title, content: string): string =
# result = "" # result = ""
<br /> <br />
<a name="reply"></a> <a name="reply"></a>
<div id="replywrapper"> <div id="replywrapper">
# let isEdit = topText == "Edit"
<div id="replytop"> <div id="replytop">
<span>Reply</span> <span>${topText}</span>
</div> </div>
<form action="/$action" method="POST"> <form action="/$action" method="POST">
${FieldValid(c, "subject", "Subject:")} ${FieldValid(c, "subject", "Subject:")}
@ -136,7 +137,7 @@
# end if # end if
<br/> <br/>
<input type="submit" name="previewBtn" value="Preview" /> <input type="submit" name="previewBtn" value="Preview" />
<input type="submit" name="postBtn" value="Post" /> <input type="submit" name="postBtn" value="Submit" />
<a href="http://nimrod-code.org/rst.html">Syntax Cheatsheet</a> <a href="http://nimrod-code.org/rst.html">Syntax Cheatsheet</a>
</form> </form>

View file

@ -100,7 +100,7 @@ proc genThreadUrl(c: TForumData, postId = "", action = "", threadid = ""): strin
result = c.req.makeUri(result, absolute = false) result = c.req.makeUri(result, absolute = false)
proc FormSession(c: var TForumData, nextAction: string): string = proc FormSession(c: var TForumData, nextAction: string): string =
return """<input type="hidden" name="threadid" value="1" /> return """<input type="hidden" name="threadid" value="$1" />
<input type="hidden" name="postid" value="$2" />""" % [ <input type="hidden" name="postid" value="$2" />""" % [
$c.threadId, $c.postid] $c.threadId, $c.postid]
@ -407,10 +407,11 @@ proc login(c: var TForumData, name, pass: string): bool =
proc genActionMenu(c: var TForumData): string = proc genActionMenu(c: var TForumData): string =
result = "" result = ""
var btns: seq[TStyledButton] = @[] var btns: seq[TStyledButton] = @[]
if c.threadId >= 0: if c.req.pathInfo != "/":
btns.add(("Thread List", c.req.makeUri("/", false))) btns.add(("Thread List", c.req.makeUri("/", false)))
if c.loggedIn: if c.loggedIn:
if c.threadId >= 0: let hasReplyBtn = c.req.pathInfo != "/donewthread" and c.req.pathInfo != "/doreply"
if c.threadId >= 0 and hasReplyBtn:
let replyUrl = c.genThreadUrl("", "reply") & "#reply" let replyUrl = c.genThreadUrl("", "reply") & "#reply"
btns.add(("Reply", replyUrl)) btns.add(("Reply", replyUrl))
btns.add(("New Thread", c.req.makeUri("/newthread", false))) btns.add(("New Thread", c.req.makeUri("/newthread", false)))
@ -473,17 +474,15 @@ get "/t/@threadid/?":
sql"select header from post where id = (select max(id) from post where thread = ?)", sql"select header from post where id = (select max(id) from post where thread = ?)",
$c.threadId).prependRe $c.threadId).prependRe
body = genPostsList(c, $c.threadId) body = genPostsList(c, $c.threadId)
if c.isPreview: echo(c.threadId)
body = genPostPreview(c, @"subject", @"content", body.add genFormPost(c, "doreply", "Reply", subject, "")
c.userName, $getGMTime(getTime()))
body.add genFormPost(c, "doreply", false, subject, "")
of "edit": of "edit":
cond c.postId != -1 cond c.postId != -1
const query = sql"select header, content from post where id = ?" const query = sql"select header, content from post where id = ?"
let row = getRow(db, query, $c.postId) let row = getRow(db, query, $c.postId)
let header = ||row[0] let header = ||row[0]
let content = ||row[1] let content = ||row[1]
body = genFormPost(c, "doedit", true, header, content) body = genFormPost(c, "doedit", "Edit", header, content)
resp c.genMain(body) resp c.genMain(body)
else: else:
cond validThreadId(c) cond validThreadId(c)
@ -514,11 +513,11 @@ template finishLogin(): stmt =
setCookie("sid", c.userpass, daysForward(7)) setCookie("sid", c.userpass, daysForward(7))
redirect(uri("/")) redirect(uri("/"))
template handleError(action: string, isEdit: bool): stmt = template handleError(action: string, topText: string): stmt =
if c.isPreview: if c.isPreview:
body.add genPostPreview(c, @"subject", @"content", body.add genPostPreview(c, @"subject", @"content",
c.userName, $getGMTime(getTime())) c.userName, $getGMTime(getTime()))
body.add genFormPost(c, action, isEdit, reuseText, reuseText) body.add genFormPost(c, action, topText, reuseText, reuseText)
resp genMain(c, body) resp genMain(c, body)
post "/dologin": post "/dologin":
@ -542,7 +541,7 @@ post "/donewthread":
redirect(uri("/")) redirect(uri("/"))
else: else:
body = "" body = ""
handleError("donewthread", false) handleError("donewthread", "New thread")
post "/doreply": post "/doreply":
createTFD() createTFD()
@ -551,7 +550,7 @@ post "/doreply":
redirect(c.genThreadUrl()) redirect(c.genThreadUrl())
else: else:
body = genPostsList(c, $c.threadId) body = genPostsList(c, $c.threadId)
handleError("doreply", false) handleError("doreply", "Reply")
post "/doedit": post "/doedit":
createTFD() createTFD()
@ -560,11 +559,11 @@ post "/doedit":
redirect(c.genThreadUrl()) redirect(c.genThreadUrl())
else: else:
body = "" body = ""
handleError("doedit", true) handleError("doedit", "Edit")
get "/newthread/?": get "/newthread/?":
createTFD() createTFD()
resp genMain(c, genFormPost(c, "donewthread", false, "", "")) resp genMain(c, genFormPost(c, "donewthread", "New thread", "", ""))
when isMainModule: when isMainModule:
docConfig = rstgen.defaultConfig() docConfig = rstgen.defaultConfig()