Reset file renaming preference if input left empty (#4462)
This commit is contained in:
parent
1d5971c48f
commit
a538a5588e
1 changed files with 12 additions and 2 deletions
|
@ -31,6 +31,7 @@ Zotero_Preferences.FileRenaming = {
|
|||
this.inputRef = document.getElementById('file-renaming-format-template');
|
||||
this.updatePreview();
|
||||
this.inputRef.addEventListener('input', this.updatePreview.bind(this));
|
||||
this.inputRef.addEventListener('blur', this.handleInputBlur.bind(this));
|
||||
|
||||
this._itemsView = Zotero.getActiveZoteroPane()?.itemsView;
|
||||
this._updatePreview = this.updatePreview.bind(this);
|
||||
|
@ -60,13 +61,22 @@ Zotero_Preferences.FileRenaming = {
|
|||
return null;
|
||||
},
|
||||
|
||||
async updatePreview() {
|
||||
updatePreview() {
|
||||
const [item, ext, attachmentTitle] = this.getActiveItem() ?? [this.mockItem ?? this.makeMockItem(), this.defaultExt, ''];
|
||||
const formatString = document.getElementById('file-renaming-format-template').value;
|
||||
const formatString = this.inputRef.value;
|
||||
const preview = Zotero.Attachments.getFileBaseNameFromItem(item, { formatString, attachmentTitle });
|
||||
document.getElementById('file-renaming-format-preview').innerText = `${preview}.${ext}`;
|
||||
},
|
||||
|
||||
handleInputBlur() {
|
||||
const formatString = this.inputRef.value;
|
||||
const prefKey = this.inputRef.getAttribute('preference');
|
||||
if (formatString.replace(/\s/g, '') === '') {
|
||||
Zotero.Prefs.clear(prefKey, true);
|
||||
this.updatePreview();
|
||||
}
|
||||
},
|
||||
|
||||
makeMockItem() {
|
||||
this.mockItem = new Zotero.Item('journalArticle');
|
||||
this.mockItem.setField('title', 'Example Title: Example Subtitle');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue