2013-07-24 01:15:58 +00:00
|
|
|
|
'use strict';
|
2013-02-23 17:42:15 +00:00
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
define(
|
|
|
|
|
[
|
2013-06-28 15:43:37 +00:00
|
|
|
|
'app',
|
2013-06-24 23:41:59 +00:00
|
|
|
|
'marionette',
|
2013-07-17 06:23:44 +00:00
|
|
|
|
'moment',
|
2013-06-24 23:41:59 +00:00
|
|
|
|
'Calendar/Collection',
|
|
|
|
|
'fullcalendar'
|
2013-07-24 04:16:52 +00:00
|
|
|
|
], function (App, Marionette, Moment, CalendarCollection) {
|
2013-03-01 04:59:06 +00:00
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
var _instance;
|
2013-02-25 00:00:17 +00:00
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
return Marionette.ItemView.extend({
|
|
|
|
|
initialize: function () {
|
|
|
|
|
this.collection = new CalendarCollection();
|
|
|
|
|
},
|
|
|
|
|
render : function () {
|
|
|
|
|
$(this.$el).empty().fullCalendar({
|
|
|
|
|
defaultView : 'basicWeek',
|
|
|
|
|
allDayDefault : false,
|
|
|
|
|
ignoreTimezone: false,
|
|
|
|
|
weekMode : 'variable',
|
|
|
|
|
timeFormat : 'h(:mm)tt',
|
|
|
|
|
header : {
|
|
|
|
|
left : 'prev,next today',
|
|
|
|
|
center: 'title',
|
2013-07-29 01:38:00 +00:00
|
|
|
|
right : 'month,basicWeek,basicDay'
|
2013-06-24 23:41:59 +00:00
|
|
|
|
},
|
|
|
|
|
buttonText : {
|
|
|
|
|
prev: '<i class="icon-arrow-left"></i>',
|
|
|
|
|
next: '<i class="icon-arrow-right"></i>'
|
|
|
|
|
},
|
|
|
|
|
events : this.getEvents,
|
|
|
|
|
eventRender : function (event, element) {
|
|
|
|
|
$(element).addClass(event.statusLevel);
|
|
|
|
|
$(element).children('.fc-event-inner').addClass(event.statusLevel);
|
|
|
|
|
},
|
2013-07-24 01:15:58 +00:00
|
|
|
|
eventClick : function (event) {
|
2013-07-24 04:16:52 +00:00
|
|
|
|
App.vent.trigger(App.Commands.ShowEpisodeDetails, {episode: event.model});
|
2013-06-24 23:41:59 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2013-06-05 05:07:42 +00:00
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
_instance = this;
|
|
|
|
|
},
|
2013-02-26 03:30:24 +00:00
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
onShow: function () {
|
|
|
|
|
this.$('.fc-button-today').click();
|
|
|
|
|
},
|
2013-02-26 03:30:24 +00:00
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
getEvents: function (start, end, callback) {
|
2013-07-17 06:23:44 +00:00
|
|
|
|
var startDate = Moment(start).toISOString();
|
|
|
|
|
var endDate = Moment(end).toISOString();
|
2013-05-01 01:54:15 +00:00
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
_instance.collection.fetch({
|
|
|
|
|
data : { start: startDate, end: endDate },
|
|
|
|
|
success: function (calendarCollection) {
|
2013-08-22 04:30:26 +00:00
|
|
|
|
calendarCollection.each(function (element) {
|
2013-06-24 23:41:59 +00:00
|
|
|
|
var episodeTitle = element.get('title');
|
2013-08-21 21:47:39 +00:00
|
|
|
|
var seriesTitle = element.get('series').title;
|
2013-07-24 05:28:06 +00:00
|
|
|
|
var start = element.get('airDateUtc');
|
2013-08-21 21:47:39 +00:00
|
|
|
|
var runtime = element.get('series').runtime;
|
2013-08-22 04:30:26 +00:00
|
|
|
|
var end = Moment(start).add('minutes', runtime).toISOString();
|
|
|
|
|
|
2013-05-01 01:54:15 +00:00
|
|
|
|
|
2013-06-28 15:43:37 +00:00
|
|
|
|
element.set({
|
2013-07-17 00:41:04 +00:00
|
|
|
|
title : seriesTitle,
|
2013-06-28 15:43:37 +00:00
|
|
|
|
episodeTitle: episodeTitle,
|
2013-07-17 00:41:04 +00:00
|
|
|
|
start : start,
|
2013-08-21 21:47:39 +00:00
|
|
|
|
end : end,
|
2013-08-22 04:30:26 +00:00
|
|
|
|
allDay : false
|
2013-06-28 15:43:37 +00:00
|
|
|
|
});
|
|
|
|
|
|
2013-08-22 04:30:26 +00:00
|
|
|
|
element.set('statusLevel', _instance.getStatusLevel(element));
|
2013-06-28 15:43:37 +00:00
|
|
|
|
element.set('model', element);
|
2013-06-24 23:41:59 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(calendarCollection.toJSON());
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-07-17 00:41:04 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getStatusLevel: function (element) {
|
|
|
|
|
var hasFile = element.get('hasFile');
|
2013-07-17 06:23:44 +00:00
|
|
|
|
var currentTime = Moment();
|
2013-07-24 05:28:06 +00:00
|
|
|
|
var start = Moment(element.get('airDateUtc'));
|
2013-07-17 06:23:44 +00:00
|
|
|
|
var end = Moment(element.get('end'));
|
2013-07-17 00:41:04 +00:00
|
|
|
|
|
2013-07-18 05:52:13 +00:00
|
|
|
|
var statusLevel = 'primary';
|
|
|
|
|
|
2013-07-29 02:30:01 +00:00
|
|
|
|
if (hasFile) {
|
|
|
|
|
statusLevel = 'success';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (currentTime.isAfter(start) && currentTime.isBefore(end)) {
|
2013-08-22 04:30:26 +00:00
|
|
|
|
var s = start.toISOString();
|
|
|
|
|
var e = end.toISOString();
|
|
|
|
|
var c = currentTime.toISOString();
|
|
|
|
|
|
2013-07-18 05:52:13 +00:00
|
|
|
|
statusLevel = 'warning';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (start.isBefore(currentTime) && !hasFile) {
|
|
|
|
|
statusLevel = 'danger';
|
2013-07-17 00:41:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-18 05:52:13 +00:00
|
|
|
|
var test = currentTime.startOf('day').format('LLLL');
|
|
|
|
|
|
|
|
|
|
if (end.isBefore(currentTime.startOf('day'))) {
|
|
|
|
|
statusLevel += ' past'
|
2013-07-17 00:41:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-18 05:52:13 +00:00
|
|
|
|
return statusLevel;
|
2013-06-24 23:41:59 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2013-02-23 17:42:15 +00:00
|
|
|
|
});
|