From 1210ab33dc059560fce70b540471e33e1e520c74 Mon Sep 17 00:00:00 2001 From: Corentin Forler Date: Wed, 18 Sep 2024 10:16:24 +0200 Subject: [PATCH 1/2] feat(print_format): Add checkbox to hide label --- .../print_format_builder/print_format_builder.js | 13 +++++++++++++ .../print_format_builder_field.html | 1 + frappe/templates/print_formats/standard_macros.html | 12 ++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/frappe/printing/page/print_format_builder/print_format_builder.js b/frappe/printing/page/print_format_builder/print_format_builder.js index 1cb90dbc3d..d85c56c6e9 100644 --- a/frappe/printing/page/print_format_builder/print_format_builder.js +++ b/frappe/printing/page/print_format_builder/print_format_builder.js @@ -484,6 +484,11 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder { { label: __("Right", null, "alignment"), value: "right" }, ], }, + { + label: __("Hide Label"), + fieldname: "nolabel", + fieldtype: "Check", + }, { label: __("Remove Field"), fieldtype: "Button", @@ -497,10 +502,12 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder { }); d.set_value("label", field.attr("data-label")); + d.set_value("nolabel", +field.attr("data-nolabel")); d.set_primary_action(__("Update"), function () { field.attr("data-align", d.get_value("align")); field.attr("data-label", d.get_value("label")); + field.attr("data-nolabel", +d.get_value("nolabel")); field.find(".field-label").html(d.get_value("label")); d.hide(); }); @@ -608,6 +615,7 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder { var parent = $(this).parents(".print-format-builder-field:first"), doctype = parent.attr("data-doctype"), label = parent.attr("data-label"), + nolabel = parent.attr("data-nolabel"), columns = parent.attr("data-columns").split(","), column_names = $.map(columns, function (v) { return v.split("|")[0]; @@ -792,6 +800,7 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder { fieldtype = $this.attr("data-fieldtype"), align = $this.attr("data-align"), label = $this.attr("data-label"), + nolabel = $this.attr("data-nolabel"), df = { fieldname: $this.attr("data-fieldname"), print_hide: 0, @@ -805,6 +814,10 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder { df.label = label; } + if (+nolabel) { + df.nolabel = 1; + } + if (fieldtype === "Table") { // append the user selected columns to visible_columns var columns = $this.attr("data-columns").split(","); diff --git a/frappe/printing/page/print_format_builder/print_format_builder_field.html b/frappe/printing/page/print_format_builder/print_format_builder_field.html index 67bc4d3e53..78f5bef24f 100644 --- a/frappe/printing/page/print_format_builder/print_format_builder_field.html +++ b/frappe/printing/page/print_format_builder/print_format_builder_field.html @@ -3,6 +3,7 @@ title="{{ __("Hidden") }}"{% } %} data-fieldname="{%= field.fieldname %}" data-label="{{ __(field.label, context=field.parent) }}" + data-nolabel="{%= field.nolabel ? 1 : 0 %}" {% if field.align %}data-align="{{ field.align }}"{% endif %} data-fieldtype="{%= field.fieldtype %}" diff --git a/frappe/templates/print_formats/standard_macros.html b/frappe/templates/print_formats/standard_macros.html index 273ce65a13..4ae0617eba 100644 --- a/frappe/templates/print_formats/standard_macros.html +++ b/frappe/templates/print_formats/standard_macros.html @@ -88,7 +88,13 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}" }) -%} {% set render_field = doc.get(df.fieldname) != 0 if df.fieldtype == "Check" else doc.get(df.fieldname) != None %} - {% if render_field %} + {% if render_field and df.nolabel %} +
+
+ {{ _(print_value(df, doc)) }} +
+
+ {% elif render_field %}
@@ -107,7 +113,9 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}" {%- macro render_text_field(df, doc) -%} {%- if doc.get(df.fieldname) != None -%}
- {%- if df.fieldtype in ("Text", "Code", "Long Text") %}{%- endif %} + {%- if df.fieldtype in ("Text", "Code", "Long Text") and not df.nolabel -%} + + {%- endif %} {%- if df.fieldtype=="Code" %}
{{ doc.get(df.fieldname)|e }}
{% else -%} From e97eb26bd1b67ce60a715b500579a017090dc6a5 Mon Sep 17 00:00:00 2001 From: Corentin Forler <10946971+cogk@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:59:18 +0200 Subject: [PATCH 2/2] chore: Use `cint` instead of unary plus operator --- .../page/print_format_builder/print_format_builder.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/printing/page/print_format_builder/print_format_builder.js b/frappe/printing/page/print_format_builder/print_format_builder.js index d85c56c6e9..5238d0d556 100644 --- a/frappe/printing/page/print_format_builder/print_format_builder.js +++ b/frappe/printing/page/print_format_builder/print_format_builder.js @@ -502,12 +502,12 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder { }); d.set_value("label", field.attr("data-label")); - d.set_value("nolabel", +field.attr("data-nolabel")); + d.set_value("nolabel", field.attr("data-nolabel")); d.set_primary_action(__("Update"), function () { field.attr("data-align", d.get_value("align")); field.attr("data-label", d.get_value("label")); - field.attr("data-nolabel", +d.get_value("nolabel")); + field.attr("data-nolabel", d.get_value("nolabel")); field.find(".field-label").html(d.get_value("label")); d.hide(); }); @@ -814,7 +814,7 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder { df.label = label; } - if (+nolabel) { + if (cint(nolabel)) { df.nolabel = 1; }