Statistics
| Branch: | Tag: | Revision:

root / ui / static / snf / js / ui / web / ui_router.js @ 24565655

History | View | Annotate | Download (2.8 kB)

1
;(function(root){
2

    
3
    // root
4
    var root = root;
5
    
6
    // setup namepsaces
7
    var snf = root.synnefo = root.synnefo || {};
8
    var models = snf.models = snf.models || {}
9
    var storage = snf.storage = snf.storage || {};
10
    var ui = snf.ui = snf.ui || {};
11

    
12
    var views = snf.views = snf.views || {}
13

    
14
    // shortcuts
15
    var bb = root.Backbone;
16
    var util = snf.util;
17

    
18
    var WebAppRouter = Backbone.Router.extend({
19
        
20
        last_vm_view: "vms_icon_view",
21

    
22
        routes: {
23
            "":                                 "index",
24
            "welcome/":                         "show_welcome",
25

    
26
            // vm views
27
            "machines/icon/":                   "vms_icon_view",
28
            "machines/list/":                   "vms_list_view",
29
            "machines/single/details/:vm":      "vm_details_view",
30
            "machines/single/":                 "vms_single_view",
31

    
32
            // network views
33
            "networks/":                        "networks_view",
34
        },
35
        
36
        show_welcome: function() {
37
            if (snf.storage.vms.length == 0) {
38
                ui.main.show_empty();
39
                this.navigate("welcome/");
40
            } else {
41
                this.index();
42
            }
43
        },
44

    
45
        index: function() {
46
            this.vms_index();
47
        },
48

    
49
        vms_index: function() {
50
            this[this.last_vm_view]();
51
        },
52

    
53
        vms_icon_view: function() {
54
            this.navigate("machines/icon/");
55
            this.last_vm_view = "vms_icon_view";
56
            ui.main.show_view("icon");
57
        },
58
        
59
        vms_list_view: function() {
60
            this.navigate("machines/list/");
61
            this.last_vm_view = "vms_list_view";
62
            ui.main.show_view("list");
63
        },
64

    
65
        vms_single_view: function() {
66
            //this.navigate("machines/single/");
67
            this.last_vm_view = "vms_single_view";
68
            ui.main.show_view("single");
69
            try {
70
                var current_vm = ui.main.current_view.current_vm_instance.id;
71
                this.vm_details_view(current_vm);
72
            } catch (err) {
73
                this.show_welcome();
74
            }
75
        },
76

    
77
        vm_create_view: function(step) {
78
            ui.main.create_vm_view.show();
79
            if (step) {
80
                ui.main.create_vm_view.show_step(parseInt(step));
81
            }
82
        },
83

    
84
        vm_details_view: function(vm) {
85
            this.navigate("machines/single/details/" + vm);
86
            ui.main.show_view("single");
87
            ui.main.current_view.show_vm(snf.storage.vms.get(parseInt(vm)));
88
        },
89

    
90
        networks_view: function() {
91
            this.navigate("networks/");
92
            ui.main.show_view("networks");
93
        }
94

    
95
    });
96

    
97
    snf.router = new WebAppRouter(); 
98
})(this);