www

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

commit 76b7adaa05e46e5a58a241ff56fdacb853300bd0
parent cbe7c086e199c501f9546f3e4f0b2c0f5ab58f89
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu,  5 Oct 2006 08:54:15 +0000

Closes #328, View button in metadata pane should show snapshot first before using URL


Diffstat:
Mchrome/content/zotero/itemPane.js | 23+++++++++++++++--------
Mchrome/content/zotero/itemPane.xul | 2+-
Mchrome/content/zotero/xpcom/data_access.js | 28+++++++++++++++++++++++++---
3 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/chrome/content/zotero/itemPane.js b/chrome/content/zotero/itemPane.js @@ -55,7 +55,6 @@ var ZoteroItemPane = new function() this.viewItem = viewItem; this.loadPane = loadPane; this.changeTypeTo = changeTypeTo; - this.onGoToURLClick = onGoToURLClick; this.onOpenURLClick = onOpenURLClick; this.addCreatorRow = addCreatorRow; this.switchCreatorMode = switchCreatorMode; @@ -175,7 +174,17 @@ var ZoteroItemPane = new function() testView: try { 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) { break testView; @@ -183,7 +192,10 @@ var ZoteroItemPane = new function() var uri = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService) .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){} 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() { var url = Zotero.OpenURL.resolve(_itemBeingEdited); diff --git a/chrome/content/zotero/itemPane.xul b/chrome/content/zotero/itemPane.xul @@ -38,7 +38,7 @@ 'typeID', typeID, otherFields)"/> </popupset> <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();"/> </hbox> <hbox align="center"> diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js @@ -879,15 +879,15 @@ Zotero.Item.prototype.isNote = function(){ /** * 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){ 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()){ - throw ("Cannot call updateNote() on unsaved note"); + throw ("Cannot call updateNote() on unsaved item"); } 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