added feature to add print formats to reports using john resig's microtemplates
This commit is contained in:
parent
6ef0b2f2bb
commit
99734d82d3
4 changed files with 51 additions and 9 deletions
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
"public/css/tag-it.css",
|
||||
"public/css/bootstrap.css",
|
||||
"public/css/bootstrap-responsive.css",
|
||||
"public/css/font-awesome.css",
|
||||
"public/css/desk.css",
|
||||
"public/css/appframe.css",
|
||||
|
|
@ -51,6 +50,7 @@
|
|||
"public/js/lib/center_image.js",
|
||||
"public/js/lib/bootstrap.min.js",
|
||||
"public/js/lib/nprogress.js",
|
||||
"public/js/lib/microtemplate.js",
|
||||
"public/js/lib/beautify-html.js",
|
||||
"public/js/lib/moment/moment.min.js",
|
||||
"public/js/lib/moment/moment-timezone.min.js",
|
||||
|
|
|
|||
|
|
@ -247,5 +247,14 @@ frappe.utils = {
|
|||
var dataURL = canvas.toDataURL("image/jpeg");
|
||||
setTimeout(function() { callback(dataURL); }, 10 );
|
||||
}
|
||||
},
|
||||
|
||||
with_print_template: function(fn) {
|
||||
if(!frappe.print_template) {
|
||||
$.get("/assets/frappe/html/print_template.html?q=4",
|
||||
function(html) { frappe.print_template = html; fn(); });
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -107,8 +107,9 @@ frappe.views.QueryReport = Class.extend({
|
|||
},
|
||||
callback: function(r) {
|
||||
me.appframe.set_title(__("Query Report")+": " + __(me.report_name));
|
||||
frappe.dom.eval(r.message || "");
|
||||
frappe.dom.eval(r.message.script || "");
|
||||
me.setup_filters();
|
||||
me.setup_html_format(r.message.html_format);
|
||||
me.refresh();
|
||||
}
|
||||
});
|
||||
|
|
@ -124,6 +125,33 @@ frappe.views.QueryReport = Class.extend({
|
|||
this.wrapper.find(".no-report-area").html(msg).toggle(true);
|
||||
}
|
||||
},
|
||||
setup_html_format: function(html_format) {
|
||||
var me = this;
|
||||
if(html_format) {
|
||||
this.appframe.add_primary_action(__('Print'), function() {
|
||||
if(!me.data) {
|
||||
msgprint(__("Run the report first"));
|
||||
return;
|
||||
}
|
||||
frappe.utils.with_print_template(function() {
|
||||
var data = [];
|
||||
$.each(me.data, function(i, d) {
|
||||
var newd = {}; data.push(newd);
|
||||
$.each(d, function(k, v) {
|
||||
newd[k.replace(/ /g, "_").toLowerCase()] = v; });
|
||||
});
|
||||
var content = tmpl.render(html_format, {data: data, filters:me.get_values(), report:me});
|
||||
|
||||
var html = $.format(frappe.print_template, [
|
||||
__(me.report_name), content]);
|
||||
var w = window.open();
|
||||
w.document.write(html);
|
||||
w.document.close();
|
||||
})
|
||||
}, "icon-print");
|
||||
|
||||
}
|
||||
},
|
||||
setup_filters: function() {
|
||||
this.clear_filters();
|
||||
var me = this;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ from __future__ import unicode_literals
|
|||
|
||||
import frappe
|
||||
import os, json
|
||||
import types
|
||||
|
||||
from frappe import _
|
||||
from frappe.modules import scrub, get_module_path
|
||||
|
|
@ -31,11 +30,16 @@ def get_script(report_name):
|
|||
module_path = get_module_path(module)
|
||||
report_folder = os.path.join(module_path, "report", scrub(report.name))
|
||||
script_path = os.path.join(report_folder, scrub(report.name) + ".js")
|
||||
print_path = os.path.join(report_folder, scrub(report.name) + ".html")
|
||||
|
||||
script = None
|
||||
script, html_format = None, None
|
||||
if os.path.exists(script_path):
|
||||
with open(script_path, "r") as script:
|
||||
script = script.read()
|
||||
with open(script_path, "r") as f:
|
||||
script = f.read()
|
||||
|
||||
if os.path.exists(print_path):
|
||||
with open(print_path, "r") as f:
|
||||
html_format = f.read()
|
||||
|
||||
if not script and report.javascript:
|
||||
script = report.javascript
|
||||
|
|
@ -47,7 +51,10 @@ def get_script(report_name):
|
|||
if frappe.lang != "en":
|
||||
frappe.response["__messages"] = frappe.get_lang_dict("report", report_name)
|
||||
|
||||
return script
|
||||
return {
|
||||
"script": script,
|
||||
"html_format": html_format
|
||||
}
|
||||
|
||||
@frappe.whitelist()
|
||||
def run(report_name, filters=()):
|
||||
|
|
@ -148,8 +155,6 @@ def get_linked_doctypes(columns):
|
|||
|
||||
def get_user_match_filters(doctypes, ref_doctype):
|
||||
match_filters = {}
|
||||
doctypes_meta = {}
|
||||
tables = []
|
||||
|
||||
for dt in doctypes:
|
||||
match_filters.update(frappe.widgets.reportview.build_match_conditions(dt, False))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue