Skip to content

Commit

Permalink
post deletion possible
Browse files Browse the repository at this point in the history
  • Loading branch information
TangentFoxy committed Jan 6, 2018
1 parent 0ed53c7 commit 81819e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
13 changes: 13 additions & 0 deletions applications/posts.moon
Expand Up @@ -148,3 +148,16 @@ class extends lapis.Application
@title = "#{@post.title} (Editing)"
return render: "posts.edit"
}

[delete: "/delete/:id[%d]"]: =>
if is_admin @
if post = Posts\find id: @params.id
if post\delete!
@session.info = "Post deleted."
else
@session.info = "Error while deleting post!"
return redirect_to: @url_for "posts_edit", id: @params.id
else
@session.info = "A post with ID #{@params.id} does not exist. (Perhaps it was already deleted?)"

return redirect_to: @url_for "posts_index"
3 changes: 1 addition & 2 deletions views/posts/edit.moon
Expand Up @@ -107,9 +107,8 @@ class EditPost extends Widget
else
a class: "button", href: @url_for("posts_view", slug: @post.slug), "View Post"
input class: "button", type: "submit", value: "Update Post"
-- a class: "button", href: @url_for("posts_preview"), "Preview Changes"
a class: "button", href: @url_for("posts_delete", id: @post.id), onclick: "return confirm('Are you sure you want to delete this post?');", "Delete Post"
else
input class: "button", type: "submit", value: "Create Post"
-- a class: "button", href: @url_for("posts_preview"), "Preview Post"
input type: "hidden", name: "html", id: "html", value: @post.html
input type: "hidden", name: "preview_html", id: "preview_html", value: @post.preview_html
4 changes: 1 addition & 3 deletions views/posts/index.moon
Expand Up @@ -8,10 +8,8 @@ class PostIndex extends Widget
widget Pagination

for post in *@posts
-- div class: "container", ->
-- h2 class: "subtitle", post.title
div class: "content", ->
h2 class: "subtitle", post.title
h2 post.title
raw post.preview_html
h3 class: "subtitle is-6", ->
a href: @url_for("posts_view", slug: post.slug), "Read More"
Expand Down

0 comments on commit 81819e5

Please sign in to comment.