Fixed default sorting for series grid

This commit is contained in:
Mark McDowall 2013-05-02 00:09:35 -07:00
parent b4242f9fb2
commit 3983a36492
4 changed files with 35 additions and 10 deletions

View File

@ -49,12 +49,6 @@ define([
editable : false,
cell : 'airDate',
headerCell: 'nzbDrone'
// headerCell: Backgrid.NzbDroneHeaderCell.extend({
// initialize: function(options) {
// this.constructor.__super__.initialize.apply(this, [options]);
// this.direction('descending');
// }
// })
},
{
name : 'edit',

View File

@ -25,6 +25,25 @@ Backgrid.NzbDroneHeaderCell = Backgrid.HeaderCell.extend({
if (this.column.get('sortable')) {
this.$el.append(" <i class='icon-sort pull-right'></i>");
if (this.collection.state) {
var sortKey = this.collection.state.sortKey;
var sortDir = this._convertIntToDirection(this.collection.state.order);
if (sortKey === this.column.get('name')) {
this.$el.children('i').addClass(this._convertDirectionToIcon(sortDir));
this._direction = sortDir;
}
}
else if (this.collection.defaultSortKey) {
var sortKey = this.collection.defaultSortKey;
var sortDir = this._convertIntToDirection(this.collection.defaultSortDir);
if (sortKey === this.column.get('name')) {
this.$el.children('i').addClass(this._convertDirectionToIcon(sortDir));
this._direction = sortDir;
}
}
}
this.delegateEvents();
return this;
@ -57,9 +76,6 @@ Backgrid.NzbDroneHeaderCell = Backgrid.HeaderCell.extend({
return 1;
});
}
else if (this.direction() === "descending") {
this.sort(columnName, "ascending");
}
else {
this.sort(columnName, "ascending", function (left, right) {
var leftVal = left.get(columnName);
@ -80,6 +96,14 @@ Backgrid.NzbDroneHeaderCell = Backgrid.HeaderCell.extend({
}
return 'icon-sort-down';
},
_convertIntToDirection: function (dir) {
if (dir === '-1') {
return 'ascending';
}
return 'descending';
}
});

View File

@ -1,6 +1,13 @@
define(['app', 'Series/SeriesModel'], function () {
NzbDrone.Series.SeriesCollection = Backbone.Collection.extend({
url : NzbDrone.Constants.ApiRoot + '/series',
model: NzbDrone.Series.SeriesModel
model: NzbDrone.Series.SeriesModel,
defaultSortKey: 'title',
defaultSortDir: '-1',
comparator: function (model) {
return model.get(this.defaultSortKey);
}
});
});