Revision 27b116db

b/ui/templates/machines_list.html
263 263
    Go through the servers in the input data. Update existing entries, add
264 264
    new ones to the list
265 265
    */
266
    console.log("updating", data);
266 267
    tableData = vmTable.fnGetData();
267 268

  
268 269
    $.each(data.servers.values, function(i,server){
269

  
270
        
270 271
        current = -1;
271 272
        // check server status to select the appropriate OS icon, defaults to on state
272 273
        osTag = os_icon(server.metadata);
273 274
        var osIcon = osTag + "-on.png", imgStr, imgSrc;
274 275
        // check if the server already exists in the datatable
275 276
        if (tableData.length > 0) {
276
            tableData.forEach(function(row,index){
277
            // ie does not support forEach use jquery helper to iterate data
278
            $.each(tableData, function(index, row){
277 279
                if (row[0].split(' ')[2].replace('id=','') == server.id){
278 280
                    current = index;
279 281
                }
......
290 292
            // when server is in deleted status it must be removed from the list
291 293
            if (server.status == "DELETED") {
292 294
                vmTable.fnDeleteRow(current);
293
            } else { // when server is not deleted, it should be updated
294
                if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
295
                    [STATUSES['STOPPED'], STATUSES['ERROR'], STATUSES['UNKNOWN'],
296
                     TRANSITIONS['Starting']].indexOf(server_row.find('span.status').text().replace(TRANSITION_STATE_APPEND, "")) >= 0) {
295
                } else { // when server is not deleted, it should be updated
296
                
297
                var current_status = server_row.find('span.status').text().replace(TRANSITION_STATE_APPEND, "");
298

  
299
                if (['BUILD', 'REBOOT'].indexOf(server.status) >= 0 && [TRANSITIONS['Starting'],STATUSES['ACTIVE']].indexOf(current_status) >= 0) {
300
                    // from running to reboot (or building which should never happen)
301
                    imgSrc = "static/icons/indicators/small/progress.gif";
302
                    tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
303
                    imgStr = "<img class=list-logo src=" + imgSrc + " title=" + osTag + "></img>";
304
                    tableData[current][1] = "<span class=imagetag>" + osTag + "</span>" + imgStr;
305
                    tableData[current][2] = "<a class=name><span class=name>" + fix_server_name(server.name) + "</span></a>";
306
                    //tableData[current][4] = "group"; //TODO
307
                    tableData[current][4] = "<span class=status>" + STATUSES[server.status] + "</span>";
308
                    vmTable.fnUpdate(tableData[current],current);
309
                } else if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
310
                    [STATUSES['STOPPED'], STATUSES['ERROR'], STATUSES['UNKNOWN'], TRANSITIONS['Starting']].indexOf(current_status) >= 0) {
297 311
                    // from stopped, on error or starting to building, active or rebooting
298 312
                    // starting is not an api state, it means the server is stopped or on error
299
                    tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
300 313
                    imgSrc = "static/icons/indicators/small/wave.gif";
314
                    tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
301 315
                    imgStr = "<img class=list-logo src=" + imgSrc + " title=" + osTag + "></img>";
302 316
                    tableData[current][1] = "<span class=imagetag>" + osTag + "</span>" + imgStr;
303 317
                    tableData[current][2] = "<a class=name><span class=name>" + fix_server_name(server.name) + "</span></a>";
......
307 321
                    setTimeout("$('#machinesview .list #"+server.id+"').parent().parent().find('.list-logo').attr('src','static/icons/machines/small/" + osIcon + "')", 1600);
308 322
                } else if (['STOPPED','ERROR', 'UNKNOWN'].indexOf(server.status) >= 0 &&
309 323
                           [STATUSES['ACTIVE'], STATUSES['BUILD'], STATUSES['REBOOT'],
310
                            TRANSITIONS['Shutting down']].indexOf(server_row.find('span.status').text().replace(TRANSITION_STATE_APPEND, "")) >= 0) {
324
                            TRANSITIONS['Shutting down']].indexOf(current_status) >= 0) {
311 325
                    tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
312 326
                    imgSrc = "static/icons/indicators/small/wave.gif";
313 327
                    imgStr = "<img class=list-logo src=" + imgSrc + " title=" + osTag + "></img>";
......
317 331
                    tableData[current][4] = "<span class=status>" + STATUSES[server.status] + "</span>";
318 332
                    vmTable.fnUpdate(tableData[current],current);
319 333
                    setTimeout("$('#machinesview .list #"+server.id+"').parent().parent().find('.list-logo').attr('src','static/icons/machines/small/" + osTag + "-off.png')", 1600);
320
                } else if ( STATUSES[server.status] == server_row.find('span.status').text().replace(TRANSITION_STATE_APPEND, "")) {
334
                } else if ( STATUSES[server.status] == current_status) {
321 335

  
322 336
                } else if (server.status == 'ACTIVE' &&
323
                           [STATUSES['BUILD'],TRANSITIONS['Rebooting']].indexOf(server_row.find('span.status').text().replace(TRANSITION_STATE_APPEND, "")) >= 0) {
337
                           [STATUSES['BUILD'],TRANSITIONS['Rebooting']].indexOf(current_status) >= 0) {
324 338
                    tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
325 339
                    imgSrc = "static/icons/indicators/small/wave.gif";
326 340
                    imgStr = "<img class=list-logo src=" + imgSrc + " title=" + osTag + "></img>";
......
337 351
            // check server status to select the appropriate OS icon
338 352
            if (['ERROR', 'STOPPED', 'UNKNOWN'].indexOf(server.status) >= 0) {
339 353
                osIcon = "static/icons/machines/small/" + osTag + "-off.png";
340
            } else if ( server.status == 'BUILD' || server.status == "DESTROY" ) {
354
            } else if ( server.status == 'BUILD' || server.status == "DESTROY" || server.status == "REBOOT") {
341 355
                osIcon = "static/icons/indicators/small/progress.gif";
342 356
            } else {
343 357
                osIcon = "static/icons/machines/small/" + osTag + "-on.png";

Also available in: Unified diff