From f08e6341c6d97d75f76923c33b5fee35d08522f8 Mon Sep 17 00:00:00 2001 From: Felix Niklas Date: Thu, 17 Sep 2015 12:21:45 +0200 Subject: [PATCH] business times: write changes to @options.hours --- .../_ui_element/business_hours.js.coffee | 6 +++++- .../app/lib/app_post/business_hours.js.coffee | 15 ++++++++++++--- .../app/views/generic/business_hours.jst.eco | 10 +++++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/business_hours.js.coffee b/app/assets/javascripts/app/controllers/_ui_element/business_hours.js.coffee index d52bea087..d14e42831 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/business_hours.js.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/business_hours.js.coffee @@ -1,6 +1,9 @@ class App.UiElement.business_hours @render: (attribute, params) -> + # Martin: our frontend doesn't create 24:00. + # you have to check second values ('till') for 00:00 + # and convert them to 24:00 hours = mon: active: true @@ -25,8 +28,9 @@ class App.UiElement.business_hours ] fri: active: true - timeframes: + timeframes: [ ['09:00','17:00'] + ] sat: active: false timeframes: [ diff --git a/app/assets/javascripts/app/lib/app_post/business_hours.js.coffee b/app/assets/javascripts/app/lib/app_post/business_hours.js.coffee index cff316841..0bbc9bd18 100644 --- a/app/assets/javascripts/app/lib/app_post/business_hours.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/business_hours.js.coffee @@ -30,9 +30,18 @@ class App.BusinessHours extends Spine.Controller @html html - @$('.js-time').timepicker - showMeridian: false # meridian = am/pm - tillMidnight: true + @$('.js-time') + .timepicker + showMeridian: false # meridian = am/pm + .on 'changeTime.timepicker', @onTimeChange + + onTimeChange: (event) => + input = @$(event.currentTarget) + day = input.attr('data-day') + slot = input.attr('data-slot') + i = input.attr('data-i') + console.log "something changed", event.time + @options.hours[day].timeframes[slot][i] = "#{event.time.hours}:#{event.time.minutes}" addTime: (event) => day = @$(event.currentTarget).attr('data-day') diff --git a/app/assets/javascripts/app/views/generic/business_hours.jst.eco b/app/assets/javascripts/app/views/generic/business_hours.jst.eco index 161c9f55e..a6333db92 100644 --- a/app/assets/javascripts/app/views/generic/business_hours.jst.eco +++ b/app/assets/javascripts/app/views/generic/business_hours.jst.eco @@ -13,15 +13,15 @@ <% end %> - <% for i in [0..@maxTimeframes-1]: %> + <% for slot in [0..@maxTimeframes-1]: %> <% for id, day of @days: %> - <% if @hours[id].timeframes[i]: %> - + <% if @hours[id].timeframes[slot]: %> + - + - + <% else: %> <% end %>