2024-12-16 17:24:37 +03:00

110 lines
4.2 KiB
JavaScript

import { generateUrl } from "@nextcloud/router";
import { baseUrl, LoadDT, showDone } from "../modules/mainFunction.mjs";
import { showError } from "@nextcloud/dialogs";
export class Trajet {
/**
* Trajet object
* @param myresp instantiate trajet object
*/
constructor(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.did = ((myresp.id_depart == null || myresp.id_depart.length === 0) ? '-' : myresp.id_depart);
this.aid = ((myresp.id_arrivee == null || myresp.id_arrivee.length === 0) ? '-' : myresp.id_arrivee);
this.nom_lieu_depart = ((myresp.nom_lieu_depart == null || myresp.nom_lieu_depart.length === 0) ? '-' : myresp.nom_lieu_depart);
this.nom_lieu_arrivee = ((myresp.nom_lieu_arrivee == null || myresp.nom_lieu_arrivee.length === 0) ? '-' : myresp.nom_lieu_arrivee);
this.depart_cnom = ((myresp.depart_cnom == null || myresp.depart_cnom.length === 0) ? '-' : myresp.depart_cnom);
this.depart_cprenoms = ((myresp.depart_cprenoms == null || myresp.depart_cprenoms.length === 0) ? '-' : myresp.depart_cprenoms);
this.arrivee_cnom = ((myresp.arrivee_cnom == null || myresp.arrivee_cnom.length === 0) ? '-' : myresp.arrivee_cnom);
this.arrivee_cprenoms = ((myresp.arrivee_cprenoms == null || myresp.arrivee_cprenoms.length === 0) ? '-' : myresp.arrivee_cprenoms);
this.distance = ((myresp.distance == null) ? '-' : myresp.distance);
this.annee = ((myresp.annee == null || myresp.annee.length === 0) ? '-' : myresp.annee);
this.mois = ((myresp.mois == null || myresp.mois.length === 0) ? '-' : Trajet.monthToText(myresp.mois));
this.baseUrl = generateUrl(`/apps/gestion/trajet/${this.id}/details`);
this.thanato = ((myresp.nom_thanato == null && myresp.prenom_thanato == null) ? '-' : myresp.nom_thanato+' '+myresp.prenom_thanato);
}
/**undefined
* Get datatable row for a trajet
*/
getDTRow() {
let myrow = [
'<div>' + this.user_id + '</div>',
'<div data-table="trajet" data-column="id_thanato" data-id="' + this.id + '" style="display:inline">' + this.thanato + '</div>',
'<div data-table="trajet" data-column="annee" data-id="' + this.id + '" style="display:inline">' + this.annee + '</div>',
'<div data-table="trajet" data-column="mois" data-id="' + this.id + '" style="display:inline">' + this.mois + '</div>',
'<div data-table="trajet" data-column="distance" data-id="' + this.id + '" style="display:inline">' + this.distance + 'km</div>',
'<div style="display:inline-block;margin-right:0px;width:80%;"><a href="'+ this.baseUrl +'"><button>Voir details</button></a></div><div data-modifier="trajet" data-id=' + this.id + ' data-table="trajet" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>'
];
return myrow;
}
static loadTrajetDT(trajetDT) {
var oReq = new XMLHttpRequest();
oReq.open('PROPFIND', baseUrl + '/getTrajets', true);
oReq.setRequestHeader("Content-Type", "application/json");
oReq.onload = function(e){
if (this.status == 200) {
LoadDT(trajetDT, JSON.parse(this.response), Trajet);
// Devis.loadDevisList();
// configuration(checkAutoIncrement);
}else{
showError(this.response);
}
};
oReq.send();
}
static monthToText(month) {
switch (parseInt(month)) {
case 1:
return 'JANVIER';
case 2:
return 'FEVRIER';
case 3:
return 'MARS';
case 4:
return 'AVRIL';
case 5:
return 'MAI';
case 6:
return 'JUIN';
case 7:
return 'JUILLET';
case 8:
return 'AOUT';
case 9:
return 'SEPTEMBRE';
case 10:
return 'OCTOBRE';
case 11:
return 'NOVEMBRE';
case 12:
return 'DECEMBRE';
}
}
/**
*
* @param {*} dt
*/
static newTrajet(dt) {
var oReq = new XMLHttpRequest();
oReq.open('POST', baseUrl + '/trajet/insert', true);
oReq.onload = function(e){
if (this.status == 200) {
showDone()
Trajet.loadTrajetDT(dt);
}else{
showError(this.response);
}
};
oReq.send();
}
}