diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-04-04 11:53:29 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-04-04 11:53:29 +0000 |
commit | 8a3151728875f0fc542f0fe7e32e728fe28cd657 (patch) | |
tree | 62285561aaba19e96192b8fc92203da685884096 /app/controllers/timelog_controller.rb | |
parent | ab31a114fd9a972e0d850c3438abaf031ebf84cd (diff) | |
download | redmine-8a3151728875f0fc542f0fe7e32e728fe28cd657.tar.gz redmine-8a3151728875f0fc542f0fe7e32e728fe28cd657.zip |
add bulk edit and bulk update actions for time entries (#7996).
get bulk edit form action working by mapping permissions.
Contributed by Adam Soltys.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5313 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/timelog_controller.rb')
-rw-r--r-- | app/controllers/timelog_controller.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index 604a8f244..6d78c514f 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -19,6 +19,7 @@ class TimelogController < ApplicationController menu_item :issues before_filter :find_project, :only => [:new, :create] before_filter :find_time_entry, :only => [:show, :edit, :update, :destroy] + before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update] before_filter :authorize, :except => [:index] before_filter :find_optional_project, :only => [:index] accept_key_auth :index, :show, :create, :update, :destroy @@ -160,6 +161,28 @@ class TimelogController < ApplicationController end end + def bulk_edit + @available_activities = TimeEntryActivity.shared.active + @custom_fields = TimeEntry.first.available_custom_fields + end + + def bulk_update + attributes = parse_params_for_bulk_time_entry_attributes(params) + + unsaved_time_entry_ids = [] + @time_entries.each do |time_entry| + time_entry.reload + time_entry.attributes = attributes + call_hook(:controller_time_entries_bulk_edit_before_save, { :params => params, :time_entry => time_entry }) + unless time_entry.save + # Keep unsaved time_entry ids to display them in flash error + unsaved_time_entry_ids << time_entry.id + end + end + set_flash_from_bulk_time_entry_save(@time_entries, unsaved_time_entry_ids) + redirect_back_or_default({:controller => 'timelog', :action => 'index', :project_id => @project}) + end + verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } def destroy if @time_entry.destroy && @time_entry.destroyed? @@ -195,6 +218,26 @@ private render_404 end + def find_time_entries + @time_entries = TimeEntry.find_all_by_id(params[:id] || params[:ids]) + raise ActiveRecord::RecordNotFound if @time_entries.empty? + @projects = @time_entries.collect(&:project).compact.uniq + @project = @projects.first if @projects.size == 1 + rescue ActiveRecord::RecordNotFound + render_404 + end + + def set_flash_from_bulk_time_entry_save(time_entries, unsaved_time_entry_ids) + if unsaved_time_entry_ids.empty? + flash[:notice] = l(:notice_successful_update) unless time_entries.empty? + else + flash[:error] = l(:notice_failed_to_save_time_entries, + :count => unsaved_time_entry_ids.size, + :total => time_entries.size, + :ids => '#' + unsaved_time_entry_ids.join(', #')) + end + end + def find_project if (issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id])).present? @issue = Issue.find(issue_id) @@ -265,4 +308,10 @@ private @to ||= (TimeEntry.latest_date_for_project(@project) || Date.today) end + def parse_params_for_bulk_time_entry_attributes(params) + attributes = (params[:time_entry] || {}).reject {|k,v| v.blank?} + attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} + attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] + attributes + end end |