diff --git a/app/assets/javascripts/supplier/initializer.js.coffee b/app/assets/javascripts/supplier/initializer.js.coffee index 4df562ff..6df995d6 100644 --- a/app/assets/javascripts/supplier/initializer.js.coffee +++ b/app/assets/javascripts/supplier/initializer.js.coffee @@ -1,13 +1,30 @@ $( -> + week_days_container = $('#week_days-group') $('.week-day-select').each( (i)-> select = $(this) - container = select.siblings('.btn-group') toggle = $('') 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' diff --git a/app/assets/stylesheets/supplier/product_categories.css.sass b/app/assets/stylesheets/supplier/product_categories.css.sass index 1483823d..2f0efc1f 100644 --- a/app/assets/stylesheets/supplier/product_categories.css.sass +++ b/app/assets/stylesheets/supplier/product_categories.css.sass @@ -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 diff --git a/app/controllers/suppliers/products_controller.rb b/app/controllers/suppliers/products_controller.rb index 9ee00c65..c755958c 100644 --- a/app/controllers/suppliers/products_controller.rb +++ b/app/controllers/suppliers/products_controller.rb @@ -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 diff --git a/app/decorators/product_decorator.rb b/app/decorators/product_decorator.rb index fc5bb936..075b2ecd 100644 --- a/app/decorators/product_decorator.rb +++ b/app/decorators/product_decorator.rb @@ -11,9 +11,7 @@ class ProductDecorator < Draper::Decorator end def display - "#{model.name} (#{h.currency(model.price)})".html_safe - end # Accessing Helpers diff --git a/app/models/product_category.rb b/app/models/product_category.rb index 52f03ac0..578d9589 100644 --- a/app/models/product_category.rb +++ b/app/models/product_category.rb @@ -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 diff --git a/app/views/suppliers/product_categories/_form.html.slim b/app/views/suppliers/product_categories/_form.html.slim index bf5059ed..3285d58f 100644 --- a/app/views/suppliers/product_categories/_form.html.slim +++ b/app/views/suppliers/product_categories/_form.html.slim @@ -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'