import { showError } from "@nextcloud/dialogs";
import { baseUrl, cur, LoadDT, showDone } from "../modules/mainFunction.mjs";
export class Article {
/**
*
* @param myresp instantiate client object
*/
constructor(myresp) {
this.id = myresp.id;
this.reference = ((myresp.reference.length === 0) ? '-' : myresp.reference);
this.description = ((myresp.description.length === 0) ? '-' : myresp.description);
this.prix_unitaire = ((myresp.prix_unitaire.length === 0) ? 0 : myresp.prix_unitaire);
}
/**
* Get datatable row for an item
*/
getDTRow() {
let myrow = [
'
' + this.id + '
',
'' + this.reference + '
',
'' + this.description + '
',
'' + cur.format(this.prix_unitaire) + '
',
''
];
return myrow;
}
/**
*
* @param {*} articleDT
*/
static loadArticleDT(articleDT) {
var oReq = new XMLHttpRequest();
oReq.open('PROPFIND', baseUrl + '/getArticles', true);
oReq.setRequestHeader("Content-Type", "application/json");
oReq.onload = function(e){
if (this.status == 200) {
LoadDT(articleDT, JSON.parse(this.response), Article);
}else{
showError(this.response);
}
};
oReq.send();
}
/**
*
* @param {*} dt
*/
static newArticle(dt) {
var oReq = new XMLHttpRequest();
oReq.open('POST', baseUrl + '/article/insert', true);
oReq.onload = function(e){
if (this.status == 200) {
showDone()
Article.loadArticleDT(dt);
}else{
showError(this.response);
}
};
oReq.send();
}
}