summaryrefslogtreecommitdiff
path: root/engines/support/app/helpers/tickets_helper.rb
blob: 11b02e403f1a2c35cdb29d0da74fc6f0fd8a8186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
module TicketsHelper
  #
  # FORM HELPERS
  #

  #
  # hidden fields that should be added to ever ticket form.
  # these are use for proper redirection after successful actions.
  #
  def hidden_ticket_fields
    haml_concat hidden_field_tag('open_status', params[:open_status])
    haml_concat hidden_field_tag('sort_order', params[:sort_order])
    haml_concat hidden_field_tag('user_id', params[:user_id])
    ""
  end

  #
  # PARAM HELPERS
  #

  def search_status
    if action?(:index)
      params[:open_status] || 'open'
    else
      nil
    end
  end

  def search_order
    params[:sort_order] || 'updated_at_desc'
  end

  #
  # LINK HELPERS
  #

  def link_to_status(new_status)
    label = t(:".#{new_status}", cascade: true)
    link_to label, auto_tickets_path(:open_status => new_status, :sort_order => search_order)
  end

  def link_to_order(order_field)
    if search_order.start_with?(order_field)
      # link for currently-filtered field. Link to other direction of this field.
      if search_order.end_with? 'asc'
        direction = 'desc'
        icon_direction = 'up'
      else
        direction = 'asc'
        icon_direction = 'down'
      end
      arrow = content_tag(:i, '', class: 'icon-arrow-'+ icon_direction)
    else
      # for not-currently-filtered field, don't display an arrow, and link to descending direction
      arrow = ''
      direction = 'desc'
    end

    label = t(:".#{order_field}", cascade: true)

    link_to auto_tickets_path(:sort_order => order_field + '_at_' + direction, :open_status => search_status) do
      arrow + label
    end
  end

end