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.tseAnswerToOutputTextArea.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; } } if (request == "exportdownload") { // like windows.location.href, but with post 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.tseAnswerToOutputTextArea.bind(instance),null,true); } }); }; this.tseAnswerToOutputTextArea = function(answer) { var existingText = $(this.outputelem).val(); if (answer.status == "OK") { $(this.outputelem).val(existingText + "\n\nResult: " + answer.msg); } else { $(this.outputelem).val(existingText + "\n\nERROR: " + answer.msg); } }; }