Statistics
| Branch: | Tag: | Revision:

root / ui / templates / standard.html @ a1a31201

History | View | Annotate | Download (10.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 class="spinner hidden"></div>
15
        </div>
16
        <img class="logo" src="" />
17
        <a href="#" class="name">
18
            <h5>Name: <span class="name">node.name</span><span class="rename"></span></h5>
19
        </a>
20
        <a href="#" class="ip">
21
            <h5>IP: <span class="public">node.public_ip</span></h5>
22
        </a>
23
        <h5 class="settings">
24
            {% trans "Show:" %} <a href="#">{% trans "disks" %}</a> | <a href="#">{% trans "networks" %}</a> | <a href="#">{% trans "group" %}</a>
25
        </h5>
26
        <div class="actions">
27
            <a href="#" class="action-start">{% trans "Start" %}</a>
28
            <a href="#" class="action-reboot">{% trans "Reboot" %}</a>
29
            <a href="#" class="action-shutdown">{% trans "Shutdown" %}</a>
30
            <a href="#" class="more">{% trans "more &hellip;" %}</a>
31
        </div>
32
        <div class="confirm_single">
33
            <button class="yes">{% trans "Confirm" %}</button>
34
            <button class="no">{% trans "Cancel" %}</button>
35
        </div>
36
        <div class="separator"></div>
37
    </div>
38

    
39
    <div class="running"></div>
40
    <div id="mini" class="separator"></div>
41
    <div class="terminated"></div>
42
</div>
43

    
44
<script>
45
// intercept reboot click 
46
$("div.actions a.action-reboot").live('click', function(){
47
    var serverID = $(this).parent().parent().attr("id");
48
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
49
    var found = false;
50
    $(this).parent().children('a').removeClass('selected');
51
    $(this).addClass('selected');
52
    $(this).parent().addClass('display')
53

54
    for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
55
        if (pending_actions[i][1]==serverID){
56
            pending_actions[i][0] = reboot;
57
            found = true
58
        }
59
    }
60
    if (!found) // no pending action for this server was found, so let's just add it to the list
61
        pending_actions.push([reboot, serverID, serverName])
62
    update_confirmations();
63
    return false;
64
});
65

66
// intercept shutdown click
67
$("div.actions a.action-shutdown").live('click', function(){ 
68
    var serverID = $(this).parent().parent().attr("id");
69
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
70
    var found = false;
71
    $(this).parent().children('a').removeClass('selected');
72
    $(this).addClass('selected');
73
    $(this).parent().addClass('display')
74

75
    for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
76
        if (pending_actions[i][1]==serverID){
77
            pending_actions[i][0] = shutdown;
78
            found = true
79
        }
80
    }
81
    if (!found) // no pending action for this server was found, so let's just add it to the list 
82
        pending_actions.push([shutdown, serverID, serverName])
83
    update_confirmations();
84
    return false;
85
});
86

87
// intercept start click
88
$("div.actions a.action-start").live('click', function(){ 
89
    var serverID = $(this).parent().parent().attr("id");
90
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
91
    var found = false;
92
    $(this).parent().children('a').removeClass('selected');
93
    $(this).addClass('selected');
94
    $(this).parent().addClass('display')
95
    for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
96
        if (pending_actions[i][1]==serverID){
97
            pending_actions[i][0] = start;
98
            found = true
99
        }
100
    }
101
    if (!found) // no pending action for this server was found, so let's just add it to the list
102
        pending_actions.push([start, serverID, serverName])
103
    update_confirmations();    
104
    return false;
105
});
106

107
$("div.confirm_single .yes").live('click', function(){
108
    var serverID = $(this).parent().parent().attr("id");
109
    for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server execute it
110
        if (pending_actions[i][1]==serverID){
111
            action = pending_actions.splice(i,1)[0]; // extract action
112
            action[0]([action[1]]); // execute action            
113
        }
114
    }
115
    $(this).parent().hide();
116
    $(this).parent().parent().children('div.actions').children('a').removeClass('selected');
117
    $(this).parent().parent().children('.state').children('.spinner').show()
118
    $(this).parent().parent().children('div.actions').removeClass('display');
119
    return false;
120
});
121

122
$("div.confirm_single .no").live('click', function(){
123
    // remove the action from the pending list
124
    var serverID = $(this).parent().parent().attr("id");
125
    
126
    $(this).parent().parent().children('div.actions').children('a').removeClass('selected');
127
    $(this).parent().parent().children('div.actions').removeClass('display');    
128
    for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server remove it
129
        if (pending_actions[i][1]==serverID){
130
            pending_actions.splice(i,1);
131
        }
132
    }
133
    $(this).parent().hide();
134
    return false;
135
});
136

137
function update_confirmations(){
138
    $('div.confirm_single').hide() // hide all confirm boxes to begin with
139
    $('div.confirm_multiple').hide()
140
    
141
    for (i=0;i<pending_actions.length;i++){ // show single confirms
142
        $("div.machine#"+pending_actions[i][1]+' .confirm_single').show();        
143
    }
144
        if (pending_actions.length>1) // if more than one pending action show multiple confirm box
145
                $('div.confirm_multiple').show();
146
}
147

148
// update the servers list
149
function update_machines_view(data){
150
    /* 
151
    Go through the servers in the input data. Update existing entries, add
152
    new ones to the list
153
    */    
154
    $.each(data.servers, function(i,server){
155
        
156
        existing = $('#' + server.id);
157
        
158
        if (existing.length > 1){
159
            existing.remove();
160
            existing = [];
161
        }
162
        
163
        if (existing.length){
164
            $("div.machine:last-child").find("div.separator").show();                
165

166
            // If the machine already exists in the DOM then simply update or delete it
167
            if (server.deleted == true) {
168
                existing.remove();            
169
                try {
170
                    console.info(existing.find("a.name span.name").text() + ' removed');
171
                } catch(err) {}            
172
            } else if (existing.find(".status").text() != STATUS_MESSAGES[server.status]) {
173
                
174
                try { // firebug console logging
175
                    console.info(existing.find("a.name span.name").text() + ' from ' 
176
                                + existing.find(".status").text() + ' to ' + STATUS_MESSAGES[server.status]);
177
                } catch(err) {}
178
                
179
                if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
180
                    [STATUS_MESSAGES['STOPPED'], STATUS_MESSAGES['ERROR']].indexOf(existing.find(".status").text()) >= 0) {
181
                    // from stopped to running
182
                    moved = existing.clone().appendTo(".running");
183
                    moved.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
184
                    existing.remove();
185
                    existing = moved;
186
                } else if (['STOPPED','ERROR'].indexOf(server.status) >= 0 &&
187
                           [STATUS_MESSAGES['ACTIVE'], STATUS_MESSAGES['BUILD'], STATUS_MESSAGES['REBOOT']].indexOf(existing.find(".status").text()) >= 0) {
188
                    moved = existing.clone().appendTo(".terminated");
189
                    moved.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'-off.png');
190
                    existing.remove();
191
                    existing = moved;
192
                } 
193
                existing.find(".status").text(STATUS_MESSAGES[server.status]);
194
                existing.find('.spinner').hide();            
195
            }
196
            existing.find("a.name span.name").text(server.name);
197
            existing.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));
198
        } else if (server.deleted != true) {
199
            // If it does not exist and it's not deleted, we should create it
200
            var machine = $("#machine-template").clone().attr("id", server.id).fadeIn("slow");
201
            machine.find("a.name span.name").text(server.name);
202
            machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
203
            machine.find("span.imagetag").text(image_tags[server.imageRef]);
204
            machine.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));            
205
            machine.find(".status").text(STATUS_MESSAGES[server.status]);
206
            if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) >= 0){
207
                machine.appendTo(".running");
208
            } else {
209
                machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'-off.png');
210
                machine.appendTo(".terminated");
211
            }
212
        }
213
    });
214

215
    $("#spinner").hide();
216
    $("div.machine:last-child").find("div.separator").hide();
217
    // the separator shows only when running and terminated machines are available
218
    if ($(".terminated a.name").length > 0 && $(".running a.name").length > 0) {
219
        $("#mini.separator").fadeIn("slow");
220
    } else {
221
        $("#mini.separator").fadeOut("slow");
222
    }
223
    // show message in case user has no servers!
224
    if (servers.length == 0) {
225
        $("#emptymachineslist").fadeIn("slow");
226
    }
227
}
228

229
// indicate that the requested action was succesfully completed
230
function display_success(serverID) {
231
    $('#'+serverID+ ' .spinner').addClass('wave');
232
    console.info('success '+serverID);
233
    setTimeout("$('#'+serverID+ ' .spinner').hide();$('#'+serverID+ ' .wave').removeClass('wave')", 5000);
234
}
235

236
if (images.length == 0) {
237
    // populate image list
238
    update_images();
239
}
240
if (flavors.length == 0) {
241
    // configure flavors
242
    update_flavors(); 
243
}
244

245
update_vms(UPDATE_INTERVAL);
246
</script>