THANASOFT-DV/gestion/src/js/objects/trajetdetails.mjs

111 lines
5.4 KiB
JavaScript

import { generateUrl } from "@nextcloud/router";
import { showMessage, showSuccess, showError } from "@nextcloud/dialogs";
import { baseUrl, LoadDT, showDone } from "../modules/mainFunction.mjs";
export class TrajetDetails {
/**
* Trajet object
* @param myresp instantiate trajet object
*/
constructor(myresp) {
console.log(myresp);
this.id = myresp.id;
this.user_id = myresp.user_id;
this.id_nextcloud = myresp.id_nextcloud;
this.date = ((myresp.date == null || myresp.date.length === 0) ? '-' : myresp.date);
this.lid = ((myresp.id_lieu == null || myresp.id_lieu.length === 0) ? '-' : myresp.id_lieu);
this.lieu = ((myresp.lieu == null || myresp.lieu.length === 0) ? '-' : myresp.lieu);
this.cid = ((myresp.cid == null || myresp.cid.length === 0) ? '-' : myresp.cid);
this.cnom = ((myresp.cnom == null || myresp.cnom.length === 0) ? '-' : myresp.cnom);
this.cprenoms = ((myresp.cprenoms == null || myresp.cprenoms.length === 0) ? '-' : myresp.cprenoms);
this.dnum = ((myresp.dnum == null || myresp.dnum.length === 0) ? '-' : myresp.dnum);
this.nom_defunt = ((myresp.nom_defunt == null) ? '-' : myresp.nom_defunt);
this.didnextcloud = ((myresp.didnextcloud == null || myresp.didnextcloud.length === 0) ? '-' : myresp.didnextcloud);
this.dnom = ((myresp.dnom == null || myresp.dnom.length === 0) ? '-' : myresp.dnom);
this.dprenoms = ((myresp.dprenoms == null || myresp.dprenoms.length === 0) ? '-' : myresp.dprenoms);
this.rang = ((myresp.rang == null || myresp.rang.length === 0) ? '-' : myresp.rang);
this.commentaire = ((myresp.commentaire == null || myresp.commentaire.length === 0) ? '-' : myresp.commentaire);
this.source = ((myresp.source == null || myresp.source.length === 0) ? '-' : myresp.source);
}
/**undefined
* Get datatable row for a trajet
*/
getDTRow() {
let myrow = [
'<div>' + this.user_id + '</div>',
(this.source.toLowerCase() == 'devis' || this.source.toLowerCase() == 'h2f')?('<div>'+this.rang+'</div>'):'<div class="editableNumber" data-table="ligne_trajet" data-column="rang" data-id="' + this.id + '" style="display:inline">' + this.rang + '</div>',
(this.source.toLowerCase() == 'devis' || this.source.toLowerCase() == 'h2f')?('<div>'+TrajetDetails.convert_date(this.date)+'</div>'):'<input style="margin:0;padding:0;" class="inputDate" type="date" value=' + this.date + ' data-table="ligne_trajet" data-column="date" data-id="' + this.id + '"/>',
(this.source.toLowerCase() == 'devis' || this.source.toLowerCase() == 'h2f')?('<div>'+this.cprenoms+' '+this.cnom+'</div>'):'<div class="loadSelect_listclient"' +' data-table="ligne_trajet" data-column="id_client" data-id="' + this.id + '" data-current="' + this.cid + '">'+ this.cid + ' (' + this.cprenoms + ' ' + this.cnom + ')</div>',
(this.source.toLowerCase() == 'devis' || this.source.toLowerCase() == 'h2f')?('<div>' + this.nom_defunt + ' | <span style="font-size: 0.7rem">' + this.dprenoms + ' ' + this.dnom + '</span></div>'):('<div><span>-</span></div>'),
(this.source.toLowerCase() == 'devis' || this.source.toLowerCase() == 'h2f')?('<div>'+this.lieu+'</div>'):'<div class="loadSelect_listlieu"' +' data-table="ligne_trajet" data-column="id_lieu" data-id="' + this.id + '" data-current="' + this.lid + '">' + this.lieu + '</div>',
'<div class="editable" data-table="ligne_trajet" data-column="commentaire" data-id="' + this.id + '" style="display:inline">' + this.commentaire + '</div>',
'<div data-table="ligne_trajet" data-column="user_id" data-id="' + this.id + '" style="display:inline">' + this.didnextcloud + '</div>',
'<div style="display:inline-block;margin-right:0px"><div data-modifier="trajetdetails" data-id=' + this.id + ' data-table="ligne_trajet" class="deleteItem icon-delete"></div></div>'
];
return myrow;
}
static convert_date(date) {
const datesplit = date.split('-');
return datesplit[2]+'/'+datesplit[1]+'/'+datesplit[0];
}
static loadTrajetdetailsDT(trajetdetailsDT) {
var path_split = (location.pathname).split('/');
var idtrajet = path_split[path_split.length-2];
var oReq = new XMLHttpRequest();
oReq.open('PROPFIND', baseUrl + '/getTrajetsdetails/'+idtrajet, true);
oReq.setRequestHeader("Content-Type", "application/json");
oReq.onload = function(e){
if (this.status == 200) {
LoadDT(trajetdetailsDT, JSON.parse(this.response), TrajetDetails);
}else{
showError(this.response);
}
};
oReq.send();
}
/**
*
*/
static saveIkNextcloud() {
showMessage('Sauvegarde en cours ...');
var path_split = (location.pathname).split('/');
var idtrajet = path_split[path_split.length-2];
var oReq = new XMLHttpRequest();
oReq.open('POST', baseUrl + '/trajetdetails/save/'+idtrajet, true);
oReq.onload = function(e){
if (this.status == 200) {
showSuccess('Sauvegarde réussi.');
}else{
showError(this.response);
}
};
oReq.send();
}
/**
*
* @param {*} dt
*/
static newTrajetdetails(dt) {
var path_split = (location.pathname).split('/');
var idtrajet = path_split[path_split.length-2];
var oReq = new XMLHttpRequest();
oReq.open('POST', baseUrl + '/trajetdetails/insert/'+idtrajet, true);
oReq.onload = function(e){
if (this.status == 200) {
showDone()
TrajetDetails.loadTrajetdetailsDT(dt);
}else{
showError(this.response);
}
};
oReq.send();
}
}