Allow to specify an order schedule for new orders.
This commit is contained in:
parent
6e990fed4c
commit
219eb71bc9
16 changed files with 204 additions and 8 deletions
|
|
@ -18,6 +18,7 @@
|
|||
//= require stupidtable
|
||||
//= require touchclick
|
||||
//= require delta_input
|
||||
//= require recurring_select
|
||||
|
||||
// Load following statements, when DOM is ready
|
||||
$(function() {
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@
|
|||
*= require token-input-bootstrappy
|
||||
*= require bootstrap-datepicker
|
||||
*= require list.unlist
|
||||
*/
|
||||
*= require recurring_select
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class Admin::ConfigsController < Admin::BaseController
|
|||
end
|
||||
|
||||
def update
|
||||
parse_recurring_selects! params[:config][:order_schedule]
|
||||
ActiveRecord::Base.transaction do
|
||||
# TODO support nested configuration keys
|
||||
params[:config].each do |key, val|
|
||||
|
|
@ -36,4 +37,16 @@ class Admin::ConfigsController < Admin::BaseController
|
|||
@tabs.uniq!
|
||||
end
|
||||
|
||||
# turn recurring rules into something palatable
|
||||
def parse_recurring_selects!(config)
|
||||
if config
|
||||
for k in [:pickup, :ends] do
|
||||
if config[k] and 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]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class OrdersController < ApplicationController
|
|||
|
||||
# Page to create a new order.
|
||||
def new
|
||||
@order = Order.new starts: Time.now, ends: 4.days.from_now, supplier_id: params[:supplier_id]
|
||||
@order = Order.new(supplier_id: params[:supplier_id]).init_dates
|
||||
end
|
||||
|
||||
# Save a new order.
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ module Admin::ConfigsHelper
|
|||
# @param key [Symbol, String] Configuration key.
|
||||
# @param options [Hash] Options passed to the form builder.
|
||||
# @option options [Boolean] :required Wether field is shown as required (default not).
|
||||
# @option options [Array<IceCube::Rule>] :rules Rules for +as: :recurring_select+
|
||||
# @return [String] Form input for configuration key.
|
||||
# @todo find way to pass current value to time_zone input without using default
|
||||
def config_input(form, key, options = {}, &block)
|
||||
return unless @cfg.allowed_key? key
|
||||
options[:label] = config_input_label(form, key)
|
||||
options[:label] ||= config_input_label(form, key)
|
||||
options[:required] ||= false
|
||||
options[:input_html] ||= {}
|
||||
config_input_field_options form, key, options[:input_html]
|
||||
|
|
@ -26,6 +27,7 @@ module Admin::ConfigsHelper
|
|||
options[:default] = options[:input_html].delete(:value)
|
||||
return form.input key, options, &block
|
||||
end
|
||||
block ||= proc { config_input_field form, key, options.merge(options[:input_html]) } if options[:as] == :select_recurring
|
||||
form.input key, options, &block
|
||||
end
|
||||
|
||||
|
|
@ -53,6 +55,11 @@ module Admin::ConfigsHelper
|
|||
unchecked_value = options.delete(:unchecked_value) || 'false'
|
||||
options[:checked] = 'checked' if v=options.delete(:value) and v!='false'
|
||||
form.hidden_field(key, value: unchecked_value, as: :hidden) + form.check_box(key, options, checked_value, false)
|
||||
elsif options[:as] == :select_recurring
|
||||
options[:value] = FoodsoftDateUtil.rule_from(options[:value])
|
||||
options[:rules] ||= []
|
||||
options[:rules].unshift options[:value] unless options[:value].blank?
|
||||
form.select_recurring key, options.delete(:rules).uniq, options
|
||||
else
|
||||
form.input_field key, options
|
||||
end
|
||||
|
|
@ -123,7 +130,7 @@ module Admin::ConfigsHelper
|
|||
# set current value
|
||||
unless options.has_key?(:value)
|
||||
value = @cfg
|
||||
cfg_path.each {|n| value = value[n.to_sym] if value.respond_to? :[] }
|
||||
cfg_path.each {|n| value = value[n] if value.respond_to? :[] }
|
||||
options[:value] = value
|
||||
end
|
||||
options
|
||||
|
|
|
|||
|
|
@ -95,6 +95,21 @@ class Order < ActiveRecord::Base
|
|||
!ends.nil? && ends < Time.now
|
||||
end
|
||||
|
||||
# sets up first guess of dates when initializing a new object
|
||||
# I guess `def initialize` would work, but it's tricky http://stackoverflow.com/questions/1186400
|
||||
def init_dates
|
||||
self.starts ||= Time.now
|
||||
if FoodsoftConfig[:order_schedule]
|
||||
# try to be smart when picking a reference day
|
||||
last = (DateTime.parse(FoodsoftConfig[:order_schedule][:initial]) rescue nil)
|
||||
last ||= Order.finished.reorder(:starts).first.try(:starts)
|
||||
last ||= self.starts
|
||||
# adjust end date
|
||||
self.ends ||= FoodsoftDateUtil.next_occurrence last, self.starts, FoodsoftConfig[:order_schedule][:ends]
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
# search GroupOrder of given Ordergroup
|
||||
def group_order(ordergroup)
|
||||
group_orders.where(:ordergroup_id => ordergroup.id).first
|
||||
|
|
|
|||
|
|
@ -10,3 +10,9 @@
|
|||
.input-prepend
|
||||
%span.add-on= t 'number.currency.format.unit'
|
||||
= config_input_field form, :minimum_balance, as: :decimal, class: 'input-small'
|
||||
|
||||
= form.simple_fields_for :order_schedule do |fields|
|
||||
= fields.simple_fields_for 'ends' do |fields|
|
||||
.fold-line
|
||||
= config_input fields, 'recurr', as: :select_recurring, input_html: {class: 'input-xlarge'}
|
||||
= config_input fields, 'time', input_html: {class: 'input-mini'}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue