aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/models/draft.js
blob: e517f1bc941e68ee7e24b689cbd9e02661cbf2fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(function(FMS, Backbone, _, $, moment) {
    _.extend( FMS, {
        Draft: Backbone.Model.extend({
            localStorage: new Backbone.LocalStorage(CONFIG.NAMESPACE + '-drafts'),

            defaults: function() {
                return {
                    lat: 0,
                    lon: 0,
                    title: '',
                    details: '',
                    may_show_name: '',
                    category: '',
                    phone: '',
                    pc: '',
                    files: [],
                    created: moment.utc()
                };
            },

            description: function() {
                var desc = '';
                if ( this.get('title') ) {
                    desc += this.get('title');
                } else {
                    desc += FMS.strings.untitled_draft;
                }
                desc += '<br><small>' + moment.utc( this.get('created') ).fromNow() + '</small>';

                return desc;
            },

            isPartial: function() {
                if (
                    this.get('title') ||
                    this.get('details') ||
                    this.get('category') ||
                    this.get('files').length
                ) {
                    return true;
                }

                return false;
            },

            createdDate: function() {
                return moment.utc( this.get('created') ).format( 'H:mm Do MMM' );
            }
        })
    });
})(FMS, Backbone, _, $, moment);

(function(FMS, Backbone, _, $) {
    _.extend( FMS, {
        Drafts: Backbone.Collection.extend({
            model: FMS.Draft,
            localStorage: new Backbone.LocalStorage(CONFIG.NAMESPACE + '-drafts')
        })
    });
})(FMS, Backbone, _, $);