Statistics
| Branch: | Tag: | Revision:

root / ui / templates / standard.html @ 146b6003

History | View | Annotate | Download (6.4 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 already displayed running servers and remove those not in
71
    the data or are marked as deleted.
72
    */
73
    $('.running .machine').each(function(i,entry) {
74
        var deleted = true;
75
        $.each(data.servers, function(j,server) {
76
            if (server.id == entry.id && ['BUILD','ACTIVE'].indexOf(server.status) >= 0) {
77
                deleted = false;
78
            }
79
        });
80
        if (deleted) {
81
            $('#'+entry.id).remove();
82
        }
83
    });
84
    // Do the same for the terminated ones.
85
    $('.terminated .machine').each(function(i,entry) {
86
        var deleted = true;
87
        $.each(data.servers, function(j,server) {
88
            if (server.id == entry.id && ['STOPPED','ERROR'].indexOf(server.status) >= 0) {
89
                deleted = false;
90
            }
91
        });
92
        if (deleted) {
93
            $('#'+entry.id).remove();
94
        }    
95
    });
96
    /* 
97
    Then go through the servers in the input data. Update existing entries, add
98
    new ones to the list
99
    */    
100
    $.each(data.servers, function(i,server){
101
        // if the machine is deleted it should not be included in any list
102
        if (server.status == 'DELETED') {
103
            return;
104
        }
105
        
106
        existing = $('#' + server.id);
107
        
108
        if (existing.length > 1){
109
            existing.remove();
110
            existing = [];
111
        }
112
        
113
        if (existing.length){ 
114
            // If the machine already exists in the DOM then simply update it
115
            if (existing.find(".status").text() != STATUS_MESSAGES[server.status]) {
116
                try {
117
                    console.info(existing.find("a.name span.name").text() + ' from ' 
118
                                + existing.find(".status").text() + ' to ' + STATUS_MESSAGES[server.status]);
119
                } catch(err) {}
120
                existing.find(".status").text(STATUS_MESSAGES[server.status]);
121
            }
122
            existing.find("a.name span.name").text(server.name);
123
            existing.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));
124
        } else {
125
            // If it does not exist, we should create it
126
            var machine = $("#machine-template").clone().attr("id", server.id).fadeIn("slow");
127
            machine.find("a.name span.name").text(server.name);
128
            machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
129
            machine.find("span.imagetag").text(image_tags[server.imageRef]);
130
            machine.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));            
131
            machine.find(".status").text(STATUS_MESSAGES[server.status]);
132
            
133
            if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) >= 0){
134
                machine.appendTo(".running");
135
            } else {
136
                machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'-off.png');
137
                machine.find("img.list-logo").attr("src","static/os_logos/"+image_tags[server.imageRef]+'-off.png');            
138
                machine.appendTo(".terminated");
139
            }
140

141
        }
142
    });
143

144
    $("#spinner").hide();
145
    $("div.machine:last-child").find("div.separator").hide();
146
    // the separator shows only when running and terminated machines are available
147
    if ($(".terminated a.name").length > 0 && $(".running a.name").length > 0) {
148
        $("#mini.separator").fadeIn("slow");
149
    } else {
150
        $("#mini.separator").fadeOut("slow");
151
    }
152
    // show message in case user has no servers!
153
    if (servers.length == 0) {
154
        $("#emptymachineslist").fadeIn("slow");
155
    }
156
}
157

158
if (images.length == 0) {
159
    // populate image list
160
    update_images();
161
}
162
if (flavors.length == 0) {
163
    // configure flavors
164
    update_flavors(); 
165
}
166

167
update_vms(UPDATE_INTERVAL);
168
</script>