Fix selection of new items
This commit is contained in:
parent
2bd246e2ea
commit
31af26af08
|
@ -2050,43 +2050,45 @@ var ZoteroPane = new function()
|
||||||
var self = this;
|
var self = this;
|
||||||
var deferred = Zotero.Promise.defer();
|
var deferred = Zotero.Promise.defer();
|
||||||
this.collectionsView.addEventListener('load', function () {
|
this.collectionsView.addEventListener('load', function () {
|
||||||
try {
|
Zotero.spawn(function* () {
|
||||||
self.addEventListener('itemsLoaded', function () {
|
try {
|
||||||
Zotero.spawn(function* () {
|
self.addEventListener('itemsLoaded', function () {
|
||||||
var selected = yield self.itemsView.selectItem(itemID, expand);
|
Zotero.spawn(function* () {
|
||||||
if (!selected) {
|
var selected = yield self.itemsView.selectItem(itemID, expand);
|
||||||
if (item.deleted) {
|
if (!selected) {
|
||||||
Zotero.debug("Item is deleted; switching to trash");
|
if (item.deleted) {
|
||||||
yield self.collectionsView.selectTrash(item.libraryID);
|
Zotero.debug("Item is deleted; switching to trash");
|
||||||
|
yield self.collectionsView.selectTrash(item.libraryID);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Zotero.debug("Item was not selected; switching to library");
|
||||||
|
yield self.collectionsView.selectLibrary(item.libraryID);
|
||||||
|
}
|
||||||
|
yield self.itemsView.selectItem(itemID, expand);
|
||||||
}
|
}
|
||||||
else {
|
deferred.resolve(true);
|
||||||
Zotero.debug("Item was not selected; switching to library");
|
})
|
||||||
yield self.collectionsView.selectLibrary(item.libraryID);
|
.catch(function(e) {
|
||||||
}
|
deferred.reject(e);
|
||||||
yield self.itemsView.selectItem(itemID, expand);
|
});
|
||||||
}
|
|
||||||
deferred.resolve(true);
|
|
||||||
})
|
|
||||||
.catch(function(e) {
|
|
||||||
deferred.reject(e);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
var currentLibraryID = self.getSelectedLibraryID();
|
var currentLibraryID = self.getSelectedLibraryID();
|
||||||
// If in a different library
|
// If in a different library
|
||||||
if (item.libraryID != currentLibraryID) {
|
if (item.libraryID != currentLibraryID) {
|
||||||
Zotero.debug("Library ID differs; switching library");
|
Zotero.debug("Library ID differs; switching library");
|
||||||
yield self.collectionsView.selectLibrary(item.libraryID);
|
yield self.collectionsView.selectLibrary(item.libraryID);
|
||||||
|
}
|
||||||
|
// Force switch to library view
|
||||||
|
else if (!self.collectionsView.selectedTreeRow.isLibrary() && inLibrary) {
|
||||||
|
Zotero.debug("Told to select in library; switching to library");
|
||||||
|
yield self.collectionsView.selectLibrary(item.libraryID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Force switch to library view
|
catch (e) {
|
||||||
else if (!self.collectionsView.selectedTreeRow.isLibrary() && inLibrary) {
|
deferred.reject(e);
|
||||||
Zotero.debug("Told to select in library; switching to library");
|
|
||||||
yield self.collectionsView.selectLibrary(item.libraryID);
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
catch (e) {
|
|
||||||
deferred.reject(e);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// open Zotero pane
|
// open Zotero pane
|
||||||
|
@ -3069,45 +3071,16 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {Promise}
|
* @return {Promise<Integer|null|false>} - The id of the new note in non-popup mode, null in
|
||||||
|
* popup mode (where a note isn't created immediately), or false if library isn't editable
|
||||||
*/
|
*/
|
||||||
this.newNote = Zotero.Promise.coroutine(function* (popup, parentKey, text, citeURI) {
|
this.newNote = Zotero.Promise.coroutine(function* (popup, parentKey, text, citeURI) {
|
||||||
if (!this.canEdit()) {
|
if (!this.canEdit()) {
|
||||||
this.displayCannotEditLibraryMessage();
|
this.displayCannotEditLibraryMessage();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!popup) {
|
if (popup) {
|
||||||
if (!text) {
|
|
||||||
text = '';
|
|
||||||
}
|
|
||||||
text = text.trim();
|
|
||||||
|
|
||||||
if (text) {
|
|
||||||
text = '<blockquote'
|
|
||||||
+ (citeURI ? ' cite="' + citeURI + '"' : '')
|
|
||||||
+ '>' + Zotero.Utilities.text2html(text) + "</blockquote>";
|
|
||||||
}
|
|
||||||
|
|
||||||
var item = new Zotero.Item('note');
|
|
||||||
item.libraryID = this.getSelectedLibraryID();
|
|
||||||
item.setNote(text);
|
|
||||||
Zotero.debug(parentKey);
|
|
||||||
if (parentKey) {
|
|
||||||
item.parentKey = parentKey;
|
|
||||||
}
|
|
||||||
var itemID = yield item.saveTx();
|
|
||||||
|
|
||||||
if (!parentKey && this.itemsView && this.collectionsView.selectedTreeRow.isCollection()) {
|
|
||||||
yield this.collectionsView.selectedTreeRow.ref.addItem(itemID);
|
|
||||||
}
|
|
||||||
|
|
||||||
yield this.selectItem(itemID);
|
|
||||||
|
|
||||||
document.getElementById('zotero-note-editor').focus();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO: _text_
|
// TODO: _text_
|
||||||
var c = this.getSelectedCollection();
|
var c = this.getSelectedCollection();
|
||||||
if (c) {
|
if (c) {
|
||||||
|
@ -3116,7 +3089,37 @@ var ZoteroPane = new function()
|
||||||
else {
|
else {
|
||||||
this.openNoteWindow(null, null, parentKey);
|
this.openNoteWindow(null, null, parentKey);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!text) {
|
||||||
|
text = '';
|
||||||
|
}
|
||||||
|
text = text.trim();
|
||||||
|
|
||||||
|
if (text) {
|
||||||
|
text = '<blockquote'
|
||||||
|
+ (citeURI ? ' cite="' + citeURI + '"' : '')
|
||||||
|
+ '>' + Zotero.Utilities.text2html(text) + "</blockquote>";
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = new Zotero.Item('note');
|
||||||
|
item.libraryID = this.getSelectedLibraryID();
|
||||||
|
item.setNote(text);
|
||||||
|
if (parentKey) {
|
||||||
|
item.parentKey = parentKey;
|
||||||
|
}
|
||||||
|
var itemID = yield item.saveTx();
|
||||||
|
|
||||||
|
if (!parentKey && this.itemsView && this.collectionsView.selectedTreeRow.isCollection()) {
|
||||||
|
yield this.collectionsView.selectedTreeRow.ref.addItem(itemID);
|
||||||
|
}
|
||||||
|
|
||||||
|
yield this.selectItem(itemID);
|
||||||
|
|
||||||
|
document.getElementById('zotero-note-editor').focus();
|
||||||
|
|
||||||
|
return itemID;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,16 @@ describe("ZoteroPane", function() {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#newNote()", function () {
|
||||||
|
it("should create a child note and select it", function* () {
|
||||||
|
var item = yield createDataObject('item');
|
||||||
|
var noteID = yield zp.newNote(false, item.key, "Test");
|
||||||
|
var selected = zp.itemsView.getSelectedItems(true);
|
||||||
|
assert.lengthOf(selected, 1);
|
||||||
|
assert.equal(selected, noteID);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("#itemSelected()", function () {
|
describe("#itemSelected()", function () {
|
||||||
it.skip("should update the item count", function* () {
|
it.skip("should update the item count", function* () {
|
||||||
var collection = new Zotero.Collection;
|
var collection = new Zotero.Collection;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user