implemented javascripts for approval/disapproval/unapproval from post/show page
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user