implemented javascripts for approval/disapproval/unapproval from post/show page

This commit is contained in:
albert
2011-02-10 19:08:23 -05:00
parent 00ea319743
commit 33f5350677
19 changed files with 234 additions and 17 deletions

View File

@@ -1,22 +1,50 @@
class PostModerationController < ApplicationController
respond_to :html, :xml, :json
before_filter :janitor_only
rescue_from Post::ApprovalError, :with => :approval_error
rescue_from Post::DisapprovalError, :with => :disapproval_error
def moderate
@search = Post.pending.available_for_moderation.search(params[:search]).order("id asc")
@posts = @search.paginate(:page => params[:page])
respond_with(@posts)
respond_to do |format|
format.html
format.json {render :json => @posts.to_json}
end
end
def approve
@post = Post.find(params[:post_id])
@post.approve!
respond_with(@post, :location => post_moderation_moderate_path)
respond_to do |format|
format.html {redirect_to(post_moderation_moderate_path, :notice => "Post approved")}
format.js
end
end
def disapprove
@post = Post.find(params[:post_id])
@post_disapproval = PostDisapproval.create(:post => @post, :user => CurrentUser.user)
respond_with(@post_disapproval, :location => post_moderation_moderate_path)
if @post_disapproval.errors.any?
raise Post::DisapprovalError.new(@post_disapproval.errors.full_messages)
end
respond_to do |format|
format.html {redirect_to(post_moderation_moderate_path, :notice => "Post disapproved")}
format.js
end
end
private
def disapproval_error(e)
respond_to do |format|
format.html {redirect_to(post_moderation_moderate_path, :notice => "You have already disapproved this post")}
format.js {render :action => "disapproval_error"}
end
end
def approval_error(e)
respond_to do |format|
format.html {redirect_to(post_moderation_moderate_path, :notice => e.message)}
format.js {@exception = e; render :action => "approval_error"}
end
end
end

View File

@@ -1,6 +1,6 @@
class UnapprovalsController < ApplicationController
before_filter :member_only
respond_to :html, :xml, :json
respond_to :html, :xml, :json, :js
rescue_from User::PrivilegeError, :with => "static/access_denied"
def new
@@ -15,7 +15,7 @@ class UnapprovalsController < ApplicationController
def create
@unapproval = Unapproval.create(params[:unapproval])
respond_with(@unapproval, :location => post_path(@unapproval.post_id))
respond_with(@unapproval)
end
def destroy