Calendar view selection now persistent.

pull/4/head
Taloth Saldono 11 years ago
parent 794c09c17a
commit b10f8a6d3f

@ -8,25 +8,24 @@ define(
'Calendar/Collection',
'System/StatusModel',
'History/Queue/QueueCollection',
'Config',
'Mixins/backbone.signalr.mixin',
'fullcalendar',
'jquery.easypiechart'
], function (vent, Marionette, moment, CalendarCollection, StatusModel, QueueCollection) {
var _instance;
], function (vent, Marionette, moment, CalendarCollection, StatusModel, QueueCollection, Config) {
return Marionette.ItemView.extend({
storageKey: 'calendar.view',
initialize: function () {
this.collection = new CalendarCollection().bindSignalR({ updateOnly: true });
this.listenTo(this.collection, 'change', this._reloadCalendarEvents);
this.listenTo(QueueCollection, 'sync', this._reloadCalendarEvents);
},
render : function () {
var self = this;
render : function () {
this.$el.empty().fullCalendar({
defaultView : 'basicWeek',
defaultView : Config.getValue(this.storageKey, 'basicWeek'),
allDayDefault : false,
ignoreTimezone: false,
weekMode : 'variable',
@ -41,16 +40,35 @@ define(
prev: '<i class="icon-arrow-left"></i>',
next: '<i class="icon-arrow-right"></i>'
},
viewRender : this._getEvents,
eventRender : function (event, element) {
self.$(element).addClass(event.statusLevel);
self.$(element).children('.fc-event-inner').addClass(event.statusLevel);
viewRender : this._viewRender.bind(this),
eventRender : this._eventRender.bind(this),
eventClick : function (event) {
vent.trigger(vent.Commands.ShowEpisodeDetails, {episode: event.model});
}
});
},
onShow: function () {
this.$('.fc-button-today').click();
},
_viewRender: function (view) {
if (Config.getValue(this.storageKey) !== view.name) {
Config.setValue(this.storageKey, view.name);
}
this._getEvents(view);
},
_eventRender: function (event, element) {
this.$(element).addClass(event.statusLevel);
this.$(element).children('.fc-event-inner').addClass(event.statusLevel);
if (event.progress > 0) {
self.$(element).find('.fc-event-time')
this.$(element).find('.fc-event-time')
.after('<span class="chart pull-right" data-percent="{0}"></span>'.format(event.progress));
self.$(element).find('.chart').easyPieChart({
this.$(element).find('.chart').easyPieChart({
barColor : '#ffffff',
trackColor: false,
scaleColor: false,
@ -60,35 +78,24 @@ define(
});
}
},
eventClick : function (event) {
vent.trigger(vent.Commands.ShowEpisodeDetails, {episode: event.model});
}
});
_instance = this;
},
onShow: function () {
this.$('.fc-button-today').click();
},
_getEvents: function (view) {
var start = moment(view.visStart).toISOString();
var end = moment(view.visEnd).toISOString();
_instance.$el.fullCalendar('removeEvents');
this.$el.fullCalendar('removeEvents');
_instance.collection.fetch({
this.collection.fetch({
data : { start: start, end: end },
success: function (collection) {
_instance._setEventData(collection);
}
success: this._setEventData.bind(this)
});
},
_setEventData: function (collection) {
var events = [];
var self = this;
collection.each(function (model) {
var seriesTitle = model.get('series').title;
var start = model.get('airDateUtc');
@ -100,15 +107,15 @@ define(
start : start,
end : end,
allDay : false,
statusLevel : _instance._getStatusLevel(model, end),
progress : _instance._getDownloadProgress(model),
statusLevel : self._getStatusLevel(model, end),
progress : self._getDownloadProgress(model),
model : model
};
events.push(event);
});
_instance.$el.fullCalendar('addEventSource', events);
this.$el.fullCalendar('addEventSource', events);
},
_getStatusLevel: function (element, endTime) {

Loading…
Cancel
Save