2013-06-22 06:24:24 +00:00
|
|
|
'use strict';
|
2013-06-24 23:41:59 +00:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'marionette',
|
|
|
|
'Series/Index/Posters/CollectionView',
|
|
|
|
'Series/Index/List/CollectionView',
|
|
|
|
'Series/Index/EmptyView',
|
|
|
|
'Series/SeriesCollection',
|
2013-07-26 02:09:17 +00:00
|
|
|
'Cells/RelativeDateCell',
|
2013-06-24 23:41:59 +00:00
|
|
|
'Cells/SeriesTitleCell',
|
|
|
|
'Cells/TemplatedCell',
|
2013-07-18 00:39:41 +00:00
|
|
|
'Cells/QualityProfileCell',
|
2013-08-18 23:32:27 +00:00
|
|
|
'Cells/EpisodeProgressCell',
|
2013-08-01 02:12:39 +00:00
|
|
|
'Shared/Grid/DateHeaderCell',
|
2013-06-24 23:41:59 +00:00
|
|
|
'Series/Index/Table/SeriesStatusCell',
|
|
|
|
'Series/Index/Table/Row',
|
2013-07-29 01:12:34 +00:00
|
|
|
'Series/Index/FooterView',
|
|
|
|
'Series/Index/FooterModel',
|
2013-08-18 23:32:27 +00:00
|
|
|
'Shared/Toolbar/ToolbarLayout'
|
2013-07-18 00:39:41 +00:00
|
|
|
], function (Marionette,
|
|
|
|
PosterCollectionView,
|
|
|
|
ListCollectionView,
|
|
|
|
EmptyView,
|
|
|
|
SeriesCollection,
|
2013-07-26 02:09:17 +00:00
|
|
|
RelativeDateCell,
|
2013-07-18 00:39:41 +00:00
|
|
|
SeriesTitleCell,
|
|
|
|
TemplatedCell,
|
|
|
|
QualityProfileCell,
|
2013-08-18 23:32:27 +00:00
|
|
|
EpisodeProgressCell,
|
2013-08-01 02:12:39 +00:00
|
|
|
DateHeaderCell,
|
2013-07-18 00:39:41 +00:00
|
|
|
SeriesStatusCell,
|
|
|
|
SeriesIndexRow,
|
2013-07-29 01:12:34 +00:00
|
|
|
FooterView,
|
|
|
|
FooterModel,
|
2013-08-18 23:32:27 +00:00
|
|
|
ToolbarLayout) {
|
2013-06-24 23:41:59 +00:00
|
|
|
return Marionette.Layout.extend({
|
2013-04-23 00:35:04 +00:00
|
|
|
template: 'Series/Index/SeriesIndexLayoutTemplate',
|
|
|
|
|
|
|
|
regions: {
|
2013-06-28 23:06:16 +00:00
|
|
|
seriesRegion: '#x-series',
|
2013-07-27 17:48:45 +00:00
|
|
|
toolbar : '#x-toolbar',
|
2013-07-29 01:12:34 +00:00
|
|
|
footer : '#x-series-footer'
|
2013-04-23 00:35:04 +00:00
|
|
|
},
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
columns:
|
|
|
|
[
|
|
|
|
{
|
2013-08-18 22:32:03 +00:00
|
|
|
name : 'statusWeight',
|
2013-08-18 06:10:18 +00:00
|
|
|
label : '',
|
2013-08-18 22:32:03 +00:00
|
|
|
cell : SeriesStatusCell
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
|
|
|
{
|
2013-07-18 02:09:34 +00:00
|
|
|
name : 'title',
|
|
|
|
label : 'Title',
|
|
|
|
cell : SeriesTitleCell,
|
|
|
|
cellValue: 'this'
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name : 'seasonCount',
|
|
|
|
label: 'Seasons',
|
|
|
|
cell : 'integer'
|
|
|
|
},
|
2013-06-08 07:57:43 +00:00
|
|
|
{
|
2013-07-18 00:39:41 +00:00
|
|
|
name : 'qualityProfileId',
|
2013-06-24 23:41:59 +00:00
|
|
|
label: 'Quality',
|
2013-07-18 00:39:41 +00:00
|
|
|
cell : QualityProfileCell
|
2013-06-08 07:57:43 +00:00
|
|
|
},
|
|
|
|
{
|
2013-06-24 23:41:59 +00:00
|
|
|
name : 'network',
|
|
|
|
label: 'Network',
|
|
|
|
cell : 'string'
|
2013-06-08 07:57:43 +00:00
|
|
|
},
|
|
|
|
{
|
2013-08-01 02:12:39 +00:00
|
|
|
name : 'nextAiring',
|
|
|
|
label : 'Next Airing',
|
|
|
|
cell : RelativeDateCell,
|
|
|
|
headerCell: DateHeaderCell
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
|
|
|
{
|
2013-08-18 23:32:27 +00:00
|
|
|
name : 'percentOfEpisodes',
|
|
|
|
label : 'Episodes',
|
|
|
|
cell : EpisodeProgressCell,
|
2013-07-17 06:23:44 +00:00
|
|
|
className: 'episode-progress-cell'
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name : 'this',
|
|
|
|
label : '',
|
|
|
|
sortable: false,
|
|
|
|
template: 'Series/Index/Table/ControlsColumnTemplate',
|
|
|
|
cell : TemplatedCell
|
2013-06-08 07:57:43 +00:00
|
|
|
}
|
2013-06-24 23:41:59 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
leftSideButtons: {
|
|
|
|
type : 'default',
|
|
|
|
storeState: false,
|
|
|
|
items :
|
|
|
|
[
|
|
|
|
{
|
|
|
|
title: 'Add Series',
|
|
|
|
icon : 'icon-plus',
|
2013-06-26 01:00:56 +00:00
|
|
|
route: 'addseries'
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title : 'RSS Sync',
|
|
|
|
icon : 'icon-rss',
|
|
|
|
command : 'rsssync',
|
|
|
|
successMessage: 'RSS Sync Completed',
|
|
|
|
errorMessage : 'RSS Sync Failed!'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title : 'Update Library',
|
|
|
|
icon : 'icon-refresh',
|
|
|
|
command : 'refreshseries',
|
|
|
|
successMessage: 'Library was updated!',
|
|
|
|
errorMessage : 'Library update failed!'
|
|
|
|
}
|
|
|
|
]
|
2013-06-08 07:57:43 +00:00
|
|
|
},
|
|
|
|
|
2013-06-08 08:59:02 +00:00
|
|
|
_showTable: function () {
|
2013-06-28 23:06:16 +00:00
|
|
|
this.currentView = new Backgrid.Grid({
|
2013-06-24 23:41:59 +00:00
|
|
|
row : SeriesIndexRow,
|
2013-06-28 23:06:16 +00:00
|
|
|
collection: SeriesCollection,
|
2013-06-24 23:41:59 +00:00
|
|
|
columns : this.columns,
|
|
|
|
className : 'table table-hover'
|
|
|
|
});
|
2013-04-23 00:35:04 +00:00
|
|
|
|
2013-06-28 23:06:16 +00:00
|
|
|
this._renderView();
|
|
|
|
this._fetchCollection();
|
2013-04-23 00:35:04 +00:00
|
|
|
},
|
|
|
|
|
2013-06-08 08:59:02 +00:00
|
|
|
_showList: function () {
|
2013-06-28 23:06:16 +00:00
|
|
|
this.currentView = new ListCollectionView();
|
|
|
|
this._fetchCollection();
|
2013-04-23 00:35:04 +00:00
|
|
|
},
|
|
|
|
|
2013-06-08 08:59:02 +00:00
|
|
|
_showPosters: function () {
|
2013-06-28 23:06:16 +00:00
|
|
|
this.currentView = new PosterCollectionView();
|
|
|
|
this._fetchCollection();
|
2013-04-24 03:11:45 +00:00
|
|
|
},
|
|
|
|
|
2013-06-28 23:06:16 +00:00
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
this.seriesCollection = SeriesCollection;
|
|
|
|
|
|
|
|
this.listenTo(SeriesCollection, 'sync', this._renderView);
|
|
|
|
this.listenTo(SeriesCollection, 'remove', this._renderView);
|
2013-04-24 00:30:25 +00:00
|
|
|
},
|
|
|
|
|
2013-06-08 08:59:02 +00:00
|
|
|
|
2013-06-28 23:06:16 +00:00
|
|
|
_renderView: function () {
|
2013-06-08 08:59:02 +00:00
|
|
|
|
2013-06-28 23:06:16 +00:00
|
|
|
if (SeriesCollection.length === 0) {
|
|
|
|
this.seriesRegion.show(new EmptyView());
|
|
|
|
this.toolbar.close();
|
2013-06-08 08:59:02 +00:00
|
|
|
}
|
2013-06-28 23:36:25 +00:00
|
|
|
else {
|
2013-06-28 23:06:16 +00:00
|
|
|
this.currentView.collection = SeriesCollection;
|
|
|
|
this.seriesRegion.show(this.currentView);
|
2013-06-08 08:59:02 +00:00
|
|
|
|
2013-06-28 23:06:16 +00:00
|
|
|
this._showToolbar();
|
2013-07-29 01:12:34 +00:00
|
|
|
this._showFooter();
|
2013-06-08 08:59:02 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-04-23 00:35:04 +00:00
|
|
|
|
|
|
|
onShow: function () {
|
2013-06-28 23:36:25 +00:00
|
|
|
this._showToolbar();
|
2013-06-28 23:25:00 +00:00
|
|
|
this._renderView();
|
2013-06-28 23:06:16 +00:00
|
|
|
this._fetchCollection();
|
|
|
|
},
|
|
|
|
|
|
|
|
_fetchCollection: function () {
|
|
|
|
SeriesCollection.fetch();
|
|
|
|
},
|
|
|
|
|
|
|
|
_showToolbar: function () {
|
|
|
|
|
|
|
|
if (this.toolbar.currentView) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-24 01:55:29 +00:00
|
|
|
|
2013-04-26 04:45:45 +00:00
|
|
|
var viewButtons = {
|
|
|
|
type : 'radio',
|
2013-06-09 20:51:32 +00:00
|
|
|
storeState : true,
|
|
|
|
menuKey : 'seriesViewMode',
|
|
|
|
defaultAction: 'listView',
|
2013-06-24 23:41:59 +00:00
|
|
|
items :
|
|
|
|
[
|
|
|
|
{
|
2013-07-04 00:57:23 +00:00
|
|
|
key : 'posterView',
|
2013-06-24 23:41:59 +00:00
|
|
|
title : '',
|
2013-07-25 05:20:28 +00:00
|
|
|
tooltip : 'Posters',
|
2013-07-04 00:57:23 +00:00
|
|
|
icon : 'icon-th-large',
|
|
|
|
callback: this._showPosters
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key : 'listView',
|
|
|
|
title : '',
|
2013-07-25 05:20:28 +00:00
|
|
|
tooltip : 'Overview List',
|
2013-07-04 00:57:23 +00:00
|
|
|
icon : 'icon-th-list',
|
2013-06-24 23:41:59 +00:00
|
|
|
callback: this._showList
|
|
|
|
},
|
|
|
|
{
|
2013-07-04 00:57:23 +00:00
|
|
|
key : 'tableView',
|
2013-06-24 23:41:59 +00:00
|
|
|
title : '',
|
2013-07-25 05:20:28 +00:00
|
|
|
tooltip : 'Table',
|
2013-07-04 00:57:23 +00:00
|
|
|
icon : 'icon-table',
|
|
|
|
callback: this._showTable
|
2013-07-17 06:23:44 +00:00
|
|
|
}
|
2013-06-24 23:41:59 +00:00
|
|
|
]
|
2013-04-26 04:45:45 +00:00
|
|
|
};
|
|
|
|
|
2013-06-19 01:02:23 +00:00
|
|
|
this.toolbar.show(new ToolbarLayout({
|
2013-06-24 23:41:59 +00:00
|
|
|
right :
|
|
|
|
[
|
|
|
|
viewButtons
|
|
|
|
],
|
|
|
|
left :
|
|
|
|
[
|
|
|
|
this.leftSideButtons
|
|
|
|
],
|
2013-05-11 20:51:32 +00:00
|
|
|
context: this
|
|
|
|
}));
|
2013-07-29 01:12:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_showFooter: function () {
|
|
|
|
var footerModel = new FooterModel();
|
2013-07-29 01:32:52 +00:00
|
|
|
var series = SeriesCollection.models.length;
|
|
|
|
var episodes = 0;
|
|
|
|
var episodeFiles = 0;
|
|
|
|
var ended = 0;
|
|
|
|
var continuing = 0;
|
|
|
|
var monitored = 0;
|
2013-07-29 01:12:34 +00:00
|
|
|
|
2013-07-29 01:32:52 +00:00
|
|
|
_.each(SeriesCollection.models, function (model){
|
|
|
|
episodes += model.get('episodeCount');
|
|
|
|
episodeFiles += model.get('episodeFileCount');
|
|
|
|
|
|
|
|
if (model.get('status').toLowerCase() === 'ended') {
|
|
|
|
ended++;
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
continuing++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (model.get('monitored')) {
|
|
|
|
monitored++;
|
|
|
|
}
|
|
|
|
});
|
2013-07-29 01:12:34 +00:00
|
|
|
|
|
|
|
footerModel.set({
|
2013-07-29 01:32:52 +00:00
|
|
|
series: series,
|
|
|
|
ended: ended,
|
|
|
|
continuing: continuing,
|
|
|
|
monitored: monitored,
|
|
|
|
unmonitored: series - monitored,
|
|
|
|
episodes: episodes,
|
|
|
|
episodeFiles: episodeFiles
|
2013-07-29 01:12:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.footer.show(new FooterView({ model: footerModel }));
|
2013-04-23 00:35:04 +00:00
|
|
|
}
|
2013-06-08 07:57:43 +00:00
|
|
|
});
|
|
|
|
});
|