aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/views/existing.js
blob: 74874198c9671562799ef3382701ac1915fa3f9e (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
(function (FMS, Backbone, _, $) {
    _.extend( FMS, {
        ExistingView: FMS.FMSView.extend({
            template: 'existing',
            id: 'existing',

            events: {
                'pagehide': 'destroy',
                'pagebeforeshow': 'beforeDisplay',
                'pageshow': 'afterDisplay',
                'click #use_report': 'useReport',
                'click #save_report': 'saveReport',
                'click #discard': 'discardReport'
            },

            useReport: function() {
                FMS.setCurrentDraft(this.model);
                this.navigate('around');
            },

            saveReport: function() {
                FMS.clearCurrentDraft();
                this.navigate('around');
            },

            discardReport: function() {
                var reset = FMS.removeDraft(this.model.id, true);
                var that = this;
                reset.done( function() { that.onDraftRemove(); } );
                reset.fail( function() { that.onDraftRemove(); } );
            },

            onDraftRemove: function() {
                FMS.clearCurrentDraft();
                this.navigate( 'around', 'left' );
            }
        })
    });
})(FMS, Backbone, _, $);