Product category improvements
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
$( ->
|
||||
week_days_container = $('#week_days-group')
|
||||
$('.week-day-select').each( (i)->
|
||||
select = $(this)
|
||||
container = select.siblings('.btn-group')
|
||||
toggle = $('<button type="button" class="btn"></button>')
|
||||
toggle.attr('data-t', 'product_category.week_days.abbreviation.'+select.data('day'))
|
||||
toggle.addClass('active') if select.val() == '1'
|
||||
container.append(toggle)
|
||||
week_days_container.append(toggle)
|
||||
toggle.click( -> select.val(Math.abs(select.val() - 1)))
|
||||
)
|
||||
|
||||
$('#full_day-controller').each ->
|
||||
control = $('#product_category_full_day')
|
||||
unless control.is(':checked')
|
||||
$(@).addClass('icon-white')
|
||||
$('#sub-day-container').removeClass('hide')
|
||||
$(@).click ->
|
||||
if control.is(':checked')
|
||||
control.prop 'checked', false
|
||||
$(@).addClass 'icon-white'
|
||||
$('#sub-day-container').removeClass('hide')
|
||||
else
|
||||
control.prop 'checked', true
|
||||
$(@).removeClass 'icon-white'
|
||||
$('#sub-day-container').addClass('hide')
|
||||
|
||||
|
||||
# GOOGLE LOCATION PICKER
|
||||
$("input.location_picker").each( (i)->
|
||||
return if typeof(google) == 'undefined'
|
||||
|
||||
@@ -10,3 +10,12 @@
|
||||
opacity: 0.4
|
||||
&.active
|
||||
opacity: 1
|
||||
#full_day-controller
|
||||
margin: 0 10px
|
||||
#sub-day-container
|
||||
display: inline-block
|
||||
&.hide
|
||||
display: none
|
||||
select
|
||||
width: 70px
|
||||
margin-right: 14px
|
||||
|
||||
@@ -15,7 +15,7 @@ module Suppliers
|
||||
# GET /products/1
|
||||
# GET /products/1.json
|
||||
def show
|
||||
@product = ProductDecorator.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@product = ProductDecorator.decorate(Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id]))
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
|
||||
@@ -11,9 +11,7 @@ class ProductDecorator < Draper::Decorator
|
||||
end
|
||||
|
||||
def display
|
||||
|
||||
"#{model.name} (#{h.currency(model.price)})".html_safe
|
||||
|
||||
end
|
||||
|
||||
# Accessing Helpers
|
||||
|
||||
@@ -5,8 +5,8 @@ class ProductCategory
|
||||
property :position, type: Fixnum, default: 0
|
||||
property :week_days, type: Array, default: Array.new(7, 1)
|
||||
property :full_day, type: :boolean, default: true
|
||||
property :start_from, type: Fixnum, default: 0
|
||||
property :end_on, type: Fixnum, default: 2880 # Two days in minutes
|
||||
property :start_from, type: Fixnum, default: 1320 # 22:00
|
||||
property :end_on, type: Fixnum, default: 1380 # 23:00
|
||||
|
||||
belongs_to :supplier
|
||||
has_and_belongs_to_many :products, storing_keys: true
|
||||
@@ -72,7 +72,7 @@ class ProductCategory
|
||||
|
||||
# time is not by default Time.now.utc since it can be specified as nil
|
||||
def self.for_supplier_in_time(supplier, time = nil)
|
||||
time ||= Time.now.utc
|
||||
time ||= Time.now.in_time_zone(supplier.time_zone)
|
||||
minute = (time.seconds_since_midnight/60).round
|
||||
week_day = time.wday
|
||||
if minute < supplier.night_offset
|
||||
|
||||
@@ -10,9 +10,18 @@
|
||||
= label_tag "product-checker-#{product.id}", product.display
|
||||
br
|
||||
.control-group
|
||||
#week_days-group.btn-group data-toggle="buttons-checkbox"
|
||||
.controls
|
||||
#week_days-group.btn-group data-toggle="buttons-checkbox"
|
||||
span#full_day-controller.icon.icon-time
|
||||
#sub-day-container.hide
|
||||
= f.input_field :start_from, as: :select, collection: (1..24).map{|h| ["#{h}:00", h*60]}
|
||||
= f.input_field :end_on, as: :select, collection: (1..24).map{|h| ["#{h}:00", h*60]}
|
||||
.hidden
|
||||
- @product_category.week_days.each.with_index do |day, i|
|
||||
= select_tag 'product_category[week_days][]', options_for_select([0,1], day), class: 'week-day-select', data: {day:%w[sunday monday tuesday wednesday thursday friday saturday][i]}
|
||||
/= f.input :full_day, as: :select, collection: [true, false], label: false, include_blank: false
|
||||
= f.input_field :full_day, as: :boolean, label: false, wrapper: false
|
||||
/= f.check_box :full_day
|
||||
|
||||
.form-actions
|
||||
= f.button :submit, class: 'btn-primary'
|
||||
|
||||
Reference in New Issue
Block a user