Remove items from open Unfiled Items view when added to collection

This commit is contained in:
Dan Stillman 2016-03-13 22:59:19 -04:00
parent 6b509820b3
commit 60830c27ee
2 changed files with 29 additions and 9 deletions

View file

@ -590,7 +590,7 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
// If no quicksearch, process modifications manually
else if (!quicksearch || quicksearch.value == '')
{
var items = yield Zotero.Items.getAsync(ids);
var items = Zotero.Items.get(ids);
for (let i = 0; i < items.length; i++) {
let item = items[i];
@ -609,9 +609,16 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
let parentItemID = this.getRow(row).ref.parentItemID;
let parentIndex = this.getParentIndex(row);
// Top-level items just have to be resorted
// Top-level item
if (this.isContainer(row)) {
sort = id;
// If Unfiled Items and itm was added to a collection, remove from view
if (collectionTreeRow.isUnfiled() && item.getCollections().length) {
this._removeRow(row);
}
// Otherwise just resort
else {
sort = id;
}
}
// If item moved from top-level to under another item, remove the old row.
else if (parentIndex == -1 && parentItemID) {
@ -1585,7 +1592,7 @@ Zotero.ItemTreeView.prototype.selectItem = Zotero.Promise.coroutine(function* (i
// Clear the quicksearch and tag selection and try again (once)
if (!noRecurse && this._ownerDocument.defaultView.ZoteroPane_Local) {
let cleared1 = yield this._ownerDocument.defaultView.ZoteroPane_Local.clearQuicksearch();
let cleared2 = yield this._ownerDocument.defaultView.ZoteroPane_Local.clearTagSelection();
let cleared2 = this._ownerDocument.defaultView.ZoteroPane_Local.clearTagSelection();
if (cleared1 || cleared2) {
return this.selectItem(id, expand, true);
}

View file

@ -1,31 +1,31 @@
"use strict";
describe("Zotero.ItemTreeView", function() {
var win, zp, itemsView, existingItemID;
var win, zp, cv, itemsView, existingItemID;
// Load Zotero pane and select library
before(function* () {
win = yield loadZoteroPane();
zp = win.ZoteroPane;
cv = zp.collectionsView;
var item = new Zotero.Item('book');
existingItemID = yield item.saveTx();
});
beforeEach(function* () {
yield zp.collectionsView.selectLibrary();
yield waitForItemsLoad(win)
yield selectLibrary(win);
itemsView = zp.itemsView;
})
after(function () {
win.close();
});
it("shouldn't show items in trash", function* () {
it("shouldn't show items in trash in library root", function* () {
var item = yield createDataObject('item', { title: "foo" });
var itemID = item.id;
item.deleted = true;
yield item.saveTx();
assert.notOk(itemsView.getRowIndexByID(itemID));
assert.isFalse(itemsView.getRowIndexByID(itemID));
})
describe("#selectItem()", function () {
@ -231,6 +231,19 @@ describe("Zotero.ItemTreeView", function() {
yield Zotero.Items.erase(items.map(item => item.id));
})
it("should remove items from Unfiled Items when added to a collection", function* () {
var collection = yield createDataObject('collection');
var item = yield createDataObject('item', { title: "Unfiled Item" });
yield cv.selectByID("U" + Zotero.Libraries.userLibraryID);
yield waitForItemsLoad(win);
assert.isNumber(zp.itemsView.getRowIndexByID(item.id));
yield Zotero.DB.executeTransaction(function* () {
yield collection.addItem(item.id);
});
assert.isFalse(zp.itemsView.getRowIndexByID(item.id));
});
})
describe("#drop()", function () {