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
This commit is contained in:
parent
c97491821f
commit
80f5047687
5 changed files with 110 additions and 9 deletions
|
@ -1075,7 +1075,11 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getItemGroup = function () {
|
||||||
|
return this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function itemSelected()
|
function itemSelected()
|
||||||
{
|
{
|
||||||
|
@ -1096,6 +1100,7 @@ var ZoteroPane = new function()
|
||||||
|
|
||||||
var tabs = document.getElementById('zotero-view-tabbox');
|
var tabs = document.getElementById('zotero-view-tabbox');
|
||||||
|
|
||||||
|
// Single item selected
|
||||||
if (this.itemsView && this.itemsView.selection.count == 1 && this.itemsView.selection.currentIndex != -1)
|
if (this.itemsView && this.itemsView.selection.count == 1 && this.itemsView.selection.currentIndex != -1)
|
||||||
{
|
{
|
||||||
var item = this.itemsView._getItemAtRow(this.itemsView.selection.currentIndex);
|
var item = this.itemsView._getItemAtRow(this.itemsView.selection.currentIndex);
|
||||||
|
@ -1142,10 +1147,23 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regular item
|
// Regular item
|
||||||
else
|
else {
|
||||||
{
|
var isCommons = this.getItemGroup().isBucket();
|
||||||
|
|
||||||
document.getElementById('zotero-item-pane-content').selectedIndex = 1;
|
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) {
|
if (this.collectionsView.editable) {
|
||||||
ZoteroItemPane.viewItem(item.ref, null, pane);
|
ZoteroItemPane.viewItem(item.ref, null, pane);
|
||||||
tabs.selectedIndex = document.getElementById('zotero-view-item').selectedIndex;
|
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;
|
document.getElementById('zotero-item-pane-content').selectedIndex = 0;
|
||||||
|
|
||||||
var label = document.getElementById('zotero-view-selected-label');
|
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 () {
|
this.restoreSelectedItems = function () {
|
||||||
var items = this.getSelectedItems();
|
var items = this.getSelectedItems();
|
||||||
if (!items) {
|
if (!items) {
|
||||||
|
|
|
@ -401,6 +401,9 @@
|
||||||
<!-- TODO: localize -->
|
<!-- TODO: localize -->
|
||||||
<button id="zotero-item-restore-button" label="Restore to Library"
|
<button id="zotero-item-restore-button" label="Restore to Library"
|
||||||
oncommand="ZoteroPane.restoreSelectedItems()" hidden="true"/>
|
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">
|
<deck id="zotero-item-pane-content" selectedIndex="0" flex="1">
|
||||||
<groupbox pack="center" align="center">
|
<groupbox pack="center" align="center">
|
||||||
<label id="zotero-view-selected-label"/>
|
<label id="zotero-view-selected-label"/>
|
||||||
|
|
|
@ -33,6 +33,10 @@ Zotero.Commons = new function() {
|
||||||
return Zotero.Prefs.get("commons.enabled");
|
return Zotero.Prefs.get("commons.enabled");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.__defineSetter__('enabled', function (val) {
|
||||||
|
return Zotero.Prefs.set("commons.enabled", !!val);
|
||||||
|
});
|
||||||
|
|
||||||
this.__defineGetter__('userIdentifier', function () {
|
this.__defineGetter__('userIdentifier', function () {
|
||||||
return Zotero.Prefs.get("commons.accessKey");
|
return Zotero.Prefs.get("commons.accessKey");
|
||||||
});
|
});
|
||||||
|
@ -41,10 +45,19 @@ Zotero.Commons = new function() {
|
||||||
return Zotero.Prefs.get("commons.accessKey");
|
return Zotero.Prefs.get("commons.accessKey");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.__defineSetter__('accessKey', function (val) {
|
||||||
|
return Zotero.Prefs.set("commons.accessKey", val);
|
||||||
|
});
|
||||||
|
|
||||||
this.__defineGetter__('secretKey', function () {
|
this.__defineGetter__('secretKey', function () {
|
||||||
return Zotero.Prefs.get("commons.secretKey");
|
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 = {
|
this.RDF_TRANSLATOR = {
|
||||||
'label': 'Zotero RDF',
|
'label': 'Zotero RDF',
|
||||||
'target': 'rdf',
|
'target': 'rdf',
|
||||||
|
@ -377,6 +390,7 @@ Zotero.Commons.Bucket = function (name) {
|
||||||
this._items = {};
|
this._items = {};
|
||||||
this._itemsLoading = false;
|
this._itemsLoading = false;
|
||||||
this._itemsLoaded = false;
|
this._itemsLoaded = false;
|
||||||
|
this._lastLoad = null;
|
||||||
|
|
||||||
this._metadataLoading = false;
|
this._metadataLoading = false;
|
||||||
this._itemDataLoaded = 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.relationPredicate = "owl:sameAs";
|
||||||
|
Zotero.Commons.Bucket.prototype.reloadSeconds = 60;
|
||||||
|
|
||||||
Zotero.Commons.Bucket.prototype.exists = function (callback, maxTries, tries) {
|
Zotero.Commons.Bucket.prototype.exists = function (callback, maxTries, tries) {
|
||||||
if (!tries) {
|
if (!tries) {
|
||||||
|
@ -450,10 +464,15 @@ Zotero.Commons.Bucket.prototype.exists = function (callback, maxTries, tries) {
|
||||||
|
|
||||||
|
|
||||||
Zotero.Commons.Bucket.prototype.getItems = function (callback) {
|
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();
|
return this._getCachedItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Zotero.debug("Loading items from IA");
|
||||||
|
|
||||||
this._itemsLoading = true;
|
this._itemsLoading = true;
|
||||||
|
|
||||||
var method = "GET";
|
var method = "GET";
|
||||||
|
@ -527,6 +546,7 @@ Zotero.Commons.Bucket.prototype.getItems = function (callback) {
|
||||||
|
|
||||||
self._itemsLoading = false;
|
self._itemsLoading = false;
|
||||||
self._itemsLoaded = true;
|
self._itemsLoaded = true;
|
||||||
|
self._lastLoad = new Date;
|
||||||
|
|
||||||
Zotero.debug(zips);
|
Zotero.debug(zips);
|
||||||
|
|
||||||
|
@ -630,7 +650,7 @@ Zotero.Commons.Bucket.prototype.getItems = function (callback) {
|
||||||
|
|
||||||
var rels = Zotero.Relations.getByURIs(null, self.relationPredicate, iaFileURI);
|
var rels = Zotero.Relations.getByURIs(null, self.relationPredicate, iaFileURI);
|
||||||
if (rels.length) {
|
if (rels.length) {
|
||||||
Zotero.debug("Commons: " + IAFileName + " has already been downloaded -- skipping");
|
Zotero.debug("Commons: " + iaFileName + " has already been downloaded -- skipping");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ Zotero.MIMETypeHandler = new function () {
|
||||||
}
|
}
|
||||||
this.addHandler("text/x-csl", function(a1, a2) { Zotero.Styles.install(a1, a2) });
|
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-schema", Zotero.Schema.importSchema);
|
||||||
|
this.addHandler("application/x-zotero-settings", Zotero.Prefs.importSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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
|
// Methods to register a preferences observer
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue