Sort collections and items using locale-specific collation sort
This commit is contained in:
parent
0dbf98ccf4
commit
2f423da309
|
@ -4548,22 +4548,29 @@ Zotero.getCollections = function(parent, recursive){
|
|||
parent = null;
|
||||
}
|
||||
|
||||
var sql = 'SELECT collectionID FROM collections C WHERE parentCollectionID';
|
||||
sql += parent ? '=' + parent : ' IS NULL';
|
||||
|
||||
sql += ' ORDER BY collectionName COLLATE NOCASE';
|
||||
|
||||
var children = Zotero.DB.columnQuery(sql);
|
||||
var sql = "SELECT collectionID AS id, collectionName AS name FROM collections C "
|
||||
+ "WHERE parentCollectionID " + (parent ? '=' + parent : ' IS NULL');
|
||||
var children = Zotero.DB.query(sql);
|
||||
|
||||
if (!children){
|
||||
Zotero.debug('No child collections of collection ' + parent, 5);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
// Do proper collation sort
|
||||
var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
|
||||
.getService(Components.interfaces.nsILocaleService);
|
||||
var collationFactory = Components.classes["@mozilla.org/intl/collation-factory;1"]
|
||||
.getService(Components.interfaces.nsICollationFactory);
|
||||
var collation = collationFactory.CreateCollation(localeService.getApplicationLocale());
|
||||
children.sort(function (a, b) {
|
||||
return collation.compareString(0, a.name, b.name);
|
||||
});
|
||||
|
||||
for (var i=0, len=children.length; i<len; i++){
|
||||
var obj = Zotero.Collections.get(children[i]);
|
||||
var obj = Zotero.Collections.get(children[i].id);
|
||||
if (!obj){
|
||||
throw ('Collection ' + children[i] + ' not found');
|
||||
throw ('Collection ' + children[i].id + ' not found');
|
||||
}
|
||||
|
||||
toReturn.push(obj);
|
||||
|
|
|
@ -718,6 +718,12 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
var columnField = this.getSortField();
|
||||
var order = this.getSortDirection() == 'ascending';
|
||||
|
||||
var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
|
||||
.getService(Components.interfaces.nsILocaleService);
|
||||
var collationFactory = Components.classes["@mozilla.org/intl/collation-factory;1"]
|
||||
.getService(Components.interfaces.nsICollationFactory);
|
||||
var collation = collationFactory.CreateCollation(localeService.getApplicationLocale());
|
||||
|
||||
// Year is really the date field truncated
|
||||
if (columnField == 'year') {
|
||||
columnField = 'date';
|
||||
|
@ -798,7 +804,8 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
}
|
||||
}
|
||||
|
||||
cmp = (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0;
|
||||
//cmp = (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0;
|
||||
cmp = collation.compareString(0, fieldA, fieldB);
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
@ -815,7 +822,8 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
return cmp;
|
||||
}
|
||||
|
||||
cmp = (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0;
|
||||
//cmp = (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0;
|
||||
cmp = collation.compareString(0, fieldA, fieldB);
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
@ -840,7 +848,8 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
|
||||
fieldA = a.getField('dateModified');
|
||||
fieldB = b.getField('dateModified');
|
||||
return (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0;
|
||||
//return (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0;
|
||||
return collation.compareString(0, fieldA, fieldB);
|
||||
}
|
||||
|
||||
function doSort(a,b)
|
||||
|
|
Loading…
Reference in New Issue
Block a user