# HG changeset patch # User Chris Cannam # Date 1299242786 0 # Node ID 3ecf99348b9f4ee52736a39aa586963958b2a17a # Parent e0dc03c8d7458a1dabd2b42ee03d81eac90a7d95 * Enable toggling file active state through the files interface diff -r e0dc03c8d745 -r 3ecf99348b9f app/controllers/attachments_controller.rb --- a/app/controllers/attachments_controller.rb Thu Mar 03 19:52:16 2011 +0000 +++ b/app/controllers/attachments_controller.rb Fri Mar 04 12:46:26 2011 +0000 @@ -16,9 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AttachmentsController < ApplicationController + before_filter :find_project before_filter :file_readable, :read_authorize, :except => :destroy before_filter :delete_authorize, :only => :destroy + before_filter :active_authorize, :only => :toggle_active verify :method => :post, :only => :destroy @@ -54,6 +56,12 @@ redirect_to :controller => 'projects', :action => 'show', :id => @project end + def toggle_active + @attachment.active = !@attachment.active? + @attachment.save! + render :layout => false + end + private def find_project @attachment = Attachment.find(params[:id]) @@ -77,6 +85,10 @@ @attachment.deletable? ? true : deny_access end + def active_authorize + true + end + def detect_content_type(attachment) content_type = attachment.content_type if content_type.blank? diff -r e0dc03c8d745 -r 3ecf99348b9f app/controllers/files_controller.rb --- a/app/controllers/files_controller.rb Thu Mar 03 19:52:16 2011 +0000 +++ b/app/controllers/files_controller.rb Fri Mar 04 12:46:26 2011 +0000 @@ -34,4 +34,5 @@ end redirect_to project_files_path(@project) end + end diff -r e0dc03c8d745 -r 3ecf99348b9f app/views/attachments/toggle_active.rhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/attachments/toggle_active.rhtml Fri Mar 04 12:46:26 2011 +0000 @@ -0,0 +1,7 @@ +<%= +file = Attachment.find(params[:id]) +active_id = "active-" + file.id.to_s +link_to_remote image_tag(file.active? ? 'true.png' : 'false.png'), + :url => {:controller => 'attachments', :action => 'toggle_active', :project_id => @project.id, :id => file}, + :update => active_id +%> diff -r e0dc03c8d745 -r 3ecf99348b9f app/views/files/index.html.erb --- a/app/views/files/index.html.erb Thu Mar 03 19:52:16 2011 +0000 +++ b/app/views/files/index.html.erb Fri Mar 04 12:46:26 2011 +0000 @@ -29,13 +29,19 @@ <% end -%> <% container.attachments.each do |file| %> "> - <%= - if active_change_allowed - check_box_tag 'active', file.id, file.active? - else - image_tag('fav.png') if file.active? - end - %> + + <% if active_change_allowed + active_id = "active-" + file.id.to_s -%> +
+ <%= link_to_remote image_tag(file.active? ? 'true.png' : 'false.png'), + :url => {:controller => 'attachments', :action => 'toggle_active', :project_id => @project.id, :id => file}, + :update => active_id + %> +
+ <% else -%> + <%= image_tag('fav.png') if file.active? %> + <% end -%> + "><%= link_to_attachment file, :download => true, :title => file.description %> <%= format_time(file.created_on) %> <%= number_to_human_size(file.filesize) %> @@ -52,4 +58,6 @@ +<%= l(:text_files_active_change) if active_change_allowed %> + <% html_title(l(:label_attachment_plural)) -%> diff -r e0dc03c8d745 -r 3ecf99348b9f config/routes.rb --- a/config/routes.rb Thu Mar 03 19:52:16 2011 +0000 +++ b/config/routes.rb Fri Mar 04 12:46:26 2011 +0000 @@ -165,6 +165,8 @@ end +# map.connect 'projects/:id/files/toggle_active', :controller => 'files', :action => 'toggle_active', :conditions => {:method => :post} + # Destroy uses a get request to prompt the user before the actual DELETE request map.project_destroy_confirm 'projects/:id/destroy', :controller => 'projects', :action => 'destroy', :conditions => {:method => :get}