Revision eae0a59a ui/static/synnefo.js

b/ui/static/synnefo.js
72 72
    if (serverIDs.length == 1){
73 73
        $("#yes-no h3").text('You are about to ' + action_string + ' vm ' + serverNames[0]);
74 74
    } else if (serverIDs.length > 1){
75
        $("#yes-no h3").text('You are about to ' + action_string + ' ' + serverIDs.length + 'machines');
75
        $("#yes-no h3").text('You are about to ' + action_string + ' ' + serverIDs.length + ' machines');
76 76
    } else {
77 77
        return false;
78 78
    }
......
104 104
    return false;
105 105
}
106 106

  
107
function auto_update_vms(interval) {
108
	update_vms();
109
	setTimeout(auto_update_vms,interval,interval);
110
}
111

  
107 112
// get and show a list of running and terminated machines
108 113
function update_vms() {
109 114
    try{ console.info('updating machines'); } catch(err){}
110
    $(".running").text('');
111
    $(".terminated").text('');
112 115

  
113 116
    $.ajax({
114 117
        url: '/api/v1.0/servers/detail',
......
120 123
                    return false;
121 124
                    },
122 125
        success: function(data, textStatus, jqXHR) {
123
            if ($(".running a.name").length + $(".terminated a.name").length == 0) {
124
            
125
                $.each(data.servers, function(i,server){
126
                    // if the machine is deleted it should not be included in any list
127
                    if (server.status == 'DELETED') {
128
                        return;
129
                    }
130
                    var machine = $("#machine-template").clone().attr("id", server.id).fadeIn("slow");
131
                    machine.find("input[type='checkbox']").attr("id", "input-" + server.id);
132
                    machine.find("input[type='checkbox']").attr("class", server.status);
133
                    machine.find("a.name span.name").text(server.name);
134
                    machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageId]+'.png');
135
                    machine.find("img.list-logo").attr("src","static/os_logos/"+image_tags[server.imageId]+'.png');
136
                    machine.find("img.list-logo").attr("title",image_tags[server.imageId]);
137
                    machine.find("span.imagetag").text(image_tags[server.imageId]);
138
    
139
                    machine.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));            
140
    
141
                    // TODO: handle SHARE_IP, SHARE_IP_NO_CONFIG, DELETE_IP, REBUILD, QUEUE_RESIZE, PREP_RESIZE, RESIZE, VERIFY_RESIZE, PASSWORD, RESCUE
142
                    if (server.status == 'BUILD'){
143
                        machine.find(".status").text('Building');
144
                        machine.appendTo(".running");
145
                    } else if (server.status == 'ACTIVE') {
146
                        machine.find(".status").text('Running');
147
                        machine.appendTo(".running"); 
148
                    } else if (server.status == 'REBOOT' || server.status == 'HARD_REBOOT') {
149
                        machine.find(".status").text('Rebooting');
150
                        machine.appendTo(".running");
151
                    } else if (server.status == 'STOPPED') {
152
                        machine.find(".status").text('Stopped');
153
                        machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageId]+'-off.png');
154
                        machine.find("img.list-logo").attr("src","static/os_logos/"+image_tags[server.imageId]+'-off.png');
155
                        machine.appendTo(".terminated");
156
                    } else if (server.status == 'ERROR') {
157
                        machine.find(".status").text('Error');
158
                        machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageId]+'-off.png');
159
                        machine.find("img.list-logo").attr("src","static/os_logos/"+image_tags[server.imageId]+'-off.png');
160
                        machine.appendTo(".terminated");
161
                    } 
162
                    else {
163
                        machine.find(".status").text('Unknown');
164
                        machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageId]+'-off.png');
165
                        machine.find("img.list-logo").attr("src","static/os_logos/"+image_tags[server.imageId]+'-off.png');
166
                        machine.appendTo(".terminated");
167
                    }
168
                });
169
            }
170
            $("#spinner").hide();
171
            $("div.machine:last-child").find("div.seperator").hide();
172
            // if the terminated list is populated then the seperator must be shown
173
            if ($(".terminated a.name").length > 0) {
174
                $("#mini.seperator").fadeIn("slow");
175
            }
176
            // creating the table in list view, if there are machines to show
177
            if ($("div.list table.list-machines tbody").length > 0) {
178
                $("div.list table.list-machines").dataTable({
179
                    "bInfo": false,
180
                    "bPaginate": false,
181
            		"bAutoWidth": false,
182
            		"bSort": true,    
183
                    "bStateSave": true,
184
                    "sScrollY": "270px",
185
                    "sScrollX": "515px",
186
                    "sScrollXInner": "500px",
187
                    "aoColumnDefs": [
188
                        { "bSortable": false, "aTargets": [ 0 ] }
189
                    ]
190
                });
191
                $("div.list table.list-machines").show();
192
                $("div.list div.actions").show();
193
            }
126
			update_machines_view(data);
194 127
        }
195 128
    });
196 129
    return false;

Also available in: Unified diff