ordersprinter/webapp/elements/tse.js

90 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2020-11-19 23:14:48 +01:00
function TSE() {
this.outputelem = null;
this.getTseParams = function() {
var tseurl = $("#tseurl").val();
var tsepass = $("#tsepass").val();
var tseclientid = $("#tseclientid").val();
var tsepin = $("#tsepin").val();
var tsepuk = $("#tsepuk").val();
var tsecredseed = $("#tsecredseed").val();
var data = {
url: tseurl,
pass: tsepass,
clientid: tseclientid,
pin: tsepin,
puk: tsepuk,
credseed: tsecredseed
};
return data;
};
this.binding = function(outputelem) {
var instance = this;
this.outputelem = outputelem;
$("#dotsesetup").off("click").on("click", function (e) {
e.stopImmediatePropagation();
e.preventDefault();
var data = instance.getTseParams();
data["request"]= "setup";
2020-11-19 23:15:07 +01:00
doAjax("POST","php/contenthandler.php?module=tse&command=tsecmd",data,instance.tseAnswerToOutputTextArea.bind(instance),null,true);
2020-11-19 23:14:48 +01:00
});
$("#submittsecmd").off("click").on("click", function (e) {
e.stopImmediatePropagation();
e.preventDefault();
var request = $("#tsecmdsel").val();
if (request == "decom") {
var answer = confirm("TSE wirklich stillegen?");
if (!answer) {
return;
}
2020-11-19 23:15:07 +01:00
}
if (request == "exportdownload") {
// like windows.location.href, but with post data
2020-11-19 23:14:48 +01:00
var tseData = instance.getTseParams();
var dataToTransfer = {
pass: tseData.pass,
pin: tseData.pin.split(","),
puk: tseData.puk.split(","),
clientid: "nothing",
cmd: "exportdownload"
};
var dataToTransferJson = JSON.stringify(dataToTransfer);
var encodedDataToTransfer = "data=" + window.btoa(dataToTransferJson);
var url = tseData.url + "/admin";
$.post(url,encodedDataToTransfer, function(data, status){
alert("Data received: " + data);
$( "body" ).html(data);
})
.fail(function(xhr, status, error) {
var msg = xhr.responseText;
alert("Fehler beim Export-Aufruf");
});
// TODO: it always ends in the fail state (maybe wrong content sent?)
alert("Nach Post");
} else {
$(instance.outputelem).val('Command: ' + request);
var data = instance.getTseParams();
data["request"]= request;
2020-11-19 23:15:07 +01:00
doAjax("POST","php/contenthandler.php?module=tse&command=tsecmd",data,instance.tseAnswerToOutputTextArea.bind(instance),null,true);
2020-11-19 23:14:48 +01:00
}
});
};
2020-11-19 23:15:07 +01:00
this.tseAnswerToOutputTextArea = function(answer) {
var existingText = $(this.outputelem).val();
if (answer.status == "OK") {
$(this.outputelem).val(existingText + "\n\nResult: " + answer.msg);
2020-11-19 23:14:48 +01:00
} else {
2020-11-19 23:15:07 +01:00
$(this.outputelem).val(existingText + "\n\nERROR: " + answer.msg);
2020-11-19 23:14:48 +01:00
}
};
}