summaryrefslogtreecommitdiff
path: root/help/app/helpers
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-07-09 11:53:58 -0700
committerjessib <jessib@leap.se>2013-07-09 11:53:58 -0700
commit09b7f01cac6df1ae11f4129b20b781b78a3706ac (patch)
tree3921eaa5edd03d80e6b402c5c2f88dda6338ab3a /help/app/helpers
parent9979b50848ce27730f880159512933e50d5ae0e4 (diff)
parent3113f8b814417a896ad5340fda88927733f8ab22 (diff)
Merge branch 'master' into feature/authentication_generic_error
Conflicts: app/views/layouts/_messages.html.haml app/views/layouts/application.html.haml users/app/assets/javascripts/users.js.coffee
Diffstat (limited to 'help/app/helpers')
-rw-r--r--help/app/helpers/auto_tickets_path_helper.rb51
-rw-r--r--help/app/helpers/tickets_helper.rb57
2 files changed, 96 insertions, 12 deletions
diff --git a/help/app/helpers/auto_tickets_path_helper.rb b/help/app/helpers/auto_tickets_path_helper.rb
new file mode 100644
index 0000000..bb71260
--- /dev/null
+++ b/help/app/helpers/auto_tickets_path_helper.rb
@@ -0,0 +1,51 @@
+#
+# These "auto" forms of the normal ticket path route helpers allow us to do two things automatically:
+#
+# (1) include the user in the path if appropriate.
+# (2) retain the sort params, if appropriate.
+#
+# Tickets views with a user_id are limited to that user. For admins, they don't need a user_id for any ticket action.
+#
+# This is available both to the views and the tickets_controller.
+#
+module AutoTicketsPathHelper
+
+ protected
+
+ def auto_tickets_path(options={})
+ options = ticket_view_options.merge options
+ if @user
+ user_tickets_path(@user, options)
+ else
+ tickets_path(options)
+ end
+ end
+
+ def auto_ticket_path(ticket, options={})
+ options = ticket_view_options.merge options
+ if @user
+ user_ticket_path(@user, ticket, options)
+ else
+ ticket_path(ticket, options)
+ end
+ end
+
+ def auto_new_ticket_path(options={})
+ options = ticket_view_options.merge options
+ if @user
+ new_user_ticket_path(@user, options)
+ else
+ new_ticket_path(options)
+ end
+ end
+
+ private
+
+ def ticket_view_options
+ hsh = {}
+ hsh[:open_status] = params[:open_status] if params[:open_status] && !params[:open_status].empty?
+ hsh[:sort_order] = params[:sort_order] if params[:sort_order] && !params[:sort_order].empty?
+ hsh
+ end
+
+end \ No newline at end of file
diff --git a/help/app/helpers/tickets_helper.rb b/help/app/helpers/tickets_helper.rb
index bd2c069..7af50d6 100644
--- a/help/app/helpers/tickets_helper.rb
+++ b/help/app/helpers/tickets_helper.rb
@@ -1,27 +1,54 @@
module TicketsHelper
+ #
+ # FORM HELPERS
+ #
- def status
- params[:open_status] || 'open'
+ #
+ # 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
- def admin
- # do we not want this set for non-admins? the param will be viewable in the url
- params[:admin_status] || 'all'
+ #
+ # PARAM HELPERS
+ #
+
+ def search_status
+ if action?(:index)
+ params[:open_status] || 'open'
+ else
+ nil
+ end
end
- def order
+ def search_order
params[:sort_order] || 'updated_at_desc'
end
+ #
+ # LINK HELPERS
+ #
+
def link_to_status(new_status)
- label = new_status + ' issues'
- link_to label, :open_status => new_status, :admin_status => admin, :sort_order => order
+ if new_status == "open"
+ label = t(:open_tickets)
+ elsif new_status == "closed"
+ label = t(:closed_tickets)
+ elsif new_status == "all"
+ label = t(:all_tickets)
+ end
+ link_to label, auto_tickets_path(:open_status => new_status, :sort_order => search_order)
end
def link_to_order(order_field)
- if order.start_with?(order_field)
+ if search_order.start_with?(order_field)
# link for currently-filtered field. Link to other direction of this field.
- if order.end_with? 'asc'
+ if search_order.end_with? 'asc'
direction = 'desc'
icon_direction = 'up'
else
@@ -35,8 +62,14 @@ module TicketsHelper
direction = 'desc'
end
- link_to :sort_order => order_field + '_at_' + direction, :open_status => status, :admin_status => admin do
- arrow + order_field + ' at'
+ if order_field == 'updated'
+ label = t(:updated)
+ elsif order_field == 'created'
+ label = t(:created)
+ end
+
+ link_to auto_tickets_path(:sort_order => order_field + '_at_' + direction, :open_status => search_status) do
+ arrow + label
end
end