2013-06-22 06:24:24 +00:00
|
|
|
'use strict';
|
2013-06-24 23:41:59 +00:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'marionette',
|
2013-08-22 03:24:50 +00:00
|
|
|
'Episode/Summary/EpisodeSummaryLayout',
|
2013-08-21 21:47:39 +00:00
|
|
|
'Episode/Search/Layout',
|
|
|
|
'Series/SeriesCollection'
|
|
|
|
], function (Marionette, SummaryLayout, SearchLayout, SeriesCollection) {
|
2013-05-15 01:17:24 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
return Marionette.Layout.extend({
|
|
|
|
template: 'Episode/LayoutTemplate',
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
regions: {
|
|
|
|
summary : '#episode-summary',
|
|
|
|
activity: '#episode-activity',
|
|
|
|
search : '#episode-search'
|
|
|
|
},
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
ui: {
|
2013-07-19 01:49:04 +00:00
|
|
|
summary : '.x-episode-summary',
|
|
|
|
activity : '.x-episode-activity',
|
|
|
|
search : '.x-episode-search',
|
|
|
|
monitored: '.x-episode-monitored'
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
events: {
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-07-19 01:49:04 +00:00
|
|
|
'click .x-episode-summary' : '_showSummary',
|
|
|
|
'click .x-episode-activity' : '_showActivity',
|
|
|
|
'click .x-episode-search' : '_showSearch',
|
|
|
|
'click .x-episode-monitored': '_toggleMonitored'
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-08-21 21:47:39 +00:00
|
|
|
templateHelpers: {},
|
|
|
|
|
|
|
|
initialize: function (options) {
|
|
|
|
this.templateHelpers.hideSeriesLink = options.hideSeriesLink;
|
|
|
|
|
2013-08-21 22:26:16 +00:00
|
|
|
this.series = SeriesCollection.find({ id: this.model.get('seriesId') });
|
|
|
|
this.templateHelpers.series = this.series.toJSON();
|
2013-08-21 21:47:39 +00:00
|
|
|
},
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
onShow: function () {
|
2013-06-28 22:12:57 +00:00
|
|
|
this._showSummary();
|
2013-07-04 03:04:26 +00:00
|
|
|
this.searchLayout = new SearchLayout({ model: this.model });
|
2013-07-19 01:49:04 +00:00
|
|
|
this._setMonitoredState();
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-06-28 22:12:57 +00:00
|
|
|
_showSummary: function (e) {
|
2013-06-24 23:41:59 +00:00
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
this.ui.summary.tab('show');
|
2013-08-21 22:26:16 +00:00
|
|
|
this.summary.show(new SummaryLayout({model: this.model, series: this.series}));
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-06-28 22:12:57 +00:00
|
|
|
_showActivity: function (e) {
|
2013-06-24 23:41:59 +00:00
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
this.ui.activity.tab('show');
|
|
|
|
},
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-06-28 22:12:57 +00:00
|
|
|
_showSearch: function (e) {
|
2013-06-24 23:41:59 +00:00
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2013-05-21 00:17:33 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
this.ui.search.tab('show');
|
2013-07-04 03:04:26 +00:00
|
|
|
this.search.show(this.searchLayout);
|
2013-07-19 01:49:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_toggleMonitored: function () {
|
|
|
|
var self = this;
|
|
|
|
var name = 'monitored';
|
|
|
|
this.model.set(name, !this.model.get(name), { silent: true });
|
|
|
|
|
|
|
|
this.ui.monitored.addClass('icon-spinner icon-spin');
|
|
|
|
|
|
|
|
var promise = this.model.save();
|
|
|
|
|
|
|
|
promise.always(function () {
|
|
|
|
self._setMonitoredState();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_setMonitoredState: function () {
|
|
|
|
var monitored = this.model.get('monitored');
|
|
|
|
|
|
|
|
this.ui.monitored.removeClass('icon-spin icon-spinner');
|
|
|
|
|
|
|
|
if (this.model.get('monitored')) {
|
|
|
|
this.ui.monitored.addClass('icon-bookmark');
|
|
|
|
this.ui.monitored.removeClass('icon-bookmark-empty');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.ui.monitored.addClass('icon-bookmark-empty');
|
|
|
|
this.ui.monitored.removeClass('icon-bookmark');
|
|
|
|
}
|
2013-06-24 23:41:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|