Sort child notes alphabetically

This commit is contained in:
Dan Stillman 2007-09-20 22:18:09 +00:00
parent 54c0fbdd16
commit e18cdcc4a7
2 changed files with 34 additions and 6 deletions

View File

@ -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;
}

View File

@ -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]]);
}
}
////////////////////////////////////////////////////////////////////////////////