2
0
mirror of https://github.com/frappe/books.git synced 2025-01-26 16:48:28 +00:00
books/client/desk/tablepage.js

71 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-03-05 22:15:21 +05:30
const Page = require('frappejs/client/view/page');
const frappe = require('frappejs');
const ModelTable = require('frappejs/client/ui/modelTable');
module.exports = class TablePage extends Page {
constructor(doctype) {
let meta = frappe.getMeta(doctype);
2018-03-08 19:01:22 +05:30
super({title: `${meta.label || meta.name}`, hasRoute: true});
2018-03-09 18:30:51 +05:30
this.filterWrapper = frappe.ui.add('div', 'filter-toolbar', this.body);
this.fitlerButton = frappe.ui.add('button', 'btn btn-sm btn-outline-secondary', this.filterWrapper, 'Set Filters');
2018-03-08 19:01:22 +05:30
this.tableWrapper = frappe.ui.add('div', 'table-page-wrapper', this.body);
2018-03-05 22:15:21 +05:30
this.doctype = doctype;
this.fullPage = true;
2018-03-09 18:30:51 +05:30
this.fitlerButton.addEventListener('click', async () => {
2018-03-08 19:01:22 +05:30
const formModal = await frappe.desk.showFormModal('FilterSelector');
formModal.form.once('apply-filters', () => {
formModal.hide();
this.run();
})
});
}
2018-03-05 22:15:21 +05:30
async show(params) {
super.show();
2018-03-08 19:01:22 +05:30
if (!this.filterSelector) {
this.filterSelector = await frappe.getSingle('FilterSelector');
this.filterSelector.reset(this.doctype);
}
2018-03-27 19:25:26 +05:30
if (frappe.params && frappe.params.filters) {
2018-03-26 14:23:46 +05:30
this.filterSelector.setFilters(frappe.params.filters);
2018-03-09 18:30:51 +05:30
}
2018-03-26 14:23:46 +05:30
frappe.params = null;
2018-03-09 18:30:51 +05:30
2018-03-05 22:15:21 +05:30
if (!this.modelTable) {
2018-03-08 19:01:22 +05:30
this.modelTable = new ModelTable({
doctype: this.doctype,
parent: this.tableWrapper,
2018-03-26 14:23:46 +05:30
layout: 'fluid',
getRowData: async (rowIndex) => {
return await frappe.getDoc(this.doctype, this.data[rowIndex].name);
},
setValue: async (control) => {
await control.handleChange();
await control.doc.update();
}
2018-03-08 19:01:22 +05:30
});
2018-03-05 22:15:21 +05:30
}
2018-03-08 19:01:22 +05:30
this.run();
}
async run() {
2018-03-09 18:30:51 +05:30
this.displayFilters();
2018-03-26 14:23:46 +05:30
this.data = await frappe.db.getAll({
2018-03-05 22:15:21 +05:30
doctype: this.doctype,
fields: ['*'],
2018-03-08 19:01:22 +05:30
filters: this.filterSelector.getFilters(),
2018-03-05 22:15:21 +05:30
start: this.start,
limit: 500
});
2018-03-26 14:23:46 +05:30
this.modelTable.refresh(this.data);
2018-03-05 22:15:21 +05:30
}
2018-03-09 18:30:51 +05:30
displayFilters() {
this.fitlerButton.textContent = this.filterSelector.getText();
}
2018-03-05 22:15:21 +05:30
}