@@ -150,13 +150,13 @@ def handle_exception(e): | |||||
elif http_status_code==403: | elif http_status_code==403: | ||||
frappe.respond_as_web_page(_("Not Permitted"), | frappe.respond_as_web_page(_("Not Permitted"), | ||||
_("You do not have enough permissions to complete the action"), | _("You do not have enough permissions to complete the action"), | ||||
http_status_code=http_status_code, indicator_color='red', fullpage=True) | |||||
http_status_code=http_status_code, indicator_color='red') | |||||
return_as_message = True | return_as_message = True | ||||
elif http_status_code==404: | elif http_status_code==404: | ||||
frappe.respond_as_web_page(_("Not Found"), | frappe.respond_as_web_page(_("Not Found"), | ||||
_("The resource you are looking for is not available"), | _("The resource you are looking for is not available"), | ||||
http_status_code=http_status_code, indicator_color='red', fullpage=True) | |||||
http_status_code=http_status_code, indicator_color='red') | |||||
return_as_message = True | return_as_message = True | ||||
else: | else: | ||||
@@ -166,7 +166,7 @@ def handle_exception(e): | |||||
frappe.respond_as_web_page("Server Error", | frappe.respond_as_web_page("Server Error", | ||||
traceback, http_status_code=http_status_code, | traceback, http_status_code=http_status_code, | ||||
indicator_color='red', fullpage=True) | |||||
indicator_color='red') | |||||
return_as_message = True | return_as_message = True | ||||
if e.__class__ == frappe.AuthenticationError: | if e.__class__ == frappe.AuthenticationError: | ||||
@@ -179,7 +179,7 @@ def handle_exception(e): | |||||
if return_as_message: | if return_as_message: | ||||
response = frappe.website.render.render("message", | response = frappe.website.render.render("message", | ||||
http_status_code=http_status_code, fullpage=True) | |||||
http_status_code=http_status_code) | |||||
return response | return response | ||||
@@ -236,8 +236,6 @@ def load_print(bootinfo, doclist): | |||||
print_settings.doctype = ":Print Settings" | print_settings.doctype = ":Print Settings" | ||||
doclist.append(print_settings) | doclist.append(print_settings) | ||||
load_print_css(bootinfo, print_settings) | load_print_css(bootinfo, print_settings) | ||||
doclist.extend(frappe.get_all('Print Style', 'name', | |||||
dict(disabled=0), update=dict(doctype=':Print Style'))) | |||||
def load_print_css(bootinfo, print_settings): | def load_print_css(bootinfo, print_settings): | ||||
import frappe.www.printview | import frappe.www.printview | ||||
@@ -124,7 +124,7 @@ def get_data(): | |||||
{ | { | ||||
"type": "doctype", | "type": "doctype", | ||||
"name": "Deleted Document", | "name": "Deleted Document", | ||||
"label": _("Deleted Documents"), | |||||
"label": _("Deleted Documents"), | |||||
"description": _("Restore or permanently delete a document.") | "description": _("Restore or permanently delete a document.") | ||||
}, | }, | ||||
] | ] | ||||
@@ -180,6 +180,11 @@ def get_data(): | |||||
"name": "Print Format", | "name": "Print Format", | ||||
"description": _("Customized HTML Templates for printing transactions.") | "description": _("Customized HTML Templates for printing transactions.") | ||||
}, | }, | ||||
{ | |||||
"type": "doctype", | |||||
"name": "Print Style", | |||||
"description": _("Stylesheets for Print Formats") | |||||
}, | |||||
] | ] | ||||
}, | }, | ||||
{ | { | ||||
@@ -56,8 +56,9 @@ def sync_for(app_name, force=0, sync_everything = False, verbose=False, reset_pe | |||||
def get_doc_files(files, start_path, force=0, sync_everything = False, verbose=False): | def get_doc_files(files, start_path, force=0, sync_everything = False, verbose=False): | ||||
"""walk and sync all doctypes and pages""" | """walk and sync all doctypes and pages""" | ||||
document_type = ['doctype', 'page', 'report', 'print_format', 'website_theme', 'web_form', 'email_alert'] | |||||
for doctype in document_type: | |||||
document_types = ['doctype', 'page', 'report', 'print_format', | |||||
'website_theme', 'web_form', 'email_alert', 'print_style'] | |||||
for doctype in document_types: | |||||
doctype_path = os.path.join(start_path, doctype) | doctype_path = os.path.join(start_path, doctype) | ||||
if os.path.exists(doctype_path): | if os.path.exists(doctype_path): | ||||
@@ -23,8 +23,8 @@ class TestPrintFormat(unittest.TestCase): | |||||
def test_print_user_modern(self): | def test_print_user_modern(self): | ||||
print_html = self.test_print_user("Modern") | print_html = self.test_print_user("Modern") | ||||
self.assertTrue("/* modern format: don't remove this line */" in print_html) | |||||
self.assertTrue("/* modern format: for-test */" in print_html) | |||||
def test_print_user_classic(self): | def test_print_user_classic(self): | ||||
print_html = self.test_print_user("Classic") | print_html = self.test_print_user("Classic") | ||||
self.assertTrue("font-family: serif;" in print_html) | |||||
self.assertTrue("/* classic format: for-test */" in print_html) |
@@ -2,8 +2,15 @@ | |||||
// For license information, please see license.txt | // For license information, please see license.txt | ||||
frappe.ui.form.on("Print Settings", "print_style", function (frm) { | frappe.ui.form.on("Print Settings", "print_style", function (frm) { | ||||
frm.get_field("print_style_preview").html('<img src="/assets/frappe/images/help/print-style-' + | |||||
frm.doc.print_style.toLowerCase() + '.png" class="img-responsive">'); | |||||
frappe.db.get_value('Print Style', frm.doc.print_style, 'preview').then((r) => { | |||||
if(r.message.preview) { | |||||
frm.get_field("print_style_preview").$wrapper.html( | |||||
`<img src="${r.message.preview}" class="img-responsive">`); | |||||
} else { | |||||
frm.get_field("print_style_preview").$wrapper.html( | |||||
`<p style="margin: 60px 0px" class="text-center text-muted">${__("No Preview")}</p>`); | |||||
} | |||||
}); | |||||
}); | }); | ||||
frappe.ui.form.on("Print Settings", "onload", function (frm) { | frappe.ui.form.on("Print Settings", "onload", function (frm) { | ||||
@@ -3,6 +3,13 @@ | |||||
frappe.ui.form.on('Print Style', { | frappe.ui.form.on('Print Style', { | ||||
refresh: function(frm) { | refresh: function(frm) { | ||||
/* update in local */ | |||||
if (!frm.is_new() && !locals[':Print Style'][frm.doc.name]) { | |||||
locals[':Print Style'][frm.doc.name] = frm.doc; | |||||
} | |||||
frm.add_custom_button(__('Print Settings'), () => { | |||||
frappe.set_route('Form', 'Print Settings'); | |||||
}) | |||||
} | } | ||||
}); | }); |
@@ -12,12 +12,9 @@ QUnit.test("test: Print Style", function (assert) { | |||||
// insert a new Print Style | // insert a new Print Style | ||||
() => frappe.tests.make('Print Style', [ | () => frappe.tests.make('Print Style', [ | ||||
// values to be set | // values to be set | ||||
{key: 'value'} | |||||
{print_style_name: 'Test Print Style'}, | |||||
{css: '/* some css value */'} | |||||
]), | ]), | ||||
() => { | |||||
assert.equal(cur_frm.doc.key, 'value'); | |||||
}, | |||||
() => done() | |||||
]); | ]); | ||||
}); | }); |
@@ -1,14 +1,15 @@ | |||||
{ | { | ||||
"creation": "2017-08-17 02:00:12.502887", | "creation": "2017-08-17 02:00:12.502887", | ||||
"css": "/*\n\tcommon style for whole page\n\tThis should include:\n\t+ page size related settings\n\t+ font family settings\n\t+ line spacing settings\n*/\n.print-format div,\n.print-format span,\n.print-format td,\n.print-format h1,\n.print-format h2,\n.print-format h3,\n.print-format h4 {\n\tfont-family: Georgia, serif;\n}\n", | |||||
"css": "/*\n\tcommon style for whole page\n\tThis should include:\n\t+ page size related settings\n\t+ font family settings\n\t+ line spacing settings\n*/\n.print-format div,\n.print-format span,\n.print-format td,\n.print-format h1,\n.print-format h2,\n.print-format h3,\n.print-format h4 {\n\tfont-family: Georgia, serif;\n}\n\n/* classic format: for-test */", | |||||
"disabled": 0, | "disabled": 0, | ||||
"docstatus": 0, | "docstatus": 0, | ||||
"doctype": "Print Style", | "doctype": "Print Style", | ||||
"idx": 1, | "idx": 1, | ||||
"modified": "2017-08-17 05:02:24.128436", | |||||
"modified": "2017-08-18 00:43:48.675833", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"name": "Classic", | "name": "Classic", | ||||
"owner": "Administrator", | "owner": "Administrator", | ||||
"preview": "/assets/frappe/images/help/print-style-classic.png", | |||||
"print_style_name": "Classic", | "print_style_name": "Classic", | ||||
"standard": 1 | "standard": 1 | ||||
} | } |
@@ -1,14 +1,15 @@ | |||||
{ | { | ||||
"creation": "2017-08-17 02:16:58.060374", | "creation": "2017-08-17 02:16:58.060374", | ||||
"css": ".print-heading {\n\ttext-align: right;\n\ttext-transform: uppercase;\n\tcolor: #666;\n\tpadding-bottom: 20px;\n\tmargin-bottom: 20px;\n\tborder-bottom: 1px solid #d1d8dd;\n}\n\n.print-heading h2 {\n\tfont-size: 24px;\n}\n\n.print-format th {\n\tbackground-color: #eee !important;\n\tborder-bottom: 0px !important;\n}\n\n/* modern format: don't remove this line */", | |||||
"css": ".print-heading {\n\ttext-align: right;\n\ttext-transform: uppercase;\n\tcolor: #666;\n\tpadding-bottom: 20px;\n\tmargin-bottom: 20px;\n\tborder-bottom: 1px solid #d1d8dd;\n}\n\n.print-heading h2 {\n\tfont-size: 24px;\n}\n\n.print-format th {\n\tbackground-color: #eee !important;\n\tborder-bottom: 0px !important;\n}\n\n/* modern format: for-test */", | |||||
"disabled": 0, | "disabled": 0, | ||||
"docstatus": 0, | "docstatus": 0, | ||||
"doctype": "Print Style", | "doctype": "Print Style", | ||||
"idx": 0, | "idx": 0, | ||||
"modified": "2017-08-17 05:02:05.043839", | |||||
"modified": "2017-08-18 00:44:07.438147", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"name": "Modern", | "name": "Modern", | ||||
"owner": "Administrator", | "owner": "Administrator", | ||||
"preview": "/assets/frappe/images/help/print-style-modern.png", | |||||
"print_style_name": "Modern", | "print_style_name": "Modern", | ||||
"standard": 1 | "standard": 1 | ||||
} | } |
@@ -5,10 +5,11 @@ | |||||
"docstatus": 0, | "docstatus": 0, | ||||
"doctype": "Print Style", | "doctype": "Print Style", | ||||
"idx": 0, | "idx": 0, | ||||
"modified": "2017-08-17 05:02:14.874082", | |||||
"modified": "2017-08-18 00:44:25.023898", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"name": "Monochrome", | "name": "Monochrome", | ||||
"owner": "Administrator", | "owner": "Administrator", | ||||
"preview": "/assets/frappe/images/help/print-style-monochrome.png", | |||||
"print_style_name": "Monochrome", | "print_style_name": "Monochrome", | ||||
"standard": 1 | "standard": 1 | ||||
} | } |
@@ -202,7 +202,7 @@ frappe.Application = Class.extend({ | |||||
moment.tz.add(frappe.boot.timezone_info); | moment.tz.add(frappe.boot.timezone_info); | ||||
} | } | ||||
if(frappe.boot.print_css) { | if(frappe.boot.print_css) { | ||||
frappe.dom.set_style(frappe.boot.print_css) | |||||
frappe.dom.set_style(frappe.boot.print_css, "print-style"); | |||||
} | } | ||||
frappe.user.name = frappe.boot.user.name; | frappe.user.name = frappe.boot.user.name; | ||||
} else { | } else { | ||||
@@ -38,12 +38,6 @@ frappe.ui.form.PrintPreview = Class.extend({ | |||||
me.multilingual_preview(); | me.multilingual_preview(); | ||||
}); | }); | ||||
this.print_style_select = this.wrapper | |||||
.find('.print-style-select') | |||||
.on("change", function () { | |||||
me.multilingual_preview(); | |||||
}); | |||||
//On selection of language get code and pass it to preview method | //On selection of language get code and pass it to preview method | ||||
this.language_sel = this.wrapper | this.language_sel = this.wrapper | ||||
.find(".languages") | .find(".languages") | ||||
@@ -70,13 +64,11 @@ frappe.ui.form.PrintPreview = Class.extend({ | |||||
this.wrapper.find(".btn-download-pdf").click(function () { | this.wrapper.find(".btn-download-pdf").click(function () { | ||||
if (!me.is_old_style()) { | if (!me.is_old_style()) { | ||||
let print_style = me.selected_style(); | |||||
var w = window.open( | var w = window.open( | ||||
frappe.urllib.get_full_url("/api/method/frappe.utils.print_format.download_pdf?" | frappe.urllib.get_full_url("/api/method/frappe.utils.print_format.download_pdf?" | ||||
+ "doctype=" + encodeURIComponent(me.frm.doc.doctype) | + "doctype=" + encodeURIComponent(me.frm.doc.doctype) | ||||
+ "&name=" + encodeURIComponent(me.frm.doc.name) | + "&name=" + encodeURIComponent(me.frm.doc.name) | ||||
+ "&format=" + me.selected_format() | + "&format=" + me.selected_format() | ||||
+ (print_style ? '&style=' + print_style : '') | |||||
+ "&no_letterhead=" + (me.with_letterhead() ? "0" : "1") | + "&no_letterhead=" + (me.with_letterhead() ? "0" : "1") | ||||
+ (me.lang_code ? ("&_lang=" + me.lang_code) : "")) | + (me.lang_code ? ("&_lang=" + me.lang_code) : "")) | ||||
); | ); | ||||
@@ -114,7 +106,8 @@ frappe.ui.form.PrintPreview = Class.extend({ | |||||
this.lang_code = this.frm.doc.language; | this.lang_code = this.frm.doc.language; | ||||
// Load all languages in the field | // Load all languages in the field | ||||
this.language_sel.empty() | this.language_sel.empty() | ||||
.add_options(frappe.get_languages()) | |||||
.add_options([{value:'', label:__("Select Language...")}] | |||||
.concat(frappe.get_languages())) | |||||
.val(this.lang_code); | .val(this.lang_code); | ||||
this.preview(); | this.preview(); | ||||
}, | }, | ||||
@@ -155,13 +148,11 @@ frappe.ui.form.PrintPreview = Class.extend({ | |||||
}, | }, | ||||
new_page_preview: function (printit) { | new_page_preview: function (printit) { | ||||
var me = this; | var me = this; | ||||
let print_style = me.selected_style(); | |||||
var w = window.open(frappe.urllib.get_full_url("/printview?" | var w = window.open(frappe.urllib.get_full_url("/printview?" | ||||
+ "doctype=" + encodeURIComponent(me.frm.doc.doctype) | + "doctype=" + encodeURIComponent(me.frm.doc.doctype) | ||||
+ "&name=" + encodeURIComponent(me.frm.doc.name) | + "&name=" + encodeURIComponent(me.frm.doc.name) | ||||
+ (printit ? "&trigger_print=1" : "") | + (printit ? "&trigger_print=1" : "") | ||||
+ "&format=" + me.selected_format() | + "&format=" + me.selected_format() | ||||
+ (print_style ? '&style=' + print_style : '') | |||||
+ "&no_letterhead=" + (me.with_letterhead() ? "0" : "1") | + "&no_letterhead=" + (me.with_letterhead() ? "0" : "1") | ||||
+ (me.lang_code ? ("&_lang=" + me.lang_code) : ""))); | + (me.lang_code ? ("&_lang=" + me.lang_code) : ""))); | ||||
if (!w) { | if (!w) { | ||||
@@ -174,7 +165,6 @@ frappe.ui.form.PrintPreview = Class.extend({ | |||||
args: { | args: { | ||||
doc: this.frm.doc, | doc: this.frm.doc, | ||||
print_format: this.selected_format(), | print_format: this.selected_format(), | ||||
style: this.selected_style(), | |||||
no_letterhead: !this.with_letterhead() ? 1 : 0, | no_letterhead: !this.with_letterhead() ? 1 : 0, | ||||
_lang: this.lang_code | _lang: this.lang_code | ||||
}, | }, | ||||
@@ -202,8 +192,6 @@ frappe.ui.form.PrintPreview = Class.extend({ | |||||
}, | }, | ||||
refresh_print_options: function () { | refresh_print_options: function () { | ||||
this.print_formats = frappe.meta.get_print_formats(this.frm.doctype); | this.print_formats = frappe.meta.get_print_formats(this.frm.doctype); | ||||
this.print_style_select.empty() | |||||
.add_options([''].concat(Object.keys(locals[':Print Style'] || {}).sort())); | |||||
return this.print_sel | return this.print_sel | ||||
.empty().add_options(this.print_formats); | .empty().add_options(this.print_formats); | ||||
@@ -229,9 +217,6 @@ frappe.ui.form.PrintPreview = Class.extend({ | |||||
selected_format: function () { | selected_format: function () { | ||||
return this.print_sel.val() || this.frm.meta.default_print_format || "Standard"; | return this.print_sel.val() || this.frm.meta.default_print_format || "Standard"; | ||||
}, | }, | ||||
selected_style: function () { | |||||
return this.print_style_select.val() || ''; | |||||
}, | |||||
is_old_style: function (format) { | is_old_style: function (format) { | ||||
return this.get_print_format(format).print_format_type === "Client"; | return this.get_print_format(format).print_format_type === "Client"; | ||||
}, | }, | ||||
@@ -250,8 +235,6 @@ frappe.ui.form.PrintPreview = Class.extend({ | |||||
return this.print_letterhead.is(":checked") ? 1 : 0; | return this.print_letterhead.is(":checked") ? 1 : 0; | ||||
}, | }, | ||||
set_style: function (style) { | set_style: function (style) { | ||||
$('#print-style').remove(); | |||||
console.log(style || frappe.boot.print_css); | |||||
frappe.dom.set_style(style || frappe.boot.print_css, "print-style"); | frappe.dom.set_style(style || frappe.boot.print_css, "print-style"); | ||||
} | } | ||||
}); | }); | ||||
@@ -3,9 +3,8 @@ | |||||
<div class="col-xs-2"> | <div class="col-xs-2"> | ||||
<select class="print-preview-select input-sm form-control"></select></div> | <select class="print-preview-select input-sm form-control"></select></div> | ||||
<div class="col-xs-2"> | <div class="col-xs-2"> | ||||
<select class="print-style-select input-sm form-control"></select></div> | |||||
<div class="col-xs-2"> | |||||
<select class="languages input-sm form-control"></select></div> | |||||
<select class="languages input-sm form-control" | |||||
placeholder="{{ __("Language") }}"></select></div> | |||||
<div class="col-xs-2"> | <div class="col-xs-2"> | ||||
<div class="checkbox small" style="margin-top: 7px; margin-bottom: 0px;"> | <div class="checkbox small" style="margin-top: 7px; margin-bottom: 0px;"> | ||||
<label> | <label> | ||||
@@ -13,13 +12,15 @@ | |||||
{%= __("Letter Head") %}</label> | {%= __("Letter Head") %}</label> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<div class="col-xs-4 text-right"> | |||||
<div class="col-xs-6 text-right"> | |||||
<!-- <a class="close btn-print-close" style="margin-top: 2px; margin-left: 10px;">×</a> --> | <!-- <a class="close btn-print-close" style="margin-top: 2px; margin-left: 10px;">×</a> --> | ||||
<div class="btn-group"> | <div class="btn-group"> | ||||
<a class="btn-print-print btn-sm btn btn-default"> | <a class="btn-print-print btn-sm btn btn-default"> | ||||
<strong>{%= __("Print") %}</strong></a> | <strong>{%= __("Print") %}</strong></a> | ||||
<a class="btn-sm btn btn-default" href="#Form/Print Settings"> | |||||
{%= __("Settings...") %}</a> | |||||
<a class="btn-print-edit btn-sm btn btn-default"> | <a class="btn-print-edit btn-sm btn btn-default"> | ||||
{%= __("Customize") %}</a> | |||||
{%= __("Customize...") %}</a> | |||||
<a class="btn-print-preview btn-sm btn btn-default"> | <a class="btn-print-preview btn-sm btn btn-default"> | ||||
{%= __("Full Page") %}</a> | {%= __("Full Page") %}</a> | ||||
<a class="btn-download-pdf btn-sm btn btn-default"> | <a class="btn-download-pdf btn-sm btn btn-default"> | ||||
@@ -108,6 +108,10 @@ frappe.views.ListRenderer = Class.extend({ | |||||
add_field(this.meta.title_field); | add_field(this.meta.title_field); | ||||
} | } | ||||
if (this.meta.image_field) { | |||||
add_field(this.meta.image_field); | |||||
} | |||||
// enabled / disabled | // enabled / disabled | ||||
if (frappe.meta.has_field(this.doctype, 'enabled')) { add_field('enabled'); } | if (frappe.meta.has_field(this.doctype, 'enabled')) { add_field('enabled'); } | ||||
if (frappe.meta.has_field(this.doctype, 'disabled')) { add_field('disabled'); } | if (frappe.meta.has_field(this.doctype, 'disabled')) { add_field('disabled'); } | ||||
@@ -61,8 +61,7 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}" | |||||
{%- macro render_field_with_label(df, doc) -%} | {%- macro render_field_with_label(df, doc) -%} | ||||
<div class="row {% if df.bold %}important{% endif %} data-field" {{ fieldmeta(df) }}> | <div class="row {% if df.bold %}important{% endif %} data-field" {{ fieldmeta(df) }}> | ||||
<div class="col-xs-{{ "9" if df.fieldtype=="Check" else "5" }} | |||||
{%- if not doc._align_labels_left %} text-right{%- endif -%}"> | |||||
<div class="col-xs-{{ "9" if df.fieldtype=="Check" else "5" }}"> | |||||
{% if df.fieldtype not in ("Image","HTML","Check") and | {% if df.fieldtype not in ("Image","HTML","Check") and | ||||
doc.get(df.fieldname) != None %} | doc.get(df.fieldname) != None %} | ||||
<label>{{ _(df.label) }}</label> | <label>{{ _(df.label) }}</label> | ||||