mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-07-05 17:20:05 +08:00
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
//Handles indenting,outdenting,moving up/down, and drag-n-drop.
|
|
var moveNode = function(thisModel, dragIndex, oldParModel, newParModel, dropIndex, chr){
|
|
|
|
//removeNode from OldParent part 1 = #models
|
|
oldParModel.get("children").remove(dragIndex);
|
|
thisModel.get("parents").removeOne(oldParModel.get("_id"));
|
|
|
|
//removeNode from OldParent part 2 = #views
|
|
_.each(oldParModel.get("views"), function(oldParView){
|
|
oldParView.removeNode(dragIndex);
|
|
});
|
|
|
|
//add the Node to the newParent part 1 = #models
|
|
newParModel.get("children").insert(dropIndex, thisModel.get("_id"));
|
|
thisModel.get("parents").push(newParModel.get("_id"));
|
|
|
|
//add the node to the newParent part 2 = #views
|
|
_.each(newParModel.get("views"), function(newParView){
|
|
newParView.addNode(thisModel, dropIndex, chr);
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var ids = [thisModel.get("_id"), oldParModel.get("_id"), newParModel.get("_id")];
|
|
var arrays = [thisModel.get("parents"), oldParModel.get("children"), newParModel.get("children")];
|
|
var indices = [dragIndex, dropIndex];
|
|
var data = [ids, arrays, indices, CurrentUser];
|
|
|
|
if(chr){
|
|
socket.emitWrapper("movedNode", data);
|
|
}
|
|
|
|
INPUT_PROCESSED=true;
|
|
} |