client/js/models.js
author ymh <ymh.work@gmail.com>
Fri, 15 Sep 2017 14:11:36 +0200
changeset 658 cac26275af31
parent 622 02e3c464223f
permissions -rw-r--r--
define version V0.13.02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
444
19f0b7803aed add schema version + dataloaders to ensure data migrations + small correction for php server exmple + a readme for the php server example
ymh <ymh.work@gmail.com>
parents: 443
diff changeset
     1
(function(root) {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
     2
    'use strict';
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
     3
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
     4
    var Backbone = root.Backbone;
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
     5
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
     6
    var Models = root.Rkns.Models = {};
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
     7
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
     8
    Models.getUID = function(obj) {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
     9
        var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    10
            .replace(/[xy]/g,
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    11
                     function(c) {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    12
                         var r = Math.random() * 16 | 0, v = c === 'x' ? r
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    13
                             : (r & 0x3 | 0x8);
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    14
                         return v.toString(16);
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    15
                     });
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    16
        if (typeof obj !== 'undefined') {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    17
            return obj.type + '-' + guid;
298
2f35c2ae7de8 export + import renkans
ymh <ymh.work@gmail.com>
parents: 293
diff changeset
    18
        }
2f35c2ae7de8 export + import renkans
ymh <ymh.work@gmail.com>
parents: 293
diff changeset
    19
        else {
2f35c2ae7de8 export + import renkans
ymh <ymh.work@gmail.com>
parents: 293
diff changeset
    20
            return guid;
2f35c2ae7de8 export + import renkans
ymh <ymh.work@gmail.com>
parents: 293
diff changeset
    21
        }
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    22
    };
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    23
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    24
    var RenkanModel = Backbone.RelationalModel.extend({
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    25
        idAttribute : '_id',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    26
        constructor : function(options) {
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    27
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    28
            if (typeof options !== 'undefined') {
27
6ec62ab8cb8d model modif, id -> _id
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
    29
                options._id = options._id || options.id || Models.getUID(this);
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    30
                options.title = options.title || '';
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    31
                options.description = options.description || '';
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    32
                options.uri = options.uri || '';
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    33
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    34
                if (typeof this.prepare === 'function') {
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    35
                    options = this.prepare(options);
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    36
                }
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    37
            }
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    38
            Backbone.RelationalModel.prototype.constructor.call(this, options);
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    39
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    40
        validate : function() {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    41
            if (!this.type) {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    42
                return 'object has no type';
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    43
            }
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    44
        },
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    45
        addReference : function(_options, _propName, _list, _id, _default) {
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    46
            var _element = _list.get(_id);
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    47
            if (typeof _element === 'undefined' &&
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    48
                typeof _default !== 'undefined') {
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    49
                _options[_propName] = _default;
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    50
            }
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    51
            else {
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    52
                _options[_propName] = _element;
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    53
            }
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    54
        }
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    55
    });
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    56
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    57
    // USER
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    58
    var User = Models.User = RenkanModel.extend({
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    59
        type : 'user',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    60
        prepare : function(options) {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    61
            options.color = options.color || '#666666';
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    62
            return options;
24
121a24be9da4 Added Wikipedia Search
veltr
parents: 23
diff changeset
    63
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    64
        toJSON : function() {
24
121a24be9da4 Added Wikipedia Search
veltr
parents: 23
diff changeset
    65
            return {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    66
                _id : this.get('_id'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    67
                title : this.get('title'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    68
                uri : this.get('uri'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    69
                description : this.get('description'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    70
                color : this.get('color')
27
6ec62ab8cb8d model modif, id -> _id
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
    71
            };
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 195
diff changeset
    72
        }
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    73
    });
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    74
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    75
    // NODE
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    76
    var Node = Models.Node = RenkanModel.extend({
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    77
        type : 'node',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    78
        relations : [ {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    79
            type : Backbone.HasOne,
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    80
            key : 'created_by',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    81
            relatedModel : User
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    82
        } ],
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    83
        prepare : function(options) {
195
15e048e00002 Better User List Management
veltr
parents: 175
diff changeset
    84
            var project = options.project;
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    85
            this.addReference(options, 'created_by', project.get('users'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    86
                              options.created_by, project.current_user);
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    87
            options.description = options.description || '';
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
    88
            return options;
24
121a24be9da4 Added Wikipedia Search
veltr
parents: 23
diff changeset
    89
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
    90
        toJSON : function() {
24
121a24be9da4 Added Wikipedia Search
veltr
parents: 23
diff changeset
    91
            return {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    92
                _id : this.get('_id'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    93
                title : this.get('title'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    94
                uri : this.get('uri'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    95
                description : this.get('description'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    96
                position : this.get('position'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    97
                image : this.get('image'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    98
                style : this.get('style'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
    99
                created_by : this.get('created_by') ? this.get('created_by')
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   100
                    .get('_id') : null,
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   101
                size : this.get('size'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   102
                clip_path : this.get('clip_path'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   103
                shape : this.get('shape'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   104
                type : this.get('type')
27
6ec62ab8cb8d model modif, id -> _id
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
   105
            };
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 195
diff changeset
   106
        }
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   107
    });
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   108
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   109
    // EDGE
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   110
    var Edge = Models.Edge = RenkanModel.extend({
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   111
        type : 'edge',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   112
        relations : [ {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   113
            type : Backbone.HasOne,
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   114
            key : 'created_by',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   115
            relatedModel : User
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   116
        }, {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   117
            type : Backbone.HasOne,
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   118
            key : 'from',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   119
            relatedModel : Node
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   120
        }, {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   121
            type : Backbone.HasOne,
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   122
            key : 'to',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   123
            relatedModel : Node
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   124
        } ],
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   125
        prepare : function(options) {
195
15e048e00002 Better User List Management
veltr
parents: 175
diff changeset
   126
            var project = options.project;
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   127
            this.addReference(options, 'created_by', project.get('users'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   128
                              options.created_by, project.current_user);
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   129
            this.addReference(options, 'from', project.get('nodes'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   130
                              options.from);
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   131
            this.addReference(options, 'to', project.get('nodes'), options.to);
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   132
            return options;
24
121a24be9da4 Added Wikipedia Search
veltr
parents: 23
diff changeset
   133
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   134
        toJSON : function() {
24
121a24be9da4 Added Wikipedia Search
veltr
parents: 23
diff changeset
   135
            return {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   136
                _id : this.get('_id'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   137
                title : this.get('title'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   138
                uri : this.get('uri'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   139
                description : this.get('description'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   140
                from : this.get('from') ? this.get('from').get('_id') : null,
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   141
                to : this.get('to') ? this.get('to').get('_id') : null,
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   142
                style : this.get('style'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   143
                created_by : this.get('created_by') ? this.get('created_by')
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   144
                    .get('_id') : null
27
6ec62ab8cb8d model modif, id -> _id
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
   145
            };
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 195
diff changeset
   146
        }
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   147
    });
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   148
281
9ff388c9bc8d model cleanup for views
cavaliet
parents: 271
diff changeset
   149
    // View
9ff388c9bc8d model cleanup for views
cavaliet
parents: 271
diff changeset
   150
    var View = Models.View = RenkanModel.extend({
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   151
        type : 'view',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   152
        relations : [ {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   153
            type : Backbone.HasOne,
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   154
            key : 'created_by',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   155
            relatedModel : User
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   156
        } ],
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   157
        prepare : function(options) {
299
c5086f714631 add view management on server
ymh <ymh.work@gmail.com>
parents: 298
diff changeset
   158
            var project = options.project;
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   159
            this.addReference(options, 'created_by', project.get('users'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   160
                              options.created_by, project.current_user);
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   161
            options.description = options.description || '';
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   162
            if (typeof options.offset !== 'undefined') {
299
c5086f714631 add view management on server
ymh <ymh.work@gmail.com>
parents: 298
diff changeset
   163
                var offset = {};
c5086f714631 add view management on server
ymh <ymh.work@gmail.com>
parents: 298
diff changeset
   164
                if (Array.isArray(options.offset)) {
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   165
                    offset.x = options.offset[0];
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   166
                    offset.y = options.offset.length > 1 ? options.offset[1]
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   167
                        : options.offset[0];
299
c5086f714631 add view management on server
ymh <ymh.work@gmail.com>
parents: 298
diff changeset
   168
                }
c5086f714631 add view management on server
ymh <ymh.work@gmail.com>
parents: 298
diff changeset
   169
                else if (options.offset.x != null) {
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   170
                    offset.x = options.offset.x;
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   171
                    offset.y = options.offset.y;
299
c5086f714631 add view management on server
ymh <ymh.work@gmail.com>
parents: 298
diff changeset
   172
                }
c5086f714631 add view management on server
ymh <ymh.work@gmail.com>
parents: 298
diff changeset
   173
                options.offset = offset;
c5086f714631 add view management on server
ymh <ymh.work@gmail.com>
parents: 298
diff changeset
   174
            }
c5086f714631 add view management on server
ymh <ymh.work@gmail.com>
parents: 298
diff changeset
   175
            return options;
c5086f714631 add view management on server
ymh <ymh.work@gmail.com>
parents: 298
diff changeset
   176
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   177
        toJSON : function() {
282
12ee99b182cd enhance view management.
cavaliet
parents: 281
diff changeset
   178
            return {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   179
                _id : this.get('_id'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   180
                zoom_level : this.get('zoom_level'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   181
                offset : this.get('offset'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   182
                title : this.get('title'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   183
                description : this.get('description'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   184
                created_by : this.get('created_by') ? this.get('created_by')
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   185
                    .get('_id') : null,
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   186
                hidden_nodes: this.get('hidden_nodes')
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   187
                // Don't need project id
282
12ee99b182cd enhance view management.
cavaliet
parents: 281
diff changeset
   188
            };
12ee99b182cd enhance view management.
cavaliet
parents: 281
diff changeset
   189
        }
281
9ff388c9bc8d model cleanup for views
cavaliet
parents: 271
diff changeset
   190
    });
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   191
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   192
    // PROJECT
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   193
    var Project = Models.Project = RenkanModel.extend({
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   194
        schema_version : '2',
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   195
        type : 'project',
458
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 457
diff changeset
   196
        blacklist : [ 'saveStatus', 'loadingStatus'],
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   197
        relations : [ {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   198
            type : Backbone.HasMany,
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   199
            key : 'users',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   200
            relatedModel : User,
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   201
            reverseRelation : {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   202
                key : 'project',
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   203
                includeInJSON : '_id'
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 195
diff changeset
   204
            }
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   205
        }, {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   206
            type : Backbone.HasMany,
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   207
            key : 'nodes',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   208
            relatedModel : Node,
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   209
            reverseRelation : {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   210
                key : 'project',
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   211
                includeInJSON : '_id'
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 195
diff changeset
   212
            }
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   213
        }, {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   214
            type : Backbone.HasMany,
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   215
            key : 'edges',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   216
            relatedModel : Edge,
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   217
            reverseRelation : {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   218
                key : 'project',
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   219
                includeInJSON : '_id'
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 195
diff changeset
   220
            }
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   221
        }, {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   222
            type : Backbone.HasMany,
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   223
            key : 'views',
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   224
            relatedModel : View,
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   225
            reverseRelation : {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   226
                key : 'project',
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   227
                includeInJSON : '_id'
281
9ff388c9bc8d model cleanup for views
cavaliet
parents: 271
diff changeset
   228
            }
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   229
        } ],
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   230
        addUser : function(_props, _options) {
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   231
            _props.project = this;
56
a9b9e6c7be63 Converging client and webapp
veltr
parents: 52
diff changeset
   232
            var _user = User.findOrCreate(_props);
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   233
            this.get('users').push(_user, _options);
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   234
            return _user;
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   235
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   236
        addNode : function(_props, _options) {
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   237
            _props.project = this;
56
a9b9e6c7be63 Converging client and webapp
veltr
parents: 52
diff changeset
   238
            var _node = Node.findOrCreate(_props);
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   239
            this.get('nodes').push(_node, _options);
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   240
            return _node;
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   241
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   242
        addEdge : function(_props, _options) {
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   243
            _props.project = this;
56
a9b9e6c7be63 Converging client and webapp
veltr
parents: 52
diff changeset
   244
            var _edge = Edge.findOrCreate(_props);
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   245
            this.get('edges').push(_edge, _options);
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   246
            return _edge;
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   247
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   248
        addView : function(_props, _options) {
281
9ff388c9bc8d model cleanup for views
cavaliet
parents: 271
diff changeset
   249
            _props.project = this;
9ff388c9bc8d model cleanup for views
cavaliet
parents: 271
diff changeset
   250
            // TODO: check if need to replace with create only
9ff388c9bc8d model cleanup for views
cavaliet
parents: 271
diff changeset
   251
            var _view = View.findOrCreate(_props);
9ff388c9bc8d model cleanup for views
cavaliet
parents: 271
diff changeset
   252
            // TODO: Should we remember only one view?
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   253
            this.get('views').push(_view, _options);
281
9ff388c9bc8d model cleanup for views
cavaliet
parents: 271
diff changeset
   254
            return _view;
9ff388c9bc8d model cleanup for views
cavaliet
parents: 271
diff changeset
   255
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   256
        removeNode : function(_model) {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   257
            this.get('nodes').remove(_model);
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   258
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   259
        removeEdge : function(_model) {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   260
            this.get('edges').remove(_model);
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   261
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   262
        validate : function(options) {
24
121a24be9da4 Added Wikipedia Search
veltr
parents: 23
diff changeset
   263
            var _project = this;
433
e457ec945e50 replace underscore par lodash
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
   264
            _.each(
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   265
                [].concat(options.users, options.nodes, options.edges,options.views),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   266
                function(_item) {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   267
                    if (_item) {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   268
                        _item.project = _project;
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   269
                    }
212
ee7b5831d382 correct model to accept null objects ?
ymh <ymh.work@gmail.com>
parents: 211
diff changeset
   270
                }
433
e457ec945e50 replace underscore par lodash
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
   271
            );
24
121a24be9da4 Added Wikipedia Search
veltr
parents: 23
diff changeset
   272
        },
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
   273
        getSchemaVersion : function(data) {
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   274
            var t = data;
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   275
            if(typeof(t) === 'undefined') {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   276
                t = this;
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   277
            }
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   278
            var version = t.schema_version;
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   279
            if(!version) {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   280
                return 1;
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   281
            }
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   282
            else {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   283
                return version;
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   284
            }
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
   285
        },
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   286
        // Add event handler to remove edges when a node is removed
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   287
        initialize : function() {
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   288
            var _this = this;
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   289
            this.on('remove:nodes', function(_node) {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   290
                _this.get('edges').remove(
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   291
                    _this.get('edges').filter(
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   292
                        function(_edge) {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   293
                            return _edge.get('from') === _node ||
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   294
                                _edge.get('to') === _node;
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   295
                        }));
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   296
            });
362
8f33cbeb4f32 Add blacklist and override project.toJSON to exclude attributes in blackList
rougeronj
parents: 332
diff changeset
   297
        },
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   298
        toJSON : function() {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   299
            var json = _.clone(this.attributes);
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   300
            for ( var attr in json) {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   301
                if ((json[attr] instanceof Backbone.Model) ||
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   302
                    (json[attr] instanceof Backbone.Collection) ||
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   303
                    (json[attr] instanceof RenkanModel)) {
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   304
                    json[attr] = json[attr].toJSON();
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   305
                }
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   306
            }
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   307
            return _.omit(json, this.blacklist);
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   308
        }
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents:
diff changeset
   309
    });
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   310
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   311
    var RosterUser = Models.RosterUser = Backbone.Model
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   312
        .extend({
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   313
            type : 'roster_user',
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   314
            idAttribute : '_id',
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   315
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   316
            constructor : function(options) {
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   317
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   318
                if (typeof options !== 'undefined') {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   319
                    options._id = options._id ||
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   320
                        options.id ||
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   321
                        Models.getUID(this);
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   322
                    options.title = options.title || '(untitled ' + this.type + ')';
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   323
                    options.description = options.description || '';
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   324
                    options.uri = options.uri || '';
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   325
                    options.project = options.project || null;
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   326
                    options.site_id = options.site_id || 0;
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   327
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   328
                    if (typeof this.prepare === 'function') {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   329
                        options = this.prepare(options);
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   330
                    }
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   331
                }
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   332
                Backbone.Model.prototype.constructor.call(this, options);
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   333
            },
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   334
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   335
            validate : function() {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   336
                if (!this.type) {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   337
                    return 'object has no type';
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   338
                }
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   339
            },
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   340
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   341
            prepare : function(options) {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   342
                options.color = options.color || '#666666';
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   343
                return options;
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   344
            },
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   345
622
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   346
            toJSON : function() {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   347
                return {
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   348
                    _id : this.get('_id'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   349
                    title : this.get('title'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   350
                    uri : this.get('uri'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   351
                    description : this.get('description'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   352
                    color : this.get('color'),
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   353
                    project : (this.get('project') != null) ? this.get(
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   354
                        'project').get('id') : null,
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   355
                    site_id : this.get('site_id')
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   356
                };
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   357
            }
02e3c464223f Add click origin info to help action tracing
ymh <ymh.work@gmail.com>
parents: 461
diff changeset
   358
        });
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   359
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   360
    var UsersList = Models.UsersList = Backbone.Collection.extend({
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 362
diff changeset
   361
        model : RosterUser
56
a9b9e6c7be63 Converging client and webapp
veltr
parents: 52
diff changeset
   362
    });
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   363
444
19f0b7803aed add schema version + dataloaders to ensure data migrations + small correction for php server exmple + a readme for the php server example
ymh <ymh.work@gmail.com>
parents: 443
diff changeset
   364
})(window);