Fix moving items between collections
`mozSourceNode` seems to no longer be set in `dataTransfer` objects during drags, so we now store it in `Zotero.DragDrop`.
This commit is contained in:
parent
76bc61e882
commit
1a49018bdc
|
@ -2518,6 +2518,12 @@ Zotero.ItemTreeView.prototype.onDragStart = function (event) {
|
||||||
|
|
||||||
var itemIDs = this.getSelectedItems(true);
|
var itemIDs = this.getSelectedItems(true);
|
||||||
event.dataTransfer.setData("zotero/item", itemIDs);
|
event.dataTransfer.setData("zotero/item", itemIDs);
|
||||||
|
// dataTransfer.mozSourceNode doesn't seem to be properly set anymore (tested in 50), so store
|
||||||
|
// target separately
|
||||||
|
if (!event.dataTransfer.mozSourceNode) {
|
||||||
|
Zotero.debug("mozSourceNode not set -- storing source node");
|
||||||
|
Zotero.DragDrop.currentSourceNode = event.target;
|
||||||
|
}
|
||||||
|
|
||||||
var items = Zotero.Items.get(itemIDs);
|
var items = Zotero.Items.get(itemIDs);
|
||||||
|
|
||||||
|
@ -2609,6 +2615,12 @@ Zotero.ItemTreeView.prototype.onDragStart = function (event) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Zotero.ItemTreeView.prototype.onDragEnd = function (event) {
|
||||||
|
setTimeout(function () {
|
||||||
|
Zotero.DragDrop.currentDragSource = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Implements nsIFlavorDataProvider for dragging attachment files to OS
|
// Implements nsIFlavorDataProvider for dragging attachment files to OS
|
||||||
//
|
//
|
||||||
|
|
|
@ -310,10 +310,10 @@ Zotero.LibraryTreeView.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.dataTransfer.getData("zotero/item")) {
|
if (event.dataTransfer.getData("zotero/item")) {
|
||||||
var sourceCollectionTreeRow = Zotero.DragDrop.getDragSource();
|
var sourceCollectionTreeRow = Zotero.DragDrop.getDragSource(event.dataTransfer);
|
||||||
if (sourceCollectionTreeRow) {
|
if (sourceCollectionTreeRow) {
|
||||||
if (this.type == 'collection') {
|
if (this.type == 'collection') {
|
||||||
var targetCollectionTreeRow = Zotero.DragDrop.getDragTarget();
|
var targetCollectionTreeRow = Zotero.DragDrop.getDragTarget(event);
|
||||||
}
|
}
|
||||||
else if (this.type == 'item') {
|
else if (this.type == 'item') {
|
||||||
var targetCollectionTreeRow = this.collectionTreeRow;
|
var targetCollectionTreeRow = this.collectionTreeRow;
|
||||||
|
|
|
@ -2312,6 +2312,7 @@ Zotero.VersionHeader = {
|
||||||
Zotero.DragDrop = {
|
Zotero.DragDrop = {
|
||||||
currentEvent: null,
|
currentEvent: null,
|
||||||
currentOrientation: 0,
|
currentOrientation: 0,
|
||||||
|
currentSourceNode: null,
|
||||||
|
|
||||||
getDataFromDataTransfer: function (dataTransfer, firstOnly) {
|
getDataFromDataTransfer: function (dataTransfer, firstOnly) {
|
||||||
var dt = dataTransfer;
|
var dt = dataTransfer;
|
||||||
|
@ -2374,7 +2375,7 @@ Zotero.DragDrop = {
|
||||||
// For items, the drag source is the CollectionTreeRow of the parent window
|
// For items, the drag source is the CollectionTreeRow of the parent window
|
||||||
// of the source tree
|
// of the source tree
|
||||||
if (dataTransfer.types.contains("zotero/item")) {
|
if (dataTransfer.types.contains("zotero/item")) {
|
||||||
var sourceNode = dataTransfer.mozSourceNode;
|
let sourceNode = dataTransfer.mozSourceNode || this.currentSourceNode;
|
||||||
if (!sourceNode || sourceNode.tagName != 'treechildren'
|
if (!sourceNode || sourceNode.tagName != 'treechildren'
|
||||||
|| sourceNode.parentElement.id != 'zotero-items-tree') {
|
|| sourceNode.parentElement.id != 'zotero-items-tree') {
|
||||||
return false;
|
return false;
|
||||||
|
@ -2385,9 +2386,8 @@ Zotero.DragDrop = {
|
||||||
}
|
}
|
||||||
return win.ZoteroPane.collectionsView.selectedTreeRow;
|
return win.ZoteroPane.collectionsView.selectedTreeRow;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -554,7 +554,8 @@
|
||||||
<treechildren ondragstart="ZoteroPane_Local.itemsView.onDragStart(event)"
|
<treechildren ondragstart="ZoteroPane_Local.itemsView.onDragStart(event)"
|
||||||
ondragenter="return ZoteroPane_Local.itemsView.onDragEnter(event)"
|
ondragenter="return ZoteroPane_Local.itemsView.onDragEnter(event)"
|
||||||
ondragover="return ZoteroPane_Local.itemsView.onDragOver(event)"
|
ondragover="return ZoteroPane_Local.itemsView.onDragOver(event)"
|
||||||
ondrop="return ZoteroPane_Local.itemsView.onDrop(event)"/>
|
ondrop="return ZoteroPane_Local.itemsView.onDrop(event)"
|
||||||
|
ondragend="ZoteroPane_Local.itemsView.onDragEnd(event)"/>
|
||||||
</tree>
|
</tree>
|
||||||
|
|
||||||
<!-- Label for displaying messages when items pane is hidden
|
<!-- Label for displaying messages when items pane is hidden
|
||||||
|
|
|
@ -450,7 +450,7 @@ describe("Zotero.CollectionTreeView", function() {
|
||||||
* value returned after the drag. Otherwise, an 'add' event will be waited for, and
|
* value returned after the drag. Otherwise, an 'add' event will be waited for, and
|
||||||
* an object with 'ids' and 'extraData' will be returned.
|
* an object with 'ids' and 'extraData' will be returned.
|
||||||
*/
|
*/
|
||||||
var drop = Zotero.Promise.coroutine(function* (objectType, targetRow, ids, promise) {
|
var drop = Zotero.Promise.coroutine(function* (objectType, targetRow, ids, promise, action = 'copy') {
|
||||||
if (typeof targetRow == 'string') {
|
if (typeof targetRow == 'string') {
|
||||||
var row = cv.getRowIndexByID(targetRow);
|
var row = cv.getRowIndexByID(targetRow);
|
||||||
var orient = 0;
|
var orient = 0;
|
||||||
|
@ -465,9 +465,9 @@ describe("Zotero.CollectionTreeView", function() {
|
||||||
promise = waitForNotifierEvent("add", objectType);
|
promise = waitForNotifierEvent("add", objectType);
|
||||||
}
|
}
|
||||||
yield cv.drop(row, orient, {
|
yield cv.drop(row, orient, {
|
||||||
dropEffect: 'copy',
|
dropEffect: action,
|
||||||
effectAllowed: 'copy',
|
effectAllowed: action,
|
||||||
mozSourceNode: win.document.getElementById(`zotero-${objectType}s-tree`),
|
mozSourceNode: win.document.getElementById(`zotero-${objectType}s-tree`).treeBoxObject.treeBody,
|
||||||
types: {
|
types: {
|
||||||
contains: function (type) {
|
contains: function (type) {
|
||||||
return type == `zotero/${objectType}`;
|
return type == `zotero/${objectType}`;
|
||||||
|
@ -546,6 +546,41 @@ describe("Zotero.CollectionTreeView", function() {
|
||||||
assert.equal(treeRow.ref.id, item.id);
|
assert.equal(treeRow.ref.id, item.id);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should move an item from one collection to another", function* () {
|
||||||
|
var collection1 = yield createDataObject('collection');
|
||||||
|
yield waitForItemsLoad(win);
|
||||||
|
var collection2 = yield createDataObject('collection', false, { skipSelect: true });
|
||||||
|
var item = yield createDataObject('item', { collections: [collection1.id] });
|
||||||
|
|
||||||
|
// Add observer to wait for collection add
|
||||||
|
var deferred = Zotero.Promise.defer();
|
||||||
|
var observerID = Zotero.Notifier.registerObserver({
|
||||||
|
notify: function (event, type, ids, extraData) {
|
||||||
|
if (type == 'collection-item' && event == 'add'
|
||||||
|
&& ids[0] == collection2.id + "-" + item.id) {
|
||||||
|
setTimeout(function () {
|
||||||
|
deferred.resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 'collection-item', 'test');
|
||||||
|
|
||||||
|
yield drop('item', 'C' + collection2.id, [item.id], deferred.promise, 'move');
|
||||||
|
|
||||||
|
Zotero.Notifier.unregisterObserver(observerID);
|
||||||
|
|
||||||
|
// Source collection should be empty
|
||||||
|
assert.equal(zp.itemsView.rowCount, 0);
|
||||||
|
|
||||||
|
yield cv.selectCollection(collection2.id);
|
||||||
|
yield waitForItemsLoad(win);
|
||||||
|
|
||||||
|
// Target collection should have item
|
||||||
|
assert.equal(zp.itemsView.rowCount, 1);
|
||||||
|
var treeRow = zp.itemsView.getRow(0);
|
||||||
|
assert.equal(treeRow.ref.id, item.id);
|
||||||
|
});
|
||||||
|
|
||||||
it("should copy an item with an attachment to a group", function* () {
|
it("should copy an item with an attachment to a group", function* () {
|
||||||
var group = yield createGroup();
|
var group = yield createGroup();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user