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') else if(action == 'add')
{ {
// Multiple adds not currently supported // skipSelect isn't necessary if more than one object
let id = ids[0]; let selectRow = ids.length == 1 && (!extraData[ids[0]] || !extraData[ids[0]].skipSelect);
let selectRow = !extraData[id] || !extraData[id].skipSelect;
switch (type) for (let id of ids) {
{ switch (type) {
case 'collection': case 'collection':
case 'search': case 'search':
yield this._addSortedRow(type, id); yield this._addSortedRow(type, id);
if (selectRow) { if (selectRow) {
if (type == 'collection') { if (type == 'collection') {
yield this.selectCollection(id); 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 'feed':
yield this.reload();
case 'group': yield this.selectByID("L" + id);
yield this.reload(); break;
yield this.selectByID(currentTreeRow.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); 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* () { it("shouldn't refresh the items list when a collection is modified", function* () {
var collection = yield createDataObject('collection'); var collection = yield createDataObject('collection');
yield waitForItemsLoad(win); yield waitForItemsLoad(win);