Files
HackFlowy/public/js/libs/myLib/removeNode.js
T
Curtis SerVaas ea4a65ddc9 Clean start
2014-07-24 15:22:08 -04:00

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);
});
}