nlvmi/web/nlvmi.js

92 lines
2.6 KiB
JavaScript

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;
}
function dropdown(i,e) {
document.getElementById(i).innerHTML = e;
document.getElementById(i +'h').value = e;
if (i == "serverbutton") {
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: "serverbuttoni="+ e,
success: function(response) {
document.getElementById('drivesdiv').innerHTML = response;
},
});
}
}
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 dname = $(this).data('deleteName');
var did = $(this).data('deleteId');
var delwhat = $(this).data('deleteWhat');
post('?', {delwhat: delwhat,deleteid: did,deletename: dname});
});
$('#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({'deleteWhat': data.deleteWhat,'deleteName': data.deleteName,'deleteId': data.deleteId});
});
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 = "";
}
},
});
}
function arrow(dir, id){
data = "&neworder="+ dir +"&vid="+ id;
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: data,
success: function(response) {
if (response != "success"){
window.alert('Failure!\n' + response);
} else {
window.location.href = "";
}
},
});
}