Revision 146b6003

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
    });
b/ui/templates/home.html
3 3
<head>
4 4
	<title>{{ project }}</title>
5 5
	<!-- include the Tools -->
6
	<script src="static/jquery.tools.min.js"></script>
6
    <!-- jquery tools minified for deployment-->
7
    <!--script src="static/jquery.tools.min.js"></script-->
8
    
9
	<!-- jquery tools source for debugging -->    
10
    <script src="http://flowplayer.org/tools/download/1.2.5/jquery-1.4.2.js"></script>   
11
	<script src="http://flowplayer.org/tools/download/1.2.5/tabs/tabs.js"></script>
12
	<script src="http://flowplayer.org/tools/download/1.2.5/scrollable/scrollable.js"></script>
13
	<script src="http://flowplayer.org/tools/download/1.2.5/overlay/overlay.js"></script>
14
	<script src="http://flowplayer.org/tools/download/1.2.5/rangeinput/rangeinput.js"></script>
15
	<script src="http://flowplayer.org/tools/download/1.2.5/toolbox/toolbox.expose.js"></script>
16
    
7 17
    <script src="static/jquery.cookie.js"></script>
8 18
    <script src="static/jQueryRotate.js"></script>
9 19
    <script src="static/jquery.dataTables.min.js"></script>
......
23 33
        
24 34
        var ERRORS = {
25 35
            // error message header
26
            'header' : '{% trans "Error!" %}',
36
            'HEADER' : '{% trans "Error!" %}',
27 37
            // default
28
            'default' : '{% trans "Could not contact the service. Please check your network connectivity and try again." %}',
38
            'DEFAULT' : '{% trans "Could not contact the service. Please check your network connectivity and try again." %}',
29 39
            // bad request
30 40
            '400' : '{% trans "Malformed request." %}',
31 41
            // not found
......
35 45
            // service unavailable
36 46
            '503' : '{% trans "This service is unavailable right now, please try again later." %}',
37 47
            // no images unavailable
38
            'no_images' : '{% trans "Cannot show the Create machine wizard: No images found." %}',
48
            'NO_IMAGES' : '{% trans "Cannot show the Create machine wizard: No images found." %}',
39 49
            // no images unavailable
40
            'no_flavors' : '{% trans "Cannot show the Create machine wizard: No machine configurations found." %}'
50
            'NO_FLAVORS' : '{% trans "Cannot show the Create machine wizard: No machine configurations found." %}'
41 51
        };
42 52
        
43 53
        var SUCCESS = {
44
            'header' : '{% trans "Success!" %}',
45
            'default' : '{% trans "Your request has been succefully executed." %}',
54
            'HEADER' : '{% trans "Success!" %}',
55
            'DEFAULT' : '{% trans "Your request has been succefully executed." %}',
46 56
        };
47 57
        
48 58
        // ajax error checking  
49
        function ajax_error(jqXHR) {
59
        function ajax_error(status) {
50 60
            // prepare the error message
51
            $("#error-success h3").text(ERRORS['header']);
61
            $("#error-success h3").text(ERRORS['HEADER']);
52 62
            
53
            if (ERRORS[jqXHR.status]) {
54
                $("#error-success p").text(ERRORS[jqXHR.status]);
63
            if (status != undefined && ERRORS[status]) {
64
                $("#error-success p").text(ERRORS[status]);
55 65
            } else {
56
                $("#error-success p").text(ERRORS['default']);   
66
                $("#error-success p").text(ERRORS['DEFAULT']);   
57 67
            }
58 68
            
59 69
            // bring up error notification
......
78 88
        }
79 89
        
80 90
        // ajax success checking
81
        function ajax_success() {          
91
        function ajax_success(status, password) {
82 92
            // prepare the error message
83
            $("#error-success h3").text(SUCCESS['header']);
84
            $("#error-success p").text(SUCCESS['default']);             
93
            $("#error-success h3").text(SUCCESS['HEADER']);
94
            $("#error-success p").text(SUCCESS['DEFAULT']);             
85 95
            // bring up success notification
86 96
            var triggers = $("a#notification").overlay({
87 97
                // some mask tweaks suitable for modal dialogs
b/ui/templates/list.html
234 234
    ]
235 235
});
236 236

  
237
auto_update_vms(UPDATE_INTERVAL);
237

  
238
if (images.length == 0) {
239
    // populate image list
240
    update_images();
241
}
242
if (flavors.length == 0) {
243
    // configure flavors
244
    update_flavors(); 
245
}
246
update_vms(UPDATE_INTERVAL);
238 247

  
239 248
</script>
b/ui/templates/machines.html
199 199

  
200 200
// launch VM creation wizard
201 201
$("a#create").click(function(){
202

  
203
    //do not launch wizard if no images or flavors are found
204
    if (images.length == 0)
205
      {
206
        function fake_jqXHR() {
207
        this.status = 'no_images';
208
        }
209
        var jqXHR = new fake_jqXHR();
210
        ajax_error(jqXHR);
211
        return false;
212
      } 
213
    else if (flavors.length == 0)
214
      {
215
        function fake_jqXHR() {
216
        this.status = 'no_flavors';
217
        }
218
        var jqXHR = new fake_jqXHR();
219
        ajax_error(jqXHR);
220
        return false;
221
      } 
222
    else 
223
      {
202
    // launch wizard only if images and flavors are found
203
    if (images.length > 0  && flavors.length > 0) {
224 204
        $("#wizard").scrollable().begin();
225 205
        $("#wizard").show();
226
        $('a#create').data('overlay').load()    
227
      }
206
        $('a#create').data('overlay').load()   
207
    } else if (images.length == 0 ) {
208
        ajax_error('NO_IMAGES');
209
        return false;   
210
    } else if (flavors.length == 0) {
211
        ajax_error('NO_FLAVORS');
212
        return false;
213
    }
228 214
});
229 215

  
230 216
// create wizard overlay
......
365 351
    data: JSON.stringify(payload),
366 352
    timeout: TIMEOUT,
367 353
    error: function(jqXHR, textStatus, errorThrown) { 
368
                ajax_error(jqXHR);
354
                ajax_error(jqXHR.status);
369 355
           },
370 356
    success: function(data, textStatus, jqXHR) {
371 357
                if ( jqXHR.status == '202') {
372
                    ajax_success(jqXHR);                   
358
                    ajax_success(jqXHR.status);                   
373 359
                } else {
374
                    ajax_error(jqXHR);
360
                    ajax_error(jqXHR.status);
375 361
                }
376 362
            }
377 363
    });
......
385 371
// create tabs for main menu
386 372
$("ul.tabs").tabs("div.panes ul");
387 373

  
388
// populate image list
389
update_images();
390
// configure flavors
391
update_flavors(); 
392 374
</script>
b/ui/templates/standard.html
155 155
    }
156 156
}
157 157

  
158
auto_update_vms(UPDATE_INTERVAL);
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);
159 168
</script>

Also available in: Unified diff