www

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

commit 80f504768763924f467aa76e79853e88f7d565de
parent c97491821fed8b116f38842156549e91415b8f5b
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sun, 29 Aug 2010 04:14:05 +0000

Commons:

- Reload bucket on bucket click if not loaded in the last 60 seconds
- Add "Show Original" button to Commons metadata pane to switch back to original linked item, if it exists
- Hide metadata pane tabs in Commons view
- Add support for setting credentials via zotero.org (untested, and not yet stored in Fx login manager)

Also:

- Add ZoteroPane.getItemGroup() function



Diffstat:
Mchrome/content/zotero/overlay.js | 49+++++++++++++++++++++++++++++++++++++++++++------
Mchrome/content/zotero/overlay.xul | 3+++
Mchrome/content/zotero/xpcom/commons.js | 26+++++++++++++++++++++++---
Mchrome/content/zotero/xpcom/mimeTypeHandler.js | 1+
Mchrome/content/zotero/xpcom/zotero.js | 40++++++++++++++++++++++++++++++++++++++++
5 files changed, 110 insertions(+), 9 deletions(-)

diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js @@ -1075,7 +1075,11 @@ var ZoteroPane = new function() } } } - + + this.getItemGroup = function () { + return this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex); + } + function itemSelected() { @@ -1096,6 +1100,7 @@ var ZoteroPane = new function() var tabs = document.getElementById('zotero-view-tabbox'); + // Single item selected if (this.itemsView && this.itemsView.selection.count == 1 && this.itemsView.selection.currentIndex != -1) { var item = this.itemsView._getItemAtRow(this.itemsView.selection.currentIndex); @@ -1142,10 +1147,23 @@ var ZoteroPane = new function() } // Regular item - else - { + else { + var isCommons = this.getItemGroup().isBucket(); + document.getElementById('zotero-item-pane-content').selectedIndex = 1; - var pane = document.getElementById('zotero-view-tabbox').selectedIndex; + var tabBox = document.getElementById('zotero-view-tabbox'); + var pane = tabBox.selectedIndex; + tabBox.firstChild.hidden = isCommons; + + var button = document.getElementById('zotero-item-show-original'); + if (isCommons) { + button.hidden = false; + button.disabled = !this.getOriginalItem(); + } + else { + button.hidden = true; + } + if (this.collectionsView.editable) { ZoteroItemPane.viewItem(item.ref, null, pane); tabs.selectedIndex = document.getElementById('zotero-view-item').selectedIndex; @@ -1156,8 +1174,8 @@ var ZoteroPane = new function() } } } - else - { + // Zero or multiple items selected + else { document.getElementById('zotero-item-pane-content').selectedIndex = 0; var label = document.getElementById('zotero-view-selected-label'); @@ -1439,6 +1457,25 @@ var ZoteroPane = new function() } + // Currently used only for Commons to find original linked item + this.getOriginalItem = function () { + var item = this.getSelectedItems()[0]; + var itemGroup = this.getItemGroup(); + // TEMP: Commons buckets only + return itemGroup.ref.getLocalItem(item); + } + + + this.showOriginalItem = function () { + var item = this.getOriginalItem(); + if (!item) { + Zotero.debug("Original item not found"); + return; + } + this.selectItem(item.id); + } + + this.restoreSelectedItems = function () { var items = this.getSelectedItems(); if (!items) { diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul @@ -401,6 +401,9 @@ <!-- TODO: localize --> <button id="zotero-item-restore-button" label="Restore to Library" oncommand="ZoteroPane.restoreSelectedItems()" hidden="true"/> + <!-- TODO: localize --> + <button id="zotero-item-show-original" label="Show Original" + oncommand="ZoteroPane.showOriginalItem()" hidden="true"/> <deck id="zotero-item-pane-content" selectedIndex="0" flex="1"> <groupbox pack="center" align="center"> <label id="zotero-view-selected-label"/> diff --git a/chrome/content/zotero/xpcom/commons.js b/chrome/content/zotero/xpcom/commons.js @@ -33,6 +33,10 @@ Zotero.Commons = new function() { return Zotero.Prefs.get("commons.enabled"); }); + this.__defineSetter__('enabled', function (val) { + return Zotero.Prefs.set("commons.enabled", !!val); + }); + this.__defineGetter__('userIdentifier', function () { return Zotero.Prefs.get("commons.accessKey"); }); @@ -41,10 +45,19 @@ Zotero.Commons = new function() { return Zotero.Prefs.get("commons.accessKey"); }); + this.__defineSetter__('accessKey', function (val) { + return Zotero.Prefs.set("commons.accessKey", val); + }); + this.__defineGetter__('secretKey', function () { return Zotero.Prefs.get("commons.secretKey"); }); + this.__defineSetter__('secretKey', function (val) { + // TODO: use login manager + return Zotero.Prefs.set("commons.secretKey", val); + }); + this.RDF_TRANSLATOR = { 'label': 'Zotero RDF', 'target': 'rdf', @@ -377,6 +390,7 @@ Zotero.Commons.Bucket = function (name) { this._items = {}; this._itemsLoading = false; this._itemsLoaded = false; + this._lastLoad = null; this._metadataLoading = false; this._itemDataLoaded = false; @@ -406,7 +420,7 @@ Zotero.Commons.Bucket.prototype.__defineGetter__('apiURI', function() { Zotero.Commons.Bucket.prototype.relationPredicate = "owl:sameAs"; - +Zotero.Commons.Bucket.prototype.reloadSeconds = 60; Zotero.Commons.Bucket.prototype.exists = function (callback, maxTries, tries) { if (!tries) { @@ -450,10 +464,15 @@ Zotero.Commons.Bucket.prototype.exists = function (callback, maxTries, tries) { Zotero.Commons.Bucket.prototype.getItems = function (callback) { - if (this._itemsLoaded || this._itemsLoading) { + if (this._itemsLoading || + // Reload if data is too old + (this._itemsLoaded && (!this._lastLoad || (new Date - this._lastLoad) < (this.reloadSeconds * 1000)))) { + Zotero.debug("Using cached items"); return this._getCachedItems(); } + Zotero.debug("Loading items from IA"); + this._itemsLoading = true; var method = "GET"; @@ -527,6 +546,7 @@ Zotero.Commons.Bucket.prototype.getItems = function (callback) { self._itemsLoading = false; self._itemsLoaded = true; + self._lastLoad = new Date; Zotero.debug(zips); @@ -630,7 +650,7 @@ Zotero.Commons.Bucket.prototype.getItems = function (callback) { var rels = Zotero.Relations.getByURIs(null, self.relationPredicate, iaFileURI); if (rels.length) { - Zotero.debug("Commons: " + IAFileName + " has already been downloaded -- skipping"); + Zotero.debug("Commons: " + iaFileName + " has already been downloaded -- skipping"); continue; } diff --git a/chrome/content/zotero/xpcom/mimeTypeHandler.js b/chrome/content/zotero/xpcom/mimeTypeHandler.js @@ -65,6 +65,7 @@ Zotero.MIMETypeHandler = new function () { } this.addHandler("text/x-csl", function(a1, a2) { Zotero.Styles.install(a1, a2) }); this.addHandler("application/x-zotero-schema", Zotero.Schema.importSchema); + this.addHandler("application/x-zotero-settings", Zotero.Prefs.importSettings); } /** diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js @@ -1360,6 +1360,46 @@ Zotero.Prefs = new function(){ } + // Import settings bundles + this.importSettings = function (str, uri) { + var prompt = Components.classes["@mozilla.org/network/default-prompt;1"] + .createInstance(Components.interfaces.nsIPrompt); + + if (!uri.match(/https:\/\/([^\.]+\.)?zotero.org\//)) { + Zotero.debug("Ignoring settings file not from https://zotero.org"); + return; + } + + str = Zotero.Utilities.prototype.trim(str); + + Zotero.debug(str); + + prompt.confirm( + "", + "Apply settings from zotero.org?" + ); + + // Convert to DOM XML + var xml = Components.classes["@mozilla.org/xmlextras/domparser;1"] + .createInstance(Components.interfaces.nsIDOMParser) + .parseFromString(str, "text/xml"); + + // TODO: allow arbitrary settings? + + var commonsEnable = xml.getElementById('commons-enable'); + if (commonsEnable.nodeValue == 'true') { + Zotero.Commons.enabled = true; + Zotero.Commons.accessKey = xml.getElementById('commons-accessKey').nodeValue; + Zotero.Commons.secretKey = xml.getElementById('commons-secretKey').nodeValue; + ZoteroPane.collectionsView.refresh(); + } + else if (commonsEnable == 'false') { + Zotero.Commons.enabled = false; + ZoteroPane.collectionsView.refresh(); + } + } + + // // Methods to register a preferences observer //