fixed pool deletion logic

This commit is contained in:
albert
2012-03-15 18:26:39 -04:00
parent 1736ed17a9
commit 779d83e253
7 changed files with 48 additions and 8 deletions

View File

@@ -49,10 +49,19 @@ class PoolsController < ApplicationController
if !@pool.deletable_by?(CurrentUser.user)
raise User::PrivilegeError
end
@pool.destroy
@pool.update_attribute(:is_deleted, true)
respond_with(@pool, :notice => "Pool deleted")
end
def undelete
@pool = Pool.find(params[:id])
if !@pool.deletable_by?(CurrentUser.user)
raise User::PrivilegeError
end
@pool.update_attribute(:is_deleted, false)
respond_with(@pool, :notice => "Pool undeleted")
end
def revert
@pool = Pool.find(params[:id])
@version = PoolVersion.find(params[:version_id])

View File

@@ -12,9 +12,9 @@ class Pool < ActiveRecord::Base
before_validation :initialize_creator, :on => :create
after_save :create_version
before_destroy :create_mod_action_for_destroy
attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :as => [:member, :privileged, :contributor, :janitor, :moderator, :admin, :default]
attr_accessible :is_active, :as => [:janitor, :moderator, :admin]
scope :active, where("is_active = true")
attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :as => [:member, :privileged, :contributor, :janitor, :moderator, :admin, :default]
attr_accessible :is_deleted, :as => [:janitor, :moderator, :admin]
scope :active, where("is_active = true and is_deleted = false")
def self.name_to_id(name)
if name =~ /^\d+$/
@@ -56,6 +56,7 @@ class Pool < ActiveRecord::Base
end
def initialize_is_active
self.is_deleted = false if is_deleted.nil?
self.is_active = true if is_active.nil?
end

View File

@@ -9,7 +9,11 @@
<li><%= link_to "Posts", posts_path(:tags => "pool:#{@pool.id}") %></li>
<li><%= link_to "Edit", edit_pool_path(@pool) %></li>
<% if @pool.deletable_by?(CurrentUser.user) %>
<li><%= link_to "Delete", pool_path(@pool), :method => :delete, :confirm => "Are you sure you want to delete this pool?", :remote => true %></li>
<% if @pool.is_deleted? %>
<li><%= link_to "Undelete", undelete_pool_path(@pool), :method => :post, :remote => true %></li>
<% else %>
<li><%= link_to "Delete", pool_path(@pool), :method => :delete, :confirm => "Are you sure you want to delete this pool?", :remote => true %></li>
<% end %>
<% end %>
<li><%= link_to "Order", edit_pool_order_path(@pool) %></li>
<% end %>

View File

@@ -46,6 +46,8 @@
<menu id="post-sections">
<li><a href="#comments">Comments</a></li>
<li><a href="#edit" id="post-edit-link">Edit</a></li>
<li><a href="#favorite-tab">Favorite</a></li>
<li><a href="#share">Share</a></li>
</menu>
<section id="comments">
@@ -59,6 +61,14 @@
<section id="edit" style="display: none;">
<%= render "posts/partials/show/edit", :post => @post %>
</section>
<section id="favorite-tab" style="display: none;">
<p>Favoriting...</p>
</section>
<section id="share-tab" style="display: none;">
<h1>Share</h1>
</section>
</section>
</div>