Module: RecurringSelectHelper::FormOptionsHelper

Included in:
InstanceTag, RecurringSelectTag
Defined in:
app/helpers/recurring_select_helper.rb

Instance Method Summary collapse

Instance Method Details

#recurring_options_for_select(currently_selected_rule = nil, default_schedules = nil, options = {}) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/recurring_select_helper.rb', line 27

def recurring_options_for_select(currently_selected_rule = nil, default_schedules = nil, options = {})

  options_array = []
  blank_option_label = options[:blank_label] || I18n.t("recurring_select.not_recurring")
  blank_option = [blank_option_label, "null"]
  separator = [I18n.t("recurring_select.or"), {:disabled => true}]

  if default_schedules.blank?
    if currently_selected_rule.present?
      options_array << ice_cube_rule_to_option(currently_selected_rule)
      options_array << separator
      options_array << [I18n.t("recurring_select.change_schedule"), "custom"]
      options_array << blank_option if options[:allow_blank]
    else
      options_array << blank_option
      options_array << [I18n.t("recurring_select.set_schedule"), "custom"]
    end
  else
    options_array << blank_option if options[:allow_blank]

    options_array += default_schedules.collect{|dc|
      ice_cube_rule_to_option(dc)
    }

    if currently_selected_rule.present? and !current_rule_in_defaults?(currently_selected_rule, default_schedules)
      options_array << ice_cube_rule_to_option(currently_selected_rule, true)
      custom_label = [I18n.t("recurring_select.new_custom_schedule"), "custom"]
    else
      custom_label = [I18n.t("recurring_select.custom_schedule"), "custom"]
    end

    options_array << separator
    options_array << custom_label
  end

  options_for_select(options_array, currently_selected_rule.to_json)
end