#-- # Copyright (C) 2008 Dimitrij Denissenko # Please read LICENSE document for more information. #++ module TicketsHelper def ipeh_for_ticket_change_content(ticket_change) tag_id = "ticket-change-content-#{ticket_change.id}" options = {:rows => 10, :no_wrap => true} options[:load_text_url] = {:action => 'show_change_content', :id => ticket_change.id} options[:url] = {:action => 'modify_change_content', :id => ticket_change.id} inplace_editor_handle(_('Edit comment'), tag_id, options) end def ipeh_for_ticket_summary(ticket) tag_id = "ticket-summary" options = {:no_wrap => true} options[:url] = {:action => 'modify_summary', :id => ticket.id} inplace_editor_handle(_('Edit summary'), tag_id, options) end def ipeh_for_ticket_content(ticket) tag_id = 'ticket-content' options = {:rows => 12} options[:load_text_url] = {:action => 'show_content', :id => ticket.id} options[:url] = {:action => 'modify_content', :id => ticket.id} inplace_editor_handle(_('Edit content'), tag_id, options) end def link_to_ticket_list(caption, options = {}) link_to caption, stored_params.merge('action' => 'index').merge(options.stringify_keys) end def modifiable?(object, type) return true if User.current.admin? return false if object.user.blank? author_modifiable = RetroCM[:ticketing][:author_modifiable][type.to_sym] == true author_modifiable && object.user.current? end def links_to_ticket_change_actions(ticket_change) html = [] if ticket_change.has_content? && modifiable?(ticket_change, :ticket_changes) html << ipeh_for_ticket_change_content(ticket_change) end if User.current.admin? url_opts = {:action => 'delete_ticket_change', :id => ticket_change.id} opts = {:confirm => _('Really delete ticket change?'), :method => :post} html << link_to(_('Delete ticket change'), url_opts, opts) end html.blank? ? '' : ' ' + content_tag(:span, html.join(' | '), :class => 'tiny') end def link_to_attachment(obj, attachment, mode) link_to attachment.original_filename, :action => 'attachment', :id => obj.id, :mode => "#{mode}#{attachment.hash}", :filename => attachment.original_filename end def format_ticket_property(property) (['Assigned user'] + Ticket.static_property_klasses).include?(property) ? _(property) : property end def ticket_link(caption, ticket) link_to caption, :action => 'show', :id => ticket.id end def summary_tooltip_for(ticket) content = content_tag(:p, h(truncate(ticket.content, 400))) title = "#{h(ticket.summary)}
#{h(ticket.author)}" ticket_tooltip(ticket.id, :summary, content, title) end def latest_change_tooltip_for(ticket) content, title = '', nil if last_change = ticket.ticket_changes.last content << content_tag(:p, last_change.changes.map do |(property, property_change)| format_ticket_property(property) + ' ' + html_format_ticket_property_change(property_change) end.join('
')) if last_change.has_changes? content << content_tag(:p, h(truncate(last_change.content, 200))) if last_change.has_content? title = "#{_('Last change')}
#{h(last_change.author)}" else content << content_tag(:em, _('New ticket')) end ticket_tooltip(ticket.id, :last_change, content, title) end def toggle_internal_navigation(open, close) open = "ticket-#{open}-selector" close = "ticket-#{close}-selector" hide = "Element.hide('#{close}');" toggle = "Element.toggle('#{open}');" "if ($('#{close}') != undefined) #{hide} #{toggle}" end def user_assignment_input if RetroCM[:ticketing][:user_assignment][:field_type] == 'text-field' text_field('ticket', 'assigned_user_login') else users = Project.current.users_with_permission(:create_and_work_on_tickets) - [User.public_user] usernames = users.map(&:login).sort {|a,b| a.downcase <=> b.downcase } select 'ticket', 'assigned_user_login', usernames, :include_blank => true end end def ticket_html_class(ticket) classes = [] classes << ticket.priority.name.to_s.downcase + '-ticket' classes << case ticket.state.id when 2; 'in-progress' when 3; 'resolved' else ; 'open' end + '-ticket' classes.join(' ') end def ticket_subscription if @ticket.subscriber?(User.current) message = _('You are currently subscribed to this ticket and you will be notified about its changes.') title = _('Unsubscribe from this ticket.') else message = _('Do you wish to receive notifications about changes of this ticket?') title = _('Subscribe to this ticket.') end content = message + ' ' + link_to(title, {:action => 'toggle_subscription', :id => @ticket.id}, :method => :post) content_tag('div', content, :class => 'ticket-subscription') end def subscription_to_tickets_permitted?(user) !user.public? && user.has_permission?(Project.current, :subscribe_to_tickets) end def subscription_check_box(user) return '' if !subscription_to_tickets_permitted?(user) || @ticket.subscriber?(user) field = check_box_tag('subscribe', 1, RetroCM[:ticketing][:subscription][:encourage_subscription]) label = content_tag('label', _('Notify me about changes of this ticket per email'), :class => 'inline', :for => 'subscribe') content_tag('p', field + ' ' + label) end def property_value(type_id) property = @ticket.property_map[type_id] property ? property.name : '' end def property_select(property_type) choices = content_tag(:option, '', :value => '') + options_from_collection_for_select(property_type.ticket_properties, :id, :name, @ticket.property_ids) select_tag('ticket[property_ids][]', choices, :id => "ticket_property_#{property_type.id}_ids") end def html_format_ticket_property_change(property_change) format_ticket_property_change(property_change, lambda { |v| content_tag(:em, v) }) end protected def format_ticket_property_change(property_change, wrap_proc = nil) if !property_change[:old].blank? && !property_change[:new].blank? values = [:old, :new].map do |i| wrap_proc ? wrap_proc.call(property_change[i]) : property_change[i] end _('changed from %s to %s', *values) elsif property_change[:old].blank? new_value = wrap_proc ? wrap_proc.call(property_change[:new]) : property_change[:new] _('set to %s', new_value) elsif property_change[:new].blank? old_value = wrap_proc ? wrap_proc.call(property_change[:old]) : property_change[:old] _('reset (from %s)', old_value) end end private def ticket_tooltip(ticket_id, type, content, title = nil) options = { 'effect' => "'appear'", 'duration' => 0.2, 'className' => "'tooltip ticket-tooltip'" } options['title'] = "'#{escape_javascript(title)}'" if title "new Tip('info_#{ticket_id}_#{type}', '#{escape_javascript(content)}', #{options_for_javascript(options)});" end end