client/js/full-json.js
changeset 24 121a24be9da4
parent 23 70c8af9b44ec
child 25 b5ada3bb8e53
equal deleted inserted replaced
23:70c8af9b44ec 24:121a24be9da4
     5     if (typeof _opts.http_method == "undefined") {
     5     if (typeof _opts.http_method == "undefined") {
     6         _opts.http_method = 'PUT';
     6         _opts.http_method = 'PUT';
     7     }
     7     }
     8     var _load = function() {
     8     var _load = function() {
     9         Rkns.$.getJSON(_opts.url, function(_data) {
     9         Rkns.$.getJSON(_opts.url, function(_data) {
    10             _proj.get("users").add(_data.users);
    10             console.log("Setting data");
    11             Rkns._(_data.nodes).each(function(_item) {
    11             _proj.set(_data);
    12                 _proj.addNode(_item);
       
    13             });
       
    14             Rkns._(_data.edges).each(function(_item) {
       
    15                 _proj.addEdge(_item);
       
    16             });
       
    17         });
    12         });
    18     }
    13     }
    19     var _save = function() {
    14     var _save = function() {
    20         var _data = {
    15         var _data = _proj.toJSON();
    21             users: _proj.get("users").map(function(_item) {
       
    22                 return {
       
    23                     id: _item.get("id"),
       
    24                     title: _item.get("title"),
       
    25                     uri: _item.get("uri"),
       
    26                     description: _item.get("description"),
       
    27                     color: _item.get("color")
       
    28                 }
       
    29             }),
       
    30             nodes: _proj.get("nodes").map(function(_item) {
       
    31                 return {
       
    32                     id: _item.get("id"),
       
    33                     title: _item.get("title"),
       
    34                     uri: _item.get("uri"),
       
    35                     description: _item.get("description"),
       
    36                     position: _item.get("position"),
       
    37                     created_by: _item.get("created_by").get("id")
       
    38                 }
       
    39             }),
       
    40             edges: _proj.get("edges").map(function(_item) {
       
    41                 return {
       
    42                     id: _item.get("id"),
       
    43                     title: _item.get("title"),
       
    44                     uri: _item.get("uri"),
       
    45                     description: _item.get("description"),
       
    46                     from: _item.get("from").get("id"),
       
    47                     to: _item.get("to").get("id"),
       
    48                     created_by: _item.get("created_by").get("id")
       
    49                 }
       
    50             })
       
    51         };
       
    52         Rkns.$.ajax({
    16         Rkns.$.ajax({
    53             type: _opts.http_method,
    17             type: _opts.http_method,
    54             url: _opts.url,
    18             url: _opts.url,
    55             contentType: "application/json",
    19             contentType: "application/json",
    56             data: JSON.stringify(_data),
    20             data: JSON.stringify(_data),