You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Prowlarr/UI/Calendar/CalendarView.js

104 lines
3.7 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

'use strict';
define(
[
'app',
'marionette',
'moment',
'Calendar/Collection',
'Episode/Layout',
'fullcalendar'
], function (App, Marionette, Moment, CalendarCollection, EpisodeLayout) {
var _instance;
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);
},
eventClick : function (event) {
var view = new EpisodeLayout({ model: event.model });
App.modalRegion.show(view);
}
});
_instance = this;
},
onShow: function () {
this.$('.fc-button-today').click();
},
getEvents: function (start, end, callback) {
var startDate = Moment(start).toISOString();
var endDate = Moment(end).toISOString();
_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');
var statusLevel = _instance.getStatusLevel(element);
element.set({
title : seriesTitle,
episodeTitle: episodeTitle,
start : start,
allDay : false,
statusLevel : statusLevel
});
element.set('model', element);
});
callback(calendarCollection.toJSON());
}
});
},
getStatusLevel: function (element) {
var hasFile = element.get('hasFile');
var currentTime = Moment();
var start = Moment(element.get('airDate'));
var end = Moment(element.get('end'));
if (currentTime.isAfter(start) && currentTime.isBefore(end)) {
return 'warning';
}
if (start.isBefore(currentTime) && !hasFile) {
return 'danger';
}
if (hasFile) {
return 'success';
}
return 'primary';
}
});
});