Product category improvements

This commit is contained in:
2013-02-26 09:40:29 +01:00
parent 0c3bec5c4a
commit 08333cb1bb
6 changed files with 42 additions and 9 deletions
@@ -1,13 +1,30 @@
$( -> $( ->
week_days_container = $('#week_days-group')
$('.week-day-select').each( (i)-> $('.week-day-select').each( (i)->
select = $(this) select = $(this)
container = select.siblings('.btn-group')
toggle = $('<button type="button" class="btn"></button>') toggle = $('<button type="button" class="btn"></button>')
toggle.attr('data-t', 'product_category.week_days.abbreviation.'+select.data('day')) toggle.attr('data-t', 'product_category.week_days.abbreviation.'+select.data('day'))
toggle.addClass('active') if select.val() == '1' toggle.addClass('active') if select.val() == '1'
container.append(toggle) week_days_container.append(toggle)
toggle.click( -> select.val(Math.abs(select.val() - 1))) 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 # GOOGLE LOCATION PICKER
$("input.location_picker").each( (i)-> $("input.location_picker").each( (i)->
return if typeof(google) == 'undefined' return if typeof(google) == 'undefined'
@@ -10,3 +10,12 @@
opacity: 0.4 opacity: 0.4
&.active &.active
opacity: 1 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
# GET /products/1.json # GET /products/1.json
def show 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| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
-2
View File
@@ -11,9 +11,7 @@ class ProductDecorator < Draper::Decorator
end end
def display def display
"#{model.name} (#{h.currency(model.price)})".html_safe "#{model.name} (#{h.currency(model.price)})".html_safe
end end
# Accessing Helpers # Accessing Helpers
+3 -3
View File
@@ -5,8 +5,8 @@ class ProductCategory
property :position, type: Fixnum, default: 0 property :position, type: Fixnum, default: 0
property :week_days, type: Array, default: Array.new(7, 1) property :week_days, type: Array, default: Array.new(7, 1)
property :full_day, type: :boolean, default: true property :full_day, type: :boolean, default: true
property :start_from, type: Fixnum, default: 0 property :start_from, type: Fixnum, default: 1320 # 22:00
property :end_on, type: Fixnum, default: 2880 # Two days in minutes property :end_on, type: Fixnum, default: 1380 # 23:00
belongs_to :supplier belongs_to :supplier
has_and_belongs_to_many :products, storing_keys: true 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 # time is not by default Time.now.utc since it can be specified as nil
def self.for_supplier_in_time(supplier, time = 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 minute = (time.seconds_since_midnight/60).round
week_day = time.wday week_day = time.wday
if minute < supplier.night_offset if minute < supplier.night_offset
@@ -10,9 +10,18 @@
= label_tag "product-checker-#{product.id}", product.display = label_tag "product-checker-#{product.id}", product.display
br br
.control-group .control-group
.controls
#week_days-group.btn-group data-toggle="buttons-checkbox" #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| - @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]} = 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 .form-actions
= f.button :submit, class: 'btn-primary' = f.button :submit, class: 'btn-primary'