@ -7,14 +7,17 @@ define(
'moment' ,
'moment' ,
'Calendar/Collection' ,
'Calendar/Collection' ,
'System/StatusModel' ,
'System/StatusModel' ,
'History/Queue/QueueCollection' ,
'Mixins/backbone.signalr.mixin' ,
'fullcalendar'
'fullcalendar'
] , function ( vent , Marionette , moment , CalendarCollection , StatusModel ) {
] , function ( vent , Marionette , moment , CalendarCollection , StatusModel , QueueCollection ) {
var _instance ;
var _instance ;
return Marionette . ItemView . extend ( {
return Marionette . ItemView . extend ( {
initialize : function ( ) {
initialize : function ( ) {
this . collection = new CalendarCollection ( ) ;
this . collection = new CalendarCollection ( ) . bindSignalR ( ) ;
this . listenTo ( this . collection , 'change' , this . _reloadCalendarEvents ) ;
} ,
} ,
render : function ( ) {
render : function ( ) {
@ -36,7 +39,7 @@ define(
prev : '<i class="icon-arrow-left"></i>' ,
prev : '<i class="icon-arrow-left"></i>' ,
next : '<i class="icon-arrow-right"></i>'
next : '<i class="icon-arrow-right"></i>'
} ,
} ,
events : this . getEvents,
viewRender : this . _ getEvents,
eventRender : function ( event , element ) {
eventRender : function ( event , element ) {
self . $ ( element ) . addClass ( event . statusLevel ) ;
self . $ ( element ) . addClass ( event . statusLevel ) ;
self . $ ( element ) . children ( '.fc-event-inner' ) . addClass ( event . statusLevel ) ;
self . $ ( element ) . children ( '.fc-event-inner' ) . addClass ( event . statusLevel ) ;
@ -53,43 +56,50 @@ define(
this . $ ( '.fc-button-today' ) . click ( ) ;
this . $ ( '.fc-button-today' ) . click ( ) ;
} ,
} ,
getEvents : function ( start , end , callback ) {
_getEvents : function ( view ) {
var startDate = moment ( start ) . toISOString ( ) ;
var start = moment ( view . visStart ) . toISOString ( ) ;
var endDate = moment ( end ) . toISOString ( ) ;
var end = moment ( view . visEnd ) . toISOString ( ) ;
_instance . $el . fullCalendar ( 'removeEvents' ) ;
_instance . collection . fetch ( {
_instance . collection . fetch ( {
data : { start : startDate , end : endDate } ,
data : { start : start , end : end } ,
success : function ( calendarCollection ) {
success : function ( collection ) {
calendarCollection . each ( function ( element ) {
_instance . _setEventData ( collection ) ;
var episodeTitle = element . get ( 'title' ) ;
}
var seriesTitle = element . get ( 'series' ) . title ;
} ) ;
var start = element . get ( 'airDateUtc' ) ;
} ,
var runtime = element . get ( 'series' ) . runtime ;
var end = moment ( start ) . add ( 'minutes' , runtime ) . toISOString ( ) ;
_setEventData : function ( collection ) {
var events = [ ] ;
collection . each ( function ( model ) {
var seriesTitle = model . get ( 'series' ) . title ;
var start = model . get ( 'airDateUtc' ) ;
var runtime = model . get ( 'series' ) . runtime ;
var end = moment ( start ) . add ( 'minutes' , runtime ) . toISOString ( ) ;
element . set ( {
var event = {
title : seriesTitle ,
title : seriesTitle ,
episodeTitle : episodeTitle ,
start : start ,
start : start ,
end : end ,
end : end ,
allDay : false
allDay : false ,
} ) ;
statusLevel : _instance . _getStatusLevel ( model , end ) ,
model : model
} ;
element . set ( 'statusLevel' , _instance . getStatusLevel ( element ) ) ;
events . push ( event ) ;
element . set ( 'model' , element ) ;
} ) ;
} ) ;
callback ( calendarCollection . toJSON ( ) ) ;
_instance . $el . fullCalendar ( 'addEventSource' , events ) ;
}
} ) ;
} ,
} ,
getStatusLevel: function ( element ) {
_ getStatusLevel: function ( element , endTime ) {
var hasFile = element . get ( 'hasFile' ) ;
var hasFile = element . get ( 'hasFile' ) ;
var downloading = QueueCollection . findEpisode ( element . get ( 'id' ) ) || element . get ( 'downloading' ) ;
var currentTime = moment ( ) ;
var currentTime = moment ( ) ;
var start = moment ( element . get ( 'airDateUtc' ) ) ;
var start = moment ( element . get ( 'airDateUtc' ) ) ;
var end = moment ( e lement. get ( 'end' ) ) ;
var end = moment ( e ndTime ) ;
var statusLevel = 'primary' ;
var statusLevel = 'primary' ;
@ -97,6 +107,10 @@ define(
statusLevel = 'success' ;
statusLevel = 'success' ;
}
}
if ( downloading ) {
statusLevel = 'purple' ;
}
else if ( currentTime . isAfter ( start ) && currentTime . isBefore ( end ) ) {
else if ( currentTime . isAfter ( start ) && currentTime . isBefore ( end ) ) {
statusLevel = 'warning' ;
statusLevel = 'warning' ;
}
}
@ -105,13 +119,17 @@ define(
statusLevel = 'danger' ;
statusLevel = 'danger' ;
}
}
var test = currentTime . startOf ( 'day' ) . format ( 'LLLL' ) ;
if ( end . isBefore ( currentTime . startOf ( 'day' ) ) ) {
if ( end . isBefore ( currentTime . startOf ( 'day' ) ) ) {
statusLevel += ' past' ;
statusLevel += ' past' ;
}
}
return statusLevel ;
return statusLevel ;
} ,
_reloadCalendarEvents : function ( ) {
window . alert ( 'collection changed' ) ;
this . $el . fullCalendar ( 'removeEvents' ) ;
this . _setEventData ( this . collection ) ;
}
}
} ) ;
} ) ;
} ) ;
} ) ;