/**
*
*/
function Client (id,name,url,remoteaccesscode,basicAuthUser,basicAuthPassword,remark) {
this.id = id;
this.name = name;
this.url = url;
this.remoteaccesscode = remoteaccesscode;
this.basicAuthUser = basicAuthUser;
this.basicAuthPassword = basicAuthPassword;
this.remark = remark;
}
/**
* Display the parameters of a client as an HTML form.
*
* @returns {String}
*/
Client.prototype.showSettings = function() {
var txt = "";
if (this.id == "new") {
txt += "
";
txt += "
";
txt += "
";
txt += "
";
txt += "
";
txt += "
";
txt += "
";
txt += "
";
} else {
txt += "
";
txt += "
";
txt += "
";
txt += "
";
txt += "
";
txt += "
";
txt += "
";
txt += " ";
txt += "
";
}
return txt;
};
/**
* Bind the action buttons (create new client, delete or change clients settings) to the
* functions that are responsible for its execution.
*/
Client.prototype.handleactions = function() {
var self = this;
$("#changeClient_" + this.id).off("click").on("click", function (e) {
e.stopImmediatePropagation();
e.preventDefault();
var data = self.getData(this.id.split("_")[1]);
doAjax("POST","php/clients.php?command=changeclient",data,self.handleactionresult,"Kommunikationsfehler");
});
$("#deleteClient_" + this.id).off("click").on("click", function (e) {
e.stopImmediatePropagation();
e.preventDefault();
var data = self.getData(this.id.split("_")[1]);
doAjax("POST","php/clients.php?command=deleteclient",data,self.handleactionresult,"Kommunikationsfehler");
});
$("#createNewClient").off("click").on("click", function (e) {
e.stopImmediatePropagation();
e.preventDefault();
var data = self.getData("new");
doAjax("POST","php/clients.php?command=createclient",data,self.handleactionresult,"Kommunikationsfehler");
});
}
/**
* Read the parameters of an instance from the web UI and add the "id" to the data set.
*
* @param id id of the client (is used also in the id of the html input fields)
* @returns an object that contains the data in a format that can be handled by the PHP client methods
*/
Client.prototype.getData = function(id) {
var data = {
id:id,
name:$("#client_name_" + id).val(),
url:$("#client_url_" + id).val(),
code:$("#client_remoteaccesscode_" + id).val(),
basicauthuser:$("#client_basicAuthUser_" + id).val(),
basicauthpass:$("#client_basicAuthPassword_" + id).val(),
remark:$("#client_remark_" + id).val()
};
return data;
}
/**
* Handle the answer of an AJAX call to create, change or delete a client
* @param answer
*/
Client.prototype.handleactionresult = function(answer) {
if (answer.status[0] == 1) {
reloadPage(window.location.href);
} else {
alert("Fehler: " + answer.status[1]);
}
}