Make Zotero.Item::attachmentFilename work without file
And have getFilePath() return false instead of failing on unsaved items
This commit is contained in:
parent
90286d2a50
commit
7cfa857887
|
@ -1979,6 +1979,11 @@ Zotero.Item.prototype.getFilePath = function () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this._identified) {
|
||||||
|
Zotero.debug("Can't get file path for unsaved file");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Imported file with relative path
|
// Imported file with relative path
|
||||||
if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL ||
|
if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL ||
|
||||||
linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_FILE) {
|
linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_FILE) {
|
||||||
|
@ -2560,11 +2565,15 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentFilename', {
|
||||||
if (!this.isAttachment()) {
|
if (!this.isAttachment()) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
var file = this.getFile();
|
var path = this.attachmentPath;
|
||||||
if (!file) {
|
if (!path) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return file.leafName;
|
var prefixedPath = path.match(/^(?:attachments|storage):(.+)$/);
|
||||||
|
if (prefixedPath) {
|
||||||
|
return prefixedPath[1];
|
||||||
|
}
|
||||||
|
return OS.Path.basename(path);
|
||||||
},
|
},
|
||||||
set: function (val) {
|
set: function (val) {
|
||||||
if (!this.isAttachment()) {
|
if (!this.isAttachment()) {
|
||||||
|
@ -2655,7 +2664,6 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentPath', {
|
||||||
this._changed.attachmentData = {};
|
this._changed.attachmentData = {};
|
||||||
}
|
}
|
||||||
this._changed.attachmentData.path = true;
|
this._changed.attachmentData.path = true;
|
||||||
|
|
||||||
this._attachmentPath = val;
|
this._attachmentPath = val;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user