Allow clearing default order schedule
This commit is contained in:
parent
61a5314b95
commit
c1413ff817
4 changed files with 14 additions and 7 deletions
|
@ -41,9 +41,14 @@ class Admin::ConfigsController < Admin::BaseController
|
||||||
def parse_recurring_selects!(config)
|
def parse_recurring_selects!(config)
|
||||||
if config
|
if config
|
||||||
for k in [:pickup, :ends] do
|
for k in [:pickup, :ends] do
|
||||||
if config[k] && config[k][:recurr]
|
if config[k]
|
||||||
config[k][:recurr] = ActiveSupport::JSON.decode(config[k][:recurr])
|
# allow clearing it using dummy value '{}' ('' would break recurring_select)
|
||||||
config[k][:recurr] = FoodsoftDateUtil.rule_from(config[k][:recurr]).to_ical if config[k][:recurr]
|
if config[k][:recurr].present? && config[k][:recurr] != '{}'
|
||||||
|
config[k][:recurr] = ActiveSupport::JSON.decode(config[k][:recurr])
|
||||||
|
config[k][:recurr] = FoodsoftDateUtil.rule_from(config[k][:recurr]).to_ical if config[k][:recurr]
|
||||||
|
else
|
||||||
|
config[k] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,6 +59,7 @@ module Admin::ConfigsHelper
|
||||||
options[:value] = FoodsoftDateUtil.rule_from(options[:value])
|
options[:value] = FoodsoftDateUtil.rule_from(options[:value])
|
||||||
options[:rules] ||= []
|
options[:rules] ||= []
|
||||||
options[:rules].unshift options[:value] unless options[:value].blank?
|
options[:rules].unshift options[:value] unless options[:value].blank?
|
||||||
|
options[:rules].push [I18n.t('recurring_select.not_recurring'), '{}'] if options.delete(:allow_blank) # blank after current value
|
||||||
form.select_recurring key, options.delete(:rules).uniq, options
|
form.select_recurring key, options.delete(:rules).uniq, options
|
||||||
else
|
else
|
||||||
form.input_field key, options
|
form.input_field key, options
|
||||||
|
@ -73,7 +74,7 @@ module Admin::ConfigsHelper
|
||||||
head = content_tag :label do
|
head = content_tag :label do
|
||||||
lbl = options[:label] || config_input_label(form, key)
|
lbl = options[:label] || config_input_label(form, key)
|
||||||
field = config_input_field(form, key, as: :boolean, boolean_style: :inline,
|
field = config_input_field(form, key, as: :boolean, boolean_style: :inline,
|
||||||
data: {toggle: 'collapse', target: "##{key}-fields"})
|
data: {toggle: 'collapse', target: "##{key}-fields"})
|
||||||
content_tag :h4 do
|
content_tag :h4 do
|
||||||
# put in span to keep space for tooltip at right
|
# put in span to keep space for tooltip at right
|
||||||
content_tag :span, (lbl + field).html_safe, config_input_tooltip_options(form, key, {})
|
content_tag :span, (lbl + field).html_safe, config_input_tooltip_options(form, key, {})
|
||||||
|
|
|
@ -14,5 +14,5 @@
|
||||||
= form.simple_fields_for :order_schedule do |fields|
|
= form.simple_fields_for :order_schedule do |fields|
|
||||||
= fields.simple_fields_for 'ends' do |fields|
|
= fields.simple_fields_for 'ends' do |fields|
|
||||||
.fold-line
|
.fold-line
|
||||||
= config_input fields, 'recurr', as: :select_recurring, input_html: {class: 'input-xlarge'}
|
= config_input fields, 'recurr', as: :select_recurring, input_html: {class: 'input-xlarge'}, allow_blank: true
|
||||||
= config_input fields, 'time', input_html: {class: 'input-mini'}
|
= config_input fields, 'time', input_html: {class: 'input-mini'}
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
module FoodsoftDateUtil
|
module FoodsoftDateUtil
|
||||||
# find next occurence given a recurring ical string and time
|
# find next occurence given a recurring ical string and time
|
||||||
def self.next_occurrence(start=Time.now, from=start, options={})
|
def self.next_occurrence(start=Time.now, from=start, options={})
|
||||||
if options[:recurr]
|
occ = nil
|
||||||
|
if options && options[:recurr]
|
||||||
schedule = IceCube::Schedule.new(start)
|
schedule = IceCube::Schedule.new(start)
|
||||||
schedule.add_recurrence_rule rule_from(options[:recurr])
|
schedule.add_recurrence_rule rule_from(options[:recurr])
|
||||||
# @todo handle ical parse errors
|
# @todo handle ical parse errors
|
||||||
occ = (schedule.next_occurrence(from).to_time rescue nil)
|
occ = (schedule.next_occurrence(from).to_time rescue nil)
|
||||||
end
|
end
|
||||||
if occ && options[:time]
|
if options && options[:time] && occ
|
||||||
occ = occ.beginning_of_day.advance(seconds: Time.parse(options[:time]).seconds_since_midnight)
|
occ = occ.beginning_of_day.advance(seconds: Time.parse(options[:time]).seconds_since_midnight)
|
||||||
end
|
end
|
||||||
occ
|
occ
|
||||||
|
|
Loading…
Reference in a new issue