2018-01-16 06:09:17 +00:00
|
|
|
const frappe = require('frappejs');
|
2018-01-31 10:13:33 +00:00
|
|
|
const Observable = require('frappejs/utils/observable');
|
2018-01-12 12:25:07 +00:00
|
|
|
|
2018-01-31 10:13:33 +00:00
|
|
|
module.exports = class Page extends Observable {
|
2018-01-12 12:25:07 +00:00
|
|
|
constructor(title) {
|
2018-01-31 10:13:33 +00:00
|
|
|
super();
|
2018-01-12 12:25:07 +00:00
|
|
|
this.title = title;
|
|
|
|
this.make();
|
|
|
|
}
|
|
|
|
|
|
|
|
make() {
|
2018-01-23 08:00:29 +00:00
|
|
|
this.wrapper = frappe.ui.add('div', 'page hide', frappe.desk.body);
|
2018-02-08 09:38:47 +00:00
|
|
|
this.wrapper.innerHTML = `<div class="page-head hide"></div>
|
|
|
|
<div class="page-body"></div>`
|
|
|
|
this.head = this.wrapper.querySelector('.page-head');
|
|
|
|
this.body = this.wrapper.querySelector('.page-body');
|
2018-01-12 12:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
2018-01-15 11:55:31 +00:00
|
|
|
this.wrapper.classList.add('hide');
|
2018-01-12 12:25:07 +00:00
|
|
|
this.trigger('hide');
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:38:47 +00:00
|
|
|
addButton(label, cssClass, action) {
|
|
|
|
this.head.classList.remove('hide');
|
|
|
|
this.button = frappe.ui.add('button', 'btn btn-sm ' + cssClass, this.head);
|
|
|
|
this.button.innerHTML = label;
|
|
|
|
this.button.addEventListener('click', action);
|
|
|
|
return this.button;
|
|
|
|
}
|
|
|
|
|
2018-01-16 06:09:17 +00:00
|
|
|
async show(params) {
|
2018-01-12 12:25:07 +00:00
|
|
|
if (frappe.router.current_page) {
|
|
|
|
frappe.router.current_page.hide();
|
|
|
|
}
|
2018-01-15 11:55:31 +00:00
|
|
|
this.wrapper.classList.remove('hide');
|
|
|
|
this.body.classList.remove('hide');
|
|
|
|
|
|
|
|
if (this.page_error) {
|
|
|
|
this.page_error.classList.add('hide');
|
|
|
|
}
|
|
|
|
|
2018-01-12 12:25:07 +00:00
|
|
|
frappe.router.current_page = this;
|
|
|
|
document.title = this.title;
|
|
|
|
|
2018-01-16 06:09:17 +00:00
|
|
|
await this.trigger('show', params);
|
2018-01-12 12:25:07 +00:00
|
|
|
}
|
|
|
|
|
2018-02-08 09:38:47 +00:00
|
|
|
renderError(title, message) {
|
2018-01-15 11:55:31 +00:00
|
|
|
if (!this.page_error) {
|
|
|
|
this.page_error = frappe.ui.add('div', 'page-error', this.wrapper);
|
|
|
|
}
|
|
|
|
this.body.classList.add('hide');
|
|
|
|
this.page_error.classList.remove('hide');
|
2018-01-23 08:00:29 +00:00
|
|
|
this.page_error.innerHTML = `<h3 class="text-extra-muted">${title ? title : ""}</h3><p class="text-muted">${message ? message : ""}</p>`;
|
2018-01-15 11:55:31 +00:00
|
|
|
}
|
|
|
|
}
|