Handle multi-collection/search add in collectionTreeView::notify()

This commit is contained in:
Dan Stillman 2016-02-21 05:19:01 -05:00
parent 6c43e75d26
commit c099bd432a
2 changed files with 49 additions and 26 deletions

View file

@ -469,36 +469,40 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function*
}
else if(action == 'add')
{
// Multiple adds not currently supported
let id = ids[0];
let selectRow = !extraData[id] || !extraData[id].skipSelect;
// skipSelect isn't necessary if more than one object
let selectRow = ids.length == 1 && (!extraData[ids[0]] || !extraData[ids[0]].skipSelect);
switch (type)
{
case 'collection':
case 'search':
yield this._addSortedRow(type, id);
if (selectRow) {
if (type == 'collection') {
yield this.selectCollection(id);
for (let id of ids) {
switch (type) {
case 'collection':
case 'search':
yield this._addSortedRow(type, id);
if (selectRow) {
if (type == 'collection') {
yield this.selectCollection(id);
}
else if (type == 'search') {
yield this.selectSearch(id);
}
}
else if (type == 'search') {
yield this.selectSearch(id);
break;
case 'group':
if (ids.length != 1) {
Zotero.logError("WARNING: Multiple groups shouldn't currently be added "
+ "together in collectionTreeView::notify()")
}
}
yield this.reload();
yield this.selectByID(currentTreeRow.id);
break;
break;
case 'group':
yield this.reload();
yield this.selectByID(currentTreeRow.id);
break;
case 'feed':
yield this.reload();
yield this.selectByID("L" + id);
break;
case 'feed':
yield this.reload();
yield this.selectByID("L" + id);
break;
}
}
}

View file

@ -215,6 +215,25 @@ describe("Zotero.CollectionTreeView", function() {
assert.equal(aRow, bRow + 1);
})
it("should add multiple collections", function* () {
var col1, col2;
yield Zotero.DB.executeTransaction(function* () {
col1 = createUnsavedDataObject('collection');
col2 = createUnsavedDataObject('collection');
yield col1.save();
yield col2.save();
});
var aRow = cv.getRowIndexByID("C" + col1.id);
var bRow = cv.getRowIndexByID("C" + col2.id);
assert.isAbove(aRow, 0);
assert.isAbove(bRow, 0);
// skipSelect is implied for multiple collections, so library should still be selected
assert.equal(cv.selection.currentIndex, 0);
});
it("shouldn't refresh the items list when a collection is modified", function* () {
var collection = yield createDataObject('collection');
yield waitForItemsLoad(win);