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

66 lines
2.0 KiB
JavaScript

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 = [
'<div>' + this.id + '</div>',
'<div class="editable" data-table="article" data-column="reference" data-id="' + this.id + '">' + this.reference + '</div>',
'<div class="editable" data-table="article" data-column="description" data-id="' + this.id + '">' + this.description + '</div>',
'<div class="editableNumeric" data-table="article" data-column="prix_unitaire" data-id="' + this.id + '">' + cur.format(this.prix_unitaire) + '</div>',
'<div data-modifier="article" data-id=' + this.id + ' data-table="article" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>'
];
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();
}
}