##// END OF EJS Templates
Adds tracker update to context menu and bulk edit form (#2405)....
Jean-Philippe Lang -
r2995:f134e72fec4a
parent child
Show More
@@ -1,530 +1,533
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class IssuesController < ApplicationController
19 19 menu_item :new_issue, :only => :new
20 20 default_search_scope :issues
21 21
22 22 before_filter :find_issue, :only => [:show, :edit, :reply]
23 23 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
24 24 before_filter :find_project, :only => [:new, :update_form, :preview]
25 25 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu]
26 26 before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
27 27 accept_key_auth :index, :show, :changes
28 28
29 29 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
30 30
31 31 helper :journals
32 32 helper :projects
33 33 include ProjectsHelper
34 34 helper :custom_fields
35 35 include CustomFieldsHelper
36 36 helper :issue_relations
37 37 include IssueRelationsHelper
38 38 helper :watchers
39 39 include WatchersHelper
40 40 helper :attachments
41 41 include AttachmentsHelper
42 42 helper :queries
43 43 helper :sort
44 44 include SortHelper
45 45 include IssuesHelper
46 46 helper :timelog
47 47 include Redmine::Export::PDF
48 48
49 49 verify :method => :post,
50 50 :only => :destroy,
51 51 :render => { :nothing => true, :status => :method_not_allowed }
52 52
53 53 def index
54 54 retrieve_query
55 55 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
56 56 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
57 57
58 58 if @query.valid?
59 59 limit = per_page_option
60 60 respond_to do |format|
61 61 format.html { }
62 62 format.atom { limit = Setting.feeds_limit.to_i }
63 63 format.csv { limit = Setting.issues_export_limit.to_i }
64 64 format.pdf { limit = Setting.issues_export_limit.to_i }
65 65 end
66 66
67 67 @issue_count = @query.issue_count
68 68 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
69 69 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
70 70 :order => sort_clause,
71 71 :offset => @issue_pages.current.offset,
72 72 :limit => limit)
73 73 @issue_count_by_group = @query.issue_count_by_group
74 74
75 75 respond_to do |format|
76 76 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
77 77 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
78 78 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
79 79 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
80 80 end
81 81 else
82 82 # Send html if the query is not valid
83 83 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
84 84 end
85 85 rescue ActiveRecord::RecordNotFound
86 86 render_404
87 87 end
88 88
89 89 def changes
90 90 retrieve_query
91 91 sort_init 'id', 'desc'
92 92 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
93 93
94 94 if @query.valid?
95 95 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
96 96 :limit => 25)
97 97 end
98 98 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
99 99 render :layout => false, :content_type => 'application/atom+xml'
100 100 rescue ActiveRecord::RecordNotFound
101 101 render_404
102 102 end
103 103
104 104 def show
105 105 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
106 106 @journals.each_with_index {|j,i| j.indice = i+1}
107 107 @journals.reverse! if User.current.wants_comments_in_reverse_order?
108 108 @changesets = @issue.changesets
109 109 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
110 110 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
111 111 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
112 112 @priorities = IssuePriority.all
113 113 @time_entry = TimeEntry.new
114 114 respond_to do |format|
115 115 format.html { render :template => 'issues/show.rhtml' }
116 116 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
117 117 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
118 118 end
119 119 end
120 120
121 121 # Add a new issue
122 122 # The new issue will be created from an existing one if copy_from parameter is given
123 123 def new
124 124 @issue = Issue.new
125 125 @issue.copy_from(params[:copy_from]) if params[:copy_from]
126 126 @issue.project = @project
127 127 # Tracker must be set before custom field values
128 128 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
129 129 if @issue.tracker.nil?
130 130 render_error l(:error_no_tracker_in_project)
131 131 return
132 132 end
133 133 if params[:issue].is_a?(Hash)
134 134 @issue.attributes = params[:issue]
135 135 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
136 136 end
137 137 @issue.author = User.current
138 138
139 139 default_status = IssueStatus.default
140 140 unless default_status
141 141 render_error l(:error_no_default_issue_status)
142 142 return
143 143 end
144 144 @issue.status = default_status
145 145 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
146 146
147 147 if request.get? || request.xhr?
148 148 @issue.start_date ||= Date.today
149 149 else
150 150 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
151 151 # Check that the user is allowed to apply the requested status
152 152 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
153 153 if @issue.save
154 154 attach_files(@issue, params[:attachments])
155 155 flash[:notice] = l(:notice_successful_create)
156 156 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
157 157 redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
158 158 { :action => 'show', :id => @issue })
159 159 return
160 160 end
161 161 end
162 162 @priorities = IssuePriority.all
163 163 render :layout => !request.xhr?
164 164 end
165 165
166 166 # Attributes that can be updated on workflow transition (without :edit permission)
167 167 # TODO: make it configurable (at least per role)
168 168 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
169 169
170 170 def edit
171 171 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
172 172 @priorities = IssuePriority.all
173 173 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
174 174 @time_entry = TimeEntry.new
175 175
176 176 @notes = params[:notes]
177 177 journal = @issue.init_journal(User.current, @notes)
178 178 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
179 179 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
180 180 attrs = params[:issue].dup
181 181 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
182 182 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
183 183 @issue.attributes = attrs
184 184 end
185 185
186 186 if request.post?
187 187 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
188 188 @time_entry.attributes = params[:time_entry]
189 189 attachments = attach_files(@issue, params[:attachments])
190 190 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
191 191
192 192 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
193 193
194 194 if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save
195 195 # Log spend time
196 196 if User.current.allowed_to?(:log_time, @project)
197 197 @time_entry.save
198 198 end
199 199 if !journal.new_record?
200 200 # Only send notification if something was actually changed
201 201 flash[:notice] = l(:notice_successful_update)
202 202 end
203 203 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
204 204 redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
205 205 end
206 206 end
207 207 rescue ActiveRecord::StaleObjectError
208 208 # Optimistic locking exception
209 209 flash.now[:error] = l(:notice_locking_conflict)
210 210 # Remove the previously added attachments if issue was not updated
211 211 attachments.each(&:destroy)
212 212 end
213 213
214 214 def reply
215 215 journal = Journal.find(params[:journal_id]) if params[:journal_id]
216 216 if journal
217 217 user = journal.user
218 218 text = journal.notes
219 219 else
220 220 user = @issue.author
221 221 text = @issue.description
222 222 end
223 223 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
224 224 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
225 225 render(:update) { |page|
226 226 page.<< "$('notes').value = \"#{content}\";"
227 227 page.show 'update'
228 228 page << "Form.Element.focus('notes');"
229 229 page << "Element.scrollTo('update');"
230 230 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
231 231 }
232 232 end
233 233
234 234 # Bulk edit a set of issues
235 235 def bulk_edit
236 236 if request.post?
237 tracker = params[:tracker_id].blank? ? nil : @project.trackers.find_by_id(params[:tracker_id])
237 238 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
238 239 priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
239 240 assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
240 241 category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
241 242 fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
242 243 custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
243 244
244 245 unsaved_issue_ids = []
245 246 @issues.each do |issue|
246 247 journal = issue.init_journal(User.current, params[:notes])
248 issue.tracker = tracker if tracker
247 249 issue.priority = priority if priority
248 250 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
249 251 issue.category = category if category || params[:category_id] == 'none'
250 252 issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
251 253 issue.start_date = params[:start_date] unless params[:start_date].blank?
252 254 issue.due_date = params[:due_date] unless params[:due_date].blank?
253 255 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
254 256 issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty?
255 257 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
256 258 # Don't save any change to the issue if the user is not authorized to apply the requested status
257 259 unless (status.nil? || (issue.new_statuses_allowed_to(User.current).include?(status) && issue.status = status)) && issue.save
258 260 # Keep unsaved issue ids to display them in flash error
259 261 unsaved_issue_ids << issue.id
260 262 end
261 263 end
262 264 if unsaved_issue_ids.empty?
263 265 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
264 266 else
265 267 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
266 268 :total => @issues.size,
267 269 :ids => '#' + unsaved_issue_ids.join(', #'))
268 270 end
269 271 redirect_to(params[:back_to] || {:controller => 'issues', :action => 'index', :project_id => @project})
270 272 return
271 273 end
272 274 # Find potential statuses the user could be allowed to switch issues to
273 275 @available_statuses = Workflow.find(:all, :include => :new_status,
274 276 :conditions => {:role_id => User.current.roles_for_project(@project).collect(&:id)}).collect(&:new_status).compact.uniq.sort
275 277 @custom_fields = @project.issue_custom_fields.select {|f| f.field_format == 'list'}
276 278 end
277 279
278 280 def move
279 281 @allowed_projects = []
280 282 # find projects to which the user is allowed to move the issue
281 283 if User.current.admin?
282 284 # admin is allowed to move issues to any active (visible) project
283 285 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
284 286 else
285 287 User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
286 288 end
287 289 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
288 290 @target_project ||= @project
289 291 @trackers = @target_project.trackers
290 292 if request.post?
291 293 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
292 294 unsaved_issue_ids = []
293 295 moved_issues = []
294 296 @issues.each do |issue|
295 297 issue.init_journal(User.current)
296 298 if r = issue.move_to(@target_project, new_tracker, params[:copy_options])
297 299 moved_issues << r
298 300 else
299 301 unsaved_issue_ids << issue.id
300 302 end
301 303 end
302 304 if unsaved_issue_ids.empty?
303 305 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
304 306 else
305 307 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
306 308 :total => @issues.size,
307 309 :ids => '#' + unsaved_issue_ids.join(', #'))
308 310 end
309 311 if params[:follow]
310 312 if @issues.size == 1 && moved_issues.size == 1
311 313 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
312 314 else
313 315 redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
314 316 end
315 317 else
316 318 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
317 319 end
318 320 return
319 321 end
320 322 render :layout => false if request.xhr?
321 323 end
322 324
323 325 def destroy
324 326 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
325 327 if @hours > 0
326 328 case params[:todo]
327 329 when 'destroy'
328 330 # nothing to do
329 331 when 'nullify'
330 332 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
331 333 when 'reassign'
332 334 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
333 335 if reassign_to.nil?
334 336 flash.now[:error] = l(:error_issue_not_found_in_project)
335 337 return
336 338 else
337 339 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
338 340 end
339 341 else
340 342 # display the destroy form
341 343 return
342 344 end
343 345 end
344 346 @issues.each(&:destroy)
345 347 redirect_to :action => 'index', :project_id => @project
346 348 end
347 349
348 350 def gantt
349 351 @gantt = Redmine::Helpers::Gantt.new(params)
350 352 retrieve_query
351 353 if @query.valid?
352 354 events = []
353 355 # Issues that have start and due dates
354 356 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
355 357 :order => "start_date, due_date",
356 358 :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
357 359 )
358 360 # Issues that don't have a due date but that are assigned to a version with a date
359 361 events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version],
360 362 :order => "start_date, effective_date",
361 363 :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
362 364 )
363 365 # Versions
364 366 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
365 367
366 368 @gantt.events = events
367 369 end
368 370
369 371 basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
370 372
371 373 respond_to do |format|
372 374 format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
373 375 format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
374 376 format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
375 377 end
376 378 end
377 379
378 380 def calendar
379 381 if params[:year] and params[:year].to_i > 1900
380 382 @year = params[:year].to_i
381 383 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
382 384 @month = params[:month].to_i
383 385 end
384 386 end
385 387 @year ||= Date.today.year
386 388 @month ||= Date.today.month
387 389
388 390 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
389 391 retrieve_query
390 392 if @query.valid?
391 393 events = []
392 394 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
393 395 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
394 396 )
395 397 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
396 398
397 399 @calendar.events = events
398 400 end
399 401
400 402 render :layout => false if request.xhr?
401 403 end
402 404
403 405 def context_menu
404 406 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
405 407 if (@issues.size == 1)
406 408 @issue = @issues.first
407 409 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
408 410 end
409 411 projects = @issues.collect(&:project).compact.uniq
410 412 @project = projects.first if projects.size == 1
411 413
412 414 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
413 415 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
414 416 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
415 417 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
416 418 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
417 419 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
418 420 }
419 421 if @project
420 422 @assignables = @project.assignable_users
421 423 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
422 424 end
423 425
426 @trackers = @project.trackers
424 427 @priorities = IssuePriority.all.reverse
425 428 @statuses = IssueStatus.find(:all, :order => 'position')
426 429 @back = params[:back_url] || request.env['HTTP_REFERER']
427 430
428 431 render :layout => false
429 432 end
430 433
431 434 def update_form
432 435 if params[:id]
433 436 @issue = @project.issues.visible.find(params[:id])
434 437 else
435 438 @issue = Issue.new
436 439 @issue.project = @project
437 440 end
438 441 @issue.attributes = params[:issue]
439 442 @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
440 443 @priorities = IssuePriority.all
441 444
442 445 render :partial => 'attributes'
443 446 end
444 447
445 448 def preview
446 449 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
447 450 @attachements = @issue.attachments if @issue
448 451 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
449 452 render :partial => 'common/preview'
450 453 end
451 454
452 455 private
453 456 def find_issue
454 457 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
455 458 @project = @issue.project
456 459 rescue ActiveRecord::RecordNotFound
457 460 render_404
458 461 end
459 462
460 463 # Filter for bulk operations
461 464 def find_issues
462 465 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
463 466 raise ActiveRecord::RecordNotFound if @issues.empty?
464 467 projects = @issues.collect(&:project).compact.uniq
465 468 if projects.size == 1
466 469 @project = projects.first
467 470 else
468 471 # TODO: let users bulk edit/move/destroy issues from different projects
469 472 render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
470 473 end
471 474 rescue ActiveRecord::RecordNotFound
472 475 render_404
473 476 end
474 477
475 478 def find_project
476 479 @project = Project.find(params[:project_id])
477 480 rescue ActiveRecord::RecordNotFound
478 481 render_404
479 482 end
480 483
481 484 def find_optional_project
482 485 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
483 486 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
484 487 allowed ? true : deny_access
485 488 rescue ActiveRecord::RecordNotFound
486 489 render_404
487 490 end
488 491
489 492 # Retrieve query from session or build a new query
490 493 def retrieve_query
491 494 if !params[:query_id].blank?
492 495 cond = "project_id IS NULL"
493 496 cond << " OR project_id = #{@project.id}" if @project
494 497 @query = Query.find(params[:query_id], :conditions => cond)
495 498 @query.project = @project
496 499 session[:query] = {:id => @query.id, :project_id => @query.project_id}
497 500 sort_clear
498 501 else
499 502 if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
500 503 # Give it a name, required to be valid
501 504 @query = Query.new(:name => "_")
502 505 @query.project = @project
503 506 if params[:fields] and params[:fields].is_a? Array
504 507 params[:fields].each do |field|
505 508 @query.add_filter(field, params[:operators][field], params[:values][field])
506 509 end
507 510 else
508 511 @query.available_filters.keys.each do |field|
509 512 @query.add_short_filter(field, params[field]) if params[field]
510 513 end
511 514 end
512 515 @query.group_by = params[:group_by]
513 516 @query.column_names = params[:query] && params[:query][:column_names]
514 517 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
515 518 else
516 519 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
517 520 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
518 521 @query.project = @project
519 522 end
520 523 end
521 524 end
522 525
523 526 # Rescues an invalid query statement. Just in case...
524 527 def query_statement_invalid(exception)
525 528 logger.error "Query::StatementInvalid: #{exception.message}" if logger
526 529 session.delete(:query)
527 530 sort_clear
528 531 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
529 532 end
530 533 end
@@ -1,58 +1,62
1 1 <h2><%= l(:label_bulk_edit_selected_issues) %></h2>
2 2
3 3 <ul><%= @issues.collect {|i| content_tag('li', link_to(h("#{i.tracker} ##{i.id}"), { :action => 'show', :id => i }) + h(": #{i.subject}")) }.join("\n") %></ul>
4 4
5 5 <% form_tag() do %>
6 6 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %>
7 7 <div class="box">
8 8 <fieldset>
9 9 <legend><%= l(:label_change_properties) %></legend>
10 10 <p>
11 <label><%= l(:field_tracker) %>:
12 <%= select_tag('tracker_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@project.trackers, :id, :name)) %></label>
11 13 <% if @available_statuses.any? %>
12 14 <label><%= l(:field_status) %>:
13 15 <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %></label>
14 16 <% end %>
17 </p>
18 <p>
15 19 <label><%= l(:field_priority) %>:
16 20 <%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(IssuePriority.all, :id, :name)) %></label>
17 21 <label><%= l(:field_category) %>:
18 22 <%= select_tag('category_id', content_tag('option', l(:label_no_change_option), :value => '') +
19 23 content_tag('option', l(:label_none), :value => 'none') +
20 24 options_from_collection_for_select(@project.issue_categories, :id, :name)) %></label>
21 25 </p>
22 26 <p>
23 27 <label><%= l(:field_assigned_to) %>:
24 28 <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
25 29 content_tag('option', l(:label_nobody), :value => 'none') +
26 30 options_from_collection_for_select(@project.assignable_users, :id, :name)) %></label>
27 31 <label><%= l(:field_fixed_version) %>:
28 32 <%= select_tag('fixed_version_id', content_tag('option', l(:label_no_change_option), :value => '') +
29 33 content_tag('option', l(:label_none), :value => 'none') +
30 34 options_from_collection_for_select(@project.versions.open.sort, :id, :name)) %></label>
31 35 </p>
32 36
33 37 <p>
34 38 <label><%= l(:field_start_date) %>:
35 39 <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %></label>
36 40 <label><%= l(:field_due_date) %>:
37 41 <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %></label>
38 42 <label><%= l(:field_done_ratio) %>:
39 43 <%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label>
40 44 </p>
41 45
42 46 <% @custom_fields.each do |custom_field| %>
43 47 <p><label><%= h(custom_field.name) %></label>
44 48 <%= select_tag "custom_field_values[#{custom_field.id}]", options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values) %></label>
45 49 </p>
46 50 <% end %>
47 51
48 52 <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
49 53 </fieldset>
50 54
51 55 <fieldset><legend><%= l(:field_notes) %></legend>
52 56 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
53 57 <%= wikitoolbar_for 'notes' %>
54 58 </fieldset>
55 59 </div>
56 60
57 61 <p><%= submit_tag l(:button_submit) %>
58 62 <% end %>
@@ -1,97 +1,106
1 1 <ul>
2 2 <%= call_hook(:view_issues_context_menu_start, {:issues => @issues, :can => @can, :back => @back }) %>
3 3
4 4 <% if !@issue.nil? -%>
5 5 <li><%= context_menu_link l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue},
6 6 :class => 'icon-edit', :disabled => !@can[:edit] %></li>
7 7 <li class="folder">
8 8 <a href="#" class="submenu" onclick="return false;"><%= l(:field_status) %></a>
9 9 <ul>
10 10 <% @statuses.each do |s| -%>
11 11 <li><%= context_menu_link s.name, {:controller => 'issues', :action => 'edit', :id => @issue, :issue => {:status_id => s}, :back_to => @back}, :method => :post,
12 12 :selected => (s == @issue.status), :disabled => !(@can[:update] && @allowed_statuses.include?(s)) %></li>
13 13 <% end -%>
14 14 </ul>
15 15 </li>
16 16 <% else %>
17 17 <li><%= context_menu_link l(:button_edit), {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id)},
18 18 :class => 'icon-edit', :disabled => !@can[:edit] %></li>
19 19 <% end %>
20 20
21 21 <li class="folder">
22 <a href="#" class="submenu"><%= l(:field_tracker) %></a>
23 <ul>
24 <% @trackers.each do |t| -%>
25 <li><%= context_menu_link t.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'tracker_id' => t, :back_to => @back}, :method => :post,
26 :selected => (@issue && t == @issue.tracker), :disabled => !@can[:edit] %></li>
27 <% end -%>
28 </ul>
29 </li>
30 <li class="folder">
22 31 <a href="#" class="submenu"><%= l(:field_priority) %></a>
23 32 <ul>
24 33 <% @priorities.each do |p| -%>
25 34 <li><%= context_menu_link p.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'priority_id' => p, :back_to => @back}, :method => :post,
26 35 :selected => (@issue && p == @issue.priority), :disabled => !@can[:edit] %></li>
27 36 <% end -%>
28 37 </ul>
29 38 </li>
30 39 <% unless @project.nil? || @project.versions.open.empty? -%>
31 40 <li class="folder">
32 41 <a href="#" class="submenu"><%= l(:field_fixed_version) %></a>
33 42 <ul>
34 43 <% @project.versions.open.sort.each do |v| -%>
35 44 <li><%= context_menu_link v.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'fixed_version_id' => v, :back_to => @back}, :method => :post,
36 45 :selected => (@issue && v == @issue.fixed_version), :disabled => !@can[:update] %></li>
37 46 <% end -%>
38 47 <li><%= context_menu_link l(:label_none), {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'fixed_version_id' => 'none', :back_to => @back}, :method => :post,
39 48 :selected => (@issue && @issue.fixed_version.nil?), :disabled => !@can[:update] %></li>
40 49 </ul>
41 50 </li>
42 51 <% end %>
43 52 <% unless @assignables.nil? || @assignables.empty? -%>
44 53 <li class="folder">
45 54 <a href="#" class="submenu"><%= l(:field_assigned_to) %></a>
46 55 <ul>
47 56 <% @assignables.each do |u| -%>
48 57 <li><%= context_menu_link u.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'assigned_to_id' => u, :back_to => @back}, :method => :post,
49 58 :selected => (@issue && u == @issue.assigned_to), :disabled => !@can[:update] %></li>
50 59 <% end -%>
51 60 <li><%= context_menu_link l(:label_nobody), {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'assigned_to_id' => 'none', :back_to => @back}, :method => :post,
52 61 :selected => (@issue && @issue.assigned_to.nil?), :disabled => !@can[:update] %></li>
53 62 </ul>
54 63 </li>
55 64 <% end %>
56 65 <% unless @project.nil? || @project.issue_categories.empty? -%>
57 66 <li class="folder">
58 67 <a href="#" class="submenu"><%= l(:field_category) %></a>
59 68 <ul>
60 69 <% @project.issue_categories.each do |u| -%>
61 70 <li><%= context_menu_link u.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'category_id' => u, :back_to => @back}, :method => :post,
62 71 :selected => (@issue && u == @issue.category), :disabled => !@can[:update] %></li>
63 72 <% end -%>
64 73 <li><%= context_menu_link l(:label_none), {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'category_id' => 'none', :back_to => @back}, :method => :post,
65 74 :selected => (@issue && @issue.category.nil?), :disabled => !@can[:update] %></li>
66 75 </ul>
67 76 </li>
68 77 <% end -%>
69 78 <li class="folder">
70 79 <a href="#" class="submenu"><%= l(:field_done_ratio) %></a>
71 80 <ul>
72 81 <% (0..10).map{|x|x*10}.each do |p| -%>
73 82 <li><%= context_menu_link "#{p}%", {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'done_ratio' => p, :back_to => @back}, :method => :post,
74 83 :selected => (@issue && p == @issue.done_ratio), :disabled => !@can[:edit] %></li>
75 84 <% end -%>
76 85 </ul>
77 86 </li>
78 87
79 88 <% if !@issue.nil? %>
80 89 <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
81 90 :class => 'icon-copy', :disabled => !@can[:copy] %></li>
82 91 <% if @can[:log_time] -%>
83 92 <li><%= context_menu_link l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue},
84 93 :class => 'icon-time-add' %></li>
85 94 <% end %>
86 95 <% if User.current.logged? %>
87 96 <li><%= watcher_link(@issue, User.current) %></li>
88 97 <% end %>
89 98 <% end %>
90 99
91 100 <li><%= context_menu_link l(:button_move), {:controller => 'issues', :action => 'move', :ids => @issues.collect(&:id)},
92 101 :class => 'icon-move', :disabled => !@can[:move] %></li>
93 102 <li><%= context_menu_link l(:button_delete), {:controller => 'issues', :action => 'destroy', :ids => @issues.collect(&:id)},
94 103 :method => :post, :confirm => l(:text_issues_destroy_confirmation), :class => 'icon-del', :disabled => !@can[:delete] %></li>
95 104
96 105 <%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %>
97 106 </ul>
General Comments 0
You need to be logged in to leave comments. Login now