5
0
mirror of git://git.proxmox.com/git/novnc-pve.git synced 2024-12-22 17:34:20 +03:00

improve error handling, remove debugging code

This commit is contained in:
Dietmar Maurer 2014-08-05 06:49:01 +02:00
parent 3122e1833e
commit d3d524cccb

View File

@ -112,7 +112,6 @@ API2Request: function(reqOpts) {
xhr.setRequestHeader('Cache-Control', 'no-cache'); xhr.setRequestHeader('Cache-Control', 'no-cache');
if (reqOpts.method === 'POST' || reqOpts.method === 'PUT') { if (reqOpts.method === 'POST' || reqOpts.method === 'PUT') {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
console.dir(PVE);
xhr.setRequestHeader('CSRFPreventionToken', PVE.CSRFPreventionToken); xhr.setRequestHeader('CSRFPreventionToken', PVE.CSRFPreventionToken);
xhr.send(data); xhr.send(data);
} else if (reqOpts.method === 'GET') { } else if (reqOpts.method === 'GET') {
@ -124,6 +123,26 @@ API2Request: function(reqOpts) {
}, },
// show msg for 5 seconds
pve_show_msg: function(klass, msg, permanant) {
var oldklass = $D('noVNC-control-bar').getAttribute("class");
$D('noVNC-control-bar').setAttribute("class", klass);
var oldmsg = $D('noVNC_status').innerHTML;
$D('noVNC_status').innerHTML = msg;
if (permanent) return;
setTimeout(function() {
var curmsg = $D('noVNC_status').innerHTML;
if (curmsg === msg) {
$D('noVNC_status').innerHTML = oldmsg;
}
var curklass = $D('noVNC-control-bar').getAttribute("class");
if (curklass === klass) {
$D('noVNC-control-bar').setAttribute("class", oldklass);
}
}, 5000);
},
pve_vm_command: function(cmd, params, reload) { pve_vm_command: function(cmd, params, reload) {
var baseUrl; var baseUrl;
@ -135,33 +154,15 @@ pve_vm_command: function(cmd, params, reload) {
throw "unknown VM type"; throw "unknown VM type";
} }
var show_msg = function(klass, msg) {
// show msg for 5 seconds
var oldklass = $D('noVNC-control-bar').getAttribute("class");
$D('noVNC-control-bar').setAttribute("class", klass);
var oldmsg = $D('noVNC_status').innerHTML;
$D('noVNC_status').innerHTML = msg;
setTimeout(function() {
var curmsg = $D('noVNC_status').innerHTML;
if (curmsg === msg) {
$D('noVNC_status').innerHTML = oldmsg;
}
var curklass = $D('noVNC-control-bar').getAttribute("class");
if (curklass === klass) {
$D('noVNC-control-bar').setAttribute("class", oldklass);
}
}, 5000);
};
UI.API2Request({ UI.API2Request({
params: params, params: params,
url: baseUrl + "/status/" + cmd, url: baseUrl + "/status/" + cmd,
method: 'POST', method: 'POST',
failure: function(msg) { failure: function(msg) {
show_msg('noVNC_status_warn', msg); UI.pve_show_msg('noVNC_status_warn', msg);
}, },
success: function() { success: function() {
show_msg('noVNC_status_normall', "VM command '" + cmd +"' successful"); UI.pve_show_msg('noVNC_status_normall', "VM command '" + cmd +"' successful");
if (reload) { if (reload) {
setTimeout(function() { setTimeout(function() {
UI.pveReload(); UI.pveReload();
@ -307,8 +308,6 @@ pve_start: function(callback) {
document.title = title; document.title = title;
var start_vnc_viewer = function(param) { var start_vnc_viewer = function(param) {
console.dir(param);
var wsparams = UI.urlEncode({ var wsparams = UI.urlEncode({
port: param.port, port: param.port,
vncticket: param.ticket vncticket: param.ticket
@ -336,7 +335,7 @@ pve_start: function(callback) {
start_vnc_viewer(result.data); start_vnc_viewer(result.data);
}, },
failure: function(msg) { failure: function(msg) {
console.log("ERROR: " + msg); UI.pve_show_msg('noVNC_status_error', msg, 1);
} }
}); });
}, },
@ -585,7 +584,6 @@ addMouseHandlers: function() {
// Read form control compatible setting from cookie // Read form control compatible setting from cookie
getSetting: function(name) { getSetting: function(name) {
console.log("GET: " + name);
var val, ctrl = $D('noVNC_' + name); var val, ctrl = $D('noVNC_' + name);
val = WebUtil.readSetting(name); val = WebUtil.readSetting(name);
if (val !== null && ctrl.type === 'checkbox') { if (val !== null && ctrl.type === 'checkbox') {