Remove coroutine from translate.js not supported in connector
From 7fc352b9
This commit is contained in:
parent
a853bb0661
commit
deb8503863
|
@ -1540,73 +1540,68 @@ Zotero.Translate.Base.prototype = {
|
||||||
* Saves items to the database, taking care to defer attachmentProgress notifications
|
* Saves items to the database, taking care to defer attachmentProgress notifications
|
||||||
* until after save
|
* until after save
|
||||||
*/
|
*/
|
||||||
_saveItems: Zotero.Promise.coroutine(function* (items) {
|
_saveItems: Zotero.Promise.method(function (items) {
|
||||||
var itemDoneEventsDispatched = false;
|
var itemDoneEventsDispatched = false;
|
||||||
var deferredProgress = [];
|
var deferredProgress = [];
|
||||||
var attachmentsWithProgress = [];
|
var attachmentsWithProgress = [];
|
||||||
|
|
||||||
try {
|
function attachmentCallback(attachment, progress, error) {
|
||||||
var newItems = yield this._itemSaver.saveItems(
|
var attachmentIndex = this._savingAttachments.indexOf(attachment);
|
||||||
items.slice(),
|
if(progress === false || progress === 100) {
|
||||||
function (attachment, progress, error) {
|
if(attachmentIndex !== -1) {
|
||||||
var attachmentIndex = this._savingAttachments.indexOf(attachment);
|
this._savingAttachments.splice(attachmentIndex, 1);
|
||||||
if(progress === false || progress === 100) {
|
}
|
||||||
if(attachmentIndex !== -1) {
|
} else if(attachmentIndex === -1) {
|
||||||
this._savingAttachments.splice(attachmentIndex, 1);
|
this._savingAttachments.push(attachment);
|
||||||
}
|
}
|
||||||
} else if(attachmentIndex === -1) {
|
|
||||||
this._savingAttachments.push(attachment);
|
if(itemDoneEventsDispatched) {
|
||||||
}
|
// itemDone event has already fired, so we can fire attachmentProgress
|
||||||
|
// notifications
|
||||||
if(itemDoneEventsDispatched) {
|
this._runHandler("attachmentProgress", attachment, progress, error);
|
||||||
// itemDone event has already fired, so we can fire attachmentProgress
|
this._checkIfDone();
|
||||||
// notifications
|
} else {
|
||||||
this._runHandler("attachmentProgress", attachment, progress, error);
|
// Defer until after we fire the itemDone event
|
||||||
this._checkIfDone();
|
deferredProgress.push([attachment, progress, error]);
|
||||||
} else {
|
attachmentsWithProgress.push(attachment);
|
||||||
// Defer until after we fire the itemDone event
|
}
|
||||||
deferredProgress.push([attachment, progress, error]);
|
|
||||||
attachmentsWithProgress.push(attachment);
|
|
||||||
}
|
|
||||||
}.bind(this)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
|
||||||
|
return this._itemSaver.saveItems(items.slice(), attachmentCallback.bind(this)).then(function(newItems) {
|
||||||
|
// Remove attachments not being saved from item.attachments
|
||||||
|
for(var i=0; i<items.length; i++) {
|
||||||
|
var item = items[i];
|
||||||
|
for(var j=0; j<item.attachments.length; j++) {
|
||||||
|
if(attachmentsWithProgress.indexOf(item.attachments[j]) === -1) {
|
||||||
|
item.attachments.splice(j--, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger itemDone events
|
||||||
|
for(var i=0, nItems = items.length; i<nItems; i++) {
|
||||||
|
this._runHandler("itemDone", newItems[i], items[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Specify that itemDone event was dispatched, so that we don't defer
|
||||||
|
// attachmentProgress notifications anymore
|
||||||
|
itemDoneEventsDispatched = true;
|
||||||
|
|
||||||
|
// Run deferred attachmentProgress notifications
|
||||||
|
for(var i=0; i<deferredProgress.length; i++) {
|
||||||
|
this._runHandler("attachmentProgress", deferredProgress[i][0],
|
||||||
|
deferredProgress[i][1], deferredProgress[i][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._savingItems -= items.length;
|
||||||
|
this.newItems = this.newItems.concat(newItems);
|
||||||
|
this._checkIfDone();
|
||||||
|
}.bind(this)).catch(function(e) {
|
||||||
this._savingItems -= items.length;
|
this._savingItems -= items.length;
|
||||||
Zotero.debug("REDUCING SAVING ITEMS ERROR TO " + this._savingItems);
|
Zotero.debug("REDUCING SAVING ITEMS ERROR TO " + this._savingItems);
|
||||||
Zotero.logError(e);
|
Zotero.logError(e);
|
||||||
this.complete(false, e);
|
this.complete(false, e);
|
||||||
return;
|
}.bind(this));
|
||||||
}
|
|
||||||
|
|
||||||
// Remove attachments not being saved from item.attachments
|
|
||||||
for(var i=0; i<items.length; i++) {
|
|
||||||
var item = items[i];
|
|
||||||
for(var j=0; j<item.attachments.length; j++) {
|
|
||||||
if(attachmentsWithProgress.indexOf(item.attachments[j]) === -1) {
|
|
||||||
item.attachments.splice(j--, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger itemDone events
|
|
||||||
for(var i=0, nItems = items.length; i<nItems; i++) {
|
|
||||||
this._runHandler("itemDone", newItems[i], items[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specify that itemDone event was dispatched, so that we don't defer
|
|
||||||
// attachmentProgress notifications anymore
|
|
||||||
itemDoneEventsDispatched = true;
|
|
||||||
|
|
||||||
// Run deferred attachmentProgress notifications
|
|
||||||
for(var i=0; i<deferredProgress.length; i++) {
|
|
||||||
this._runHandler("attachmentProgress", deferredProgress[i][0],
|
|
||||||
deferredProgress[i][1], deferredProgress[i][2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._savingItems -= items.length;
|
|
||||||
this.newItems = this.newItems.concat(newItems);
|
|
||||||
this._checkIfDone();
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user