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',
|
|
|
|
'Cells/AirDateCell',
|
|
|
|
'Cells/SeriesTitleCell',
|
|
|
|
'Cells/TemplatedCell',
|
|
|
|
'Series/Index/Table/SeriesStatusCell',
|
|
|
|
'Series/Index/Table/Row',
|
|
|
|
'Shared/Toolbar/ToolbarLayout',
|
|
|
|
'Config',
|
|
|
|
'Shared/LoadingView'
|
|
|
|
], function (Marionette, PosterCollectionView, ListCollectionView, EmptyView, SeriesCollection, AirDateCell, SeriesTitleCell, TemplatedCell, SeriesStatusCell, SeriesIndexRow,
|
|
|
|
ToolbarLayout, Config, LoadingView) {
|
|
|
|
return Marionette.Layout.extend({
|
2013-04-23 00:35:04 +00:00
|
|
|
template: 'Series/Index/SeriesIndexLayoutTemplate',
|
|
|
|
|
|
|
|
regions: {
|
2013-04-24 01:55:29 +00:00
|
|
|
series : '#x-series',
|
|
|
|
toolbar: '#x-toolbar'
|
2013-04-23 00:35:04 +00:00
|
|
|
},
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
columns:
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name : 'status',
|
|
|
|
label: '',
|
|
|
|
cell : SeriesStatusCell
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name : 'this',
|
|
|
|
label: 'Title',
|
|
|
|
cell : SeriesTitleCell
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name : 'seasonCount',
|
|
|
|
label: 'Seasons',
|
|
|
|
cell : 'integer'
|
|
|
|
},
|
2013-06-08 07:57:43 +00:00
|
|
|
{
|
2013-06-24 23:41:59 +00:00
|
|
|
name : 'quality',
|
|
|
|
label: 'Quality',
|
|
|
|
cell : 'integer'
|
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-06-24 23:41:59 +00:00
|
|
|
name : 'nextAiring',
|
|
|
|
label: 'Next Airing',
|
|
|
|
cell : AirDateCell
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name : 'this',
|
|
|
|
label : 'Episodes',
|
|
|
|
sortable: false,
|
|
|
|
template: 'Series/EpisodeProgressTemplate',
|
|
|
|
cell : TemplatedCell
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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',
|
|
|
|
route: 'series/add'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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-24 23:41:59 +00:00
|
|
|
var view = new Backgrid.Grid({
|
|
|
|
row : SeriesIndexRow,
|
|
|
|
columns : this.columns,
|
|
|
|
collection: this.seriesCollection,
|
|
|
|
className : 'table table-hover'
|
|
|
|
});
|
2013-04-23 00:35:04 +00:00
|
|
|
|
2013-06-08 08:59:02 +00:00
|
|
|
this._fetchCollection(view);
|
2013-04-23 00:35:04 +00:00
|
|
|
},
|
|
|
|
|
2013-06-08 08:59:02 +00:00
|
|
|
_showList: function () {
|
2013-06-19 01:02:23 +00:00
|
|
|
var view = new ListCollectionView();
|
2013-06-08 08:59:02 +00:00
|
|
|
this._fetchCollection(view);
|
2013-04-23 00:35:04 +00:00
|
|
|
},
|
|
|
|
|
2013-06-08 08:59:02 +00:00
|
|
|
_showPosters: function () {
|
2013-06-19 01:02:23 +00:00
|
|
|
var view = new PosterCollectionView();
|
2013-06-08 08:59:02 +00:00
|
|
|
this._fetchCollection(view);
|
2013-04-24 03:11:45 +00:00
|
|
|
},
|
|
|
|
|
2013-06-08 08:59:02 +00:00
|
|
|
_showEmpty: function () {
|
2013-06-19 01:02:23 +00:00
|
|
|
this.series.show(new EmptyView());
|
2013-04-24 00:30:25 +00:00
|
|
|
},
|
|
|
|
|
2013-06-08 08:59:02 +00:00
|
|
|
_fetchCollection: function (view) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if (this.seriesCollection.models.length === 0) {
|
2013-06-19 01:02:23 +00:00
|
|
|
this.series.show(new LoadingView());
|
2013-06-08 08:59:02 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
this.seriesCollection.fetch().done(function () {
|
|
|
|
if (self.seriesCollection.models.length === 0) {
|
|
|
|
self._showEmpty();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
view.collection = self.seriesCollection;
|
|
|
|
self.series.show(view);
|
|
|
|
}
|
|
|
|
});
|
2013-06-08 08:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
view.collection = this.seriesCollection;
|
|
|
|
this.series.show(view);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-04-23 00:35:04 +00:00
|
|
|
initialize: function () {
|
2013-06-19 01:02:23 +00:00
|
|
|
this.seriesCollection = new SeriesCollection();
|
2013-04-23 00:35:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onShow: function () {
|
2013-04-24 01:55:29 +00:00
|
|
|
|
2013-06-08 07:57:43 +00:00
|
|
|
//TODO: Move this outside of the function - 'this' is not available for the call back though (use string like events?)
|
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 :
|
|
|
|
[
|
|
|
|
{
|
|
|
|
key : 'tableView',
|
|
|
|
title : '',
|
|
|
|
icon : 'icon-table',
|
|
|
|
callback: this._showTable
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key : 'listView',
|
|
|
|
title : '',
|
|
|
|
icon : 'icon-list',
|
|
|
|
callback: this._showList
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key : 'posterView',
|
|
|
|
title : '',
|
|
|
|
icon : 'icon-picture',
|
|
|
|
callback: this._showPosters
|
|
|
|
}
|
|
|
|
]
|
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-04-23 00:35:04 +00:00
|
|
|
}
|
2013-06-08 07:57:43 +00:00
|
|
|
});
|
|
|
|
});
|