Closes #328, View button in metadata pane should show snapshot first before using URL
This commit is contained in:
parent
cbe7c086e1
commit
76b7adaa05
3 changed files with 41 additions and 12 deletions
|
@ -55,7 +55,6 @@ var ZoteroItemPane = new function()
|
||||||
this.viewItem = viewItem;
|
this.viewItem = viewItem;
|
||||||
this.loadPane = loadPane;
|
this.loadPane = loadPane;
|
||||||
this.changeTypeTo = changeTypeTo;
|
this.changeTypeTo = changeTypeTo;
|
||||||
this.onGoToURLClick = onGoToURLClick;
|
|
||||||
this.onOpenURLClick = onOpenURLClick;
|
this.onOpenURLClick = onOpenURLClick;
|
||||||
this.addCreatorRow = addCreatorRow;
|
this.addCreatorRow = addCreatorRow;
|
||||||
this.switchCreatorMode = switchCreatorMode;
|
this.switchCreatorMode = switchCreatorMode;
|
||||||
|
@ -175,7 +174,17 @@ var ZoteroItemPane = new function()
|
||||||
testView: try
|
testView: try
|
||||||
{
|
{
|
||||||
var validURI = false;
|
var validURI = false;
|
||||||
var spec = _itemBeingEdited.getField('url');
|
|
||||||
|
var snapID = _itemBeingEdited.getBestSnapshot();
|
||||||
|
if (snapID)
|
||||||
|
{
|
||||||
|
var spec = Zotero.Items.get(snapID).getLocalFileURL();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var spec = _itemBeingEdited.getField('url');
|
||||||
|
}
|
||||||
|
|
||||||
if (!spec)
|
if (!spec)
|
||||||
{
|
{
|
||||||
break testView;
|
break testView;
|
||||||
|
@ -183,7 +192,10 @@ var ZoteroItemPane = new function()
|
||||||
var uri = Components.classes["@mozilla.org/network/io-service;1"]
|
var uri = Components.classes["@mozilla.org/network/io-service;1"]
|
||||||
.getService(Components.interfaces.nsIIOService)
|
.getService(Components.interfaces.nsIIOService)
|
||||||
.newURI(spec, null, null);
|
.newURI(spec, null, null);
|
||||||
validURI = uri.scheme && uri.host;
|
|
||||||
|
validURI = uri.scheme && (uri.host || uri.scheme=='file');
|
||||||
|
|
||||||
|
document.getElementById('tb-go-to-url').setAttribute('viewURL', spec);
|
||||||
}
|
}
|
||||||
catch (e){}
|
catch (e){}
|
||||||
document.getElementById('tb-go-to-url').setAttribute('disabled', !validURI);
|
document.getElementById('tb-go-to-url').setAttribute('disabled', !validURI);
|
||||||
|
@ -392,11 +404,6 @@ var ZoteroItemPane = new function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onGoToURLClick()
|
|
||||||
{
|
|
||||||
window.loadURI(_itemBeingEdited.getField('url'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function onOpenURLClick()
|
function onOpenURLClick()
|
||||||
{
|
{
|
||||||
var url = Zotero.OpenURL.resolve(_itemBeingEdited);
|
var url = Zotero.OpenURL.resolve(_itemBeingEdited);
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
'typeID', typeID, otherFields)"/>
|
'typeID', typeID, otherFields)"/>
|
||||||
</popupset>
|
</popupset>
|
||||||
<hbox align="center">
|
<hbox align="center">
|
||||||
<button id="tb-go-to-url" label="&toolbar.goToURL.label;" tooltiptext="&toolbar.goToURL.tooltip;" flex="1" oncommand="ZoteroItemPane.onGoToURLClick();" disabled="false"/>
|
<button id="tb-go-to-url" label="&toolbar.goToURL.label;" tooltiptext="&toolbar.goToURL.tooltip;" flex="1" oncommand="window.loadURI(this.getAttribute('viewURL'))" disabled="false"/>
|
||||||
<button id="tb-openurl" label="&toolbar.openURL.label;" tooltiptext="&toolbar.openURL.tooltip;" flex="1" oncommand="ZoteroItemPane.onOpenURLClick();"/>
|
<button id="tb-openurl" label="&toolbar.openURL.label;" tooltiptext="&toolbar.openURL.tooltip;" flex="1" oncommand="ZoteroItemPane.onOpenURLClick();"/>
|
||||||
</hbox>
|
</hbox>
|
||||||
<hbox align="center">
|
<hbox align="center">
|
||||||
|
|
|
@ -879,15 +879,15 @@ Zotero.Item.prototype.isNote = function(){
|
||||||
/**
|
/**
|
||||||
* Update an item note
|
* Update an item note
|
||||||
*
|
*
|
||||||
* Note: This can only be called on note items.
|
* Note: This can only be called on notes and attachments
|
||||||
**/
|
**/
|
||||||
Zotero.Item.prototype.updateNote = function(text){
|
Zotero.Item.prototype.updateNote = function(text){
|
||||||
if (!this.isNote() && !this.isAttachment()){
|
if (!this.isNote() && !this.isAttachment()){
|
||||||
throw ("updateNote() can only be called on items of type 'note'");
|
throw ("updateNote() can only be called on notes and attachments");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.getID()){
|
if (!this.getID()){
|
||||||
throw ("Cannot call updateNote() on unsaved note");
|
throw ("Cannot call updateNote() on unsaved item");
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.DB.beginTransaction();
|
Zotero.DB.beginTransaction();
|
||||||
|
@ -1261,6 +1261,28 @@ Zotero.Item.prototype.getAttachments = function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the itemID of the latest child snapshot of this item with the
|
||||||
|
* same URL as the item itself, or false if none
|
||||||
|
*/
|
||||||
|
Zotero.Item.prototype.getBestSnapshot = function(){
|
||||||
|
if (!this.isRegularItem()){
|
||||||
|
throw ("getBestSnapshot() can only be called on regular items");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.getField('url')){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sql = "SELECT IA.itemID FROM itemAttachments IA NATURAL JOIN items I "
|
||||||
|
+ "LEFT JOIN itemData ID ON (IA.itemID=ID.itemID AND fieldID=1) "
|
||||||
|
+ "WHERE sourceItemID=? AND linkMode=? AND value=? "
|
||||||
|
+ "ORDER BY dateAdded DESC LIMIT 1";
|
||||||
|
|
||||||
|
return Zotero.DB.valueQuery(sql, [this.getID(),
|
||||||
|
Zotero.Attachments.LINK_MODE_IMPORTED_URL, {string:this.getField('url')}]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Methods dealing with item tags
|
// Methods dealing with item tags
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue