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 5f25812d6..d52bea087 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,36 +1,42 @@ class App.UiElement.business_hours @render: (attribute, params) -> - hours = { - mon: { + hours = + mon: active: true - timeframes: ['09:00-17:00'] - } - tue: { + timeframes: [ + ['09:00','17:00'] + ] + tue: active: true - timeframes: ['00:00-24:00'] - } - wed: { + timeframes: [ + ['00:00','24:00'] + ] + wed: active: true - timeframes: ['09:00-17:00'] - } - thu: { + timeframes: [ + ['09:00','17:00'] + ] + thu: active: true - timeframes: ['09:00-12:00', '13:00-17:00'] - } - fri: { + timeframes: [ + ['09:00','12:00'] + ['13:00','17:00'] + ] + fri: active: true - timeframes: ['09:00-17:00'] - } - sat: { + timeframes: + ['09:00','17:00'] + sat: active: false - timeframes: ['10:00-14:00'] - } - sun: { + timeframes: [ + ['10:00','14:00'] + ] + sun: active: false - timeframes: ['10:00-14:00'] - } - } + timeframes: [ + ['10:00','14:00'] + ] businessHours = new App.BusinessHours hours: hours 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 47f5290cf..cff316841 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 @@ -4,13 +4,14 @@ class App.BusinessHours extends Spine.Controller tag: 'table' events: - 'click .js-activateColumn': 'activateColumn' + 'click .js-toggle-day': 'toggleDay' + 'click .js-add-time': 'addTime' + 'click .js-remove-time': 'removeTime' constructor: -> super - render: => - days = + @days = mon: App.i18n.translateInline('Monday') tue: App.i18n.translateInline('Tuesday') wed: App.i18n.translateInline('Wednesday') @@ -19,18 +20,32 @@ class App.BusinessHours extends Spine.Controller sat: App.i18n.translateInline('Saturday') sun: App.i18n.translateInline('Sunday') - html = App.view('generic/business_hours') - days: days - hours: @options.hours + render: => + maxTimeframeDay = _.max @hours, (day) -> day.timeframes.length - console.log "BusinessHours:", "days", days, "hours", @options.hours, "html", html + html = App.view('generic/business_hours') + days: @days + hours: @options.hours + maxTimeframes: maxTimeframeDay.timeframes.length @html html @$('.js-time').timepicker showMeridian: false # meridian = am/pm + tillMidnight: true - activateColumn: (event) => + addTime: (event) => + day = @$(event.currentTarget).attr('data-day') + @options.hours[day].timeframes.push(['13:00', '17:00']) + @render() + + removeTime: (event) => + day = @$(event.currentTarget).attr('data-day') + @options.hours[day].timeframes.pop() + @render() + + toggleDay: (event) => checkbox = @$(event.currentTarget) - columnName = checkbox.attr('data-target') - @$("[data-column=#{columnName}]").toggleClass('is-active', checkbox.prop('checked')) + day = checkbox.attr('data-target') + @options.hours[day].active = checkbox.prop('checked') + @$("[data-day=#{day}]").toggleClass('is-active', checkbox.prop('checked')) 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 157a472f8..161c9f55e 100644 --- a/app/assets/javascripts/app/views/generic/business_hours.jst.eco +++ b/app/assets/javascripts/app/views/generic/business_hours.jst.eco @@ -4,7 +4,7 @@