Statistics
| Branch: | Tag: | Revision:

root / ui / templates / standard.html @ 1a49199e

History | View | Annotate | Download (6.6 kB)

1
{% load i18n %}
2

    
3
<!-- the standard view -->
4
<div id="machinesview" class="standard">
5
    <div id="emptymachineslist">{% trans "You have no virtual machines! Press Create New to create some!" %}</div>
6
    <div id="spinner"></div>
7
    <div class="machine" id="machine-template" style="display:none">
8
        <div class="state">
9
            <div class="status">{% trans "Running" %}</div>
10
            <div class="indicator"></div>
11
            <div class="indicator"></div>
12
            <div class="indicator"></div>
13
            <div class="indicator"></div>
14
        </div>
15
        <img class="logo" src="" />
16
        <a href="#" class="name">
17
            <h5>Name: <span class="name">node.name</span><span class="rename"></span></h5>
18
        </a>
19
        <a href="#" class="ip">
20
            <h5>IP: <span class="public">node.public_ip</span></h5>
21
        </a>
22
        <h5 class="settings">
23
            {% trans "Show:" %} <a href="#">{% trans "disks" %}</a> | <a href="#">{% trans "networks" %}</a> | <a href="#">{% trans "group" %}</a>
24
        </h5>
25
        <div class="actions">
26
            <a href="#" class="action-start">{% trans "Start" %}</a>
27
            <a href="#" class="action-reboot">{% trans "Reboot" %}</a>
28
            <a href="#" class="action-shutdown">{% trans "Shutdown" %}</a>
29
            <a href="#" class="more">{% trans "more &hellip;" %}</a>
30
        </div>
31
        <div class="separator"></div>
32
    </div>
33

    
34
    <div class="running"></div>
35
    <div id="mini" class="separator"></div>
36
    <div class="terminated"></div>
37
</div>
38

    
39
<div id="machines" class="separator"></div>
40

    
41
<script>
42
// intercept reboot click 
43
$("div.actions a.action-reboot").live('click', function(){
44
    var serverID = $(this).parent().parent().attr("id");
45
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
46
    confirm_action('reboot', reboot, [serverID], [serverName]);
47
    return false;
48
});
49

50
// intercept shutdown click
51
$("div.actions a.action-shutdown").live('click', function(){ 
52
    var serverID = $(this).parent().parent().attr("id");
53
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
54
    confirm_action('shutdown', shutdown, [serverID], [serverName]);
55
    return false;
56
});
57

58
// intercept start click
59
$("div.actions a.action-start").live('click', function(){ 
60
    var serverID = $(this).parent().parent().attr("id");
61
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
62
//    confirm_action('start', start, [serverID], [serverName]);
63
    start([serverID]);
64
    return false;
65
});
66

67
// update the servers list
68
function update_machines_view(data){
69
    /* 
70
    Go through the servers in the input data. Update existing entries, add
71
    new ones to the list
72
    */    
73
    $.each(data.servers, function(i,server){
74
        
75
        existing = $('#' + server.id);
76
        
77
        if (existing.length > 1){
78
            existing.remove();
79
            existing = [];
80
        }
81
        
82
        if (existing.length){
83
            // If the machine already exists in the DOM then simply update or delete it
84
            if (server.deleted == true) {
85
                existing.remove();            
86
                try {
87
                    console.info(existing.find("a.name span.name").text() + ' removed');
88
                } catch(err) {}            
89
            } else if (existing.find(".status").text() != STATUS_MESSAGES[server.status]) {
90
                
91
                try { // firebug console logging
92
                    console.info(existing.find("a.name span.name").text() + ' from ' 
93
                                + existing.find(".status").text() + ' to ' + STATUS_MESSAGES[server.status]);
94
                } catch(err) {}
95
                
96
                if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
97
                    [STATUS_MESSAGES['STOPPED'], STATUS_MESSAGES['ERROR']].indexOf(existing.find(".status").text()) >= 0) {
98
                    // from stopped to running
99
                    moved = existing.clone().appendTo(".running");
100
                    moved.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
101
                    existing.remove();
102
                    existing = moved;
103
                } else if (['STOPPED','ERROR'].indexOf(server.status) >= 0 &&
104
                           [STATUS_MESSAGES['ACTIVE'], STATUS_MESSAGES['BUILD'], STATUS_MESSAGES['REBOOT']].indexOf(existing.find(".status").text()) >= 0) {
105
                    moved = existing.clone().appendTo(".terminated");
106
                    moved.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'-off.png');
107
                    existing.remove();
108
                    existing = moved;
109
                } 
110
                existing.find(".status").text(STATUS_MESSAGES[server.status]);
111
            
112
            }
113
            existing.find("a.name span.name").text(server.name);
114
            existing.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));
115
        } else if (server.deleted != true) {
116
            // If it does not exist and it's not deleted, we should create it
117
            var machine = $("#machine-template").clone().attr("id", server.id).fadeIn("slow");
118
            machine.find("a.name span.name").text(server.name);
119
            machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
120
            machine.find("span.imagetag").text(image_tags[server.imageRef]);
121
            machine.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));            
122
            machine.find(".status").text(STATUS_MESSAGES[server.status]);
123
            
124
            if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) >= 0){
125
                machine.appendTo(".running");
126
            } else {
127
                machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'-off.png');
128
                machine.appendTo(".terminated");
129
            }
130

131
        }
132
    });
133

134
    $("#spinner").hide();
135
    $("div.machine:last-child").find("div.separator").hide();
136
    // the separator shows only when running and terminated machines are available
137
    if ($(".terminated a.name").length > 0 && $(".running a.name").length > 0) {
138
        $("#mini.separator").fadeIn("slow");
139
    } else {
140
        $("#mini.separator").fadeOut("slow");
141
    }
142
    // show message in case user has no servers!
143
    if (servers.length == 0) {
144
        $("#emptymachineslist").fadeIn("slow");
145
    }
146
}
147

148
if (images.length == 0) {
149
    // populate image list
150
    update_images();
151
}
152
if (flavors.length == 0) {
153
    // configure flavors
154
    update_flavors(); 
155
}
156

157
update_vms(UPDATE_INTERVAL);
158
</script>