sonarr-repo-only/UI/Series/Index/SeriesIndexLayout.js

231 lines
7.7 KiB
JavaScript
Raw Normal View History

2013-06-22 06:24:24 +00:00
'use strict';
define(
[
'marionette',
'Series/Index/Posters/CollectionView',
'Series/Index/List/CollectionView',
'Series/Index/EmptyView',
'Series/SeriesCollection',
'Cells/RelativeDateCell',
'Cells/SeriesTitleCell',
'Cells/TemplatedCell',
2013-07-18 00:39:41 +00:00
'Cells/QualityProfileCell',
'Series/Index/Table/SeriesStatusCell',
'Series/Index/Table/Row',
2013-07-27 17:48:45 +00:00
'Series/Index/LegendView',
'Shared/Toolbar/ToolbarLayout',
'Shared/LoadingView'
2013-07-18 00:39:41 +00:00
], function (Marionette,
PosterCollectionView,
ListCollectionView,
EmptyView,
SeriesCollection,
RelativeDateCell,
2013-07-18 00:39:41 +00:00
SeriesTitleCell,
TemplatedCell,
QualityProfileCell,
SeriesStatusCell,
SeriesIndexRow,
2013-07-27 17:48:45 +00:00
LegendView,
2013-07-18 00:39:41 +00:00
ToolbarLayout,
LoadingView) {
return Marionette.Layout.extend({
2013-04-23 00:35:04 +00:00
template: 'Series/Index/SeriesIndexLayoutTemplate',
regions: {
seriesRegion: '#x-series',
2013-07-27 17:48:45 +00:00
toolbar : '#x-toolbar',
legend : '#x-legend'
2013-04-23 00:35:04 +00:00
},
columns:
[
{
name : 'status',
label: '',
cell : SeriesStatusCell
},
{
2013-07-18 02:09:34 +00:00
name : 'title',
label : 'Title',
cell : SeriesTitleCell,
cellValue: 'this'
},
{
name : 'seasonCount',
label: 'Seasons',
cell : 'integer'
},
2013-06-08 07:57:43 +00:00
{
2013-07-18 00:39:41 +00:00
name : 'qualityProfileId',
label: 'Quality',
2013-07-18 00:39:41 +00:00
cell : QualityProfileCell
2013-06-08 07:57:43 +00:00
},
{
name : 'network',
label: 'Network',
cell : 'string'
2013-06-08 07:57:43 +00:00
},
{
name : 'nextAiring',
label: 'Next Airing',
cell : RelativeDateCell
},
{
name : 'this',
label : 'Episodes',
sortable: false,
template: 'Series/EpisodeProgressTemplate',
cell : TemplatedCell,
className: 'episode-progress-cell'
},
{
name : 'this',
label : '',
sortable: false,
template: 'Series/Index/Table/ControlsColumnTemplate',
cell : TemplatedCell
2013-06-08 07:57:43 +00:00
}
],
leftSideButtons: {
type : 'default',
storeState: false,
items :
[
{
title: 'Add Series',
icon : 'icon-plus',
2013-06-26 01:00:56 +00:00
route: 'addseries'
},
{
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
},
_showTable: function () {
this.currentView = new Backgrid.Grid({
row : SeriesIndexRow,
collection: SeriesCollection,
columns : this.columns,
className : 'table table-hover'
});
2013-04-23 00:35:04 +00:00
this._renderView();
this._fetchCollection();
2013-04-23 00:35:04 +00:00
},
_showList: function () {
this.currentView = new ListCollectionView();
this._fetchCollection();
2013-04-23 00:35:04 +00:00
},
_showPosters: function () {
this.currentView = new PosterCollectionView();
this._fetchCollection();
2013-04-24 03:11:45 +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
},
_renderView: function () {
if (SeriesCollection.length === 0) {
this.seriesRegion.show(new EmptyView());
this.toolbar.close();
}
2013-06-28 23:36:25 +00:00
else {
this.currentView.collection = SeriesCollection;
this.seriesRegion.show(this.currentView);
2013-07-27 17:48:45 +00:00
this.legend.show(new LegendView());
this._showToolbar();
}
},
2013-04-23 00:35:04 +00:00
onShow: function () {
2013-06-28 23:36:25 +00:00
this._showToolbar();
this._renderView();
this._fetchCollection();
},
_fetchCollection: function () {
if (SeriesCollection.length === 0) {
this.seriesRegion.show(new LoadingView());
}
SeriesCollection.fetch();
},
_showToolbar: function () {
if (this.toolbar.currentView) {
return;
}
var viewButtons = {
type : 'radio',
storeState : true,
menuKey : 'seriesViewMode',
defaultAction: 'listView',
items :
[
{
2013-07-04 00:57:23 +00:00
key : 'posterView',
title : '',
tooltip : 'Posters',
2013-07-04 00:57:23 +00:00
icon : 'icon-th-large',
callback: this._showPosters
},
{
key : 'listView',
title : '',
tooltip : 'Overview List',
2013-07-04 00:57:23 +00:00
icon : 'icon-th-list',
callback: this._showList
},
{
2013-07-04 00:57:23 +00:00
key : 'tableView',
title : '',
tooltip : 'Table',
2013-07-04 00:57:23 +00:00
icon : 'icon-table',
callback: this._showTable
}
]
};
2013-06-19 01:02:23 +00:00
this.toolbar.show(new ToolbarLayout({
right :
[
viewButtons
],
left :
[
this.leftSideButtons
],
2013-05-11 20:51:32 +00:00
context: this
}));
2013-04-23 00:35:04 +00:00
}
2013-06-08 07:57:43 +00:00
});
});