2016-07-13 19:12:16 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
##
|
|
|
|
# Controller used in the public calendar global
|
|
|
|
##
|
|
|
|
|
2016-06-28 18:58:44 +02:00
|
|
|
Application.Controllers.controller "CalendarController", ["$scope", "$state", "$uibModal", "moment", "Availability", 'Slot', 'Setting', 'growl', 'dialogs', 'bookingWindowStart', 'bookingWindowEnd', '_t', 'uiCalendarConfig', 'CalendarConfig'
|
|
|
|
($scope, $state, $uibModal, moment, Availability, Slot, Setting, growl, dialogs, bookingWindowStart, bookingWindowEnd, _t, uiCalendarConfig, CalendarConfig) ->
|
2016-07-13 19:12:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
### PRIVATE STATIC CONSTANTS ###
|
|
|
|
|
|
|
|
|
|
|
|
### PUBLIC SCOPE ###
|
|
|
|
|
2016-06-29 12:40:17 +02:00
|
|
|
## add availabilities url to event sources
|
2016-07-13 19:12:16 +02:00
|
|
|
$scope.eventSources = []
|
|
|
|
$scope.eventSources.push
|
|
|
|
url: '/api/availabilities/public'
|
|
|
|
textColor: 'black'
|
|
|
|
|
|
|
|
## fullCalendar (v2) configuration
|
|
|
|
$scope.calendarConfig = CalendarConfig
|
2016-06-29 12:40:17 +02:00
|
|
|
slotEventOverlap: true
|
2016-07-13 19:12:16 +02:00
|
|
|
header:
|
|
|
|
left: 'month agendaWeek agendaDay'
|
|
|
|
center: 'title'
|
|
|
|
right: 'today prev,next'
|
|
|
|
minTime: moment.duration(moment(bookingWindowStart.setting.value).format('HH:mm:ss'))
|
|
|
|
maxTime: moment.duration(moment(bookingWindowEnd.setting.value).format('HH:mm:ss'))
|
2016-06-28 18:58:44 +02:00
|
|
|
eventClick: (event, jsEvent, view)->
|
|
|
|
calendarEventClickCb(event, jsEvent, view)
|
|
|
|
viewRender: (view, element) ->
|
2016-06-29 12:40:17 +02:00
|
|
|
viewRenderCb(view, element)
|
2016-06-28 18:58:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
### PRIVATE SCOPE ###
|
|
|
|
|
|
|
|
calendarEventClickCb = (event, jsEvent, view) ->
|
|
|
|
## current calendar object
|
|
|
|
calendar = uiCalendarConfig.calendars.calendar
|
|
|
|
if event.available_type == 'machines'
|
|
|
|
calendar.fullCalendar('changeView', 'agendaDay')
|
2016-06-29 12:40:17 +02:00
|
|
|
calendar.fullCalendar('gotoDate', event.start)
|
2016-06-28 18:58:44 +02:00
|
|
|
else
|
|
|
|
if event.available_type == 'event'
|
|
|
|
$state.go('app.public.events_show', {id: event.event_id})
|
2016-06-29 17:58:53 +02:00
|
|
|
else if event.available_type == 'training'
|
|
|
|
else
|
|
|
|
$state.go('app.public.machines_show', {id: event.machine_id})
|
2016-06-29 12:40:17 +02:00
|
|
|
|
|
|
|
## agendaDay view: disable slotEventOverlap
|
|
|
|
## agendaWeek view: enable slotEventOverlap
|
|
|
|
toggleSlotEventOverlap = (view) ->
|
|
|
|
# set defaultView, because when we change slotEventOverlap
|
|
|
|
# ui-calendar will trigger rerender calendar
|
|
|
|
$scope.calendarConfig.defaultView = view.type
|
2016-06-29 17:51:26 +02:00
|
|
|
today = moment().utc().startOf('day')
|
2016-06-29 12:40:17 +02:00
|
|
|
if today > view.start and today <= view.end and today != view.start
|
|
|
|
$scope.calendarConfig.defaultDate = today
|
|
|
|
else
|
|
|
|
$scope.calendarConfig.defaultDate = view.start
|
|
|
|
if view.type == 'agendaDay'
|
|
|
|
$scope.calendarConfig.slotEventOverlap = false
|
|
|
|
else
|
|
|
|
$scope.calendarConfig.slotEventOverlap = true
|
|
|
|
|
|
|
|
## function is called when calendar view is rendered or changed
|
|
|
|
viewRenderCb = (view, element) ->
|
|
|
|
toggleSlotEventOverlap(view)
|
|
|
|
if view.type == 'agendaDay'
|
|
|
|
# get availabilties by 1 day for show machine slots
|
|
|
|
uiCalendarConfig.calendars.calendar.fullCalendar('refetchEvents')
|
2016-07-13 19:12:16 +02:00
|
|
|
]
|