Module: RedmineCrm::FormTagHelper

Defined in:
lib/redmine_crm/helpers/form_tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#datetime_calendar_for(field_id) ⇒ Object



76
77
78
79
# File 'lib/redmine_crm/helpers/form_tag_helper.rb', line 76

def datetime_calendar_for(field_id)
  include_datetime_calendar_headers_tags
  javascript_tag("$(function() { $('##{field_id}').datetimepicker(dateTimePickerOptions); });")
end

#include_datetime_calendar_headers_tagsObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/redmine_crm/helpers/form_tag_helper.rb', line 81

def include_datetime_calendar_headers_tags
  unless @datetime_calendar_headers_tags
    tags = ''.html_safe
    @datetime_calendar_headers_tags = true
    content_for :header_tags do
      start_of_week = Setting.start_of_week
      start_of_week = l(:general_first_day_of_week, :default => '1') if start_of_week.blank?
      start_of_week = start_of_week.to_i % 7

      locale_keys = ::I18n.backend.send(:translations)[::I18n.config.locale]
      time_format = Setting.time_format.blank? ? locale_keys[:time][:formats][:time] : Setting.time_format
      time_format = time_format.to_s.gsub('%H', 'H').gsub('%I', 'hh').gsub('%M', 'mm').gsub('%p', 'tt')

      date_format = 'yy-mm-dd'
      tags << javascript_tag(
        "var dateTimePickerOptions = {dateFormat: '#{date_format}', timeFormat: '#{time_format}', firstDay: #{start_of_week}," +
          "showOn: 'button', buttonImageOnly: true, buttonImage: '" +
          path_to_image('/images/calendar.png') +
          "', showButtonPanel: true, controlType: 'select', oneLine: true, };")
      tags
    end
  end
end

#select2_tag(name, option_tags = nil, options = {}) ⇒ Object Also known as: select2

Allows include select2 into your views.

Examples

select2_tag 'city_id', '<option value="1">Lisbon</option>...'
select2_tag 'city_id', options_for_select(...)
select2_tag 'tag_list', nil, :multiple => true, :data => [{ id: 0, text: 'deal' }, ...], :tags => true, :include_hidden => false %>
select2_tag 'tag_list', options_for_select(...), :multiple => true, :style => 'width: 100%;', :url => '/tags', :placeholder => '+ add tag', :tags => true %>

You may use select_tag options and additional options.

Additional options

  • :url Allows searches for remote data using the ajax.

  • :data Load dropdown options from a local array if url option not set.

  • :placeholder Supports displaying a placeholder value.

  • :include_hidden Adds hidden field after select when multiple option true. Default value true.

  • :allow_clear Provides support for clearable selections. Default value false.

  • :min_input_length Minimum number of characters required to start a search. Default value 0.

  • :format_state Defines template of search results in the drop-down.

  • :tags Used to enable tagging feature.

Note: The HTML specification says when multiple parameter passed to select and all options got deselected web browsers do not send any value to server.

In case if you don’t want the helper to generate this hidden field you can specify include_hidden: false option.

Note: Select2 assets must be available on a page.

To include select2 assets to a page, you need to use the helper select2_assets.
For example:
  <% content_for :header_tags do %>
    <%= select2_assets %>
  <% end %>

Also aliased as: select2

select2 'city_id', options_for_select(...)


40
41
42
43
44
45
46
47
48
# File 'lib/redmine_crm/helpers/form_tag_helper.rb', line 40

def select2_tag(name, option_tags = nil, options = {})
  s = select_tag(name, option_tags, options)

  if options[:multiple] && options.fetch(:include_hidden, true)
    s << hidden_field_tag("#{name}[]", '')
  end

  s + javascript_tag("select2Tag('#{sanitize_to_id(name)}', #{options.to_json});")
end

#transform_to_select2(type, options = {}) ⇒ Object

Transforms select filters of type fields into select2

Examples

transform_to_select2 'tags', url: auto_complete_tags_url
transform_to_select2 'people', format_state: 'formatStateWithAvatar', min_input_length: 1, url: '/managers'

Options

  • :url Defines URL to search remote data using the ajax.

  • :format_state Defines template of search results in the drop-down.

  • :min_input_length Minimum number of characters required to start a search. Default value 0.

  • :width Sets the width of the control. Default value ‘60%’.

  • :multiple Supports multi-value select box. If set to false the selection will not allow multiple choices. Default value true.

Note: Select2 assets must be available on a page.

To include select2 assets to a page, you need to use the helper select2_assets.
For example:
  <% content_for :header_tags do %>
    <%= select2_assets %>
  <% end %>


72
73
74
# File 'lib/redmine_crm/helpers/form_tag_helper.rb', line 72

def transform_to_select2(type, options = {})
  javascript_tag("setSelect2Filter('#{type}', #{options.to_json});") unless type.empty?
end