diff --git a/frappe/printing/doctype/letter_head/letter_head.json b/frappe/printing/doctype/letter_head/letter_head.json index f6c9def567..f723a6b489 100644 --- a/frappe/printing/doctype/letter_head/letter_head.json +++ b/frappe/printing/doctype/letter_head/letter_head.json @@ -1,4 +1,5 @@ { + "actions": [], "allow_rename": 1, "autoname": "field:letter_head_name", "creation": "2012-11-22 17:45:46", @@ -13,6 +14,9 @@ "is_default", "letter_head_image_section", "image", + "image_height", + "image_width", + "align", "header_section", "content", "footer_section", @@ -100,15 +104,34 @@ "fieldname": "footer", "fieldtype": "HTML Editor", "label": "Footer HTML" + }, + { + "default": "Left", + "fieldname": "align", + "fieldtype": "Select", + "label": "Align", + "options": "Left\nRight\nCenter" + }, + { + "fieldname": "image_height", + "fieldtype": "Float", + "label": "Image Height" + }, + { + "fieldname": "image_width", + "fieldtype": "Float", + "label": "Image Width" } ], "icon": "fa fa-font", "idx": 1, + "links": [], "max_attachments": 3, - "modified": "2019-11-11 18:46:43.375120", + "modified": "2021-10-03 14:37:58.314696", "modified_by": "Administrator", "module": "Printing", "name": "Letter Head", + "naming_rule": "By fieldname", "owner": "Administrator", "permissions": [ { diff --git a/frappe/printing/doctype/letter_head/letter_head.py b/frappe/printing/doctype/letter_head/letter_head.py index eeaef28393..67c0d236e0 100644 --- a/frappe/printing/doctype/letter_head/letter_head.py +++ b/frappe/printing/doctype/letter_head/letter_head.py @@ -2,7 +2,7 @@ # License: MIT. See LICENSE import frappe -from frappe.utils import is_image +from frappe.utils import is_image, flt from frappe.model.document import Document from frappe import _ @@ -26,7 +26,15 @@ class LetterHead(Document): def set_image(self): if self.source=='Image': if self.image and is_image(self.image): - self.content = ''.format(self.image) + self.image_width = flt(self.image_width) + self.image_height = flt(self.image_height) + dimension = 'width' if self.image_width > self.image_height else 'height' + dimension_value = self.get('image_' + dimension) + self.content = f''' +
+ {self.name} +
+ ''' frappe.msgprint(frappe._('Header HTML set from attachment {0}').format(self.image), alert = True) else: frappe.msgprint(frappe._('Please attach an image file to set HTML'), alert = True, indicator = 'orange') diff --git a/frappe/public/js/print_format_builder/LetterHeadEditor.vue b/frappe/public/js/print_format_builder/LetterHeadEditor.vue index d958a6e67a..d8db40ce2e 100644 --- a/frappe/public/js/print_format_builder/LetterHeadEditor.vue +++ b/frappe/public/js/print_format_builder/LetterHeadEditor.vue @@ -1,43 +1,172 @@ - diff --git a/frappe/public/js/print_format_builder/PrintFormat.vue b/frappe/public/js/print_format_builder/PrintFormat.vue index 74cfb84133..7163282067 100644 --- a/frappe/public/js/print_format_builder/PrintFormat.vue +++ b/frappe/public/js/print_format_builder/PrintFormat.vue @@ -32,7 +32,12 @@ @change="$set(layout, 'footer', $event)" :button-label="__('Edit Footer')" /> - + @@ -85,6 +90,10 @@ export default { sections.push(_section); } this.$set(this.layout, "sections", sections); + }, + update_letterhead_footer(val) { + this.letterhead.footer = val; + this.letterhead._dirty = true; } } }; diff --git a/frappe/public/js/print_format_builder/store.js b/frappe/public/js/print_format_builder/store.js index f72cf0c450..57c48632c8 100644 --- a/frappe/public/js/print_format_builder/store.js +++ b/frappe/public/js/print_format_builder/store.js @@ -115,9 +115,11 @@ export function getStore(print_format_name) { }) .then(() => { if (this.letterhead && this.letterhead._dirty) { - return frappe.call("frappe.client.save", { - doc: this.letterhead - }); + return frappe + .call("frappe.client.save", { + doc: this.letterhead + }) + .then(r => (this.letterhead = r.message)); } }) .then(() => this.fetch()) @@ -125,7 +127,6 @@ export function getStore(print_format_name) { }, reset_changes() { this.fetch(); - }, get_layout() { if (this.print_format) { @@ -143,7 +144,7 @@ export function getStore(print_format_name) { return create_default_layout(this.meta); }, change_letterhead(letterhead) { - frappe.db.get_doc("Letter Head", letterhead).then(doc => { + return frappe.db.get_doc("Letter Head", letterhead).then(doc => { this.letterhead = doc; }); } diff --git a/frappe/public/js/print_format_builder/utils.js b/frappe/public/js/print_format_builder/utils.js index 77d4e2a36d..6c52b2e4a4 100644 --- a/frappe/public/js/print_format_builder/utils.js +++ b/frappe/public/js/print_format_builder/utils.js @@ -94,8 +94,8 @@ export function get_table_columns(df) { typeof tf.width == "number" && tf.width < 100 ? tf.width : tf.width - ? 20 - : 10; + ? 20 + : 10; table_columns.push({ label: tf.label, fieldname: tf.fieldname, @@ -118,3 +118,13 @@ export function pluck(object, keys) { } return out; } + +export function get_image_dimensions(src) { + return new Promise(resolve => { + let img = new Image(); + img.onload = function() { + resolve({ width: this.width, height: this.height }); + }; + img.src = src; + }); +} diff --git a/frappe/templates/print_format/print_format.html b/frappe/templates/print_format/print_format.html index 7e710e8c3f..69fb50d959 100644 --- a/frappe/templates/print_format/print_format.html +++ b/frappe/templates/print_format/print_format.html @@ -13,7 +13,7 @@ - {{ header }} + {{ header or '' }} {% for section in layout.sections %}
{% if section.label %} @@ -31,6 +31,6 @@
{% endfor %} - {{ footer }} + {{ footer or '' }} diff --git a/frappe/templates/print_format/print_header.html b/frappe/templates/print_format/print_header.html index 69a5360d6f..9b1357e08c 100644 --- a/frappe/templates/print_format/print_header.html +++ b/frappe/templates/print_format/print_header.html @@ -6,7 +6,7 @@ position: fixed; top: 0; left: 0; - width: 100%; + width: {{ body_width | int }}mm; padding-top: {{ print_format.margin_top | int }}mm; padding-left: {{ print_format.margin_left | int }}mm; padding-right: {{ print_format.margin_right | int }}mm;