let blog moderators edit posts
parent
ec177b13a5
commit
5ebc321edb
|
@ -107,8 +107,8 @@ final class Ublog(env: Env) extends LilaController(env) {
|
|||
|
||||
def edit(id: String) = AuthBody { implicit ctx => me =>
|
||||
NotForKids {
|
||||
OptionOk(env.ublog.api.getPost(UblogPost.Id(id)).map(_.filter(_.isBy(me)))) { post =>
|
||||
html.ublog.form.edit(me, post, env.ublog.form.edit(post))
|
||||
OptionOk(env.ublog.api.findByUserBlogOrAdmin(UblogPost.Id(id), me)) { post =>
|
||||
html.ublog.form.edit(post, env.ublog.form.edit(post))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ final class Ublog(env: Env) extends LilaController(env) {
|
|||
.edit(prev)
|
||||
.bindFromRequest()(ctx.body, formBinding)
|
||||
.fold(
|
||||
err => BadRequest(html.ublog.form.edit(me, prev, err)).fuccess,
|
||||
err => BadRequest(html.ublog.form.edit(prev, err)).fuccess,
|
||||
data =>
|
||||
env.ublog.api.update(data, prev, me) map { post =>
|
||||
Redirect(urlOfPost(post)).flashSuccess
|
||||
|
|
|
@ -30,27 +30,30 @@ object form {
|
|||
standardFlash(),
|
||||
h1(trans.ublog.newPost()),
|
||||
etiquette,
|
||||
inner(user, f, none, captcha.some)
|
||||
inner(f, Left(user), captcha.some)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def edit(user: User, post: UblogPost, f: Form[UblogPostData])(implicit ctx: Context) =
|
||||
def edit(post: UblogPost, f: Form[UblogPostData])(implicit ctx: Context) =
|
||||
views.html.base.layout(
|
||||
moreCss = moreCss,
|
||||
moreJs = jsModule("ublogForm"),
|
||||
title = s"${trans.ublog.xBlog.txt(user.username)} blog • ${post.title}"
|
||||
title = s"${trans.ublog.xBlog.txt(titleNameOrId(post.created.by))} blog • ${post.title}"
|
||||
) {
|
||||
main(cls := "page-menu page-small")(
|
||||
views.html.blog.bits.menu(none, "mine".some),
|
||||
div(cls := "page-menu__content box box-pad ublog-post-form")(
|
||||
standardFlash(),
|
||||
div(cls := "box__top")(
|
||||
h1(trans.ublog.editYourBlogPost()),
|
||||
h1(
|
||||
if (ctx isUserId post.created.by) trans.ublog.editYourBlogPost()
|
||||
else s"Edit ${usernameOrId(post.created.by)}'s post"
|
||||
),
|
||||
a(href := postView.urlOfPost(post), dataIcon := "", cls := "text", targetBlank)("Preview")
|
||||
),
|
||||
imageForm(user, post),
|
||||
inner(user, f, post.some, none),
|
||||
imageForm(post),
|
||||
inner(f, Right(post), none),
|
||||
postForm(
|
||||
cls := "ublog-post-form__delete",
|
||||
action := routes.Ublog.delete(post.id.value)
|
||||
|
@ -66,7 +69,7 @@ object form {
|
|||
)
|
||||
}
|
||||
|
||||
private def imageForm(user: User, post: UblogPost)(implicit ctx: Context) =
|
||||
private def imageForm(post: UblogPost)(implicit ctx: Context) =
|
||||
postForm(
|
||||
cls := "ublog-post-form__image",
|
||||
action := routes.Ublog.image(post.id.value),
|
||||
|
@ -84,15 +87,15 @@ object form {
|
|||
|
||||
def formImage(post: UblogPost) = postView.thumbnail(post, _.Small)
|
||||
|
||||
private def inner(user: User, form: Form[UblogPostData], post: Option[UblogPost], captcha: Option[Captcha])(
|
||||
private def inner(form: Form[UblogPostData], post: Either[User, UblogPost], captcha: Option[Captcha])(
|
||||
implicit ctx: Context
|
||||
) =
|
||||
postForm(
|
||||
cls := "form3",
|
||||
action := post.fold(routes.Ublog.create)(p => routes.Ublog.update(p.id.value))
|
||||
action := post.fold(_ => routes.Ublog.create, p => routes.Ublog.update(p.id.value))
|
||||
)(
|
||||
form3.globalError(form),
|
||||
post.isDefined option form3.split(
|
||||
post.isRight option form3.split(
|
||||
form3.checkbox(
|
||||
form("live"),
|
||||
trans.ublog.publishOnYourBlog(),
|
||||
|
@ -131,10 +134,13 @@ object form {
|
|||
views.html.base.captcha(form, c)
|
||||
},
|
||||
form3.actions(
|
||||
a(href := post.fold(routes.Ublog.index(user.username))(views.html.ublog.post.urlOfPost))(
|
||||
a(
|
||||
href := post
|
||||
.fold(user => routes.Ublog.index(user.username), views.html.ublog.post.urlOfPost)
|
||||
)(
|
||||
trans.cancel()
|
||||
),
|
||||
form3.submit((if (post.isDefined) trans.apply else trans.ublog.saveDraft)())
|
||||
form3.submit((if (post.isRight) trans.apply else trans.ublog.saveDraft)())
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ object post {
|
|||
views.html.blog.bits.menu(none, (if (ctx is user) "mine" else "community").some),
|
||||
div(cls := "page-menu__content box box-pad ublog-post")(
|
||||
post.image.isDefined option thumbnail(post, _.Large)(cls := "ublog-post__image"),
|
||||
ctx.is(user) option standardFlash(),
|
||||
ctx.is(user) || isGranted(_.ModerateBlog) option standardFlash(),
|
||||
h1(cls := "ublog-post__title")(post.title),
|
||||
div(cls := "ublog-post__meta")(
|
||||
a(
|
||||
|
@ -74,19 +74,18 @@ object post {
|
|||
if (post.live) trans.ublog.thisPostIsPublished() else trans.ublog.thisIsADraft()
|
||||
),
|
||||
" ",
|
||||
a(
|
||||
href := editUrlOfPost(post),
|
||||
cls := "button button-empty text",
|
||||
dataIcon := ""
|
||||
)(trans.edit())
|
||||
editButton(post)
|
||||
)
|
||||
else if (isGranted(_.ModerateBlog))
|
||||
form(
|
||||
method := "post",
|
||||
action := routes.Ublog.delete(post.id.value),
|
||||
cls := "ublog-post__meta__delete",
|
||||
title := "MOD: Delete this post"
|
||||
)(submitButton(dataIcon := "", cls := "button button-empty button-red confirm"))
|
||||
frag(
|
||||
editButton(post),
|
||||
form(
|
||||
method := "post",
|
||||
action := routes.Ublog.delete(post.id.value),
|
||||
cls := "ublog-post__meta__delete",
|
||||
title := "MOD: Delete this post"
|
||||
)(submitButton(dataIcon := "", cls := "button button-empty button-red confirm"))
|
||||
)
|
||||
else
|
||||
a(
|
||||
titleOrText(trans.reportXToModerators.txt(user.username)),
|
||||
|
@ -117,6 +116,12 @@ object post {
|
|||
)
|
||||
}
|
||||
|
||||
private def editButton(post: UblogPost)(implicit ctx: Context) = a(
|
||||
href := editUrlOfPost(post),
|
||||
cls := "button button-empty text",
|
||||
dataIcon := ""
|
||||
)(trans.edit())
|
||||
|
||||
private def likeButton(post: UblogPost, liked: Boolean)(implicit ctx: Context) = button(
|
||||
tpe := "button",
|
||||
cls := List(
|
||||
|
|
|
@ -19,6 +19,8 @@ sealed trait UserContext {
|
|||
|
||||
def is(user: User): Boolean = me contains user
|
||||
|
||||
def isUserId(id: User.ID): Boolean = userId contains id
|
||||
|
||||
def userId = me.map(_.id)
|
||||
|
||||
def username = me.map(_.username)
|
||||
|
|
Loading…
Reference in New Issue