Series shows loading while collection is fetched

This commit is contained in:
Mark McDowall 2013-06-08 01:59:02 -07:00
parent 7824060c28
commit 10cc388600
1 changed files with 43 additions and 21 deletions

View File

@ -90,39 +90,62 @@ define([
] ]
}, },
showTable: function () { _showTable: function () {
var view = new Backgrid.Grid(
this.series.show(new Backgrid.Grid(
{ {
row : NzbDrone.Series.Index.Table.Row, row : NzbDrone.Series.Index.Table.Row,
columns : this.columns, columns : this.columns,
collection: this.seriesCollection, collection: this.seriesCollection,
className : 'table table-hover' className : 'table table-hover'
})); });
this._fetchCollection(view);
}, },
showList: function () { _showList: function () {
this.series.show(new NzbDrone.Series.Index.List.CollectionView({ collection: this.seriesCollection })); var view = new NzbDrone.Series.Index.List.CollectionView();
this._fetchCollection(view);
}, },
showPosters: function () { _showPosters: function () {
this.series.show(new NzbDrone.Series.Index.Posters.CollectionView({ collection: this.seriesCollection })); var view = new NzbDrone.Series.Index.Posters.CollectionView();
this._fetchCollection(view);
}, },
showEmpty: function () { _showEmpty: function () {
this.series.show(new NzbDrone.Series.Index.EmptyView()); this.series.show(new NzbDrone.Series.Index.EmptyView());
}, },
_fetchCollection: function (view) {
var self = this;
if (this.seriesCollection.models.length === 0) {
this.series.show(new NzbDrone.Shared.LoadingView());
this.seriesCollection.fetch()
.done(function () {
if (self.seriesCollection.models.length === 0) {
self._showEmpty();
}
else {
view.collection = self.seriesCollection;
self.series.show(view);
}
});
}
else {
view.collection = this.seriesCollection;
this.series.show(view);
}
},
initialize: function () { initialize: function () {
this.seriesCollection = new NzbDrone.Series.SeriesCollection(); this.seriesCollection = new NzbDrone.Series.SeriesCollection();
this.seriesCollection.fetch();
}, },
onShow: function () { onShow: function () {
//This gets cleared immediately because of the viewButton callback
this.series.show(new NzbDrone.Shared.LoadingView());
//TODO: Move this outside of the function - 'this' is not available for the call back though (use string like events?) //TODO: Move this outside of the function - 'this' is not available for the call back though (use string like events?)
var viewButtons = { var viewButtons = {
type : 'radio', type : 'radio',
@ -134,19 +157,19 @@ define([
key : 'tableView', key : 'tableView',
title : '', title : '',
icon : 'icon-table', icon : 'icon-table',
callback: this.showTable callback: this._showTable
}, },
{ {
key : 'listView', key : 'listView',
title : '', title : '',
icon : 'icon-list', icon : 'icon-list',
callback: this.showList callback: this._showList
}, },
{ {
key : 'posterView', key : 'posterView',
title : '', title : '',
icon : 'icon-picture', icon : 'icon-picture',
callback: this.showPosters callback: this._showPosters
} }
] ]
}; };
@ -157,6 +180,5 @@ define([
context: this context: this
})); }));
} }
}); });
}); });