--- a/client/js/model.js Fri Jul 27 12:22:10 2012 +0200
+++ b/client/js/model.js Fri Jul 27 19:15:32 2012 +0200
@@ -3,35 +3,30 @@
Rkns.Model._BaseElement = function(_project, _props) {
if (typeof _props !== "undefined") {
this._project = _project;
- this.id = _props.id || Rkns.utils.getUID(this.type);
+ this.id = _props.id || Rkns.Utils.getUID(this.type);
this.title = _props.title || "(untitled " + this.type + ")";
this.description = _props.description || "";
this.uri = _props.uri || "";
}
}
-Rkns.Model._BaseElement.prototype.addReference = function(_propName, _list, _id) {
- this[ _propName + "_id" ] = _id;
+Rkns.Model._BaseElement.prototype.addReference = function(_propName, _list, _id, _default) {
var _element = _list.getElement(_id);
- this[ _propName ] = _element;
+ if (typeof _element === "undefined" && typeof _default !== "undefined") {
+ this[ _propName ] = _default;
+ this[ _propName + "_id" ] = _default.id;
+ } else {
+ this[ _propName + "_id" ] = _id;
+ this[ _propName ] = _element;
+ }
}
Rkns.Model._BaseElement.prototype.updateGraphics = function() {
- this._project._renderer.redraw();
+ this._project.renderer.redraw();
}
Rkns.Model._BaseElement.prototype.updateData = function() {
-}
-
-Rkns.Model._BaseElement.prototype.propagateChanges = function(_from) {
- switch(_from) {
- case Rkns._FROM_GRAPHICS:
- this.updateData();
- break;
- case Rkns._FROM_DATA:
- this.updateGraphics();
- break;
- }
+ this._project.serializer.save(this);
}
/* Element Class Generator */
@@ -55,11 +50,11 @@
Rkns.Model.Node = Rkns.Model._elementClass("node");
Rkns.Model.Node.prototype._init = function(_project, _props) {
- this.addReference("created_by", this._project.users, _props.created_by);
+ this.addReference("created_by", this._project.users, _props.created_by, _project.current_user);
this.position = _props.position;
}
-Rkns.Model.Node.prototype.setPosition = function(_from, _x, _y) {
+Rkns.Model.Node.prototype.setPosition = function(_x, _y) {
if (typeof _x === "object") {
if (typeof _x.x !== "undefined" && typeof _x.y !== "undefined") {
this.position.x = _x.x;
@@ -76,7 +71,6 @@
this.position.y = +_y;
}
}
- this.propagateChanges(_from);
}
/* Edge Model */
@@ -84,7 +78,7 @@
Rkns.Model.Edge = Rkns.Model._elementClass("edge");
Rkns.Model.Edge.prototype._init = function(_project, _props) {
- this.addReference("created_by", this._project.users, _props.created_by);
+ this.addReference("created_by", this._project.users, _props.created_by, _project.current_user);
this.addReference("from", this._project.nodes, _props.from);
this.addReference("to", this._project.nodes, _props.to);
}