From d3e29108a8c6b7522c564c2df8b8098ed49bba29 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 1 Dec 2006 06:01:26 +0000 Subject: [PATCH] Addresses #400, Report generation A work in progress: - Implemented zotero:// custom protocol handler, which will likely be useful for other things too - First version of XHTML/CSS detail view -- definitely needs feedback, work, and refinement but is more or less functional - Added XUL-side interface and context menu options for loading report URLs Going forward: - Other formats (RTF, CSV) - Other views (list view, annotated bibliography, etc.) - Report options window (let the user which fields to include (with saved templates?)) - Ability to specify custom CSS files? - Extension of Zotero protocol handler to trigger Zotero events? This would allow more interactive reports with the ability to click to select items in the Z pane, run searches by clicking on tags, etc., but would have to be limited to idempotent actions. Other changes: - ZoteroPane.getSortField() and ZoteroPane.getSortDirection() - Zotero.Utilities.htmlSpecialChars(str) - Fixed sort direction in items pane (triangle icon now goes the right direction, though the default direction on clicking a new column is incorrect) - firstCreator now included in toArray(), though it's not particularly correct (#287, more or less) - ZoteroPane.getSelectedCollection/SavedSearch/Items now take asIDs parameter to return ids instead of objects --- chrome/content/zotero/overlay.js | 108 ++++-- chrome/content/zotero/overlay.xul | 3 + chrome/content/zotero/reportInterface.js | 84 +++++ chrome/content/zotero/xpcom/data_access.js | 2 +- chrome/content/zotero/xpcom/itemTreeView.js | 16 +- chrome/content/zotero/xpcom/report.js | 272 +++++++++++++ chrome/content/zotero/xpcom/utilities.js | 41 ++ chrome/locale/en-US/zotero/zotero.properties | 16 +- chrome/skin/default/zotero/report/detail.css | 107 ++++++ .../default/zotero/report/detail_print.css | 27 ++ components/zotero-protocol-handler.js | 356 ++++++++++++++++++ components/zotero-service.js | 4 + 12 files changed, 1002 insertions(+), 34 deletions(-) create mode 100644 chrome/content/zotero/reportInterface.js create mode 100644 chrome/content/zotero/xpcom/report.js create mode 100644 chrome/skin/default/zotero/report/detail.css create mode 100644 chrome/skin/default/zotero/report/detail_print.css create mode 100644 components/zotero-protocol-handler.js diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index b00a1884c..58fefa44c 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -51,6 +51,8 @@ var ZoteroPane = new function() this.getSelectedCollection = getSelectedCollection; this.getSelectedSavedSearch = getSelectedSavedSearch; this.getSelectedItems = getSelectedItems; + this.getSortField = getSortField; + this.getSortDirection = getSortDirection; this.buildCollectionContextMenu = buildCollectionContextMenu; this.buildItemContextMenu = buildItemContextMenu; this.onDoubleClick = onDoubleClick; @@ -536,11 +538,17 @@ var ZoteroPane = new function() } + /* + * Returns Zotero.ItemTreeView instance for collections pane + */ function getCollectionsView() { return collectionsView; } + /* + * Returns Zotero.ItemTreeView instance for items pane + */ function getItemsView() { return itemsView; @@ -568,31 +576,46 @@ var ZoteroPane = new function() } } - function getSelectedCollection() + function getSelectedCollection(asID) { if(collectionsView.selection.count > 0 && collectionsView.selection.currentIndex != -1) { var collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex); - if(collection && collection.isCollection()) - return collection.ref; - } - return false; - } - - function getSelectedSavedSearch() - { - if(collectionsView.selection.count > 0 && collectionsView.selection.currentIndex != -1) - { - var collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex); - if(collection && collection.isSearch()) - { - return collection.ref; + if (collection && collection.isCollection()) { + if (asID) { + return collection.ref.getID(); + } + else { + return collection.ref; + } } } return false; } - function getSelectedItems() + function getSelectedSavedSearch(asID) + { + if(collectionsView.selection.count > 0 && collectionsView.selection.currentIndex != -1) + { + var collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex); + if (collection && collection.isSearch()) { + if (asID) { + return collection.ref.id; + } + else { + return collection.ref; + } + } + } + return false; + } + + /* + * Return an array of Item objects for selected items + * + * If asIDs is true, return an array of itemIDs instead + */ + function getSelectedItems(asIDs) { if(itemsView) { @@ -602,13 +625,38 @@ var ZoteroPane = new function() for (var i=0, len=itemsView.selection.getRangeCount(); i0) { - var enable = [9,11]; + var enable = [9,11,14]; } else { - var disable = [9,11]; + var disable = [9,11,14]; } - + + menu.childNodes[14].setAttribute('label', Zotero.getString('pane.collections.menu.generateReport.collection')); } // Saved Search else if (collectionsView.selection.count == 1 && collectionsView._getItemAtRow(collectionsView.selection.currentIndex).isSearch()) { var hide = [0,1,2,3,4,6,9,11,13]; - var show = [5,7,8,10,12]; + var show = [5,7,8,10,12,14]; if (itemsView.rowCount>0) { - var enable = [10,12]; + var enable = [10,12,14]; } else { - var disable = [10,12]; + var disable = [10,12,14]; } + + menu.childNodes[14].setAttribute('label', Zotero.getString('pane.collections.menu.generateReport.savedSearch')); } // Library else { - var hide = [2,4,5,6,7,8,9,10,11,12]; + var hide = [2,4,5,6,7,8,9,10,11,12,14]; var show = [0,1,3,13]; } @@ -680,7 +731,7 @@ var ZoteroPane = new function() if(itemsView && itemsView.selection.count > 0) { - enable.push(4,5,6,8); + enable.push(0,1,2,4,5,6,7,8,9); // Multiple items selected if (itemsView.selection.count > 1) @@ -707,7 +758,7 @@ var ZoteroPane = new function() } else { - disable.push(4,5,7,8); + disable.push(0,1,2,4,5,7,8,9); } // Remove from collection @@ -725,6 +776,7 @@ var ZoteroPane = new function() menu.childNodes[5].setAttribute('label', Zotero.getString('pane.items.menu.erase' + multiple)); menu.childNodes[7].setAttribute('label', Zotero.getString('pane.items.menu.export' + multiple)); menu.childNodes[8].setAttribute('label', Zotero.getString('pane.items.menu.createBib' + multiple)); + menu.childNodes[9].setAttribute('label', Zotero.getString('pane.items.menu.generateReport' + multiple)); for (var i in disable) { diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul index 4611cadb1..81b888186 100644 --- a/chrome/content/zotero/overlay.xul +++ b/chrome/content/zotero/overlay.xul @@ -32,6 +32,7 @@