Statistics
| Branch: | Tag: | Revision:

root / ui / templates / standard.html @ ab5282e4

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
            $("div.machine:last-child").find("div.separator").show();                
84

85
            // If the machine already exists in the DOM then simply update or delete it
86
            if (server.deleted == true) {
87
                existing.remove();            
88
                try {
89
                    console.info(existing.find("a.name span.name").text() + ' removed');
90
                } catch(err) {}            
91
            } else if (existing.find(".status").text() != STATUS_MESSAGES[server.status]) {
92
                
93
                try { // firebug console logging
94
                    console.info(existing.find("a.name span.name").text() + ' from ' 
95
                                + existing.find(".status").text() + ' to ' + STATUS_MESSAGES[server.status]);
96
                } catch(err) {}
97
                
98
                if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
99
                    [STATUS_MESSAGES['STOPPED'], STATUS_MESSAGES['ERROR']].indexOf(existing.find(".status").text()) >= 0) {
100
                    // from stopped to running
101
                    moved = existing.clone().appendTo(".running");
102
                    moved.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
103
                    existing.remove();
104
                    existing = moved;
105
                } else if (['STOPPED','ERROR'].indexOf(server.status) >= 0 &&
106
                           [STATUS_MESSAGES['ACTIVE'], STATUS_MESSAGES['BUILD'], STATUS_MESSAGES['REBOOT']].indexOf(existing.find(".status").text()) >= 0) {
107
                    moved = existing.clone().appendTo(".terminated");
108
                    moved.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'-off.png');
109
                    existing.remove();
110
                    existing = moved;
111
                } 
112
                existing.find(".status").text(STATUS_MESSAGES[server.status]);
113
            
114
            }
115
            existing.find("a.name span.name").text(server.name);
116
            existing.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));
117
        } else if (server.deleted != true) {
118
            // If it does not exist and it's not deleted, we should create it
119
            var machine = $("#machine-template").clone().attr("id", server.id).fadeIn("slow");
120
            machine.find("a.name span.name").text(server.name);
121
            machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
122
            machine.find("span.imagetag").text(image_tags[server.imageRef]);
123
            machine.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));            
124
            machine.find(".status").text(STATUS_MESSAGES[server.status]);
125
            if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) >= 0){
126
                machine.appendTo(".running");
127
            } else {
128
                machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'-off.png');
129
                machine.appendTo(".terminated");
130
            }
131

132
        }
133
    });
134

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

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

158
update_vms(UPDATE_INTERVAL);
159
</script>