www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit d69dc3d5a79b3e4d1a88c21e32897e8513503719
parent 1647f281358d1673face18906e21de09fb831988
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 19 Mar 2013 15:42:39 -0400

If Year column is visible and not Date, don't sort by full date

Otherwise use full date, even if Date column is hidden

Addresses #275

Diffstat:
Mchrome/content/zotero/xpcom/itemTreeView.js | 37+++++++++++++++++++++++++++++++------
1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js @@ -1271,6 +1271,12 @@ Zotero.ItemTreeView.prototype.sort = function(itemID) columnField = 'date'; } + // The visible fields affect the secondary sorting + var visibleFields = {}; + this.getVisibleFields().forEach(function (val) { + visibleFields[val] = true; + }); + // Some fields (e.g. dates) need to be retrieved unformatted for sorting switch (columnField) { case 'date': @@ -1424,12 +1430,31 @@ Zotero.ItemTreeView.prototype.sort = function(itemID) } if (columnField !== 'date') { - fieldA = a.getField('date', true).substr(0, 10); - fieldB = b.getField('date', true).substr(0, 10); - - cmp = strcmp(fieldA, fieldB); - if (cmp !== 0) { - return cmp; + // If year is visible and not date, don't use full date + if (visibleFields.year && !visibleFields.date) { + fieldA = a.getField('date', true).substr(0, 4); + if (fieldA == '0000') { + fieldA = ""; + } + fieldB = b.getField('date', true).substr(0, 4); + if (fieldB == '0000') { + fieldB = ""; + } + + cmp = strcmp(fieldA, fieldB); + if (cmp !== 0) { + return cmp; + } + } + // Otherwise use full date, even if Date column is hidden + else { + fieldA = a.getField('date', true).substr(0, 10); + fieldB = b.getField('date', true).substr(0, 10); + + cmp = strcmp(fieldA, fieldB); + if (cmp !== 0) { + return cmp; + } } }