From e18cdcc4a7afeeab3b5f8907287f93c9ba56ff69 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 20 Sep 2007 22:18:09 +0000 Subject: [PATCH] Sort child notes alphabetically --- chrome/content/zotero/xpcom/data_access.js | 26 ++++++++++++++++++--- chrome/content/zotero/xpcom/itemTreeView.js | 14 ++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index 14a3b89d0..a3c112efa 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -1356,9 +1356,29 @@ Zotero.Item.prototype.getNotes = function(){ return []; } - var sql = "SELECT itemID FROM itemNotes NATURAL JOIN items " - + "WHERE sourceItemID=" + this.getID() + " ORDER BY dateAdded"; - return Zotero.DB.columnQuery(sql); + // DEBUG: Not just using itemNoteTitles just in case something went wrong + // during migration and there's no titles row + // + // TODO: move titles into itemNotes table + var sql = "SELECT N.itemID, title FROM itemNotes N NATURAL JOIN items " + + "LEFT JOIN itemNoteTitles USING (itemID) WHERE sourceItemID=" + this.getID(); + var notes = Zotero.DB.query(sql); + if (!notes) { + return false; + } + + // Sort by title + var collation = Zotero.getLocaleCollation(); + var f = function (a, b) { + return collation.compareString(1, a.title, b.title); + } + + var noteIDs = []; + notes.sort(f); + for each(var note in notes) { + noteIDs.push(note.itemID); + } + return noteIDs; } diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index a9b4d7c05..fab961ac9 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -362,7 +362,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids) sort = ids[i]; } // If not moved from under one item to another - else if (parentIndex == -1 || !sourceItemID) { + else if (!(sourceItemID && parentIndex != -1 && this._itemRowMap[sourceItemID] != parentIndex)) { sort = ids[i]; } madeChanges = true; @@ -738,6 +738,14 @@ Zotero.ItemTreeView.prototype.sort = function(itemID) this._needsSort = false; } + // Single child item sort -- just toggle parent open and closed + if (itemID && this._getItemAtRow(this._itemRowMap[itemID]).ref.getSource()) { + var parentIndex = this.getParentIndex(this._itemRowMap[itemID]); + this.toggleOpenState(parentIndex); + this.toggleOpenState(parentIndex); + return; + } + var columnField = this.getSortField(); var order = this.getSortDirection() == 'ascending'; @@ -930,9 +938,9 @@ Zotero.ItemTreeView.prototype.sort = function(itemID) this._refreshHashMap(); // Reopen closed containers - for(var i = 0; i < openRows.length; i++) + for (var i = 0; i < openRows.length; i++) { this.toggleOpenState(this._itemRowMap[openRows[i]]); - + } } ////////////////////////////////////////////////////////////////////////////////