aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/router.js
blob: 5327a1c0abf83a9b53f761d9a6e34803809df996 (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
;(function (FMS, Backbone, _, $) {
    _.extend(FMS, {
        appRouter: Backbone.Router.extend({
            currentView: null,

            routes: {
                '': 'home',
                'home': 'home',
                'around': 'around'
            },

            initialize: function() {
            },

            back: function() {
                if (this.currentView && this.currentView.prev) {
                    this.currentView.onClickButtonPrev();
                }
            },

            around: function(){
                var aroundView = new FMS.AroundView();
                this.changeView(aroundView);
            },

            home: function(){
                var homeView = new FMS.HomeView();
                this.changeView(homeView);
            },

            changeView: function(view) {
                console.log( 'change View to ' + view.id );
                $(view.el).attr('data-role', 'page');
                view.render();
                $('body').append($(view.el));
                $.mobile.changePage($(view.el), { changeHash: false });

                if(!_.isNull(this.currentView)) {
                    this.currentView.destroy();
                }
                view.afterDisplay();
                this.currentView = view;
            }
        })
    });
})(FMS, Backbone, _, $);