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 = [ '
' + this.user_id + '
', (this.source.toLowerCase() == 'devis' || this.source.toLowerCase() == 'h2f')?('
'+this.rang+'
'):'
' + this.rang + '
', (this.source.toLowerCase() == 'devis' || this.source.toLowerCase() == 'h2f')?('
'+TrajetDetails.convert_date(this.date)+'
'):'', (this.source.toLowerCase() == 'devis' || this.source.toLowerCase() == 'h2f')?('
'+this.cprenoms+' '+this.cnom+'
'):'
'+ this.cid + ' (' + this.cprenoms + ' ' + this.cnom + ')
', (this.source.toLowerCase() == 'devis' || this.source.toLowerCase() == 'h2f')?('
' + this.nom_defunt + ' | ' + this.dprenoms + ' ' + this.dnom + '
'):('
-
'), (this.source.toLowerCase() == 'devis' || this.source.toLowerCase() == 'h2f')?('
'+this.lieu+'
'):'
' + this.lieu + '
', '
' + this.commentaire + '
', '
' + this.didnextcloud + '
', '
' ]; 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(); } }