sonarr-repo-only/UI/Calendar/CalendarCollectionView.js

75 lines
3.1 KiB
JavaScript
Raw Normal View History

'use strict';
define(['app', 'Calendar/CalendarItemView'], function (app) {
NzbDrone.Calendar.CalendarCollectionView = Backbone.Marionette.CompositeView.extend({
itemView : NzbDrone.Calendar.CalendarItemView,
2013-02-28 16:34:18 +00:00
itemViewContainer: '#events',
template : 'Calendar/CalendarCollectionTemplate',
className : 'row',
ui: {
calendar: '#calendar'
},
initialize : function (context, action, query, collection) {
2013-02-25 00:00:17 +00:00
this.collection = collection;
2013-02-26 03:30:24 +00:00
this.calendar = new NzbDrone.Calendar.CalendarCollection();
},
onCompositeCollectionRendered: function () {
2013-02-25 00:00:17 +00:00
$(this.ui.calendar).fullCalendar({
allDayDefault : false,
2013-02-28 16:34:18 +00:00
ignoreTimezone: false,
weekMode : 'variable',
timeFormat : 'h(:mm)tt',
header : {
left : 'prev,next today',
center: 'title',
right : 'month,basicWeek'
},
buttonText : {
2013-02-25 00:00:17 +00:00
prev: '<i class="icon-arrow-left"></i>',
next: '<i class="icon-arrow-right"></i>'
2013-02-26 03:30:24 +00:00
},
events : this.getEvents,
eventRender : function (event, element) {
$(element).addClass(event.statusLevel);
$(element).children('.fc-event-inner').addClass(event.statusLevel);
2013-02-28 06:48:25 +00:00
element.popover({
title : '{seriesTitle} - {season}x{episode} - {episodeTitle}'.assign({
seriesTitle : event.seriesTitle,
season : event.seasonNumber,
episode : event.episodeNumber.pad(2),
2013-02-28 06:48:25 +00:00
episodeTitle: event.episodeTitle
}),
content : event.overview,
2013-02-28 06:48:25 +00:00
placement: 'bottom',
trigger : 'manual'
2013-02-28 06:48:25 +00:00
});
},
eventMouseover: function (event, jsEvent, view) {
2013-02-28 06:48:25 +00:00
$(this).popover('show');
},
eventMouseout : function (event, jsEvent, view) {
2013-02-28 06:48:25 +00:00
$(this).popover('hide');
}
});
2013-02-25 00:00:17 +00:00
2013-02-26 03:30:24 +00:00
NzbDrone.Calendar.CalendarCollectionView.Instance = this;
$(this.ui.calendar).fullCalendar('addEventSource', this.calendar.toJSON());
},
getEvents : function (start, end, callback) {
2013-02-26 03:30:24 +00: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 03:30:24 +00:00
bbView.calendar.fetch({
data : { start: startDate, end: endDate },
success: function (calendarCollection) {
2013-02-26 03:30:24 +00:00
callback(calendarCollection.toJSON());
}
});
}
});
});