www

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

commit 48f7dd5b6e7adda944011f8f3815f48577d34656
parent 42f3875b0c965c1df18ea6b53677ea6fd4d0e2c1
Author: Simon Kornblith <simon@simonster.com>
Date:   Sun, 10 Jun 2012 15:30:23 -0400

Add endpoint for getting selected collection

Addresses #23, "Saving item..." notification should show the name of the library where item is imported

Diffstat:
Mchrome/content/zotero/xpcom/server_connector.js | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+), 0 deletions(-)

diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js @@ -520,6 +520,64 @@ Zotero.Server.Connector.GetTranslatorCode.prototype = { } /** + * Get selected collection + * + * Accepts: + * Nothing + * Returns: + * libraryID + * libraryName + * collectionID + * collectionName + */ +Zotero.Server.Connector.GetSelectedCollection = function() {}; +Zotero.Server.Endpoints["/connector/getSelectedCollection"] = Zotero.Server.Connector.GetSelectedCollection; +Zotero.Server.Connector.GetSelectedCollection.prototype = { + "supportedMethods":["POST"], + "supportedDataTypes":["application/json"], + + /** + * Returns a 200 response to say the server is alive + * @param {String} data POST data or GET query string + * @param {Function} sendResponseCallback function to send HTTP response + */ + "init":function(postData, sendResponseCallback) { + var zp = Zotero.getActiveZoteroPane(), + libraryID = null, + collection = null, + editable = true; + + try { + libraryID = zp.getSelectedLibraryID(); + editable = ZoteroPane.collectionsView.editable; + collection = zp.getSelectedCollection(); + } catch(e) {} + + var response = { + "editable":editable, + "libraryID":libraryID + }; + + if(libraryID) { + response.libraryName = Zotero.Libraries.getName(libraryID); + } else { + response.libraryName = Zotero.getString("pane.collections.library"); + } + + if(collection && collection.id) { + response.id = collection.id; + response.name = collection.name; + } else { + response.id = null; + response.name = response.libraryName; + } + + sendResponseCallback(200, "application/json", JSON.stringify(response)); + } +} + + +/** * Test connection * * Accepts: