Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / static / snf / js / ui / web / ui_router.js @ 9fd7a7a8

History | View | Annotate | Download (4.3 kB)

1
// Copyright 2011 GRNET S.A. All rights reserved.
2
// 
3
// Redistribution and use in source and binary forms, with or
4
// without modification, are permitted provided that the following
5
// conditions are met:
6
// 
7
//   1. Redistributions of source code must retain the above
8
//      copyright notice, this list of conditions and the following
9
//      disclaimer.
10
// 
11
//   2. Redistributions in binary form must reproduce the above
12
//      copyright notice, this list of conditions and the following
13
//      disclaimer in the documentation and/or other materials
14
//      provided with the distribution.
15
// 
16
// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
// POSSIBILITY OF SUCH DAMAGE.
28
// 
29
// The views and conclusions contained in the software and
30
// documentation are those of the authors and should not be
31
// interpreted as representing official policies, either expressed
32
// or implied, of GRNET S.A.
33
// 
34

    
35
;(function(root){
36

    
37
    // root
38
    var root = root;
39
    
40
    // setup namepsaces
41
    var snf = root.synnefo = root.synnefo || {};
42
    var models = snf.models = snf.models || {}
43
    var storage = snf.storage = snf.storage || {};
44
    var ui = snf.ui = snf.ui || {};
45

    
46
    var views = snf.views = snf.views || {}
47

    
48
    // shortcuts
49
    var bb = root.Backbone;
50
    var util = snf.util;
51

    
52
    var WebAppRouter = Backbone.Router.extend({
53
        
54
        last_vm_view: "vms_icon_view",
55

    
56
        routes: {
57
            "":                                 "index",
58
            "welcome/":                         "show_welcome",
59

    
60
            // vm views
61
            "machines/icon/":                   "vms_icon_view",
62
            "machines/list/":                   "vms_list_view",
63
            "machines/single/details/:vm":      "vm_details_view",
64
            "machines/single/":                 "vms_single_view",
65

    
66
            // network views
67
            "networks/":                        "networks_view"
68
        },
69
        
70
        show_welcome: function() {
71
            if (snf.storage.vms.length == 0) {
72
                ui.main.show_empty();
73
            } else {
74
                this.index();
75
            }
76
        },
77

    
78
        index: function() {
79
            ui.main.show_view("icon");
80
        },
81

    
82
        vms_index: function() {
83
            this[this.last_vm_view]();
84
        },
85

    
86
        vms_icon_view: function() {
87
            this.navigate("machines/icon/");
88
            this.last_vm_view = "vms_icon_view";
89
            ui.main.show_view("icon");
90
        },
91
        
92
        vms_list_view: function() {
93
            this.navigate("machines/list/");
94
            this.last_vm_view = "vms_list_view";
95
            ui.main.show_view("list");
96
        },
97

    
98
        vms_single_view: function() {
99
            //this.navigate("machines/single/");
100
            this.last_vm_view = "vms_single_view";
101
            ui.main.show_view("single");
102
            try {
103
                var current_vm = ui.main.current_view.current_vm_instance.id;
104
                this.vm_details_view(current_vm);
105
            } catch (err) {
106
                this.show_welcome();
107
            }
108
        },
109

    
110
        vm_create_view: function(step) {
111
            ui.main.create_vm_view.show();
112
            if (step) {
113
                ui.main.create_vm_view.show_step(parseInt(step));
114
            }
115
        },
116

    
117
        vm_details_view: function(vm) {
118
            this.navigate("machines/single/details/" + vm);
119
            ui.main.show_view("single");
120
            ui.main.current_view.show_vm(snf.storage.vms.get(parseInt(vm)));
121
        },
122

    
123
        networks_view: function() {
124
            this.navigate("networks/");
125
            ui.main.show_view("networks");
126
        }
127

    
128
    });
129

    
130
    snf.router = new WebAppRouter(); 
131
})(this);