##// END OF EJS Templates
Fixes context menu broken by r3109 (#2405)....
Jean-Philippe Lang -
r2997:8b8c24e61f37
parent child
Show More
@@ -1,533 +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 237 tracker = params[:tracker_id].blank? ? nil : @project.trackers.find_by_id(params[:tracker_id])
238 238 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
239 239 priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
240 240 assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
241 241 category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
242 242 fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
243 243 custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
244 244
245 245 unsaved_issue_ids = []
246 246 @issues.each do |issue|
247 247 journal = issue.init_journal(User.current, params[:notes])
248 248 issue.tracker = tracker if tracker
249 249 issue.priority = priority if priority
250 250 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
251 251 issue.category = category if category || params[:category_id] == 'none'
252 252 issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
253 253 issue.start_date = params[:start_date] unless params[:start_date].blank?
254 254 issue.due_date = params[:due_date] unless params[:due_date].blank?
255 255 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
256 256 issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty?
257 257 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
258 258 # Don't save any change to the issue if the user is not authorized to apply the requested status
259 259 unless (status.nil? || (issue.new_statuses_allowed_to(User.current).include?(status) && issue.status = status)) && issue.save
260 260 # Keep unsaved issue ids to display them in flash error
261 261 unsaved_issue_ids << issue.id
262 262 end
263 263 end
264 264 if unsaved_issue_ids.empty?
265 265 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
266 266 else
267 267 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
268 268 :total => @issues.size,
269 269 :ids => '#' + unsaved_issue_ids.join(', #'))
270 270 end
271 271 redirect_to(params[:back_to] || {:controller => 'issues', :action => 'index', :project_id => @project})
272 272 return
273 273 end
274 274 # Find potential statuses the user could be allowed to switch issues to
275 275 @available_statuses = Workflow.find(:all, :include => :new_status,
276 276 :conditions => {:role_id => User.current.roles_for_project(@project).collect(&:id)}).collect(&:new_status).compact.uniq.sort
277 277 @custom_fields = @project.issue_custom_fields.select {|f| f.field_format == 'list'}
278 278 end
279 279
280 280 def move
281 281 @allowed_projects = []
282 282 # find projects to which the user is allowed to move the issue
283 283 if User.current.admin?
284 284 # admin is allowed to move issues to any active (visible) project
285 285 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
286 286 else
287 287 User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
288 288 end
289 289 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
290 290 @target_project ||= @project
291 291 @trackers = @target_project.trackers
292 292 if request.post?
293 293 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
294 294 unsaved_issue_ids = []
295 295 moved_issues = []
296 296 @issues.each do |issue|
297 297 issue.init_journal(User.current)
298 298 if r = issue.move_to(@target_project, new_tracker, params[:copy_options])
299 299 moved_issues << r
300 300 else
301 301 unsaved_issue_ids << issue.id
302 302 end
303 303 end
304 304 if unsaved_issue_ids.empty?
305 305 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
306 306 else
307 307 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
308 308 :total => @issues.size,
309 309 :ids => '#' + unsaved_issue_ids.join(', #'))
310 310 end
311 311 if params[:follow]
312 312 if @issues.size == 1 && moved_issues.size == 1
313 313 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
314 314 else
315 315 redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
316 316 end
317 317 else
318 318 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
319 319 end
320 320 return
321 321 end
322 322 render :layout => false if request.xhr?
323 323 end
324 324
325 325 def destroy
326 326 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
327 327 if @hours > 0
328 328 case params[:todo]
329 329 when 'destroy'
330 330 # nothing to do
331 331 when 'nullify'
332 332 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
333 333 when 'reassign'
334 334 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
335 335 if reassign_to.nil?
336 336 flash.now[:error] = l(:error_issue_not_found_in_project)
337 337 return
338 338 else
339 339 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
340 340 end
341 341 else
342 342 # display the destroy form
343 343 return
344 344 end
345 345 end
346 346 @issues.each(&:destroy)
347 347 redirect_to :action => 'index', :project_id => @project
348 348 end
349 349
350 350 def gantt
351 351 @gantt = Redmine::Helpers::Gantt.new(params)
352 352 retrieve_query
353 353 if @query.valid?
354 354 events = []
355 355 # Issues that have start and due dates
356 356 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
357 357 :order => "start_date, due_date",
358 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]
359 359 )
360 360 # Issues that don't have a due date but that are assigned to a version with a date
361 361 events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version],
362 362 :order => "start_date, effective_date",
363 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]
364 364 )
365 365 # Versions
366 366 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
367 367
368 368 @gantt.events = events
369 369 end
370 370
371 371 basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
372 372
373 373 respond_to do |format|
374 374 format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
375 375 format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
376 376 format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
377 377 end
378 378 end
379 379
380 380 def calendar
381 381 if params[:year] and params[:year].to_i > 1900
382 382 @year = params[:year].to_i
383 383 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
384 384 @month = params[:month].to_i
385 385 end
386 386 end
387 387 @year ||= Date.today.year
388 388 @month ||= Date.today.month
389 389
390 390 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
391 391 retrieve_query
392 392 if @query.valid?
393 393 events = []
394 394 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
395 395 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
396 396 )
397 397 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
398 398
399 399 @calendar.events = events
400 400 end
401 401
402 402 render :layout => false if request.xhr?
403 403 end
404 404
405 405 def context_menu
406 406 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
407 407 if (@issues.size == 1)
408 408 @issue = @issues.first
409 409 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
410 410 end
411 411 projects = @issues.collect(&:project).compact.uniq
412 412 @project = projects.first if projects.size == 1
413 413
414 414 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
415 415 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
416 416 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
417 417 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
418 418 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
419 419 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
420 420 }
421 421 if @project
422 422 @assignables = @project.assignable_users
423 423 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
424 @trackers = @project.trackers
424 425 end
425 426
426 @trackers = @project.trackers
427 427 @priorities = IssuePriority.all.reverse
428 428 @statuses = IssueStatus.find(:all, :order => 'position')
429 429 @back = params[:back_url] || request.env['HTTP_REFERER']
430 430
431 431 render :layout => false
432 432 end
433 433
434 434 def update_form
435 435 if params[:id]
436 436 @issue = @project.issues.visible.find(params[:id])
437 437 else
438 438 @issue = Issue.new
439 439 @issue.project = @project
440 440 end
441 441 @issue.attributes = params[:issue]
442 442 @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
443 443 @priorities = IssuePriority.all
444 444
445 445 render :partial => 'attributes'
446 446 end
447 447
448 448 def preview
449 449 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
450 450 @attachements = @issue.attachments if @issue
451 451 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
452 452 render :partial => 'common/preview'
453 453 end
454 454
455 455 private
456 456 def find_issue
457 457 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
458 458 @project = @issue.project
459 459 rescue ActiveRecord::RecordNotFound
460 460 render_404
461 461 end
462 462
463 463 # Filter for bulk operations
464 464 def find_issues
465 465 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
466 466 raise ActiveRecord::RecordNotFound if @issues.empty?
467 467 projects = @issues.collect(&:project).compact.uniq
468 468 if projects.size == 1
469 469 @project = projects.first
470 470 else
471 471 # TODO: let users bulk edit/move/destroy issues from different projects
472 472 render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
473 473 end
474 474 rescue ActiveRecord::RecordNotFound
475 475 render_404
476 476 end
477 477
478 478 def find_project
479 479 @project = Project.find(params[:project_id])
480 480 rescue ActiveRecord::RecordNotFound
481 481 render_404
482 482 end
483 483
484 484 def find_optional_project
485 485 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
486 486 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
487 487 allowed ? true : deny_access
488 488 rescue ActiveRecord::RecordNotFound
489 489 render_404
490 490 end
491 491
492 492 # Retrieve query from session or build a new query
493 493 def retrieve_query
494 494 if !params[:query_id].blank?
495 495 cond = "project_id IS NULL"
496 496 cond << " OR project_id = #{@project.id}" if @project
497 497 @query = Query.find(params[:query_id], :conditions => cond)
498 498 @query.project = @project
499 499 session[:query] = {:id => @query.id, :project_id => @query.project_id}
500 500 sort_clear
501 501 else
502 502 if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
503 503 # Give it a name, required to be valid
504 504 @query = Query.new(:name => "_")
505 505 @query.project = @project
506 506 if params[:fields] and params[:fields].is_a? Array
507 507 params[:fields].each do |field|
508 508 @query.add_filter(field, params[:operators][field], params[:values][field])
509 509 end
510 510 else
511 511 @query.available_filters.keys.each do |field|
512 512 @query.add_short_filter(field, params[field]) if params[field]
513 513 end
514 514 end
515 515 @query.group_by = params[:group_by]
516 516 @query.column_names = params[:query] && params[:query][:column_names]
517 517 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
518 518 else
519 519 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
520 520 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
521 521 @query.project = @project
522 522 end
523 523 end
524 524 end
525 525
526 526 # Rescues an invalid query statement. Just in case...
527 527 def query_statement_invalid(exception)
528 528 logger.error "Query::StatementInvalid: #{exception.message}" if logger
529 529 session.delete(:query)
530 530 sort_clear
531 531 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
532 532 end
533 533 end
@@ -1,106 +1,108
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 <% unless @tracker.nil? %>
21 22 <li class="folder">
22 23 <a href="#" class="submenu"><%= l(:field_tracker) %></a>
23 24 <ul>
24 25 <% @trackers.each do |t| -%>
25 26 <li><%= context_menu_link t.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'tracker_id' => t, :back_to => @back}, :method => :post,
26 27 :selected => (@issue && t == @issue.tracker), :disabled => !@can[:edit] %></li>
27 28 <% end -%>
28 29 </ul>
29 30 </li>
31 <% end %>
30 32 <li class="folder">
31 33 <a href="#" class="submenu"><%= l(:field_priority) %></a>
32 34 <ul>
33 35 <% @priorities.each do |p| -%>
34 36 <li><%= context_menu_link p.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'priority_id' => p, :back_to => @back}, :method => :post,
35 37 :selected => (@issue && p == @issue.priority), :disabled => !@can[:edit] %></li>
36 38 <% end -%>
37 39 </ul>
38 40 </li>
39 41 <% unless @project.nil? || @project.versions.open.empty? -%>
40 42 <li class="folder">
41 43 <a href="#" class="submenu"><%= l(:field_fixed_version) %></a>
42 44 <ul>
43 45 <% @project.versions.open.sort.each do |v| -%>
44 46 <li><%= context_menu_link v.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'fixed_version_id' => v, :back_to => @back}, :method => :post,
45 47 :selected => (@issue && v == @issue.fixed_version), :disabled => !@can[:update] %></li>
46 48 <% end -%>
47 49 <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,
48 50 :selected => (@issue && @issue.fixed_version.nil?), :disabled => !@can[:update] %></li>
49 51 </ul>
50 52 </li>
51 53 <% end %>
52 54 <% unless @assignables.nil? || @assignables.empty? -%>
53 55 <li class="folder">
54 56 <a href="#" class="submenu"><%= l(:field_assigned_to) %></a>
55 57 <ul>
56 58 <% @assignables.each do |u| -%>
57 59 <li><%= context_menu_link u.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'assigned_to_id' => u, :back_to => @back}, :method => :post,
58 60 :selected => (@issue && u == @issue.assigned_to), :disabled => !@can[:update] %></li>
59 61 <% end -%>
60 62 <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,
61 63 :selected => (@issue && @issue.assigned_to.nil?), :disabled => !@can[:update] %></li>
62 64 </ul>
63 65 </li>
64 66 <% end %>
65 67 <% unless @project.nil? || @project.issue_categories.empty? -%>
66 68 <li class="folder">
67 69 <a href="#" class="submenu"><%= l(:field_category) %></a>
68 70 <ul>
69 71 <% @project.issue_categories.each do |u| -%>
70 72 <li><%= context_menu_link u.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'category_id' => u, :back_to => @back}, :method => :post,
71 73 :selected => (@issue && u == @issue.category), :disabled => !@can[:update] %></li>
72 74 <% end -%>
73 75 <li><%= context_menu_link l(:label_none), {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'category_id' => 'none', :back_to => @back}, :method => :post,
74 76 :selected => (@issue && @issue.category.nil?), :disabled => !@can[:update] %></li>
75 77 </ul>
76 78 </li>
77 79 <% end -%>
78 80 <li class="folder">
79 81 <a href="#" class="submenu"><%= l(:field_done_ratio) %></a>
80 82 <ul>
81 83 <% (0..10).map{|x|x*10}.each do |p| -%>
82 84 <li><%= context_menu_link "#{p}%", {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'done_ratio' => p, :back_to => @back}, :method => :post,
83 85 :selected => (@issue && p == @issue.done_ratio), :disabled => !@can[:edit] %></li>
84 86 <% end -%>
85 87 </ul>
86 88 </li>
87 89
88 90 <% if !@issue.nil? %>
89 91 <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
90 92 :class => 'icon-copy', :disabled => !@can[:copy] %></li>
91 93 <% if @can[:log_time] -%>
92 94 <li><%= context_menu_link l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue},
93 95 :class => 'icon-time-add' %></li>
94 96 <% end %>
95 97 <% if User.current.logged? %>
96 98 <li><%= watcher_link(@issue, User.current) %></li>
97 99 <% end %>
98 100 <% end %>
99 101
100 102 <li><%= context_menu_link l(:button_move), {:controller => 'issues', :action => 'move', :ids => @issues.collect(&:id)},
101 103 :class => 'icon-move', :disabled => !@can[:move] %></li>
102 104 <li><%= context_menu_link l(:button_delete), {:controller => 'issues', :action => 'destroy', :ids => @issues.collect(&:id)},
103 105 :method => :post, :confirm => l(:text_issues_destroy_confirmation), :class => 'icon-del', :disabled => !@can[:delete] %></li>
104 106
105 107 <%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %>
106 108 </ul>
General Comments 0
You need to be logged in to leave comments. Login now