2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00
books/client/desk/listpage.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-02-08 09:38:47 +00:00
const frappe = require('frappejs');
2018-01-30 12:03:04 +00:00
const Page = require('frappejs/client/view/page');
const view = require('frappejs/client/view');
2018-02-08 09:38:47 +00:00
module.exports = class ListPage extends Page {
2018-03-05 16:45:21 +00:00
constructor(name) {
2018-02-14 16:44:50 +00:00
2018-02-19 16:41:10 +00:00
// if center column is present, list does not have its route
const hasRoute = frappe.desk.center ? false : true;
2018-02-14 16:44:50 +00:00
2018-02-19 16:41:10 +00:00
super({
2018-03-05 16:45:21 +00:00
title: frappe._("List"),
2018-02-19 16:41:10 +00:00
parent: hasRoute ? frappe.desk.body : frappe.desk.center,
hasRoute: hasRoute
});
2018-02-14 16:44:50 +00:00
2018-03-08 13:31:22 +00:00
this.name = name;
2018-03-05 16:45:21 +00:00
this.list = new (view.getListClass(name))({
doctype: name,
2018-02-19 16:41:10 +00:00
parent: this.body,
page: this
});
2018-02-14 16:44:50 +00:00
frappe.docs.on('change', (params) => {
2018-03-05 16:45:21 +00:00
if (params.doc.doctype === this.list.meta.name) {
this.list.refreshRow(params.doc);
}
2018-02-19 16:41:10 +00:00
});
}
2018-03-05 16:45:21 +00:00
async show(params) {
super.show();
2018-03-08 13:31:22 +00:00
this.setTitle(this.name===this.list.meta.name ? (this.list.meta.label || this.list.meta.name) : this.name);
2018-03-07 10:37:58 +00:00
if (frappe.desk.body.activePage && frappe.router.getRoute()[0]==='list') {
frappe.desk.body.activePage.hide();
}
2018-03-05 16:45:21 +00:00
await this.list.refresh();
}
2018-01-30 12:03:04 +00:00
}