nlvmi/web/nlvmi.js

107 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-08-15 13:50:00 +02:00
function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
2018-08-12 15:09:47 +02:00
function dropdown(i,e) {
document.getElementById(i).innerHTML = e;
document.getElementById(i +'h').value = e;
if (i == "serverbutton") {
console.log("here");
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: "serverbuttoni="+e,
success: function(response) {
document.getElementById('cdromdiv').innerHTML = response;
},
});
console.log("a");
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: "serverbuttona="+e,
success: function(response) {
document.getElementById('drive1div').innerHTML = response;
},
});
console.log("b");
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: "serverbuttonb="+e,
success: function(response) {
document.getElementById('drive2div').innerHTML = response;
},
});
console.log("c");
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: "serverbuttonc="+e,
success: function(response) {
document.getElementById('drive3div').innerHTML = response;
},
});
}
2018-08-12 15:09:47 +02:00
}
2018-08-13 16:49:49 +02:00
function post(path, params, method) {
method = method || "post";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
$('#confirm-delete').on('click', '.btn-ok', function(e) {
var $modalDiv = $('#confirm-detele'.delegateTarget);
var vmname = $(this).data('deleteName');
var vmid = $(this).data('deleteVm');
post('?', {deletevm: vmid,deletename: vmname});
});
$('#confirm-delete').on('show.bs.modal', function(e) {
var data = $(e.relatedTarget).data();
$('.title', this).text(data.deleteVm);
document.getElementById('modaltext2').innerHTML = data.deleteText;
$('.btn-ok', this).data({'deleteName': data.deleteName,'deleteVm': data.deleteVm});
});
2018-08-15 13:50:00 +02:00
function submitbutton(formid){
data = $('#'+ formid).serialize();
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: data,
success: function(response) {
if (response != "success"){
window.alert('Failure!\n'+ response);
} else {
window.location.href = "";
}
},
});
}