- Fix an error with translate.translate(true)
- Add Zotero.Libraries.isEditable(libraryID) (currently unused) - Addresses #1444, Attachment arrow/count persists after delete, for items (problem probably remains for collections) - Dragging PDF favicon or link or clicking Create New Item from Current Page when viewing a PDF creates a top-level PDF -- this is a temporary solution that allows "Retrieve PDF Metadata" to be used until it can be run automatically - Allow PDF child snapshots to be dragged out of parents - Dragging a link to a collection now creates parent item and child snapshot - ZoteroPane.newItem(), addItemFromDocument(), addItemFromPage(), addItemFromURL(), and canEdit() now all take an optional row parameter
This commit is contained in:
parent
fa348d346c
commit
f018e7d433
7 changed files with 129 additions and 35 deletions
|
@ -621,27 +621,41 @@ var ZoteroPane = new function()
|
||||||
*
|
*
|
||||||
* _data_ is an optional object with field:value for itemData
|
* _data_ is an optional object with field:value for itemData
|
||||||
*/
|
*/
|
||||||
function newItem(typeID, data)
|
function newItem(typeID, data, row)
|
||||||
{
|
{
|
||||||
if (!Zotero.stateCheck()) {
|
if (!Zotero.stateCheck()) {
|
||||||
this.displayErrorMessage(true);
|
this.displayErrorMessage(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.canEdit()) {
|
if (!this.canEdit(row)) {
|
||||||
this.displayCannotEditLibraryMessage();
|
this.displayCannotEditLibraryMessage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Currently selected row
|
||||||
|
if (row === undefined) {
|
||||||
|
row = this.collectionsView.selection.currentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row !== undefined) {
|
||||||
|
var itemGroup = this.collectionsView._getItemAtRow(row);
|
||||||
|
var libraryID = itemGroup.ref.libraryID;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var libraryID = null;
|
||||||
|
var itemGroup = null;
|
||||||
|
}
|
||||||
|
|
||||||
var item = new Zotero.Item(typeID);
|
var item = new Zotero.Item(typeID);
|
||||||
item.libraryID = this.getSelectedLibraryID();
|
item.libraryID = libraryID;
|
||||||
for (var i in data) {
|
for (var i in data) {
|
||||||
item.setField(i, data[i]);
|
item.setField(i, data[i]);
|
||||||
}
|
}
|
||||||
var itemID = item.save();
|
var itemID = item.save();
|
||||||
|
|
||||||
if (this.itemsView && this.itemsView._itemGroup.isCollection()) {
|
if (itemGroup && itemGroup.isCollection()) {
|
||||||
this.itemsView._itemGroup.ref.addItem(itemID);
|
itemGroup.ref.addItem(itemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set to Info tab
|
//set to Info tab
|
||||||
|
@ -652,6 +666,7 @@ var ZoteroPane = new function()
|
||||||
return Zotero.Items.get(itemID);
|
return Zotero.Items.get(itemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function newCollection(parent)
|
function newCollection(parent)
|
||||||
{
|
{
|
||||||
if (!Zotero.stateCheck()) {
|
if (!Zotero.stateCheck()) {
|
||||||
|
@ -2228,8 +2243,8 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.addItemFromPage = function (itemType) {
|
this.addItemFromPage = function (itemType, row) {
|
||||||
return this.addItemFromDocument(window.content.document, itemType);
|
return this.addItemFromDocument(window.content.document, itemType, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2239,17 +2254,31 @@ var ZoteroPane = new function()
|
||||||
* @param {Boolean} [saveSnapshot] Force saving of a snapshot,
|
* @param {Boolean} [saveSnapshot] Force saving of a snapshot,
|
||||||
* regardless of automaticSnapshots pref
|
* regardless of automaticSnapshots pref
|
||||||
*/
|
*/
|
||||||
this.addItemFromDocument = function (doc, itemType, saveSnapshot) {
|
this.addItemFromDocument = function (doc, itemType, saveSnapshot, row) {
|
||||||
if (!Zotero.stateCheck()) {
|
if (!Zotero.stateCheck()) {
|
||||||
this.displayErrorMessage(true);
|
this.displayErrorMessage(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.canEdit()) {
|
// Currently selected row
|
||||||
|
if (row === undefined) {
|
||||||
|
row = this.collectionsView.selection.currentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.canEdit(row)) {
|
||||||
this.displayCannotEditLibraryMessage();
|
this.displayCannotEditLibraryMessage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (row !== undefined) {
|
||||||
|
var itemGroup = this.collectionsView._getItemAtRow(row);
|
||||||
|
var libraryID = itemGroup.ref.libraryID;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var libraryID = null;
|
||||||
|
var itemGroup = null;
|
||||||
|
}
|
||||||
|
|
||||||
var progressWin = new Zotero.ProgressWindow();
|
var progressWin = new Zotero.ProgressWindow();
|
||||||
progressWin.changeHeadline(Zotero.getString('ingester.scraping'));
|
progressWin.changeHeadline(Zotero.getString('ingester.scraping'));
|
||||||
var icon = 'chrome://zotero/skin/treeitem-webpage.png';
|
var icon = 'chrome://zotero/skin/treeitem-webpage.png';
|
||||||
|
@ -2263,14 +2292,54 @@ var ZoteroPane = new function()
|
||||||
accessDate: "CURRENT_TIMESTAMP"
|
accessDate: "CURRENT_TIMESTAMP"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this, needless to say, is a temporary hack
|
||||||
|
if (itemType == 'temporaryPDFHack') {
|
||||||
|
itemType = null;
|
||||||
|
var isPDF = false;
|
||||||
|
if (doc.title.indexOf('application/pdf') != -1) {
|
||||||
|
isPDF = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var ios = Components.classes["@mozilla.org/network/io-service;1"].
|
||||||
|
getService(Components.interfaces.nsIIOService);
|
||||||
|
try {
|
||||||
|
var uri = ios.newURI(doc.location, null, null);
|
||||||
|
if (uri.fileName && uri.fileName.match(/pdf$/)) {
|
||||||
|
isPDF = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.debug(e);
|
||||||
|
Components.utils.reportError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPDF) {
|
||||||
|
if (libraryID) {
|
||||||
|
var pr = Components.classes["@mozilla.org/network/default-prompt;1"]
|
||||||
|
.getService(Components.interfaces.nsIPrompt);
|
||||||
|
pr.alert("", "Files cannot currently be added to group libraries.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemGroup && itemGroup.isCollection()) {
|
||||||
|
var collectionID = itemGroup.ref.id;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var collectionID = false;
|
||||||
|
}
|
||||||
|
Zotero.Attachments.importFromDocument(doc, false, false, collectionID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Save web page item by default
|
// Save web page item by default
|
||||||
if (!itemType) {
|
if (!itemType) {
|
||||||
itemType = 'webpage';
|
itemType = 'webpage';
|
||||||
}
|
}
|
||||||
itemType = Zotero.ItemTypes.getID(itemType);
|
itemType = Zotero.ItemTypes.getID(itemType);
|
||||||
var item = this.newItem(itemType, data);
|
var item = this.newItem(itemType, data, row);
|
||||||
|
|
||||||
var filesEditable = false;
|
|
||||||
if (item.libraryID) {
|
if (item.libraryID) {
|
||||||
var group = Zotero.Groups.getByLibraryID(item.libraryID);
|
var group = Zotero.Groups.getByLibraryID(item.libraryID);
|
||||||
filesEditable = group.filesEditable;
|
filesEditable = group.filesEditable;
|
||||||
|
@ -2295,13 +2364,13 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.addItemFromURL = function (url, itemType) {
|
this.addItemFromURL = function (url, itemType, row) {
|
||||||
if (url == window.content.document.location.href) {
|
if (url == window.content.document.location.href) {
|
||||||
return this.addItemFromPage(itemType);
|
return this.addItemFromPage(itemType, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
var processor = function (doc) {
|
var processor = function (doc) {
|
||||||
ZoteroPane.addItemFromDocument(doc, itemType);
|
ZoteroPane.addItemFromDocument(doc, itemType, null, row);
|
||||||
};
|
};
|
||||||
|
|
||||||
var done = function () {}
|
var done = function () {}
|
||||||
|
@ -2445,10 +2514,17 @@ var ZoteroPane = new function()
|
||||||
* Test if the user can edit the currently selected library/collection,
|
* Test if the user can edit the currently selected library/collection,
|
||||||
* and display an error if not
|
* and display an error if not
|
||||||
*
|
*
|
||||||
|
* @param {Integer} [row]
|
||||||
|
*
|
||||||
* @return {Boolean} TRUE if user can edit, FALSE if not
|
* @return {Boolean} TRUE if user can edit, FALSE if not
|
||||||
*/
|
*/
|
||||||
this.canEdit = function () {
|
this.canEdit = function (row) {
|
||||||
var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
|
// Currently selected row
|
||||||
|
if (row === undefined) {
|
||||||
|
row = this.collectionsView.selection.currentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
var itemGroup = this.collectionsView._getItemAtRow(row);
|
||||||
return itemGroup.isEditable();
|
return itemGroup.isEditable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@
|
||||||
</menu>
|
</menu>
|
||||||
</menupopup>
|
</menupopup>
|
||||||
</toolbarbutton>
|
</toolbarbutton>
|
||||||
<toolbarbutton id="zotero-tb-item-from-page" tooltiptext="&zotero.toolbar.newItemFromPage.label;" oncommand="ZoteroPane.addItemFromPage()"/>
|
<toolbarbutton id="zotero-tb-item-from-page" tooltiptext="&zotero.toolbar.newItemFromPage.label;" oncommand="ZoteroPane.addItemFromPage('temporaryPDFHack')"/>
|
||||||
<toolbarbutton id="zotero-tb-lookup" tooltiptext="&zotero.toolbar.lookup.label;" oncommand="ZoteroPane.openLookupWindow()"/>
|
<toolbarbutton id="zotero-tb-lookup" tooltiptext="&zotero.toolbar.lookup.label;" oncommand="ZoteroPane.openLookupWindow()"/>
|
||||||
<!--
|
<!--
|
||||||
<toolbarseparator/>
|
<toolbarseparator/>
|
||||||
|
|
|
@ -1329,7 +1329,10 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
|
||||||
|
|
||||||
// Still string, so remote URL
|
// Still string, so remote URL
|
||||||
if (typeof file == 'string') {
|
if (typeof file == 'string') {
|
||||||
Zotero.Attachments.importFromURL(url, false, false, false, parentCollectionID);
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
|
var win = wm.getMostRecentWindow("navigator:browser");
|
||||||
|
win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', row); // TODO: don't do this
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1757,23 +1757,18 @@ Zotero.Item.prototype.save = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._previousData) {
|
if (this._previousData) {
|
||||||
var oldSourceItemIDOrKey = this._previousData.sourceItem;
|
var oldSourceItemID = this._previousData.sourceItemID;
|
||||||
if (oldSourceItemIDOrKey) {
|
if (oldSourceItemID) {
|
||||||
if (typeof oldSourceItemIDOrKey == 'number') {
|
var oldSourceItem = Zotero.Items.get(oldSourceItemID);
|
||||||
var oldSourceItem = Zotero.Items.get(oldSourceItemIDOrKey);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var oldSourceItem = Zotero.Items.getByLibraryAndKey(this.libraryID, oldSourceItemIDOrKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (oldSourceItem) {
|
if (oldSourceItem) {
|
||||||
var oldSourceItemNotifierData = {};
|
var oldSourceItemNotifierData = {};
|
||||||
oldSourceItemNotifierData[oldSourceItem.id] =
|
oldSourceItemNotifierData[oldSourceItem.id] =
|
||||||
{ old: oldSourceItem.serialize() };
|
{ old: oldSourceItem.serialize() };
|
||||||
}
|
}
|
||||||
else if (oldSourceItemIDOrKey) {
|
else if (oldSourceItemID) {
|
||||||
var oldSourceItemNotifierData = null;
|
var oldSourceItemNotifierData = null;
|
||||||
Zotero.debug("Old source item " + oldSourceItemIDOrKey
|
Zotero.debug("Old source item " + oldSourceItemID
|
||||||
+ " didn't exist in setSource()", 2);
|
+ " didn't exist in setSource()", 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1782,7 +1777,7 @@ Zotero.Item.prototype.save = function() {
|
||||||
// If this was an independent item, remove from any collections
|
// If this was an independent item, remove from any collections
|
||||||
// where it existed previously and add source instead if
|
// where it existed previously and add source instead if
|
||||||
// there is one
|
// there is one
|
||||||
if (!oldSourceItemIDOrKey) {
|
if (!oldSourceItemID) {
|
||||||
var sql = "SELECT collectionID FROM collectionItems "
|
var sql = "SELECT collectionID FROM collectionItems "
|
||||||
+ "WHERE itemID=?";
|
+ "WHERE itemID=?";
|
||||||
var changedCollections = Zotero.DB.columnQuery(sql, this.id);
|
var changedCollections = Zotero.DB.columnQuery(sql, this.id);
|
||||||
|
@ -1796,9 +1791,13 @@ Zotero.Item.prototype.save = function() {
|
||||||
sql = "DELETE FROM collectionItems WHERE itemID=?";
|
sql = "DELETE FROM collectionItems WHERE itemID=?";
|
||||||
Zotero.DB.query(sql, this.id);
|
Zotero.DB.query(sql, this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for each(var c in changedCollections) {
|
||||||
|
Zotero.Notifier.trigger('remove', 'collection-item', c + '-' + this.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Collections.reload(changedCollections);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: collection notifier trigger?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update DB, if not a note or attachment we already changed above
|
// Update DB, if not a note or attachment we already changed above
|
||||||
|
|
|
@ -41,4 +41,18 @@ Zotero.Libraries = new function () {
|
||||||
}
|
}
|
||||||
return libraryType;
|
return libraryType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.isEditable = function (libraryID) {
|
||||||
|
var type = this.getType(libraryID);
|
||||||
|
switch (type) {
|
||||||
|
case 'group':
|
||||||
|
var groupID = Zotero.Groups.getGroupIDFromLibraryID(libraryID);
|
||||||
|
var group = Zotero.Groups.get(groupID);
|
||||||
|
return group.editable;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw ("Unsupported library type '" + type + "' in Zotero.Libraries.getName()");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2078,7 +2078,9 @@ Zotero.ItemTreeView.prototype.canDrop = function(row, orient, dragData)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.isWebAttachment()) {
|
// Don't allow web attachments to be dragged out of parents,
|
||||||
|
// but do allow PDFs for now so they can be recognized
|
||||||
|
if (item.isWebAttachment() && item.attachmentMIMEType != 'application/pdf') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2168,7 +2170,7 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient)
|
||||||
item.setSource();
|
item.setSource();
|
||||||
item.save()
|
item.save()
|
||||||
}
|
}
|
||||||
itemGroup.ref.addItem(id);
|
itemGroup.ref.addItem(item.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2241,7 +2243,7 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient)
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
.getService(Components.interfaces.nsIWindowMediator);
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
var win = wm.getMostRecentWindow("navigator:browser");
|
var win = wm.getMostRecentWindow("navigator:browser");
|
||||||
win.ZoteroPane.addItemFromURL(url);
|
win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack'); // TODO: don't do this
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -635,7 +635,7 @@ Zotero.Translate.prototype.translate = function(libraryID, saveAttachments) {
|
||||||
throw("cannot translate: no location specified");
|
throw("cannot translate: no location specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.libraryID = (libraryID == undefined) ? null : libraryID;
|
this.libraryID = (libraryID === true || libraryID == undefined) ? null : libraryID;
|
||||||
this.saveAttachments = !(saveAttachments === false);
|
this.saveAttachments = !(saveAttachments === false);
|
||||||
this.saveFiles = this.saveAttachments;
|
this.saveFiles = this.saveAttachments;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue