131 lines
4.2 KiB
JavaScript
131 lines
4.2 KiB
JavaScript
import { showError } from "@nextcloud/dialogs";
|
|
import { baseUrl, checkSelectPurJs, LoadDT, showDone } from "../modules/mainFunction.mjs";
|
|
import { updateDB } from "../modules/ajaxRequest.mjs";
|
|
|
|
export class ClientGroupFacturation {
|
|
|
|
/**
|
|
*
|
|
* @param myresp instantiate client group facturation object
|
|
*/
|
|
constructor(myresp) {
|
|
this.id = myresp.id;
|
|
this.clientGroupFacturationName = ((myresp.group_facturation_name.length === 0) ? '-' : myresp.group_facturation_name);
|
|
}
|
|
|
|
/**
|
|
* Get datatable row for a client group facturation
|
|
*/
|
|
getDTRow() {
|
|
let clientGroupFacturationRow = [
|
|
'<div>' + this.id + '</div>',
|
|
'<div class="editable" data-table="client_group_facturation" data-column="group_facturation_name" data-id="' + this.id + '">' + this.clientGroupFacturationName + '</div>',
|
|
'<div data-modifier="clientGroupFacturation" data-id=' + this.id + ' data-table="client_group_facturation" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>'
|
|
];
|
|
|
|
return clientGroupFacturationRow;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} clientGroupFacturationDatatable
|
|
*/
|
|
static loadClientGroupFacturationDatatable(clientGroupFacturationDatatable) {
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open('PROPFIND', baseUrl + '/client/getClientGroupFacturations', true);
|
|
oReq.setRequestHeader("Content-Type", "application/json");
|
|
oReq.onload = function(e){
|
|
if (this.status == 200) {
|
|
LoadDT(clientGroupFacturationDatatable, JSON.parse(this.response), ClientGroupFacturation);
|
|
}else{
|
|
showError(this.response);
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
|
|
static getClientGroupFacturations(callback){
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open('PROPFIND', baseUrl + '/client/getClientGroupFacturations', true);
|
|
oReq.setRequestHeader("Content-Type", "application/json");
|
|
oReq.onload = function(e){
|
|
if (this.status == 200) {
|
|
callback(JSON.parse(this.response));
|
|
}else{
|
|
showError(this.response);
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} lid
|
|
*/
|
|
static loadClientGroupFacturationListToSelect(e){
|
|
ClientGroupFacturation.getClientGroupFacturations(response => {
|
|
|
|
var selectElement = document.createElement("select");
|
|
selectElement.dataset.current = e.target.dataset.current;
|
|
selectElement.dataset.id = e.target.dataset.id;
|
|
selectElement.dataset.old = e.target.innerHTML;
|
|
|
|
selectElement.addEventListener("change", el=>{
|
|
if(el.target.value != 0){
|
|
updateDB(el.target.parentElement.dataset.table,
|
|
el.target.parentElement.dataset.column,
|
|
el.target.value,
|
|
el.target.parentElement.dataset.id
|
|
);
|
|
|
|
// location.reload();
|
|
|
|
var parentElement = el.target.parentElement
|
|
parentElement.innerHTML = el.target.options[el.target.selectedIndex].text;
|
|
parentElement.dataset.current = el.target.value;
|
|
}else{
|
|
var parentElement = el.target.parentElement
|
|
parentElement.innerHTML = el.target.dataset.old
|
|
}
|
|
});
|
|
|
|
var option = document.createElement("option");
|
|
option.value = 0;
|
|
option.text = t('gestion', 'Cancel');
|
|
selectElement.appendChild(option);
|
|
|
|
JSON.parse(response).forEach(myresp => {
|
|
var txt = document.createElement("textarea");
|
|
txt.innerHTML = myresp.group_facturation_name;
|
|
var option = document.createElement("option");
|
|
option.value = myresp.id;
|
|
option.text = txt.value;
|
|
selectElement.appendChild(option);
|
|
});
|
|
|
|
checkSelectPurJs(selectElement);
|
|
|
|
e.target.innerHTML = ''
|
|
e.target.appendChild(selectElement);
|
|
});
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} dt
|
|
*/
|
|
static createDefaultClientGroupFacturation(dt) {
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open('POST', baseUrl + '/client/createDefaultClientGroupFacturation', true);
|
|
oReq.onload = function(e){
|
|
if (this.status == 200) {
|
|
showDone()
|
|
ClientGroupFacturation.loadClientGroupFacturationDatatable(dt);
|
|
}else{
|
|
showError(this.response);
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
}
|