client/js/models.js
changeset 27 6ec62ab8cb8d
parent 24 121a24be9da4
child 37 db991a757015
equal deleted inserted replaced
26:2fad193bae98 27:6ec62ab8cb8d
    19     var RenkanModel = Backbone.RelationalModel.extend({
    19     var RenkanModel = Backbone.RelationalModel.extend({
    20         idAttribute : "_id",
    20         idAttribute : "_id",
    21         constructor: function(options) {
    21         constructor: function(options) {
    22             
    22             
    23             if (typeof options !== "undefined") {
    23             if (typeof options !== "undefined") {
    24                 options._id = options.id || Models.getUID(this);
    24                 options._id = options._id || options.id || Models.getUID(this);
    25                 options.title = options.title || "(untitled " + this.type + ")";
    25                 options.title = options.title || "(untitled " + this.type + ")";
    26                 options.description = options.description || "";
    26                 options.description = options.description || "";
    27                 options.uri = options.uri || "";
    27                 options.uri = options.uri || "";
    28                 
    28                 
    29                 if(typeof this.prepare === "function") {
    29                 if(typeof this.prepare === "function") {
    55             options.color = options.color || "#666666";
    55             options.color = options.color || "#666666";
    56             return options;
    56             return options;
    57         },
    57         },
    58         toJSON: function() {
    58         toJSON: function() {
    59             return {
    59             return {
    60                 id: this.get("id"),
    60                 _id: this.get("_id"),
    61                 title: this.get("title"),
    61                 title: this.get("title"),
    62                 uri: this.get("uri"),
    62                 uri: this.get("uri"),
    63                 description: this.get("description"),
    63                 description: this.get("description"),
    64                 color: this.get("color"),
    64                 color: this.get("color"),
    65             }
    65             };
    66         },
    66         },
    67     });
    67     });
    68     
    68     
    69     // NODE
    69     // NODE
    70     var Node = Models.Node = RenkanModel.extend({
    70     var Node = Models.Node = RenkanModel.extend({
    80             options.description = options.description || "";
    80             options.description = options.description || "";
    81             return options;
    81             return options;
    82         },
    82         },
    83         toJSON: function() {
    83         toJSON: function() {
    84             return {
    84             return {
    85                 id: this.get("id"),
    85                 _id: this.get("_id"),
    86                 title: this.get("title"),
    86                 title: this.get("title"),
    87                 uri: this.get("uri"),
    87                 uri: this.get("uri"),
    88                 description: this.get("description"),
    88                 description: this.get("description"),
    89                 position: this.get("position"),
    89                 position: this.get("position"),
    90                 created_by: this.get("created_by").get("id")
    90                 created_by: this.get("created_by").get("_id")
    91             }
    91             };
    92         },
    92         },
    93     });
    93     });
    94     
    94     
    95     // EDGE
    95     // EDGE
    96     var Edge = Models.Edge = RenkanModel.extend({
    96     var Edge = Models.Edge = RenkanModel.extend({
   119             this.addReference(options, "to", project.get("nodes"), options.to);
   119             this.addReference(options, "to", project.get("nodes"), options.to);
   120             return options;
   120             return options;
   121         },
   121         },
   122         toJSON: function() {
   122         toJSON: function() {
   123             return {
   123             return {
   124                 id: this.get("id"),
   124                 _id: this.get("_id"),
   125                 title: this.get("title"),
   125                 title: this.get("title"),
   126                 uri: this.get("uri"),
   126                 uri: this.get("uri"),
   127                 description: this.get("description"),
   127                 description: this.get("description"),
   128                 from: this.get("from").get("id"),
   128                 from: this.get("from").get("_id"),
   129                 to: this.get("to").get("id"),
   129                 to: this.get("to").get("_id"),
   130                 created_by: this.get("created_by").get("id"),
   130                 created_by: this.get("created_by").get("_id"),
   131             }
   131             };
   132         },
   132         },
   133     });
   133     });
   134         
   134         
   135     // PROJECT
   135     // PROJECT
   136     var Project = Models.Project = RenkanModel.extend({
   136     var Project = Models.Project = RenkanModel.extend({