much smarter handling of series collection rendering.
This commit is contained in:
parent
263700954e
commit
b9b9ad6fb5
|
@ -1,4 +1,4 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
define(
|
define(
|
||||||
[
|
[
|
||||||
'marionette',
|
'marionette',
|
||||||
|
|
|
@ -49,8 +49,8 @@ define(
|
||||||
this.searchCollection = new AddSeriesCollection();
|
this.searchCollection = new AddSeriesCollection();
|
||||||
|
|
||||||
this.searchCollection.fetch({
|
this.searchCollection.fetch({
|
||||||
data : { term: this.ui.searchText.val() },
|
data: { term: this.ui.searchText.val() }
|
||||||
success: function () {
|
}).done(function () {
|
||||||
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
self.collection.add(self.searchCollection.shift());
|
self.collection.add(self.searchCollection.shift());
|
||||||
|
@ -59,11 +59,9 @@ define(
|
||||||
self._showAll();
|
self._showAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
}).fail(function () {
|
||||||
fail : function () {
|
|
||||||
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return deferred.promise();
|
return deferred.promise();
|
||||||
|
|
|
@ -73,9 +73,11 @@ define(
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.model.save(undefined, {
|
SeriesCollection.add(this.model);
|
||||||
url : SeriesCollection.prototype.url,
|
|
||||||
success: function () {
|
|
||||||
|
this.model.save()
|
||||||
|
.done(function () {
|
||||||
self.close();
|
self.close();
|
||||||
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
||||||
Messenger.show({
|
Messenger.show({
|
||||||
|
@ -83,11 +85,9 @@ define(
|
||||||
});
|
});
|
||||||
|
|
||||||
App.vent.trigger(App.Events.SeriesAdded, { series: self.model });
|
App.vent.trigger(App.Events.SeriesAdded, { series: self.model });
|
||||||
self.model.collection.remove(self.model);
|
})
|
||||||
},
|
.fail(function () {
|
||||||
fail : function () {
|
|
||||||
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -53,3 +53,7 @@
|
||||||
.icon(@remove);
|
.icon(@remove);
|
||||||
color : @errorText;
|
color : @errorText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.icon-nd-add:before {
|
||||||
|
.icon(@plus);
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
define(
|
define(
|
||||||
[
|
[
|
||||||
'app',
|
'app',
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
<div class="well span11">
|
<div class="row">
|
||||||
|
<div class="well span11">
|
||||||
<i class="icon-comment"/>
|
<i class="icon-comment"/>
|
||||||
You must be new around here, You should add some series.
|
You must be new around here, You should add some series.
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row span3 offset4">
|
||||||
|
<a href="/addseries" class='btn btn-large btn-block btn-success x-add-series'>
|
||||||
|
<i class='icon-nd-add'></i>
|
||||||
|
Add Series
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
'use strict';
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
define(
|
define(
|
||||||
[
|
[
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
define(
|
define(
|
||||||
[
|
[
|
||||||
|
|
|
@ -12,15 +12,14 @@ define(
|
||||||
'Series/Index/Table/SeriesStatusCell',
|
'Series/Index/Table/SeriesStatusCell',
|
||||||
'Series/Index/Table/Row',
|
'Series/Index/Table/Row',
|
||||||
'Shared/Toolbar/ToolbarLayout',
|
'Shared/Toolbar/ToolbarLayout',
|
||||||
'Config',
|
|
||||||
'Shared/LoadingView'
|
'Shared/LoadingView'
|
||||||
], function (Marionette, PosterCollectionView, ListCollectionView, EmptyView, SeriesCollection, AirDateCell, SeriesTitleCell, TemplatedCell, SeriesStatusCell, SeriesIndexRow,
|
], function (Marionette, PosterCollectionView, ListCollectionView, EmptyView, SeriesCollection, AirDateCell, SeriesTitleCell, TemplatedCell, SeriesStatusCell, SeriesIndexRow,
|
||||||
ToolbarLayout, Config, LoadingView) {
|
ToolbarLayout, LoadingView) {
|
||||||
return Marionette.Layout.extend({
|
return Marionette.Layout.extend({
|
||||||
template: 'Series/Index/SeriesIndexLayoutTemplate',
|
template: 'Series/Index/SeriesIndexLayoutTemplate',
|
||||||
|
|
||||||
regions: {
|
regions: {
|
||||||
series : '#x-series',
|
seriesRegion: '#x-series',
|
||||||
toolbar : '#x-toolbar'
|
toolbar : '#x-toolbar'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -100,60 +99,71 @@ define(
|
||||||
},
|
},
|
||||||
|
|
||||||
_showTable: function () {
|
_showTable: function () {
|
||||||
var view = new Backgrid.Grid({
|
this.currentView = new Backgrid.Grid({
|
||||||
row : SeriesIndexRow,
|
row : SeriesIndexRow,
|
||||||
|
collection: SeriesCollection,
|
||||||
columns : this.columns,
|
columns : this.columns,
|
||||||
collection: this.seriesCollection,
|
|
||||||
className : 'table table-hover'
|
className : 'table table-hover'
|
||||||
});
|
});
|
||||||
|
|
||||||
this._fetchCollection(view);
|
this._renderView();
|
||||||
|
this._fetchCollection();
|
||||||
},
|
},
|
||||||
|
|
||||||
_showList: function () {
|
_showList: function () {
|
||||||
var view = new ListCollectionView();
|
this.currentView = new ListCollectionView();
|
||||||
this._fetchCollection(view);
|
this._fetchCollection();
|
||||||
},
|
},
|
||||||
|
|
||||||
_showPosters: function () {
|
_showPosters: function () {
|
||||||
var view = new PosterCollectionView();
|
this.currentView = new PosterCollectionView();
|
||||||
this._fetchCollection(view);
|
this._fetchCollection();
|
||||||
},
|
},
|
||||||
|
|
||||||
_showEmpty: function () {
|
|
||||||
this.series.show(new EmptyView());
|
|
||||||
},
|
|
||||||
|
|
||||||
_fetchCollection: function (view) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (this.seriesCollection.models.length === 0) {
|
|
||||||
this.series.show(new 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 SeriesCollection();
|
this.seriesCollection = SeriesCollection;
|
||||||
|
|
||||||
|
this.listenTo(SeriesCollection, 'sync', this._renderView);
|
||||||
|
this.listenTo(SeriesCollection, 'remove', this._renderView);
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow: function () {
|
|
||||||
|
|
||||||
//TODO: Move this outside of the function - 'this' is not available for the call back though (use string like events?)
|
_renderView: function () {
|
||||||
|
|
||||||
|
if (SeriesCollection.length === 0) {
|
||||||
|
this.seriesRegion.show(new EmptyView());
|
||||||
|
this.toolbar.close();
|
||||||
|
}
|
||||||
|
else if (this.currentView && !this.currentView.isClosed) {
|
||||||
|
this.currentView.collection = SeriesCollection;
|
||||||
|
this.seriesRegion.show(this.currentView);
|
||||||
|
|
||||||
|
this._showToolbar();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
onShow: function () {
|
||||||
|
this._fetchCollection();
|
||||||
|
this._showToolbar();
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
_fetchCollection: function () {
|
||||||
|
if (SeriesCollection.length === 0) {
|
||||||
|
this.seriesRegion.show(new LoadingView());
|
||||||
|
}
|
||||||
|
|
||||||
|
SeriesCollection.fetch();
|
||||||
|
},
|
||||||
|
|
||||||
|
_showToolbar: function () {
|
||||||
|
|
||||||
|
if (this.toolbar.currentView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var viewButtons = {
|
var viewButtons = {
|
||||||
type : 'radio',
|
type : 'radio',
|
||||||
storeState : true,
|
storeState : true,
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
define(
|
define(
|
||||||
[
|
[
|
||||||
'backbone',
|
'backbone',
|
||||||
'Series/SeriesModel'
|
'Series/SeriesModel'
|
||||||
], function (Backbone, SeriesModel) {
|
], function (Backbone, SeriesModel) {
|
||||||
return Backbone.Collection.extend({
|
var collection = Backbone.Collection.extend({
|
||||||
url : window.ApiRoot + '/series',
|
url : window.ApiRoot + '/series',
|
||||||
model: SeriesModel,
|
model: SeriesModel,
|
||||||
|
|
||||||
|
@ -17,4 +17,6 @@ define(
|
||||||
order : -1
|
order : -1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return new collection();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue