lila/app/views/forum/topic.scala

234 lines
8.0 KiB
Scala
Raw Normal View History

2019-02-11 22:04:27 -07:00
package views.html
package forum
import play.api.data.Form
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.paginator.Paginator
import controllers.routes
object topic {
def form(categ: lila.forum.Categ, form: Form[_], captcha: lila.common.Captcha)(implicit ctx: Context) =
2019-04-13 20:50:24 -06:00
views.html.base.layout(
title = "New forum topic",
2019-04-21 08:33:50 -06:00
moreCss = cssTag("forum"),
2019-04-13 20:50:24 -06:00
moreJs = frag(
jsModule("forum"),
2019-04-13 20:50:24 -06:00
captchaTag
)
) {
2019-12-13 07:30:20 -07:00
main(cls := "forum forum-topic topic-form page-small box box-pad")(
h1(
a(href := routes.ForumCateg.show(categ.slug), dataIcon := "", cls := "text"),
2019-12-13 07:30:20 -07:00
categ.name
),
st.section(cls := "warning")(
h2(dataIcon := "", cls := "text")(trans.important()),
2019-12-13 07:30:20 -07:00
p(
trans.yourQuestionMayHaveBeenAnswered(
strong(a(href := routes.Main.faq)(trans.inTheFAQ()))
2020-04-29 10:43:33 -06:00
)
2019-02-11 22:04:27 -07:00
),
2019-12-13 07:30:20 -07:00
p(
trans.toReportSomeoneForCheatingOrBadBehavior(
strong(a(href := routes.Report.form)(trans.useTheReportForm()))
)
2019-02-11 22:04:27 -07:00
),
2019-12-13 07:30:20 -07:00
p(
trans.toRequestSupport(
strong(a(href := routes.Main.contact)(trans.tryTheContactPage()))
)
),
p(
"Make sure to read ",
strong(a(href := routes.Page.loneBookmark("forum-etiquette"))("the forum etiquette"))
2019-12-13 07:30:20 -07:00
)
),
postForm(cls := "form3", action := routes.ForumTopic.create(categ.slug))(
form3.group(form("name"), trans.subject())(form3.input(_)(autofocus)),
form3.group(form("post")("text"), trans.message())(
form3.textarea(_, klass = "post-text-area")(rows := 10)
),
views.html.base.captcha(form("post"), captcha),
form3.actions(
a(href := routes.ForumCateg.show(categ.slug))(trans.cancel()),
isGranted(_.PublicMod) option
form3.submit(
2020-04-29 13:15:49 -06:00
frag("Create as a mod"),
2019-12-13 07:30:20 -07:00
nameValue = (form("post")("modIcon").name, "true").some,
icon = "".some
),
form3.submit(trans.createTheTopic())
2019-02-11 22:04:27 -07:00
)
)
2019-12-13 07:30:20 -07:00
)
}
2019-02-11 22:04:27 -07:00
def show(
2019-12-13 07:30:20 -07:00
categ: lila.forum.Categ,
topic: lila.forum.Topic,
posts: Paginator[lila.forum.Post],
formWithCaptcha: Option[FormWithCaptcha],
unsub: Option[Boolean],
canModCateg: Boolean
)(implicit ctx: Context) =
views.html.base.layout(
title = s"${topic.name} • page ${posts.currentPage}/${posts.nbPages}${categ.name}",
moreJs = frag(
jsModule("forum"),
2019-12-13 07:30:20 -07:00
formWithCaptcha.isDefined option captchaTag,
2020-09-21 10:01:43 -06:00
jsModule("expandText")
2019-12-13 07:30:20 -07:00
),
moreCss = cssTag("forum"),
openGraph = lila.app.ui
.OpenGraph(
title = topic.name,
url = s"$netBaseUrl${routes.ForumTopic.show(categ.slug, topic.slug, posts.currentPage).url}",
description = shorten(posts.currentPageResults.headOption.??(_.text), 152)
)
.some
) {
val teamOnly = categ.team.filterNot(myTeam)
val pager = views.html.base.bits
.paginationByQuery(routes.ForumTopic.show(categ.slug, topic.slug, 1), posts, showPost = true)
2019-02-11 22:04:27 -07:00
2019-04-23 20:10:03 -06:00
main(cls := "forum forum-topic page-small box box-pad")(
2019-02-11 22:04:27 -07:00
h1(
a(
href := routes.ForumCateg.show(categ.slug),
dataIcon := "",
2019-02-11 22:04:27 -07:00
cls := "text"
),
topic.name
),
2019-02-12 00:20:01 -07:00
pager,
2020-09-02 09:53:29 -06:00
div(cls := "forum-topic__posts expand-text")(
2019-02-12 00:20:01 -07:00
posts.currentPageResults.map { p =>
post.show(
categ,
topic,
p,
s"${routes.ForumTopic.show(categ.slug, topic.slug, posts.currentPage)}#${p.number}",
canModCateg = canModCateg,
canReact = teamOnly.isEmpty
2019-02-11 22:04:27 -07:00
)
}
),
2019-02-12 00:20:01 -07:00
div(cls := "forum-topic__actions")(
2019-05-11 00:54:30 -06:00
if (posts.hasNextPage) emptyFrag
else if (topic.isOld)
p(trans.thisTopicIsArchived())
2019-02-12 00:20:01 -07:00
else if (formWithCaptcha.isDefined)
2019-04-22 03:42:25 -06:00
h2(id := "reply")(trans.replyToThisTopic())
else if (topic.closed) p(trans.thisTopicIsNowClosed())
2019-12-13 07:30:20 -07:00
else
teamOnly.map { teamId =>
2019-12-13 07:30:20 -07:00
p(
trans.joinTheTeamXToPost(
2020-04-29 10:43:33 -06:00
a(href := routes.Team.show(teamId))(trans.teamNamedX(teamIdToName(teamId)))
)
2019-12-13 07:30:20 -07:00
)
2021-02-10 15:04:24 -07:00
} orElse {
if (ctx.me.exists(_.isBot)) p("Bots cannot post in the forum.").some
else ctx.isAuth option p(trans.youCannotPostYetPlaySomeGames())
2020-08-03 11:12:17 -06:00
},
2019-02-12 00:20:01 -07:00
div(
unsub.map { uns =>
2019-12-13 07:30:20 -07:00
postForm(
cls := s"unsub ${if (uns) "on" else "off"}",
action := routes.Timeline.unsub(s"forum:${topic.id}")
)(
button(cls := "button button-empty text on", dataIcon := "", bits.dataUnsub := "off")(
trans.subscribe()
2019-12-13 07:30:20 -07:00
),
button(cls := "button button-empty text off", dataIcon := "", bits.dataUnsub := "on")(
trans.unsubscribe()
2019-12-13 07:30:20 -07:00
)
2019-02-11 22:04:27 -07:00
)
2019-02-12 00:20:01 -07:00
},
isGranted(_.ModerateForum) option
2019-08-02 01:54:15 -06:00
postForm(action := routes.ForumTopic.hide(categ.slug, topic.slug))(
2019-12-13 07:30:20 -07:00
button(cls := "button button-empty button-green")(
2020-04-29 13:15:49 -06:00
if (topic.hidden) "Feature" else "Un-feature"
2019-12-13 07:30:20 -07:00
)
2019-02-12 00:20:01 -07:00
),
canModCateg option frag(
2019-08-02 01:54:15 -06:00
postForm(action := routes.ForumTopic.close(categ.slug, topic.slug))(
2020-04-29 10:43:33 -06:00
button(cls := "button button-empty button-red")(
2020-04-29 13:15:49 -06:00
if (topic.closed) "Reopen" else "Close"
2020-04-29 10:43:33 -06:00
)
2019-02-12 00:20:01 -07:00
),
2019-08-02 01:54:15 -06:00
postForm(action := routes.ForumTopic.sticky(categ.slug, topic.slug))(
2019-12-13 07:30:20 -07:00
button(cls := "button button-empty button-brag")(
2020-04-29 13:15:49 -06:00
if (topic.isSticky) "Unsticky" else "Sticky"
2019-12-13 07:30:20 -07:00
)
),
deleteModal
)
2019-02-12 00:20:01 -07:00
)
2019-02-11 22:04:27 -07:00
),
2020-09-21 01:28:28 -06:00
formWithCaptcha.map { case (form, captcha) =>
postForm(
cls := "form3 reply",
action := s"${routes.ForumPost.create(categ.slug, topic.slug, posts.currentPage)}#reply",
novalidate
)(
form3.group(
form("text"),
trans.message(),
help = a(dataIcon := "", cls := "text", href := routes.Page.loneBookmark("forum-etiquette"))(
"Forum etiquette"
).some
) { f =>
2020-09-21 01:28:28 -06:00
form3.textarea(f, klass = "post-text-area")(rows := 10, bits.dataTopic := topic.id)
},
views.html.base.captcha(form, captcha),
form3.actions(
a(href := routes.ForumCateg.show(categ.slug))(trans.cancel()),
isGranted(_.PublicMod) option
form3.submit(
frag("Reply as a mod"),
nameValue = (form("modIcon").name, "true").some,
icon = "".some
),
form3.submit(trans.reply())
2019-02-12 00:20:01 -07:00
)
2020-09-21 01:28:28 -06:00
)
},
pager
2019-02-11 22:04:27 -07:00
)
}
private def deleteModal(implicit ctx: Context) =
div(cls := "forum-delete-modal none")(
p("Delete the post"),
st.form(method := "post", cls := "form3")(
st.select(
name := "reason",
cls := "form-control"
)(
option(value := "")("no message"),
List(
"public shaming",
"disrespecting other players",
"spamming",
"inappropriate behavior"
).map { reason =>
option(value := reason)(reason)
}
),
form3.actions(
button(cls := "cancel button button-empty", value := "cancel")("Cancel"),
form3.submit(
frag("Delete the post"),
klass = "button-red"
)(value := "default")
)
)
)
2019-02-11 22:04:27 -07:00
}