--- a/client/js/paper-renderer.js Fri Sep 07 12:26:16 2012 +0200
+++ b/client/js/paper-renderer.js Fri Sep 07 17:50:17 2012 +0200
@@ -192,9 +192,25 @@
this.renderer = _renderer;
this.project = _renderer.renkan.project;
this.model = _model;
+ if (this.model) {
+ var _this = this;
+ this._changeBinding = function() {
+ _this.redraw();
+ }
+ this._removeBinding = function() {
+ _renderer.removeRepresentation(_this);
+ _renderer.redraw();
+ }
+ this.model.on("change", this._changeBinding );
+ this.model.on("remove", this._removeBinding );
+ }
}
}
+Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) {
+ Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1));
+}
+
Rkns.Renderer._BaseRepresentation.prototype.select = function() {}
Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {}
@@ -205,7 +221,12 @@
Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {}
-Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {}
+Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {
+ if (this.model) {
+ this.model.off("change", this._changeBinding );
+ this.model.off("remove", this._removeBinding );
+ }
+}
Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
@@ -220,11 +241,11 @@
fontSize: Rkns.Renderer._NODE_FONT_SIZE,
fillColor: 'black'
};
- this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, {});
+ this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, null);
this.edit_button.node_representation = this;
- this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, {});
+ this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, null);
this.remove_button.node_representation = this;
- this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, {});
+ this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, null);
this.link_button.node_representation = this;
this.title.paragraphStyle.justification = 'center';
}
@@ -342,6 +363,7 @@
}
Rkns.Renderer.Node.prototype.destroy = function(_event) {
+ this.super("destroy");
this.edit_button.destroy();
this.remove_button.destroy();
this.link_button.destroy();
@@ -376,9 +398,9 @@
this.text.paragraphStyle.justification = 'center';
this.text_angle = 0;
this.arrow_angle = 0;
- this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, {});
+ this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, null);
this.edit_button.edge_representation = this;
- this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, {});
+ this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, null);
this.remove_button.edge_representation = this;
}
@@ -456,6 +478,7 @@
}
Rkns.Renderer.Edge.prototype.destroy = function() {
+ this.super("destroy");
this.line.remove();
this.arrow.remove();
this.text.remove();
@@ -1121,16 +1144,6 @@
Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) {
var _repr = new Rkns.Renderer[_type](this, _model);
this.representations.push(_repr);
- if (_model) {
- var _this = this;
- _model.on("change", function() {
- _repr.redraw();
- });
- _model.on("remove", function() {
- _this.removeRepresentation(_repr);
- _this.redraw();
- });
- }
return _repr;
}