ordersprinter/webapp/elements/tse.js

91 lines
2.6 KiB
JavaScript

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";
doAjax("POST","php/contenthandler.php?module=tse&command=tsecmd",data,instance.handleTseAnswer.bind(instance),null,true);
});
$("#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;
}
} else if (request == "exportdownload") {
// like windows.location.href, but with poszt data
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;
doAjax("POST","php/contenthandler.php?module=tse&command=tsecmd",data,instance.handleTseAnswer.bind(instance),null,true);
}
});
};
this.handleTseAnswer = function(answer) {
if (answer.status != "OK") {
var txt = $(this.outputelem).val();
$(this.outputelem).val(txt + "\n\nERROR: " + answer.msg);
} else {
var txt = $(this.outputelem).val();
$(this.outputelem).val(txt + "\n\nAnswer: " + answer.msg);
}
};
}