Radarr/UI/Calendar/CalendarView.js

112 lines
4.0 KiB
JavaScript
Raw Normal View History

'use strict';
define(
[
2013-06-28 15:43:37 +00:00
'app',
'marionette',
'moment',
'Calendar/Collection',
2013-06-28 15:43:37 +00:00
'Episode/Layout',
'fullcalendar'
], function (App, Marionette, Moment, CalendarCollection, EpisodeLayout) {
var _instance;
2013-02-25 00:00:17 +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',
right : 'month,basicWeek'
},
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-06-28 15:43:37 +00:00
eventClick : function (event) {
var view = new EpisodeLayout({ model: event.model });
App.modalRegion.show(view);
}
});
2013-06-05 05:07:42 +00:00
_instance = this;
},
2013-02-26 03:30:24 +00:00
onShow: function () {
this.$('.fc-button-today').click();
},
2013-02-26 03:30:24 +00:00
getEvents: function (start, end, callback) {
var startDate = Moment(start).toISOString();
var endDate = Moment(end).toISOString();
2013-05-01 01:54:15 +00:00
_instance.collection.fetch({
data : { start: startDate, end: endDate },
success: function (calendarCollection) {
_.each(calendarCollection.models, function (element) {
var episodeTitle = element.get('title');
var seriesTitle = element.get('series').get('title');
var start = element.get('airDate');
2013-07-17 00:41:04 +00:00
var statusLevel = _instance.getStatusLevel(element);
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,
allDay : false,
statusLevel : statusLevel
2013-06-28 15:43:37 +00:00
});
element.set('model', element);
});
callback(calendarCollection.toJSON());
}
});
2013-07-17 00:41:04 +00:00
},
getStatusLevel: function (element) {
var hasFile = element.get('hasFile');
var currentTime = Moment();
var start = Moment(element.get('airDate'));
var end = Moment(element.get('end'));
2013-07-17 00:41:04 +00:00
var statusLevel = 'primary';
if (currentTime.isAfter(start) && currentTime.isBefore(end)) {
statusLevel = 'warning';
}
else if (start.isBefore(currentTime) && !hasFile) {
statusLevel = 'danger';
2013-07-17 00:41:04 +00:00
}
else if (hasFile) {
statusLevel = 'success';
2013-07-17 00:41:04 +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
}
return statusLevel;
}
});
});