2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 17:34:04 +00:00
books/client/desk/tablepage.js

71 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-03-05 16:45:21 +00:00
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 13:31:22 +00:00
super({title: `${meta.label || meta.name}`, hasRoute: true});
2018-03-09 13:00:51 +00:00
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 13:31:22 +00:00
this.tableWrapper = frappe.ui.add('div', 'table-page-wrapper', this.body);
2018-03-05 16:45:21 +00:00
this.doctype = doctype;
this.fullPage = true;
2018-03-09 13:00:51 +00:00
this.fitlerButton.addEventListener('click', async () => {
2018-03-08 13:31:22 +00:00
const formModal = await frappe.desk.showFormModal('FilterSelector');
formModal.form.once('apply-filters', () => {
formModal.hide();
this.run();
})
});
}
2018-03-05 16:45:21 +00:00
async show(params) {
super.show();
2018-03-08 13:31:22 +00:00
if (!this.filterSelector) {
this.filterSelector = await frappe.getSingle('FilterSelector');
this.filterSelector.reset(this.doctype);
}
2018-03-27 13:55:26 +00:00
if (frappe.params && frappe.params.filters) {
2018-03-26 08:53:46 +00:00
this.filterSelector.setFilters(frappe.params.filters);
2018-03-09 13:00:51 +00:00
}
2018-03-26 08:53:46 +00:00
frappe.params = null;
2018-03-09 13:00:51 +00:00
2018-03-05 16:45:21 +00:00
if (!this.modelTable) {
2018-03-08 13:31:22 +00:00
this.modelTable = new ModelTable({
doctype: this.doctype,
parent: this.tableWrapper,
2018-03-26 08:53:46 +00:00
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 13:31:22 +00:00
});
2018-03-05 16:45:21 +00:00
}
2018-03-08 13:31:22 +00:00
this.run();
}
async run() {
2018-03-09 13:00:51 +00:00
this.displayFilters();
2018-03-26 08:53:46 +00:00
this.data = await frappe.db.getAll({
2018-03-05 16:45:21 +00:00
doctype: this.doctype,
fields: ['*'],
2018-03-08 13:31:22 +00:00
filters: this.filterSelector.getFilters(),
2018-03-05 16:45:21 +00:00
start: this.start,
limit: 500
});
2018-03-26 08:53:46 +00:00
this.modelTable.refresh(this.data);
2018-03-05 16:45:21 +00:00
}
2018-03-09 13:00:51 +00:00
displayFilters() {
this.fitlerButton.textContent = this.filterSelector.getText();
}
2018-03-05 16:45:21 +00:00
}