mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-07-08 00:10:39 +08:00
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
var removeNode = function(vo, broadcast) {
|
|
upDateParentModelViews(vo, broadcast);
|
|
//#TODO => This won't work for transcluded nodes with the same parent...
|
|
if( hasDuplicates(vo.thisModel.get("parents"))){ //later.
|
|
|
|
}
|
|
else{
|
|
var newParents = _.filter(vo.thisModel.get("parents"), function(parId){
|
|
return parId != vo.parentId;
|
|
});
|
|
vo.thisModel.set("parents", newParents);
|
|
if(!broadcast){
|
|
socket.emit("removeNode", [vo.thisId, vo.thisIndex, vo.parentId]);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
var upDateParentModelViews = function(vo, broadcast){
|
|
var children = vo.parentModel.get("children");
|
|
children.remove(vo.thisIndex);
|
|
vo.parentModel.set("children", children);
|
|
|
|
|
|
if(!broadcast){
|
|
//UI STUFF
|
|
console.log("what");
|
|
if( !vo.thisLI.is(":first-child") ){
|
|
var len = vo.thisLI.prev().children().children("textarea").val().length;
|
|
vo.thisLI.prev().children().children("textarea").focus();
|
|
vo.thisLI.prev().children().children("textarea").setSelection(len, len);
|
|
}else{
|
|
var len = vo.thisLI.parent().parent().children().children("textarea").val().length;
|
|
vo.thisLI.parent().parent().children().children("textarea").focus();
|
|
vo.thisLI.parent().parent().children().children("textarea").setSelection(len, len);
|
|
}
|
|
}
|
|
|
|
_.each(vo.parentModel.get("views"), function(parentView){
|
|
parentView.removeNode(vo.thisIndex);
|
|
});
|
|
} |