added preview code to new topic - not yet tested
This commit is contained in:
+70
-1
@@ -16,6 +16,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.erbosoft.com/amy/amsterdam/database"
|
"git.erbosoft.com/amy/amsterdam/database"
|
||||||
|
"git.erbosoft.com/amy/amsterdam/htmlcheck"
|
||||||
"git.erbosoft.com/amy/amsterdam/ui"
|
"git.erbosoft.com/amy/amsterdam/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -189,7 +190,7 @@ func NewTopicForm(ctxt ui.AmContext) (string, any, error) {
|
|||||||
myLevel := ctxt.GetScratch("levelInConference").(uint16)
|
myLevel := ctxt.GetScratch("levelInConference").(uint16)
|
||||||
if !conf.TestPermission("Conference.Create", myLevel) {
|
if !conf.TestPermission("Conference.Create", myLevel) {
|
||||||
ctxt.SetRC(http.StatusForbidden)
|
ctxt.SetRC(http.StatusForbidden)
|
||||||
return ui.ErrorPage(ctxt, errors.New("you are not permitted to read this conference"))
|
return ui.ErrorPage(ctxt, errors.New("you are not permitted to create topics in this conference"))
|
||||||
}
|
}
|
||||||
ctxt.VarMap().Set("conferenceName", conf.Name)
|
ctxt.VarMap().Set("conferenceName", conf.Name)
|
||||||
ctxt.VarMap().Set("urlStem", fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.URLParam("confid")))
|
ctxt.VarMap().Set("urlStem", fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.URLParam("confid")))
|
||||||
@@ -199,3 +200,71 @@ func NewTopicForm(ctxt ui.AmContext) (string, any, error) {
|
|||||||
ctxt.VarMap().Set("amsterdam_pageTitle", "Create New Topic")
|
ctxt.VarMap().Set("amsterdam_pageTitle", "Create New Topic")
|
||||||
return "framed_template", "new_topic.jet", nil
|
return "framed_template", "new_topic.jet", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewTopic(ctxt ui.AmContext) (string, any, error) {
|
||||||
|
cmd, arg, err := singleConferencePrequel(ctxt)
|
||||||
|
if cmd != "" {
|
||||||
|
return cmd, arg, err
|
||||||
|
}
|
||||||
|
comm := ctxt.CurrentCommunity()
|
||||||
|
conf := ctxt.GetScratch("currentConference").(*database.Conference)
|
||||||
|
myLevel := ctxt.GetScratch("levelInConference").(uint16)
|
||||||
|
if !conf.TestPermission("Conference.Create", myLevel) {
|
||||||
|
ctxt.SetRC(http.StatusForbidden)
|
||||||
|
return ui.ErrorPage(ctxt, errors.New("you are not permitted to create topics in this conference"))
|
||||||
|
}
|
||||||
|
|
||||||
|
urlStem := fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.URLParam("confid"))
|
||||||
|
if ctxt.FormFieldIsSet("cancel") {
|
||||||
|
return "redirect", urlStem, nil
|
||||||
|
}
|
||||||
|
if ctxt.FormFieldIsSet("preview") {
|
||||||
|
// start by escaping the title
|
||||||
|
checker, err := htmlcheck.AmNewHTMLChecker("escaper")
|
||||||
|
if err != nil {
|
||||||
|
return ui.ErrorPage(ctxt, err)
|
||||||
|
}
|
||||||
|
checker.Append(ctxt.FormField("title"))
|
||||||
|
checker.Finish()
|
||||||
|
v, _ := checker.Value()
|
||||||
|
ctxt.VarMap().Set("topicName", v)
|
||||||
|
|
||||||
|
// escape the pseud
|
||||||
|
checker.Reset()
|
||||||
|
checker.Append(ctxt.FormField("pseud"))
|
||||||
|
checker.Finish()
|
||||||
|
v, _ = checker.Value()
|
||||||
|
ctxt.VarMap().Set("pseud", v)
|
||||||
|
|
||||||
|
// escape the data
|
||||||
|
postdata := ctxt.FormField("pb")
|
||||||
|
checker.Reset()
|
||||||
|
checker.Append(postdata)
|
||||||
|
checker.Finish()
|
||||||
|
v, _ = checker.Value()
|
||||||
|
ctxt.VarMap().Set("pb", v)
|
||||||
|
|
||||||
|
// run the preview
|
||||||
|
checker, err = htmlcheck.AmNewHTMLChecker("preview")
|
||||||
|
if err != nil {
|
||||||
|
return ui.ErrorPage(ctxt, err)
|
||||||
|
}
|
||||||
|
checker.SetContext("PostLinkDecoderContext", database.AmCreatePostLinkContext(comm.Alias, ctxt.URLParam("cid"), conf.TopTopic+1))
|
||||||
|
checker.Append(postdata)
|
||||||
|
checker.Finish()
|
||||||
|
v, _ = checker.Value()
|
||||||
|
ctxt.VarMap().Set("previewPb", v)
|
||||||
|
nErr, _ := checker.Counter("spelling")
|
||||||
|
ctxt.VarMap().Set("nError", nErr)
|
||||||
|
|
||||||
|
if ctxt.FormFieldIsSet("attach") {
|
||||||
|
ctxt.VarMap().Set("attachFile", true)
|
||||||
|
}
|
||||||
|
return "framed_template", "new_topic.jet", nil
|
||||||
|
}
|
||||||
|
if ctxt.FormFieldIsSet("post1") {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ui.ErrorPage(ctxt, errors.New("invalid button clicked on form"))
|
||||||
|
}
|
||||||
|
|||||||
@@ -273,3 +273,13 @@ func AmDecodePostLink(data string) (*PostLinkData, error) {
|
|||||||
}
|
}
|
||||||
return &rc, nil
|
return &rc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AmCreatePostLinkContext(community string, conference string, topic int16) *PostLinkData {
|
||||||
|
return &PostLinkData{
|
||||||
|
Community: community,
|
||||||
|
Conference: conference,
|
||||||
|
Topic: topic,
|
||||||
|
FirstPost: -1,
|
||||||
|
LastPost: -1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ func setupEcho() *echo.Echo {
|
|||||||
e.GET("/comm/:cid/conf", ui.AmWrap(Conferences))
|
e.GET("/comm/:cid/conf", ui.AmWrap(Conferences))
|
||||||
e.GET("/comm/:cid/conf/:confid", ui.AmWrap(Topics))
|
e.GET("/comm/:cid/conf/:confid", ui.AmWrap(Topics))
|
||||||
e.GET("/comm/:cid/conf/:confid/new_topic", ui.AmWrap(NewTopicForm))
|
e.GET("/comm/:cid/conf/:confid/new_topic", ui.AmWrap(NewTopicForm))
|
||||||
|
e.POST("/comm/:cid/conf/:confid/new_topic", ui.AmWrap(NewTopic))
|
||||||
|
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user