1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 16:02:29 +01:00
Sonarr/UI/Calendar/CalendarCollectionView.js

86 lines
3.5 KiB
JavaScript
Raw Normal View History

'use strict';
2013-03-30 20:30:00 +01:00
define(['app', 'Calendar/CalendarItemView'], function () {
NzbDrone.Calendar.CalendarCollectionView = Backbone.Marionette.CompositeView.extend({
itemView : NzbDrone.Calendar.CalendarItemView,
2013-02-28 17:34:18 +01:00
itemViewContainer: '#events',
template : 'Calendar/CalendarCollectionTemplate',
ui: {
calendar: '#calendar'
},
initialize : function () {
//should use this.collection?
2013-02-26 04:30:24 +01:00
this.calendar = new NzbDrone.Calendar.CalendarCollection();
},
onCompositeCollectionRendered: function () {
$(this.ui.calendar).empty().fullCalendar({
allDayDefault : false,
2013-02-28 17:34:18 +01:00
ignoreTimezone: false,
weekMode : 'variable',
timeFormat : 'h(:mm)tt',
header : {
left : 'prev,next today',
center: 'title',
right : 'month,basicWeek'
},
buttonText : {
2013-02-25 01:00:17 +01:00
prev: '<i class="icon-arrow-left"></i>',
next: '<i class="icon-arrow-right"></i>'
2013-02-26 04:30:24 +01:00
},
events : this.getEvents,
eventRender : function (event, element) {
$(element).addClass(event.statusLevel);
$(element).children('.fc-event-inner').addClass(event.statusLevel);
2013-02-28 07:48:25 +01:00
element.popover({
title : '{seriesTitle} - {season}x{episode} - {episodeTitle}'.assign({
2013-05-01 03:54:15 +02:00
seriesTitle : event.title,
season : event.seasonNumber,
episode : event.episodeNumber.pad(2),
2013-02-28 07:48:25 +01:00
episodeTitle: event.episodeTitle
}),
content : event.overview,
2013-02-28 07:48:25 +01:00
placement: 'bottom',
trigger : 'manual'
2013-02-28 07:48:25 +01:00
});
},
2013-03-30 20:30:00 +01:00
eventMouseover: function () {
2013-02-28 07:48:25 +01:00
$(this).popover('show');
},
2013-03-30 20:30:00 +01:00
eventMouseout : function () {
2013-02-28 07:48:25 +01:00
$(this).popover('hide');
}
});
2013-02-25 01:00:17 +01:00
2013-02-26 04:30:24 +01:00
NzbDrone.Calendar.CalendarCollectionView.Instance = this;
},
getEvents : function (start, end, callback) {
2013-02-26 04:30:24 +01:00
var bbView = NzbDrone.Calendar.CalendarCollectionView.Instance;
var startDate = Date.create(start).format(Date.ISO8601_DATETIME);
var endDate = Date.create(end).format(Date.ISO8601_DATETIME);
2013-02-26 04:30:24 +01:00
bbView.calendar.fetch({
data : { start: startDate, end: endDate },
success: function (calendarCollection) {
2013-05-01 03:54:15 +02:00
_.each(calendarCollection.models, function(element) {
var episodeTitle = element.get('title');
var seriesTitle = element.get('series').title;
var start = element.get('airDate');
var end = element.get('endTime');
2013-05-01 03:54:15 +02:00
element.set('title', seriesTitle);
element.set('episodeTitle', episodeTitle);
element.set('start', start);
element.set('end', end);
element.set('allDay', false);
2013-05-01 03:54:15 +02:00
});
2013-02-26 04:30:24 +01:00
callback(calendarCollection.toJSON());
}
});
}
});
});