Revision 146b6003 ui/static/synnefo.js

b/ui/static/synnefo.js
1
var flavors = [], images = [], servers = [], disks = [], cpus = [], ram = [];
2

  
1 3
function list_view() {
2 4
    $.cookie("list", '1'); // set list cookie
3 5
    $("div#machinesview").load($("#list").attr("href"), function(){
......
101 103
    return false;
102 104
}
103 105

  
104
function auto_update_vms(interval) {
105
	update_vms();
106
	setTimeout(auto_update_vms,interval,interval);
107
}
108

  
109 106
// get and show a list of running and terminated machines
110
function update_vms() {
107
function update_vms(interval) {
111 108
    try{ console.info('updating machines'); } catch(err){}
112 109

  
113 110
    $.ajax({
......
115 112
        type: "GET",
116 113
        timeout: TIMEOUT,
117 114
        dataType: "json",
118
        error: function(jqXHR, textStatus, errorThrown) { 
119
                    ajax_error(jqXHR);
115
        error: function(jqXHR, textStatus, errorThrown) {
116
					// don't forget to try again later
117
					if (interval) { 
118
						setTimeout(update_vms,interval,interval);
119
					}
120
					// as for now, just show an error message
121
                    if (jqXHR.status != undefined) {
122
						ajax_error(jqXHR.status);
123
					} else {
124
						ajax_error();
125
					}				
120 126
                    return false;
121 127
                    },
122 128
        success: function(data, textStatus, jqXHR) {
123
            servers = data.servers;
129
            try {
130
				servers = data.servers;
131
			} catch(err) { ajax_error('400');}
124 132
			update_machines_view(data);
133
			if (interval) {
134
				setTimeout(update_vms,interval,interval);
135
			}
125 136
        }
126 137
    });
127 138
    return false;
128 139
}
129 140

  
130
// get and show a list of anvailable standard and custom images
141
// get and show a list of available standard and custom images
131 142
function update_images() { 
132 143
    $.ajax({
133 144
        url: '/api/v1.0/images/detail',
......
136 147
        dataType: "json",
137 148
        timeout: TIMEOUT,
138 149
        error: function(jqXHR, textStatus, errorThrown) { 
139
                    ajax_error(jqXHR);
150
                    ajax_error(jqXHR.status);
140 151
                    },
141 152
        success: function(data, textStatus, jqXHR) {
142
            images = data.images;
153
            try {
154
				images = data.images;
155
			} catch(err){
156
				ajax_error("NO_IMAGES");
157
			}
143 158
            if ($("ul#standard-images li").toArray().length + $("ul#custom-images li").toArray().length == 0) {
144 159
                $.each(data.images, function(i,image){
145 160
                    var img = $('#image-template').clone().attr("id","img-"+image.id).fadeIn("slow");
......
162 177
    return false;
163 178
}
164 179

  
165
var flavors = {}, images = {}, servers = {}, disks = [], cpus = [], ram = [];
166

  
167 180
Array.prototype.unique = function () {
168 181
	var r = new Array();
169 182
	o:for(var i = 0, n = this.length; i < n; i++)
......
189 202
        dataType: "json",
190 203
        timeout: TIMEOUT,
191 204
        error: function(jqXHR, textStatus, errorThrown) { 
192
            ajax_error(jqXHR);
205
            try {
206
				ajax_error(jqXHR.status);
207
			} catch (err) {
208
				ajax_error(err);
209
			}
193 210
        },
194 211
        success: function(data, textStatus, jqXHR) {
195 212
            flavors = data.flavors;
......
224 241
            // update the indicators when sliding
225 242
            $("#cpu:range").data().rangeinput.onSlide(function(event,value){
226 243
                $("#cpu-indicator")[0].value = cpus[Number(value)];
227
                $("#custom").click();
228 244
            });
245
            $("#cpu:range").data().rangeinput.change(function(event,value){
246
                $("#custom").click();				
247
			});			
229 248
            $("#ram:range").data().rangeinput.onSlide(function(event,value){
230 249
                $("#ram-indicator")[0].value = ram[Number(value)];
231
                $("#custom").click();
232 250
            });
251
            $("#ram:range").data().rangeinput.change(function(event,value){
252
                $("#custom").click();
253
            });			
233 254
            $("#storage:range").data().rangeinput.onSlide(function(event,value){
234 255
                $("#storage-indicator")[0].value = disks[Number(value)];
235
                $("#custom").click();
236 256
            });
257
            $("#storage:range").data().rangeinput.change(function(event,value){
258
                $("#custom").click();
259
            });			
237 260
        }
238 261
    });
239 262
    return false;
......
289 312
		$("#action-" + on[action]).addClass('enabled');
290 313
	}
291 314
}
292
var success;
293
var error;
315

  
294 316
// reboot action
295 317
function reboot(serverIDs){
296 318
	if (!serverIDs.length){
297
		ajax_success();
319
		ajax_success('DEFAULT');
298 320
		return false;
299 321
	}	
300 322
    // ajax post reboot call
......
310 332
		data: JSON.stringify(payload),
311 333
		timeout: TIMEOUT,
312 334
		error: function(jqXHR, textStatus, errorThrown) {
313
					ajax_error(jqXHR);//, serverID);
314
                    error = jqXHR;
335
					ajax_error(jqXHR.status);
315 336
				},
316 337
		success: function(data, textStatus, jqXHR) {
317 338
					if ( jqXHR.status == '202') {
......
319 340
                            console.info('rebooted ' + serverID);
320 341
                        } catch(err) {}   		
321 342
						reboot(serverIDs);
322
                        success = jqXHR;
323 343
					} else {
324
						ajax_error(jqXHR);//, serverID);
325
                        error = jqXHR;
344
						ajax_error(jqXHR.status);
326 345
					}
327 346
				}
328 347
    });
......
333 352
// shutdown action
334 353
function shutdown(serverIDs) {
335 354
	if (!serverIDs.length){
336
		ajax_success();
355
		ajax_success('DEFAULT');
337 356
		return false;
338 357
	}
339 358
    // ajax post shutdown call
......
349 368
        data: JSON.stringify(payload),
350 369
        timeout: TIMEOUT,
351 370
        error: function(jqXHR, textStatus, errorThrown) { 
352
                    ajax_error(jqXHR);
371
                    ajax_error(jqXHR.status);
353 372
                    },
354 373
        success: function(data, textStatus, jqXHR) {
355 374
                    if ( jqXHR.status == '202') {
......
358 377
                        } catch(err) {}       				
359 378
                        shutdown(serverIDs);
360 379
                    } else {
361
                        ajax_error(jqXHR);
380
                        ajax_error(jqXHR.status);
362 381
                    }
363 382
                }             
364 383
    });
......
369 388
// destroy action
370 389
function destroy(serverIDs) {
371 390
	if (!serverIDs.length){
372
		ajax_success();
391
		ajax_success('DEFAULT');
373 392
		return false;
374 393
	}
375 394
    // ajax post destroy call can have an empty request body
......
383 402
        data: JSON.stringify(payload),
384 403
        timeout: TIMEOUT,
385 404
        error: function(jqXHR, textStatus, errorThrown) { 
386
                    ajax_error(jqXHR);
405
                    ajax_error(jqXHR.status);
387 406
                    },
388 407
        success: function(data, textStatus, jqXHR) {
389 408
                    if ( jqXHR.status == '202') {
......
392 411
                        } catch (err) {}        				
393 412
                        destroy(serverIDs);
394 413
                    } else {
395
                        ajax_error(jqXHR);
414
                        ajax_error(jqXHR.status);
396 415
                    }
397 416
                }             
398 417
    });
......
403 422
// start action
404 423
function start(serverIDs){
405 424
	if (!serverIDs.length){
406
		ajax_success();
425
		ajax_success('DEFAULT');
407 426
		return false;
408 427
	}	
409 428
    // ajax post start call
......
419 438
        data: JSON.stringify(payload),
420 439
        timeout: TIMEOUT,
421 440
        error: function(jqXHR, textStatus, errorThrown) { 
422
                    ajax_error(jqXHR);
441
                    ajax_error(jqXHR.status);
423 442
                    },
424 443
        success: function(data, textStatus, jqXHR) {
425 444
                    if ( jqXHR.status == '202') {
......
428 447
                        } catch(err) {}      		
429 448
                        start(serverIDs);
430 449
                    } else {
431
                        ajax_error(jqXHR);
450
                        ajax_error(jqXHR.status);
432 451
                    }
433 452
                }
434 453
    });

Also available in: Unified diff