summaryrefslogtreecommitdiff
path: root/engines/support
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-07-05 11:41:43 +0200
committerAzul <azul@leap.se>2014-07-05 11:54:11 +0200
commitbdb4b0e275c205b0b44bbe3cc4ec4c162b309b37 (patch)
tree1b92aadd34f890a6332812a01a39769e24f4a733 /engines/support
parent87e9ccbcdf4f99dd898b0715750092a27fff7e94 (diff)
make link_to_navigation more generic and reuse it
Use link_to_navigation for all important navigation items. It creates a link in a list item for use with bootstrap. It supports an :active flag and an :icon option in the html_options now. It also translates the label. This way it can be used in a lot of places as the generic navigation link.
Diffstat (limited to 'engines/support')
-rw-r--r--engines/support/app/helpers/tickets_helper.rb42
1 files changed, 21 insertions, 21 deletions
diff --git a/engines/support/app/helpers/tickets_helper.rb b/engines/support/app/helpers/tickets_helper.rb
index 11b02e4..7db31dc 100644
--- a/engines/support/app/helpers/tickets_helper.rb
+++ b/engines/support/app/helpers/tickets_helper.rb
@@ -35,32 +35,32 @@ module TicketsHelper
#
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)
+ label = ".#{new_status}"
+ link_to_navigation 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
+ direction = new_direction_for_order(order_field)
+ icon = icon_for_direction(direction)
+ # for not-currently-filtered field link to descending direction
+ direction ||= 'desc'
+ label = ".#{order_field}"
+ link_to_navigation label, auto_tickets_path(sort_order: order_field + '_at_' + direction, open_status: search_status),
+ icon: icon
+ 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
+ def new_direction_for_order(order_field)
+ # return if we're not filtering by this field
+ return unless search_order.start_with?(order_field)
+ # Link to the other direction for the filtered field.
+ search_order.end_with?('asc') ? 'desc' : 'asc'
+ end
+
+ def icon_for_direction(direction)
+ # Don't display an icon if we do not filter this field
+ return if direction.blank?
+ direction == 'asc' ? 'arrow-down' : 'arrow-up'
end
end