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

47 lines
1.4 KiB
JavaScript
Raw Normal View History

const Page = require('frappejs/client/view/page');
const frappe = require('frappejs');
const nunjucks = require('nunjucks/browser/nunjucks');
nunjucks.configure({ autoescape: false });
module.exports = class PrintPage extends Page {
constructor(doctype) {
let meta = frappe.getMeta(doctype);
2018-02-22 07:36:28 +00:00
super({title: `${meta.name}`, hasRoute: true});
this.meta = meta;
this.doctype = doctype;
this.addButton(frappe._('Edit'), 'primary', () => {
frappe.router.setRoute('edit', this.doctype, this.name)
});
}
2018-03-05 16:45:21 +00:00
async show(params) {
super.show();
this.name = params.name;
if (this.meta.print) {
// render
this.renderTemplate();
} else {
this.renderError('No Print Settings');
}
}
async renderTemplate() {
this.printFormat = await frappe.getDoc('PrintFormat', this.meta.print.printFormat);
let doc = await frappe.getDoc(this.doctype, this.name);
let context = {doc: doc, frappe: frappe};
frappe.desk.setActiveDoc(doc);
try {
this.body.innerHTML = `<div class="print-page">${nunjucks.renderString(this.printFormat.template, context)}</div>`;
2018-02-22 07:36:28 +00:00
this.setTitle(doc.name);
if (doc.submitted) this.addTitleBadge('✓', 'Submitted');
} catch (e) {
this.renderError('Template Error', e);
throw e;
}
}
}