Restore Notifier enable()/disable() for use by Attachment.importFromURL() and importFromDocument(), which do two-part saves and need to not send notifications after the first part
This commit is contained in:
parent
937072e875
commit
937ccaa850
|
@ -221,7 +221,12 @@ Zotero.Attachments = new function(){
|
|||
attachmentItem.setField('title', title);
|
||||
attachmentItem.setField('url', url);
|
||||
attachmentItem.setField('accessDate', "CURRENT_TIMESTAMP");
|
||||
// Don't send a Notifier event on the incomplete item
|
||||
var disabled = Zotero.Notifier.disable();
|
||||
attachmentItem.save();
|
||||
if (disabled) {
|
||||
Zotero.Notifier.enable();
|
||||
}
|
||||
var itemID = attachmentItem.getID();
|
||||
|
||||
// Add to collections
|
||||
|
@ -246,6 +251,8 @@ Zotero.Attachments = new function(){
|
|||
_addToDB(file, url, title, Zotero.Attachments.LINK_MODE_IMPORTED_URL,
|
||||
mimeType, null, sourceItemID, itemID);
|
||||
|
||||
Zotero.Notifier.trigger('add', 'item', itemID);
|
||||
|
||||
// We don't have any way of knowing that the file
|
||||
// is flushed to disk, so we just wait a second
|
||||
// and hope for the best -- we'll index it later
|
||||
|
@ -411,7 +418,12 @@ Zotero.Attachments = new function(){
|
|||
attachmentItem.setField('title', title);
|
||||
attachmentItem.setField('url', url);
|
||||
attachmentItem.setField('accessDate', "CURRENT_TIMESTAMP");
|
||||
// Don't send a Notifier event on the incomplete item
|
||||
var disabled = Zotero.Notifier.disable();
|
||||
attachmentItem.save();
|
||||
if (disabled) {
|
||||
Zotero.Notifier.enable();
|
||||
}
|
||||
var itemID = attachmentItem.getID();
|
||||
|
||||
// Create a new folder for this item in the storage directory
|
||||
|
@ -432,6 +444,8 @@ Zotero.Attachments = new function(){
|
|||
_addToDB(file, url, title, Zotero.Attachments.LINK_MODE_IMPORTED_URL, mimeType,
|
||||
charsetID, sourceItemID, itemID);
|
||||
|
||||
Zotero.Notifier.trigger('add', 'item', itemID);
|
||||
|
||||
// Add to collections
|
||||
if (parentCollectionIDs){
|
||||
var ids = Zotero.flattenArguments(parentCollectionIDs);
|
||||
|
|
|
@ -38,6 +38,9 @@ Zotero.Notifier = new function(){
|
|||
this.begin = begin;
|
||||
this.commit = commit;
|
||||
this.reset = reset;
|
||||
this.disable = disable;
|
||||
this.enable = enable;
|
||||
this.isEnabled = isEnabled;
|
||||
|
||||
|
||||
function registerObserver(ref, types){
|
||||
|
@ -295,4 +298,35 @@ Zotero.Notifier = new function(){
|
|||
_queue = [];
|
||||
_inTransaction = false;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// These should rarely be used now that we have event queuing
|
||||
//
|
||||
|
||||
/*
|
||||
* Disables Notifier notifications
|
||||
*
|
||||
* Returns false if the Notifier was already disabled, true otherwise
|
||||
*/
|
||||
function disable() {
|
||||
if (_disabled) {
|
||||
Zotero.debug('Notifier notifications are already disabled');
|
||||
return false;
|
||||
}
|
||||
Zotero.debug('Disabling Notifier notifications');
|
||||
_disabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function enable(enable) {
|
||||
Zotero.debug('Enabling Notifier notifications');
|
||||
_disabled = false;
|
||||
}
|
||||
|
||||
|
||||
function isEnabled() {
|
||||
return !_disabled;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user