2013-06-22 08:24:24 +02:00
|
|
|
'use strict';
|
2013-06-25 01:41:59 +02:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'marionette',
|
2013-08-22 05:24:50 +02:00
|
|
|
'Episode/Summary/EpisodeSummaryLayout',
|
2013-08-21 23:47:39 +02:00
|
|
|
'Episode/Search/Layout',
|
|
|
|
'Series/SeriesCollection'
|
|
|
|
], function (Marionette, SummaryLayout, SearchLayout, SeriesCollection) {
|
2013-05-15 03:17:24 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
return Marionette.Layout.extend({
|
|
|
|
template: 'Episode/LayoutTemplate',
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
regions: {
|
|
|
|
summary : '#episode-summary',
|
|
|
|
activity: '#episode-activity',
|
|
|
|
search : '#episode-search'
|
|
|
|
},
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
ui: {
|
2013-07-19 03:49:04 +02:00
|
|
|
summary : '.x-episode-summary',
|
|
|
|
activity : '.x-episode-activity',
|
|
|
|
search : '.x-episode-search',
|
|
|
|
monitored: '.x-episode-monitored'
|
2013-06-25 01:41:59 +02:00
|
|
|
},
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
events: {
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-07-19 03:49:04 +02:00
|
|
|
'click .x-episode-summary' : '_showSummary',
|
|
|
|
'click .x-episode-activity' : '_showActivity',
|
|
|
|
'click .x-episode-search' : '_showSearch',
|
|
|
|
'click .x-episode-monitored': '_toggleMonitored'
|
2013-06-25 01:41:59 +02:00
|
|
|
},
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-08-21 23:47:39 +02:00
|
|
|
templateHelpers: {},
|
|
|
|
|
|
|
|
initialize: function (options) {
|
|
|
|
this.templateHelpers.hideSeriesLink = options.hideSeriesLink;
|
|
|
|
|
2013-08-22 00:26:16 +02:00
|
|
|
this.series = SeriesCollection.find({ id: this.model.get('seriesId') });
|
|
|
|
this.templateHelpers.series = this.series.toJSON();
|
2013-08-21 23:47:39 +02:00
|
|
|
},
|
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
onShow: function () {
|
2013-06-29 00:12:57 +02:00
|
|
|
this._showSummary();
|
2013-07-04 05:04:26 +02:00
|
|
|
this.searchLayout = new SearchLayout({ model: this.model });
|
2013-07-19 03:49:04 +02:00
|
|
|
this._setMonitoredState();
|
2013-06-25 01:41:59 +02:00
|
|
|
},
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-06-29 00:12:57 +02:00
|
|
|
_showSummary: function (e) {
|
2013-06-25 01:41:59 +02:00
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
this.ui.summary.tab('show');
|
2013-08-22 00:26:16 +02:00
|
|
|
this.summary.show(new SummaryLayout({model: this.model, series: this.series}));
|
2013-06-25 01:41:59 +02:00
|
|
|
},
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-06-29 00:12:57 +02:00
|
|
|
_showActivity: function (e) {
|
2013-06-25 01:41:59 +02:00
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
this.ui.activity.tab('show');
|
|
|
|
},
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-06-29 00:12:57 +02:00
|
|
|
_showSearch: function (e) {
|
2013-06-25 01:41:59 +02:00
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2013-05-21 02:17:33 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
this.ui.search.tab('show');
|
2013-07-04 05:04:26 +02:00
|
|
|
this.search.show(this.searchLayout);
|
2013-07-19 03:49:04 +02: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-25 01:41:59 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|