From 53ed4b0404019546887ca72b85598dbf333e42bc Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Wed, 22 Feb 2012 13:44:01 +0800 Subject: [PATCH] Initial changes in announcement for sorting and filtering --- app/helpers/application_helper.rb | 28 ++ app/views/layouts/_orbit_bar.html.erb | 2 +- app/views/layouts/_side_bar.html.erb | 50 ++- config/locales/en.yml | 1 + .../back_end/bulletins_controller.rb | 2 +- .../back_end/bulletins/_filter.html.erb | 109 ++--- .../back_end/bulletins/_form.html.erb | 398 +++++++++++++++++- .../back_end/bulletins/edit.html.erb | 13 +- .../back_end/bulletins/index.html.erb | 69 +-- 9 files changed, 530 insertions(+), 142 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c8754b314..ad2309f9a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -55,5 +55,33 @@ module ApplicationHelper render :partial => partial, :object => new_object, :locals => {:f => f} end end + + def active_for_controllers(*controller_names) + controller_names.include?(controller.controller_name) ? 'active' : nil + end + + def visible_for_controllers(*controller_names) + controller_names.include?(controller.controller_name) ? '' : 'hide' + end + + def active_for_action(controller_name, action_name) + (controller.controller_name.eql?(controller_name) && controller.action_name.eql?(action_name)) ? 'active' : nil + end + + def sortable(column) + direction = (column == params[:sort] && params[:direction] == "asc") ? "desc" : "asc" + {:sort => column, :direction => direction} + end + + def add_filter(param_name, value) + filter = params[:filter] rescue nil + if filter && filter.has_key(param_name) + filter[param_name] << value + elsif filter + filter.merge({param_name => [value]}) + else + {param_name => [value]} + end + end end diff --git a/app/views/layouts/_orbit_bar.html.erb b/app/views/layouts/_orbit_bar.html.erb index 469ddc8f5..f4f8feef7 100644 --- a/app/views/layouts/_orbit_bar.html.erb +++ b/app/views/layouts/_orbit_bar.html.erb @@ -15,7 +15,6 @@