Module: DmCore::RenderHelper
- Defined in:
- app/helpers/dm_core/render_helper.rb
Instance Method Summary collapse
-
#avatar_for(user, size = 32) ⇒ Object
gives the public avatar for a user ——————————————————————————.
-
#page_number ⇒ Object
Used in pagination - get the current page number being displayed ——————————————————————————.
-
#pagination(collection, options = {version: :original}) ⇒ Object
——————————————————————————.
-
#simple_form_theme_wrapper ⇒ Object
Return the name of the simple_form wrapper to use, which the theme can specify.
-
#ut_country_select(object, method, options = {include_blank: true}, html_options = {}) ⇒ Object
Wrapper to pull the list of countries from our table ——————————————————————————.
-
#ut_country_select_collection(options = {include_blank: true, as: :id}) ⇒ Object
Just return the collection for the countries as: :id return the ids of the Country objects as: :code return the 2-letter country code as: :name return the country’s english name (old interface passed in only a true or false to indicate include_blank) ——————————————————————————.
-
#ut_country_select_tag(name, selected = nil, options = {include_blank: true}, html_options = {}) ⇒ Object
Wrapper to pull the list of countries from our table ——————————————————————————.
-
#ut_country_select_with_states(object, method, method_state, options = {include_blank: true}, html_options = {}) ⇒ Object
Wrapper to pull a list of countries from our table It will also call an Ajax function which changes a container with an id of ‘state_select_container’ to a drop down with the proper states for that country.
-
#ut_state_selection(object_method, country_id = 0, selected_state = nil) ⇒ Object
Generates a select menu or a text field, depending on if there are states associated with the chosen country.
Instance Method Details
#avatar_for(user, size = 32) ⇒ Object
gives the public avatar for a user
6 7 8 9 |
# File 'app/helpers/dm_core/render_helper.rb', line 6 def avatar_for(user, size=32) user = User.new(user_profile: UserProfile.new) if user.nil? # avatar comes from the user profile present(user).avatar_for(size) end |
#page_number ⇒ Object
Used in pagination - get the current page number being displayed
13 14 15 |
# File 'app/helpers/dm_core/render_helper.rb', line 13 def page_number @page_number ||= [1, params[:page].to_i].max end |
#pagination(collection, options = {version: :original}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/helpers/dm_core/render_helper.rb', line 85 def pagination(collection, = {version: :original}) if collection.total_entries > 1 if [:version] == :original content_tag(:div, class: 'pagination') do will_paginate(collection, {inner_window: 8, next_label: I18n.t('core.next_page').html_safe, previous_label: I18n.t('core.prev_page').html_safe}.merge()) end else will_paginate(collection, {inner_window: 8, next_label: I18n.t('core.next_page').html_safe, previous_label: I18n.t('core.prev_page').html_safe}.merge()) end end end |
#simple_form_theme_wrapper ⇒ Object
Return the name of the simple_form wrapper to use, which the theme can specify. Typically either :bs2_horizontal_form or :bs3_horizontal_form.
100 101 102 |
# File 'app/helpers/dm_core/render_helper.rb', line 100 def simple_form_theme_wrapper Account.current.theme_option(:simple_form_wrapper) || :bs2_horizontal_form end |
#ut_country_select(object, method, options = {include_blank: true}, html_options = {}) ⇒ Object
Wrapper to pull the list of countries from our table
19 20 21 22 |
# File 'app/helpers/dm_core/render_helper.rb', line 19 def ut_country_select(object, method, = {include_blank: true}, = {}) collection = ut_country_select_collection(include_blank: false, as: [:as]) select(object, method, collection, , ) end |
#ut_country_select_collection(options = {include_blank: true, as: :id}) ⇒ Object
Just return the collection for the countries as: :id return the ids of the Country objects as: :code return the 2-letter country code as: :name return the country’s english name (old interface passed in only a true or false to indicate include_blank)
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/dm_core/render_helper.rb', line 37 def ut_country_select_collection( = {include_blank: true, as: :id}) = {include_blank: , as: :id} if !.is_a?(Hash) collection = ([:include_blank] ? [[" ", ""]] : []) case [:as] when :code collection += ::StateCountryConstants::PRIMARY_COUNTRIES_CODE + DmCore::Country.order('english_name').collect {|p| [ p.english_name, p.code ] } when :name collection += ::StateCountryConstants::PRIMARY_COUNTRIES_NAME + DmCore::Country.order('english_name').collect {|p| [ p.english_name, p.english_name ] } else collection += ::StateCountryConstants::PRIMARY_COUNTRIES + DmCore::Country.order('english_name').collect {|p| [ p.english_name, p.id ] } end end |
#ut_country_select_tag(name, selected = nil, options = {include_blank: true}, html_options = {}) ⇒ Object
Wrapper to pull the list of countries from our table
26 27 28 29 |
# File 'app/helpers/dm_core/render_helper.rb', line 26 def ut_country_select_tag(name, selected = nil, = {include_blank: true}, = {}) collection = ut_country_select_collection() select_tag(name, (collection, selected), ) end |
#ut_country_select_with_states(object, method, method_state, options = {include_blank: true}, html_options = {}) ⇒ Object
Wrapper to pull a list of countries from our table It will also call an Ajax function which changes a container with an id of ‘state_select_container’ to a drop down with the proper states for that country.
56 57 58 59 60 61 62 63 |
# File 'app/helpers/dm_core/render_helper.rb', line 56 def ut_country_select_with_states(object, method, method_state, = {include_blank: true}, = {}) collection = ut_country_select_collection(include_blank: false, as: [:as]) state_object_method = "#{object.to_s}[#{method_state.to_s}]" [:id] ||= 'country_select' .merge!({data: {progressid: "indicator_country", objectname: state_object_method}}) select(object, method, collection, , ) end |
#ut_state_selection(object_method, country_id = 0, selected_state = nil) ⇒ Object
Generates a select menu or a text field, depending on if there are states associated with the chosen country.
> object_method: name of model ‘state’ field, used for the tag, such as ‘student’
> country_id: globlized id of the selected country
> selected_state: name of the current state selected
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/dm_core/render_helper.rb', line 71 def ut_state_selection(object_method, country_id = 0, selected_state = nil) if country_id == 0 or country_id.nil? select_tag(object_method, "<option value=''>Please select a country".html_safe) else selected_country = ::StateCountryConstants::COUNTRIES_WITH_STATES.find {|x| x[:id] == country_id} if selected_country select_tag(object_method, (selected_state, selected_country[:code]), {include_blank: true}).html_safe else text_field_tag(object_method, selected_state) end end end |