[IMP] use deferred for node and edge destruction callbacks, so the node or edge is not removed if the unlink call fails

bzr revid: xmo@openerp.com-20120305102516-3u14hvxs81qzgxd8
This commit is contained in:
Xavier Morel 2012-03-05 11:25:16 +01:00
parent 6ffffdc4de
commit df25517f09
2 changed files with 8 additions and 10 deletions

View File

@ -193,10 +193,9 @@ openerp.web.DiagramView = openerp.web.View.extend({
var i = 0;
CuteNode.destruction_callback = function(cutenode){
if(!confirm(_t("Deleting this node cannot be undone.\nIt will also delete all connected transitions.\n\nAre you sure ?"))){
return false;
return $.Deferred().reject().promise();
}
new openerp.web.DataSet(self,self.node).unlink([cutenode.id]);
return true;
return new openerp.web.DataSet(self,self.node).unlink([cutenode.id]);
};
CuteEdge.double_click_callback = function(cuteedge){
self.edit_connector(cuteedge.id);
@ -212,10 +211,9 @@ openerp.web.DiagramView = openerp.web.View.extend({
};
CuteEdge.destruction_callback = function(cuteedge){
if(!confirm(_t("Deleting this transition cannot be undone.\n\nAre you sure ?"))){
return false;
return $.Deferred().reject().promise();
}
new openerp.web.DataSet(self,self.connector).unlink([cuteedge.id]);
return true;
return new openerp.web.DataSet(self,self.connector).unlink([cuteedge.id]);
};
},

View File

@ -85,15 +85,15 @@
dummy_circle.animate({'r': close_button_radius }, 400, 'linear');
if(entity_type == "node"){
if(GraphNode.destruction_callback(entity)){
$.when(GraphNode.destruction_callback(entity)).then(function () {
//console.log("remove node",entity);
entity.remove();
}
});
}else if(entity_type == "edge"){
if(GraphEdge.destruction_callback(entity)){
$.when(GraphEdge.destruction_callback(entity)).then(function () {
//console.log("remove edge",entity);
entity.remove();
}
});
}
}
dummy_circle.click(click_action);