##// END OF EJS Templates
Allows bulk change issue private flag (#10042)....
Jean-Philippe Lang -
r8576:7f4e3771d8dc
parent child
Show More
@@ -1,406 +1,407
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class IssuesController < ApplicationController
18 class IssuesController < ApplicationController
19 menu_item :new_issue, :only => [:new, :create]
19 menu_item :new_issue, :only => [:new, :create]
20 default_search_scope :issues
20 default_search_scope :issues
21
21
22 before_filter :find_issue, :only => [:show, :edit, :update]
22 before_filter :find_issue, :only => [:show, :edit, :update]
23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy]
23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy]
24 before_filter :check_project_uniqueness, :only => [:move, :perform_move]
24 before_filter :check_project_uniqueness, :only => [:move, :perform_move]
25 before_filter :find_project, :only => [:new, :create]
25 before_filter :find_project, :only => [:new, :create]
26 before_filter :authorize, :except => [:index]
26 before_filter :authorize, :except => [:index]
27 before_filter :find_optional_project, :only => [:index]
27 before_filter :find_optional_project, :only => [:index]
28 before_filter :check_for_default_issue_status, :only => [:new, :create]
28 before_filter :check_for_default_issue_status, :only => [:new, :create]
29 before_filter :build_new_issue_from_params, :only => [:new, :create]
29 before_filter :build_new_issue_from_params, :only => [:new, :create]
30 accept_rss_auth :index, :show
30 accept_rss_auth :index, :show
31 accept_api_auth :index, :show, :create, :update, :destroy
31 accept_api_auth :index, :show, :create, :update, :destroy
32
32
33 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
33 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
34
34
35 helper :journals
35 helper :journals
36 helper :projects
36 helper :projects
37 include ProjectsHelper
37 include ProjectsHelper
38 helper :custom_fields
38 helper :custom_fields
39 include CustomFieldsHelper
39 include CustomFieldsHelper
40 helper :issue_relations
40 helper :issue_relations
41 include IssueRelationsHelper
41 include IssueRelationsHelper
42 helper :watchers
42 helper :watchers
43 include WatchersHelper
43 include WatchersHelper
44 helper :attachments
44 helper :attachments
45 include AttachmentsHelper
45 include AttachmentsHelper
46 helper :queries
46 helper :queries
47 include QueriesHelper
47 include QueriesHelper
48 helper :repositories
48 helper :repositories
49 include RepositoriesHelper
49 include RepositoriesHelper
50 helper :sort
50 helper :sort
51 include SortHelper
51 include SortHelper
52 include IssuesHelper
52 include IssuesHelper
53 helper :timelog
53 helper :timelog
54 helper :gantt
54 helper :gantt
55 include Redmine::Export::PDF
55 include Redmine::Export::PDF
56
56
57 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
57 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
58 verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
58 verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
59 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
59 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
60
60
61 def index
61 def index
62 retrieve_query
62 retrieve_query
63 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
63 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
64 sort_update(@query.sortable_columns)
64 sort_update(@query.sortable_columns)
65
65
66 if @query.valid?
66 if @query.valid?
67 case params[:format]
67 case params[:format]
68 when 'csv', 'pdf'
68 when 'csv', 'pdf'
69 @limit = Setting.issues_export_limit.to_i
69 @limit = Setting.issues_export_limit.to_i
70 when 'atom'
70 when 'atom'
71 @limit = Setting.feeds_limit.to_i
71 @limit = Setting.feeds_limit.to_i
72 when 'xml', 'json'
72 when 'xml', 'json'
73 @offset, @limit = api_offset_and_limit
73 @offset, @limit = api_offset_and_limit
74 else
74 else
75 @limit = per_page_option
75 @limit = per_page_option
76 end
76 end
77
77
78 @issue_count = @query.issue_count
78 @issue_count = @query.issue_count
79 @issue_pages = Paginator.new self, @issue_count, @limit, params['page']
79 @issue_pages = Paginator.new self, @issue_count, @limit, params['page']
80 @offset ||= @issue_pages.current.offset
80 @offset ||= @issue_pages.current.offset
81 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
81 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
82 :order => sort_clause,
82 :order => sort_clause,
83 :offset => @offset,
83 :offset => @offset,
84 :limit => @limit)
84 :limit => @limit)
85 @issue_count_by_group = @query.issue_count_by_group
85 @issue_count_by_group = @query.issue_count_by_group
86
86
87 respond_to do |format|
87 respond_to do |format|
88 format.html { render :template => 'issues/index', :layout => !request.xhr? }
88 format.html { render :template => 'issues/index', :layout => !request.xhr? }
89 format.api {
89 format.api {
90 Issue.load_relations(@issues) if include_in_api_response?('relations')
90 Issue.load_relations(@issues) if include_in_api_response?('relations')
91 }
91 }
92 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
92 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
93 format.csv { send_data(issues_to_csv(@issues, @project, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') }
93 format.csv { send_data(issues_to_csv(@issues, @project, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') }
94 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
94 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
95 end
95 end
96 else
96 else
97 respond_to do |format|
97 respond_to do |format|
98 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
98 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
99 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
99 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
100 format.api { render_validation_errors(@query) }
100 format.api { render_validation_errors(@query) }
101 end
101 end
102 end
102 end
103 rescue ActiveRecord::RecordNotFound
103 rescue ActiveRecord::RecordNotFound
104 render_404
104 render_404
105 end
105 end
106
106
107 def show
107 def show
108 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
108 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
109 @journals.each_with_index {|j,i| j.indice = i+1}
109 @journals.each_with_index {|j,i| j.indice = i+1}
110 @journals.reverse! if User.current.wants_comments_in_reverse_order?
110 @journals.reverse! if User.current.wants_comments_in_reverse_order?
111
111
112 if User.current.allowed_to?(:view_changesets, @project)
112 if User.current.allowed_to?(:view_changesets, @project)
113 @changesets = @issue.changesets.visible.all
113 @changesets = @issue.changesets.visible.all
114 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
114 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
115 end
115 end
116
116
117 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
117 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
118 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
118 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
119 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
119 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
120 @priorities = IssuePriority.active
120 @priorities = IssuePriority.active
121 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
121 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
122 respond_to do |format|
122 respond_to do |format|
123 format.html {
123 format.html {
124 retrieve_previous_and_next_issue_ids
124 retrieve_previous_and_next_issue_ids
125 render :template => 'issues/show'
125 render :template => 'issues/show'
126 }
126 }
127 format.api
127 format.api
128 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
128 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
129 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
129 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
130 end
130 end
131 end
131 end
132
132
133 # Add a new issue
133 # Add a new issue
134 # The new issue will be created from an existing one if copy_from parameter is given
134 # The new issue will be created from an existing one if copy_from parameter is given
135 def new
135 def new
136 respond_to do |format|
136 respond_to do |format|
137 format.html { render :action => 'new', :layout => !request.xhr? }
137 format.html { render :action => 'new', :layout => !request.xhr? }
138 format.js {
138 format.js {
139 render(:update) { |page|
139 render(:update) { |page|
140 if params[:project_change]
140 if params[:project_change]
141 page.replace_html 'all_attributes', :partial => 'form'
141 page.replace_html 'all_attributes', :partial => 'form'
142 else
142 else
143 page.replace_html 'attributes', :partial => 'attributes'
143 page.replace_html 'attributes', :partial => 'attributes'
144 end
144 end
145 m = User.current.allowed_to?(:log_time, @issue.project) ? 'show' : 'hide'
145 m = User.current.allowed_to?(:log_time, @issue.project) ? 'show' : 'hide'
146 page << "if ($('log_time')) {Element.#{m}('log_time');}"
146 page << "if ($('log_time')) {Element.#{m}('log_time');}"
147 }
147 }
148 }
148 }
149 end
149 end
150 end
150 end
151
151
152 def create
152 def create
153 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
153 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
154 if @issue.save
154 if @issue.save
155 attachments = Attachment.attach_files(@issue, params[:attachments])
155 attachments = Attachment.attach_files(@issue, params[:attachments])
156 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
156 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
157 respond_to do |format|
157 respond_to do |format|
158 format.html {
158 format.html {
159 render_attachment_warning_if_needed(@issue)
159 render_attachment_warning_if_needed(@issue)
160 flash[:notice] = l(:notice_issue_successful_create, :id => "<a href='#{issue_path(@issue)}'>##{@issue.id}</a>")
160 flash[:notice] = l(:notice_issue_successful_create, :id => "<a href='#{issue_path(@issue)}'>##{@issue.id}</a>")
161 redirect_to(params[:continue] ? { :action => 'new', :project_id => @issue.project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
161 redirect_to(params[:continue] ? { :action => 'new', :project_id => @issue.project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
162 { :action => 'show', :id => @issue })
162 { :action => 'show', :id => @issue })
163 }
163 }
164 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
164 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
165 end
165 end
166 return
166 return
167 else
167 else
168 respond_to do |format|
168 respond_to do |format|
169 format.html { render :action => 'new' }
169 format.html { render :action => 'new' }
170 format.api { render_validation_errors(@issue) }
170 format.api { render_validation_errors(@issue) }
171 end
171 end
172 end
172 end
173 end
173 end
174
174
175 def edit
175 def edit
176 update_issue_from_params
176 update_issue_from_params
177
177
178 @journal = @issue.current_journal
178 @journal = @issue.current_journal
179
179
180 respond_to do |format|
180 respond_to do |format|
181 format.html { }
181 format.html { }
182 format.xml { }
182 format.xml { }
183 end
183 end
184 end
184 end
185
185
186 def update
186 def update
187 update_issue_from_params
187 update_issue_from_params
188
188
189 if @issue.save_issue_with_child_records(params, @time_entry)
189 if @issue.save_issue_with_child_records(params, @time_entry)
190 render_attachment_warning_if_needed(@issue)
190 render_attachment_warning_if_needed(@issue)
191 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
191 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
192
192
193 respond_to do |format|
193 respond_to do |format|
194 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
194 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
195 format.api { head :ok }
195 format.api { head :ok }
196 end
196 end
197 else
197 else
198 render_attachment_warning_if_needed(@issue)
198 render_attachment_warning_if_needed(@issue)
199 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
199 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
200 @journal = @issue.current_journal
200 @journal = @issue.current_journal
201
201
202 respond_to do |format|
202 respond_to do |format|
203 format.html { render :action => 'edit' }
203 format.html { render :action => 'edit' }
204 format.api { render_validation_errors(@issue) }
204 format.api { render_validation_errors(@issue) }
205 end
205 end
206 end
206 end
207 end
207 end
208
208
209 # Bulk edit/copy a set of issues
209 # Bulk edit/copy a set of issues
210 def bulk_edit
210 def bulk_edit
211 @issues.sort!
211 @issues.sort!
212 @copy = params[:copy].present?
212 @copy = params[:copy].present?
213 @notes = params[:notes]
213 @notes = params[:notes]
214
214
215 if User.current.allowed_to?(:move_issues, @projects)
215 if User.current.allowed_to?(:move_issues, @projects)
216 @allowed_projects = Issue.allowed_target_projects_on_move
216 @allowed_projects = Issue.allowed_target_projects_on_move
217 if params[:issue]
217 if params[:issue]
218 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id]}
218 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id]}
219 if @target_project
219 if @target_project
220 target_projects = [@target_project]
220 target_projects = [@target_project]
221 end
221 end
222 end
222 end
223 end
223 end
224 target_projects ||= @projects
224 target_projects ||= @projects
225
225
226 @available_statuses = target_projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
226 @available_statuses = target_projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
227 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c}
227 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c}
228 @assignables = target_projects.map(&:assignable_users).inject{|memo,a| memo & a}
228 @assignables = target_projects.map(&:assignable_users).inject{|memo,a| memo & a}
229 @trackers = target_projects.map(&:trackers).inject{|memo,t| memo & t}
229 @trackers = target_projects.map(&:trackers).inject{|memo,t| memo & t}
230
230
231 @safe_attributes = @issues.map(&:safe_attribute_names).inject {|memo,attrs| memo & attrs}
231 render :layout => false if request.xhr?
232 render :layout => false if request.xhr?
232 end
233 end
233
234
234 def bulk_update
235 def bulk_update
235 @issues.sort!
236 @issues.sort!
236 @copy = params[:copy].present?
237 @copy = params[:copy].present?
237 attributes = parse_params_for_bulk_issue_attributes(params)
238 attributes = parse_params_for_bulk_issue_attributes(params)
238
239
239 unsaved_issue_ids = []
240 unsaved_issue_ids = []
240 moved_issues = []
241 moved_issues = []
241 @issues.each do |issue|
242 @issues.each do |issue|
242 issue.reload
243 issue.reload
243 if @copy
244 if @copy
244 issue = issue.copy
245 issue = issue.copy
245 end
246 end
246 journal = issue.init_journal(User.current, params[:notes])
247 journal = issue.init_journal(User.current, params[:notes])
247 issue.safe_attributes = attributes
248 issue.safe_attributes = attributes
248 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
249 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
249 if issue.save
250 if issue.save
250 moved_issues << issue
251 moved_issues << issue
251 else
252 else
252 # Keep unsaved issue ids to display them in flash error
253 # Keep unsaved issue ids to display them in flash error
253 unsaved_issue_ids << issue.id
254 unsaved_issue_ids << issue.id
254 end
255 end
255 end
256 end
256 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
257 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
257
258
258 if params[:follow]
259 if params[:follow]
259 if @issues.size == 1 && moved_issues.size == 1
260 if @issues.size == 1 && moved_issues.size == 1
260 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
261 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
261 elsif moved_issues.map(&:project).uniq.size == 1
262 elsif moved_issues.map(&:project).uniq.size == 1
262 redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first
263 redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first
263 end
264 end
264 else
265 else
265 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
266 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
266 end
267 end
267 end
268 end
268
269
269 verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed }
270 verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed }
270 def destroy
271 def destroy
271 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
272 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
272 if @hours > 0
273 if @hours > 0
273 case params[:todo]
274 case params[:todo]
274 when 'destroy'
275 when 'destroy'
275 # nothing to do
276 # nothing to do
276 when 'nullify'
277 when 'nullify'
277 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
278 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
278 when 'reassign'
279 when 'reassign'
279 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
280 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
280 if reassign_to.nil?
281 if reassign_to.nil?
281 flash.now[:error] = l(:error_issue_not_found_in_project)
282 flash.now[:error] = l(:error_issue_not_found_in_project)
282 return
283 return
283 else
284 else
284 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
285 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
285 end
286 end
286 else
287 else
287 # display the destroy form if it's a user request
288 # display the destroy form if it's a user request
288 return unless api_request?
289 return unless api_request?
289 end
290 end
290 end
291 end
291 @issues.each do |issue|
292 @issues.each do |issue|
292 begin
293 begin
293 issue.reload.destroy
294 issue.reload.destroy
294 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
295 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
295 # nothing to do, issue was already deleted (eg. by a parent)
296 # nothing to do, issue was already deleted (eg. by a parent)
296 end
297 end
297 end
298 end
298 respond_to do |format|
299 respond_to do |format|
299 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
300 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
300 format.api { head :ok }
301 format.api { head :ok }
301 end
302 end
302 end
303 end
303
304
304 private
305 private
305 def find_issue
306 def find_issue
306 # Issue.visible.find(...) can not be used to redirect user to the login form
307 # Issue.visible.find(...) can not be used to redirect user to the login form
307 # if the issue actually exists but requires authentication
308 # if the issue actually exists but requires authentication
308 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
309 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
309 unless @issue.visible?
310 unless @issue.visible?
310 deny_access
311 deny_access
311 return
312 return
312 end
313 end
313 @project = @issue.project
314 @project = @issue.project
314 rescue ActiveRecord::RecordNotFound
315 rescue ActiveRecord::RecordNotFound
315 render_404
316 render_404
316 end
317 end
317
318
318 def find_project
319 def find_project
319 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
320 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
320 @project = Project.find(project_id)
321 @project = Project.find(project_id)
321 rescue ActiveRecord::RecordNotFound
322 rescue ActiveRecord::RecordNotFound
322 render_404
323 render_404
323 end
324 end
324
325
325 def retrieve_previous_and_next_issue_ids
326 def retrieve_previous_and_next_issue_ids
326 retrieve_query_from_session
327 retrieve_query_from_session
327 if @query
328 if @query
328 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
329 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
329 sort_update(@query.sortable_columns, 'issues_index_sort')
330 sort_update(@query.sortable_columns, 'issues_index_sort')
330 limit = 500
331 limit = 500
331 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
332 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
332 if (idx = issue_ids.index(@issue.id)) && idx < limit
333 if (idx = issue_ids.index(@issue.id)) && idx < limit
333 if issue_ids.size < 500
334 if issue_ids.size < 500
334 @issue_position = idx + 1
335 @issue_position = idx + 1
335 @issue_count = issue_ids.size
336 @issue_count = issue_ids.size
336 end
337 end
337 @prev_issue_id = issue_ids[idx - 1] if idx > 0
338 @prev_issue_id = issue_ids[idx - 1] if idx > 0
338 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
339 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
339 end
340 end
340 end
341 end
341 end
342 end
342
343
343 # Used by #edit and #update to set some common instance variables
344 # Used by #edit and #update to set some common instance variables
344 # from the params
345 # from the params
345 # TODO: Refactor, not everything in here is needed by #edit
346 # TODO: Refactor, not everything in here is needed by #edit
346 def update_issue_from_params
347 def update_issue_from_params
347 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
348 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
348 @priorities = IssuePriority.active
349 @priorities = IssuePriority.active
349 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
350 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
350 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
351 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
351 @time_entry.attributes = params[:time_entry]
352 @time_entry.attributes = params[:time_entry]
352
353
353 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
354 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
354 @issue.init_journal(User.current, @notes)
355 @issue.init_journal(User.current, @notes)
355 @issue.safe_attributes = params[:issue]
356 @issue.safe_attributes = params[:issue]
356 end
357 end
357
358
358 # TODO: Refactor, lots of extra code in here
359 # TODO: Refactor, lots of extra code in here
359 # TODO: Changing tracker on an existing issue should not trigger this
360 # TODO: Changing tracker on an existing issue should not trigger this
360 def build_new_issue_from_params
361 def build_new_issue_from_params
361 if params[:id].blank?
362 if params[:id].blank?
362 @issue = Issue.new
363 @issue = Issue.new
363 if params[:copy_from]
364 if params[:copy_from]
364 begin
365 begin
365 @copy_from = Issue.visible.find(params[:copy_from])
366 @copy_from = Issue.visible.find(params[:copy_from])
366 @copy_attachments = params[:copy_attachments].present? || request.get?
367 @copy_attachments = params[:copy_attachments].present? || request.get?
367 @issue.copy_from(@copy_from, :attachments => @copy_attachments)
368 @issue.copy_from(@copy_from, :attachments => @copy_attachments)
368 rescue ActiveRecord::RecordNotFound
369 rescue ActiveRecord::RecordNotFound
369 render_404
370 render_404
370 return
371 return
371 end
372 end
372 end
373 end
373 @issue.project = @project
374 @issue.project = @project
374 else
375 else
375 @issue = @project.issues.visible.find(params[:id])
376 @issue = @project.issues.visible.find(params[:id])
376 end
377 end
377
378
378 @issue.project = @project
379 @issue.project = @project
379 @issue.author = User.current
380 @issue.author = User.current
380 # Tracker must be set before custom field values
381 # Tracker must be set before custom field values
381 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
382 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
382 if @issue.tracker.nil?
383 if @issue.tracker.nil?
383 render_error l(:error_no_tracker_in_project)
384 render_error l(:error_no_tracker_in_project)
384 return false
385 return false
385 end
386 end
386 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
387 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
387 @issue.safe_attributes = params[:issue]
388 @issue.safe_attributes = params[:issue]
388
389
389 @priorities = IssuePriority.active
390 @priorities = IssuePriority.active
390 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
391 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
391 end
392 end
392
393
393 def check_for_default_issue_status
394 def check_for_default_issue_status
394 if IssueStatus.default.nil?
395 if IssueStatus.default.nil?
395 render_error l(:error_no_default_issue_status)
396 render_error l(:error_no_default_issue_status)
396 return false
397 return false
397 end
398 end
398 end
399 end
399
400
400 def parse_params_for_bulk_issue_attributes(params)
401 def parse_params_for_bulk_issue_attributes(params)
401 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
402 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
402 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
403 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
403 attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
404 attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
404 attributes
405 attributes
405 end
406 end
406 end
407 end
@@ -1,117 +1,125
1 <h2><%= @copy ? l(:button_copy) : l(:label_bulk_edit_selected_issues) %></h2>
1 <h2><%= @copy ? l(:button_copy) : l(:label_bulk_edit_selected_issues) %></h2>
2
2
3 <ul><%= @issues.collect {|i|
3 <ul><%= @issues.collect {|i|
4 content_tag('li',
4 content_tag('li',
5 link_to(h("#{i.tracker} ##{i.id}"),
5 link_to(h("#{i.tracker} ##{i.id}"),
6 { :action => 'show', :id => i }
6 { :action => 'show', :id => i }
7 ) + h(": #{i.subject}"))
7 ) + h(": #{i.subject}"))
8 }.join("\n").html_safe %></ul>
8 }.join("\n").html_safe %></ul>
9
9
10 <% form_tag({:action => 'bulk_update'}, :id => 'bulk_edit_form') do %>
10 <% form_tag({:action => 'bulk_update'}, :id => 'bulk_edit_form') do %>
11 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
11 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
12 <div class="box tabular">
12 <div class="box tabular">
13 <fieldset class="attributes">
13 <fieldset class="attributes">
14 <legend><%= l(:label_change_properties) %></legend>
14 <legend><%= l(:label_change_properties) %></legend>
15
15
16 <div class="splitcontentleft">
16 <div class="splitcontentleft">
17 <% if @allowed_projects.present? %>
17 <% if @allowed_projects.present? %>
18 <p>
18 <p>
19 <label for="issue_project_id"><%= l(:field_project) %></label>
19 <label for="issue_project_id"><%= l(:field_project) %></label>
20 <%= select_tag('issue[project_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + project_tree_options_for_select(@allowed_projects, :selected => @target_project)) %>
20 <%= select_tag('issue[project_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + project_tree_options_for_select(@allowed_projects, :selected => @target_project)) %>
21 </p>
21 </p>
22 <%= observe_field :issue_project_id, :url => {:action => 'bulk_edit'},
22 <%= observe_field :issue_project_id, :url => {:action => 'bulk_edit'},
23 :update => 'content',
23 :update => 'content',
24 :with => "Form.serialize('bulk_edit_form')" %>
24 :with => "Form.serialize('bulk_edit_form')" %>
25 <% end %>
25 <% end %>
26 <p>
26 <p>
27 <label for="issue_tracker_id"><%= l(:field_tracker) %></label>
27 <label for="issue_tracker_id"><%= l(:field_tracker) %></label>
28 <%= select_tag('issue[tracker_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, :id, :name)) %>
28 <%= select_tag('issue[tracker_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, :id, :name)) %>
29 </p>
29 </p>
30 <% if @available_statuses.any? %>
30 <% if @available_statuses.any? %>
31 <p>
31 <p>
32 <label for='issue_status_id'><%= l(:field_status) %></label>
32 <label for='issue_status_id'><%= l(:field_status) %></label>
33 <%= select_tag('issue[status_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %>
33 <%= select_tag('issue[status_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %>
34 </p>
34 </p>
35 <% end %>
35 <% end %>
36 <p>
36 <p>
37 <label for='issue_priority_id'><%= l(:field_priority) %></label>
37 <label for='issue_priority_id'><%= l(:field_priority) %></label>
38 <%= select_tag('issue[priority_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(IssuePriority.active, :id, :name)) %>
38 <%= select_tag('issue[priority_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(IssuePriority.active, :id, :name)) %>
39 </p>
39 </p>
40 <p>
40 <p>
41 <label for='issue_assigned_to_id'><%= l(:field_assigned_to) %></label>
41 <label for='issue_assigned_to_id'><%= l(:field_assigned_to) %></label>
42 <%= select_tag('issue[assigned_to_id]', content_tag('option', l(:label_no_change_option), :value => '') +
42 <%= select_tag('issue[assigned_to_id]', content_tag('option', l(:label_no_change_option), :value => '') +
43 content_tag('option', l(:label_nobody), :value => 'none') +
43 content_tag('option', l(:label_nobody), :value => 'none') +
44 principals_options_for_select(@assignables)) %>
44 principals_options_for_select(@assignables)) %>
45 </p>
45 </p>
46 <% if @project %>
46 <% if @project %>
47 <p>
47 <p>
48 <label for='issue_category_id'><%= l(:field_category) %></label>
48 <label for='issue_category_id'><%= l(:field_category) %></label>
49 <%= select_tag('issue[category_id]', content_tag('option', l(:label_no_change_option), :value => '') +
49 <%= select_tag('issue[category_id]', content_tag('option', l(:label_no_change_option), :value => '') +
50 content_tag('option', l(:label_none), :value => 'none') +
50 content_tag('option', l(:label_none), :value => 'none') +
51 options_from_collection_for_select(@project.issue_categories, :id, :name)) %>
51 options_from_collection_for_select(@project.issue_categories, :id, :name)) %>
52 </p>
52 </p>
53 <% end %>
53 <% end %>
54 <% #TODO: allow editing versions when multiple projects %>
54 <% #TODO: allow editing versions when multiple projects %>
55 <% if @project %>
55 <% if @project %>
56 <p>
56 <p>
57 <label for='issue_fixed_version_id'><%= l(:field_fixed_version) %></label>
57 <label for='issue_fixed_version_id'><%= l(:field_fixed_version) %></label>
58 <%= select_tag('issue[fixed_version_id]', content_tag('option', l(:label_no_change_option), :value => '') +
58 <%= select_tag('issue[fixed_version_id]', content_tag('option', l(:label_no_change_option), :value => '') +
59 content_tag('option', l(:label_none), :value => 'none') +
59 content_tag('option', l(:label_none), :value => 'none') +
60 version_options_for_select(@project.shared_versions.open.sort)) %>
60 version_options_for_select(@project.shared_versions.open.sort)) %>
61 </p>
61 </p>
62 <% end %>
62 <% end %>
63
63
64 <% @custom_fields.each do |custom_field| %>
64 <% @custom_fields.each do |custom_field| %>
65 <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p>
65 <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p>
66 <% end %>
66 <% end %>
67
67
68 <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
68 <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
69 </div>
69 </div>
70
70
71 <div class="splitcontentright">
71 <div class="splitcontentright">
72 <% if @safe_attributes.include?('is_private') %>
73 <p>
74 <label for='issue_is_private'><%= l(:field_is_private) %></label>
75 <%= select_tag('issue[is_private]', content_tag('option', l(:label_no_change_option), :value => '') +
76 content_tag('option', l(:general_text_Yes), :value => '1') +
77 content_tag('option', l(:general_text_No), :value => '0')) %>
78 </p>
79 <% end %>
72 <% if @project && User.current.allowed_to?(:manage_subtasks, @project) %>
80 <% if @project && User.current.allowed_to?(:manage_subtasks, @project) %>
73 <p>
81 <p>
74 <label for='issue_parent_issue_id'><%= l(:field_parent_issue) %></label>
82 <label for='issue_parent_issue_id'><%= l(:field_parent_issue) %></label>
75 <%= text_field_tag 'issue[parent_issue_id]', '', :size => 10 %>
83 <%= text_field_tag 'issue[parent_issue_id]', '', :size => 10 %>
76 </p>
84 </p>
77 <div id="parent_issue_candidates" class="autocomplete"></div>
85 <div id="parent_issue_candidates" class="autocomplete"></div>
78 <%= javascript_tag "observeParentIssueField('#{auto_complete_issues_path(:project_id => @project) }')" %>
86 <%= javascript_tag "observeParentIssueField('#{auto_complete_issues_path(:project_id => @project) }')" %>
79 <% end %>
87 <% end %>
80 <p>
88 <p>
81 <label for='issue_start_date'><%= l(:field_start_date) %></label>
89 <label for='issue_start_date'><%= l(:field_start_date) %></label>
82 <%= text_field_tag 'issue[start_date]', '', :size => 10 %><%= calendar_for('issue_start_date') %>
90 <%= text_field_tag 'issue[start_date]', '', :size => 10 %><%= calendar_for('issue_start_date') %>
83 </p>
91 </p>
84 <p>
92 <p>
85 <label for='issue_due_date'><%= l(:field_due_date) %></label>
93 <label for='issue_due_date'><%= l(:field_due_date) %></label>
86 <%= text_field_tag 'issue[due_date]', '', :size => 10 %><%= calendar_for('issue_due_date') %>
94 <%= text_field_tag 'issue[due_date]', '', :size => 10 %><%= calendar_for('issue_due_date') %>
87 </p>
95 </p>
88 <% if Issue.use_field_for_done_ratio? %>
96 <% if Issue.use_field_for_done_ratio? %>
89 <p>
97 <p>
90 <label for='issue_done_ratio'><%= l(:field_done_ratio) %></label>
98 <label for='issue_done_ratio'><%= l(:field_done_ratio) %></label>
91 <%= select_tag 'issue[done_ratio]', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %>
99 <%= select_tag 'issue[done_ratio]', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %>
92 </p>
100 </p>
93 <% end %>
101 <% end %>
94 </div>
102 </div>
95
103
96 </fieldset>
104 </fieldset>
97
105
98 <fieldset><legend><%= l(:field_notes) %></legend>
106 <fieldset><legend><%= l(:field_notes) %></legend>
99 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
107 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
100 <%= wikitoolbar_for 'notes' %>
108 <%= wikitoolbar_for 'notes' %>
101 </fieldset>
109 </fieldset>
102 </div>
110 </div>
103
111
104 <p>
112 <p>
105 <% if @copy %>
113 <% if @copy %>
106 <%= hidden_field_tag 'copy', '1' %>
114 <%= hidden_field_tag 'copy', '1' %>
107 <%= submit_tag l(:button_copy) %>
115 <%= submit_tag l(:button_copy) %>
108 <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
116 <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
109 <% elsif @target_project %>
117 <% elsif @target_project %>
110 <%= submit_tag l(:button_move) %>
118 <%= submit_tag l(:button_move) %>
111 <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
119 <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
112 <% else %>
120 <% else %>
113 <%= submit_tag l(:button_submit) %>
121 <%= submit_tag l(:button_submit) %>
114 <% end %>
122 <% end %>
115 </p>
123 </p>
116
124
117 <% end %>
125 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now