diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index d39cd56d4..c558f2918 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -1789,9 +1789,34 @@ Zotero.Item.prototype.getAttachments = function(){ return []; } - var sql = "SELECT itemID FROM itemAttachments NATURAL JOIN items " - + "WHERE sourceItemID=" + this.getID() + " ORDER BY dateAdded"; - return Zotero.DB.columnQuery(sql); + var sql = "SELECT A.itemID, value AS title FROM itemAttachments A " + + "NATURAL JOIN items I LEFT JOIN itemData ID USING (itemID) " + + "LEFT JOIN itemDataValues IDV " + + "ON (fieldID=110 AND ID.valueID=IDV.valueID) " + + "WHERE sourceItemID=?"; + + if (Zotero.Prefs.get('sortAttachmentsChronologically')) { + sql += " ORDER BY dateAdded"; + return Zotero.DB.columnQuery(sql, this.getID()); + } + + var attachments = Zotero.DB.query(sql, this.getID()); + if (!attachments) { + return false; + } + + // Sort by title + var collation = Zotero.getLocaleCollation(); + var f = function (a, b) { + return collation.compareString(1, a.title, b.title); + } + + var attachmentIDs = []; + attachments.sort(f); + for each(var attachment in attachments) { + attachmentIDs.push(attachment.itemID); + } + return attachmentIDs; } @@ -3153,7 +3178,7 @@ Zotero.Notes = new function(){ /* * Constructor for Collection object * - * Generally should be called from Zotero.Collection rather than directly + * Generally should be called from Zotero.Collections rather than directly */ Zotero.Collection = function(){ this._init(); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 223f70ce3..a81bce7e5 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1597,8 +1597,6 @@ Zotero.Date = new function(){ /** * Figure out the date order from the output of toLocaleDateString() * - * Note: Currently unused - * * Returns a string with y, m, and d (e.g. 'ymd', 'mdy') */ function getLocaleDateOrder(){ diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js index 9482d83f4..a74eb1d6e 100644 --- a/defaults/preferences/zotero.js +++ b/defaults/preferences/zotero.js @@ -27,6 +27,7 @@ pref("extensions.zotero.attachmentRenameFormatString", '{%c - }{%y - }{%t{50}}') pref("extensions.zotero.capitalizeTitles", true); pref("extensions.zotero.launchNonNativeFiles", false); pref("extensions.zotero.sortNotesChronologically", false); +pref("extensions.zotero.sortAttachmentsChronologically", false); pref("extensions.zotero.lastCreatorFieldMode",0); pref("extensions.zotero.lastAbstractExpand",0);