forked from xapi-project/xen-api
/
main.js
106 lines (93 loc) · 2.93 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright (C) 2006-2009 Citrix Systems Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
function setstatus(text,colour) {
$('#status').text(text);
switch(colour) {
case 0: /* red */
$('#status').removeClass("connected").removeClass("connecting").addClass("disconnected");
break;
case 1: /* yellow */
$('#status').removeClass("connected").addClass("connecting").removeClass("disconnected");
break;
case 2: /* green */
$('#status').addClass("connected").removeClass("connecting").removeClass("disconnected");
break;
}
}
function login() {
$dw.closeall();
//$xapi.master_address=$('#master_address').val();
if($xapi.xapi_xmlrpc) delete $xapi.xapi_xmlrpc;
if($xapi.xapi_json) delete $xapi.xapi_json;
if($xapi.xapi) delete $xapi.xapi;
delete graphs;
graphs=new Object;
$xapi.username=$('#cr_username').val();
$xapi.password=$('#cr_password').val();
setstatus("Detecting server version",1);
$xapi.syncDetectServerVersion();
var vsnstring;
switch($xapi.mastersoftwareversion.product_version) {
case "4.0.0":
vsnstring="Rio";
break;
case "4.1.0":
vsnstring="Miami";
break;
case "5.0.0":
vsnstring="Orlando";
break;
case "5.1.0":
vsnstring="Midnight Ride";
break;
}
setstatus("Connecting to "+vsnstring+" server",1);
// $xapi.detectServerVersion(function () {
$xapi.init(
function()
{
$dw.populateXapiObjects()
if($xapi.status==0) {
setstatus("Failed to connect",0);
} else {
setstatus("Connected to "+vsnstring+" server",2);
}
if($xapi.status!=0) {
$.cookie('xapi_username',$('#cr_username').val());
$.cookie('xapi_password',$('#cr_password').val());
// $.cookie('xapi_host',$('#master_address').val());
$.cookie('xapi_autologin',"true");
}
})
// });
}
$(document).ready(function(){
$('#devwebmain').jqDrag('.jqDrag').jqResize('.jqResize');
if($.cookie('xapi_username'))
$('#cr_username').val($.cookie('xapi_username'));
if($.cookie('xapi_password'))
$('#cr_password').val($.cookie('xapi_password'));
//if($.cookie('xapi_host'))
//$('#master_address').val($.cookie('xapi_host'));
$dw=new $devweb();
if($.cookie('xapi_autologin'))
login();
$('#connectbutton').click(login);
$('g > g').click(function(evt) {
var tgt=$($(evt.target).parents('g')[0]);
var classname=$('title',tgt).text().toLowerCase();
if(classname in $xapi.xo)
$dw.createClassView(classname);
});
});