Updated sorting architecture so the collections can specify the sort-oddities instead of in backgrid column definitions.

This commit is contained in:
Taloth Saldono
2014-07-04 22:07:03 +02:00
parent 2b6f908038
commit 6941888832
20 changed files with 173 additions and 186 deletions
+9 -18
View File
@@ -7,7 +7,6 @@ define(
return function () {
var originalInit = this.prototype.initialize;
this.prototype.initialize = function (options) {
options = options || {};
@@ -30,18 +29,24 @@ define(
}
};
if (!this.prototype._getSortMapping) {
this.prototype._getSortMapping = function(key) {
return { name: key, sortKey: key };
};
}
var _setInitialState = function () {
var key = Config.getValue('{0}.sortKey'.format(this.tableName), this.state.sortKey);
var direction = Config.getValue('{0}.sortDirection'.format(this.tableName), this.state.order);
var order = parseInt(direction, 10);
this.state.sortKey = key;
this.state.sortKey = this._getSortMapping(key).sortKey;
this.state.order = order;
};
var _storeStateFromBackgrid = function (column, sortDirection) {
var order = _convertDirectionToInt(sortDirection);
var sortKey = column.has('sortValue') && _.isString(column.get('sortValue')) ? column.get('sortValue') : column.get('name');
var sortKey = this._getSortMapping(column.get('name')).sortKey;
Config.setValue('{0}.sortKey'.format(this.tableName), sortKey);
Config.setValue('{0}.sortDirection'.format(this.tableName), order);
@@ -49,7 +54,7 @@ define(
var _storeState = function (sortModel, sortDirection) {
var order = _convertDirectionToInt(sortDirection);
var sortKey = sortModel.get('name');
var sortKey = this._getSortMapping(sortModel.get('name')).sortKey;
Config.setValue('{0}.sortKey'.format(this.tableName), sortKey);
Config.setValue('{0}.sortDirection'.format(this.tableName), order);
@@ -62,20 +67,6 @@ define(
return '1';
};
var originalMakeComparator = this.prototype._makeComparator;
this.prototype._makeComparator = function (sortKey, order, sortValue) {
var state = this.state;
sortKey = sortKey || state.sortKey;
order = order || state.order;
if (!sortKey || !order) return;
if (!sortValue && this[sortKey]) sortValue = this[sortKey];
return originalMakeComparator.call(this, sortKey, order, sortValue);
};
return this;
};