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 // If no quicksearch, process modifications manually
else if (!quicksearch || quicksearch.value == '') 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++) { for (let i = 0; i < items.length; i++) {
let item = items[i]; let item = items[i];
@ -609,10 +609,17 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
let parentItemID = this.getRow(row).ref.parentItemID; let parentItemID = this.getRow(row).ref.parentItemID;
let parentIndex = this.getParentIndex(row); let parentIndex = this.getParentIndex(row);
// Top-level items just have to be resorted // Top-level item
if (this.isContainer(row)) { if (this.isContainer(row)) {
// 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; sort = id;
} }
}
// If item moved from top-level to under another item, remove the old row. // If item moved from top-level to under another item, remove the old row.
else if (parentIndex == -1 && parentItemID) { else if (parentIndex == -1 && parentItemID) {
this._removeRow(row); this._removeRow(row);
@ -1585,7 +1592,7 @@ Zotero.ItemTreeView.prototype.selectItem = Zotero.Promise.coroutine(function* (i
// Clear the quicksearch and tag selection and try again (once) // Clear the quicksearch and tag selection and try again (once)
if (!noRecurse && this._ownerDocument.defaultView.ZoteroPane_Local) { if (!noRecurse && this._ownerDocument.defaultView.ZoteroPane_Local) {
let cleared1 = yield this._ownerDocument.defaultView.ZoteroPane_Local.clearQuicksearch(); 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) { if (cleared1 || cleared2) {
return this.selectItem(id, expand, true); return this.selectItem(id, expand, true);
} }

View file

@ -1,31 +1,31 @@
"use strict"; "use strict";
describe("Zotero.ItemTreeView", function() { describe("Zotero.ItemTreeView", function() {
var win, zp, itemsView, existingItemID; var win, zp, cv, itemsView, existingItemID;
// Load Zotero pane and select library // Load Zotero pane and select library
before(function* () { before(function* () {
win = yield loadZoteroPane(); win = yield loadZoteroPane();
zp = win.ZoteroPane; zp = win.ZoteroPane;
cv = zp.collectionsView;
var item = new Zotero.Item('book'); var item = new Zotero.Item('book');
existingItemID = yield item.saveTx(); existingItemID = yield item.saveTx();
}); });
beforeEach(function* () { beforeEach(function* () {
yield zp.collectionsView.selectLibrary(); yield selectLibrary(win);
yield waitForItemsLoad(win)
itemsView = zp.itemsView; itemsView = zp.itemsView;
}) })
after(function () { after(function () {
win.close(); 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 item = yield createDataObject('item', { title: "foo" });
var itemID = item.id; var itemID = item.id;
item.deleted = true; item.deleted = true;
yield item.saveTx(); yield item.saveTx();
assert.notOk(itemsView.getRowIndexByID(itemID)); assert.isFalse(itemsView.getRowIndexByID(itemID));
}) })
describe("#selectItem()", function () { describe("#selectItem()", function () {
@ -231,6 +231,19 @@ describe("Zotero.ItemTreeView", function() {
yield Zotero.Items.erase(items.map(item => item.id)); 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 () { describe("#drop()", function () {