aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/views/reports.js
blob: 9708ded7a1d0a3efb5b9ede1e6c58988b91832a9 (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
(function (FMS, Backbone, _, $) {
    _.extend( FMS, {
        ReportsView: FMS.FMSView.extend({
            template: 'reports',
            id: 'reports',
            next: 'home',

            events: {
                'pagehide': 'destroy',
                'pageshow': 'afterDisplay',
                'click .del_report': 'deleteReport',
                'click .ui-btn-left': 'onClickButtonPrev',
                'click .ui-btn-right': 'onClickButtonNext'
            },

            deleteReport: function(e) {
                var el = $(e.target);
                var del = FMS.removeDraft( el.attr('id'), true );
                var that = this;
                del.done( function() { that.onRemoveDraft(el); } );
            },

            onRemoveDraft: function(el) {
                el.parent('li').remove();
            },

            render: function(){
                if ( !this.template ) {
                    console.log('no template to render');
                    return;
                }
                template = _.template( tpl.get( this.template ) );
                if ( this.model ) {
                    this.$el.html(template({ model: this.model.toJSON(), drafts: FMS.allDrafts }));
                } else {
                    this.$el.html(template());
                }
                this.afterRender();
                return this;
            }
        })
    });
})(FMS, Backbone, _, $);