62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
import { showError } from "@nextcloud/dialogs";
|
|
import { LoadDT, baseUrl, showDone } from "../modules/mainFunction.mjs";
|
|
|
|
export class Bibliotheque {
|
|
|
|
/**
|
|
*
|
|
* @param myresp instantiate client object
|
|
*/
|
|
constructor(myresp) {
|
|
this.id = myresp.id;
|
|
this.contenu = ((myresp.contenu.length === 0) ? '-' : myresp.contenu);
|
|
}
|
|
|
|
/**
|
|
* Get datatable row for biblio
|
|
*/
|
|
getDTRow() {
|
|
let myrow = [
|
|
'<div>' + this.id + '</div>',
|
|
'<div class="editable" data-table="bibliotheque" data-column="contenu" data-id="' + this.id + '">' + this.contenu + '</div>',
|
|
'<div data-modifier="bibliotheque" data-id=' + this.id + ' data-table="bibliotheque" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>'
|
|
];
|
|
return myrow;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} biblioDT
|
|
*/
|
|
static loadBibliothequeDT(biblioDT) {
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open('PROPFIND', baseUrl + '/getBibliotheques', true);
|
|
oReq.setRequestHeader("Content-Type", "application/json");
|
|
oReq.onload = function(e){
|
|
if (this.status == 200) {
|
|
LoadDT(biblioDT, JSON.parse(this.response), Bibliotheque);
|
|
}else{
|
|
showError(this.response);
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} dt
|
|
*/
|
|
static newBibliotheque(dt) {
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open('POST', baseUrl + '/bibliotheque/insert', true);
|
|
oReq.onload = function(e){
|
|
if (this.status == 200) {
|
|
showDone()
|
|
Bibliotheque.loadBibliothequeDT(dt);
|
|
}else{
|
|
showError(this.response);
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
} |