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
|
||||
|
||||
@@ -33,6 +33,10 @@ module ApplicationHelper
|
||||
end
|
||||
end
|
||||
|
||||
def wait_image(html_id)
|
||||
('<img src="/images/wait.gif" style="display: none;" id="' + html_id + '">').html_safe
|
||||
end
|
||||
|
||||
protected
|
||||
def nav_link_match(controller, url)
|
||||
url =~ case controller
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Post < ActiveRecord::Base
|
||||
class ApprovalError < Exception ; end
|
||||
class DisapprovalError < Exception ; end
|
||||
|
||||
attr_accessor :old_tag_string, :old_parent_id
|
||||
after_destroy :delete_files
|
||||
@@ -203,6 +204,10 @@ class Post < ActiveRecord::Base
|
||||
is_pending == false && is_flagged == false && unapproval.nil?
|
||||
end
|
||||
|
||||
def is_approvable?
|
||||
(is_pending? || is_flagged?) && approver_string != "approver:#{CurrentUser.name}"
|
||||
end
|
||||
|
||||
def unapprove!(reason)
|
||||
raise Unapproval::Error.new("This post is still pending approval") if is_pending?
|
||||
raise Unapproval::Error.new("This post has already been flagged") if is_flagged?
|
||||
@@ -222,7 +227,7 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def approve!
|
||||
raise ApprovalError.new("You have already approved this post previously") if approver_string == "approver:#{CurrentUser.name}"
|
||||
raise ApprovalError.new("You have previously approved this post and cannot approve it again") if approver_string == "approver:#{CurrentUser.name}"
|
||||
|
||||
self.is_flagged = false
|
||||
self.is_pending = false
|
||||
|
||||
@@ -4,7 +4,22 @@ class Unapproval < ActiveRecord::Base
|
||||
belongs_to :unapprover, :class_name => "User"
|
||||
belongs_to :post
|
||||
validates_presence_of :reason, :unapprover_id, :unapprover_ip_addr
|
||||
validate :validate_post_is_active
|
||||
before_validation :initialize_unapprover, :on => :create
|
||||
before_save :flag_post
|
||||
|
||||
def validate_post_is_active
|
||||
if post.is_pending? || post.is_flagged? || post.is_removed?
|
||||
errors[:post] << "is inactive"
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def flag_post
|
||||
post.update_attribute(:is_flagged, true)
|
||||
end
|
||||
|
||||
def initialize_unapprover
|
||||
self.unapprover_id = CurrentUser.id
|
||||
|
||||
2
app/views/post_moderation/approval_error.js.erb
Normal file
2
app/views/post_moderation/approval_error.js.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
Danbooru.Utility.j_error(<%= @exception.message.to_json.html_safe %>);
|
||||
$("img#approve-wait").hide();
|
||||
4
app/views/post_moderation/approve.js.erb
Normal file
4
app/views/post_moderation/approve.js.erb
Normal file
@@ -0,0 +1,4 @@
|
||||
$("a#approve").hide();
|
||||
$("a#disapprove").hide();
|
||||
$("a#unapprove").show();
|
||||
$("img#approve-wait").hide();
|
||||
2
app/views/post_moderation/disapproval_error.js.erb
Normal file
2
app/views/post_moderation/disapproval_error.js.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
Danbooru.Utility.j_error("You have already disapproved this post");
|
||||
$("img#disapprove-wait").hide();
|
||||
4
app/views/post_moderation/disapprove.js
Normal file
4
app/views/post_moderation/disapprove.js
Normal file
@@ -0,0 +1,4 @@
|
||||
$("a#approve").hide();
|
||||
$("a#disapprove").hide();
|
||||
$("a#unapprove").hide();
|
||||
$("img#disapprove-wait").hide();
|
||||
@@ -1,16 +1,12 @@
|
||||
<ul>
|
||||
<%= resize_image_links(post, CurrentUser.user) %>
|
||||
<li><%= link_to "Favorite", "#", :id => "add-to-favorites" %> <img src="/images/wait.gif" style="display: none;" id="add-to-favorites-wait"></li>
|
||||
<li><%= link_to "Unfavorite", "#", :id => "remove-from-favorites" %> <img src="/images/wait.gif" style="display: none;" id="remove-from-favorites-wait"></li>
|
||||
<li><%= link_to "Favorite", "#", :id => "add-to-favorites" %> <%= wait_image("add-to-favorites-wait") %></li>
|
||||
<li><%= link_to "Unfavorite", "#", :id => "remove-from-favorites" %> <%= wait_image("remove-from-favorites-wait") %></li>
|
||||
<li><%= link_to "Translate", "#" %></li>
|
||||
<% if !post.is_flagged? %>
|
||||
<li><%= link_to "Unapprove", new_unapproval_path(:post_id => post.id), :id => "unapprove" %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Unapprove", new_unapproval_path(:post_id => post.id), :id => "unapprove" %></li>
|
||||
<% if CurrentUser.is_janitor? %>
|
||||
<% if post.is_pending? || post.is_flagged? %>
|
||||
<li><%= link_to "Approve", "#", :id => "approve" %> <img src="/images/wait.gif" style="display: none;" id="approve-wait"></li>
|
||||
<li><%= link_to "Disapprove", "#", :id => "disapprove" %> <img src="/images/wait.gif" style="display: none;" id="disapprove-wait"></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Approve", "#", :id => "approve" %> <%= wait_image("approve-wait") %></li>
|
||||
<li><%= link_to "Disapprove", "#", :id => "disapprove" %> <%= wait_image("disapprove-wait") %></li>
|
||||
<% end %>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<% if post.is_removed? %>
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
<meta name="pools" content="<%= @post.pool_string %>">
|
||||
<meta name="post-id" content="<%= @post.id %>">
|
||||
<meta name="post-is-unapprovable" content="<%= @post.is_unapprovable? %>">
|
||||
<meta name="post-is-approvable" content="<%= @post.is_approvable? %>">
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "posts/partials/common/secondary_links" %>
|
||||
|
||||
9
app/views/unapprovals/create.js.erb
Normal file
9
app/views/unapprovals/create.js.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
var errors = <%= @unapproval.errors.full_messages.to_json.html_safe %>;
|
||||
if (errors.length > 0) {
|
||||
Danbooru.Utility.j_error(errors.join("; "));
|
||||
} else {
|
||||
Danbooru.Utility.j_alert("Unapproval", "Unapproval successful");
|
||||
$("a#approve").show();
|
||||
$("a#disapprove").show();
|
||||
$("a#unapprove").hide();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<p>You can unapprove a post if you believe it breaks the rules or doesn't belong on this site. You must provide a reason.</p>
|
||||
<%= form_for(@unapproval) do |f| %>
|
||||
<%= form_for(@unapproval, :remote => true, :format => :js) do |f| %>
|
||||
<%= hidden_field_tag "unapproval[post_id]", @unapproval.post_id %>
|
||||
<%= f.text_area :reason, :size => "40x5" %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user