seitime-frappe/frappe/templates/print_formats/standard_macros.html
Anand Doshi 0a9a654ccd [fix] avoid overlapping text and breaking row text in wkhtmltopdf output
- Disable header row repeat for webkit browsers
- Avoid page break within td > div
2015-09-08 12:59:42 +05:30

134 lines
4.3 KiB
HTML

{% macro render_field(df, doc) -%}
{%- if df.fieldtype=="Table" -%}
{{ render_table(df, doc) }}
{%- elif df.fieldtype=="HTML" -%}
<div>{{ frappe.render_template(df.options, {"doc": doc}) or "" }}</div>
{%- elif df.fieldtype in ("Text", "Text Editor", "Code") -%}
{{ render_text_field(df, doc) }}
{%- else -%}
{{ render_field_with_label(df, doc) }}
{%- endif -%}
{%- endmacro -%}
{%- macro render_table(df, doc) -%}
{%- set table_meta = frappe.get_meta(df.options) -%}
{%- set data = doc.get(df.fieldname)[df.start:df.end] -%}
{%- if doc.print_templates and
doc.print_templates.get(df.fieldname) -%}
{% include doc.print_templates[df.fieldname] %}
{%- else -%}
{%- if data -%}
{%- set visible_columns = get_visible_columns(doc.get(df.fieldname),
table_meta, df) -%}
<div>
<table class="table table-bordered table-condensed">
<thead>
<tr>
<th style="width: 40px">Sr</th>
{% for tdf in visible_columns %}
<th style="width: {{ get_width(tdf) }}px;" class="{{ get_align_class(tdf.fieldtype) }}">
{{ _(tdf.label) }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for d in data %}
<tr>
<td>{{ d.idx }}</td>
{% for tdf in visible_columns %}
<td class="{{ get_align_class(tdf.fieldtype) }}">
<div>{{ print_value(tdf, d, doc) }}</div></td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
{%- macro render_field_with_label(df, doc) -%}
<div class="row">
<div class="col-xs-5 text-right">
{% if df.fieldtype not in ("Image","HTML") and
doc.get(df.fieldname) != None %}
<label>{{ _(df.label) }}</label>
{% endif %}
</div>
<div class="col-xs-7 {{ get_align_class(df.fieldtype) }}">
{% if doc.get(df.fieldname) != None -%}
{{ print_value(df, doc) }}{% endif %}
</div>
</div>
{%- endmacro -%}
{%- macro render_text_field(df, doc) -%}
{%- if doc.get(df.fieldname) != None -%}
<div style="padding: 10px 0px">
{%- if df.fieldtype in ("Text", "Code") %}<label>{{ _(df.label) }}</label>{%- endif %}
{%- if df.fieldtype=="Code" %}
<pre>{{ doc.get(df.fieldname) }}</pre>
{% else -%}
{{ doc.get_formatted(df.fieldname, parent_doc or doc) }}
{% endif -%}
</div>
{%- endif -%}
{%- endmacro -%}
{%- macro print_value(df, doc, meta, parent_doc=None) -%}
{% if doc.print_templates and
doc.print_templates.get(df.fieldname) %}
{% include doc.print_templates[df.fieldname] %}
{% elif df.fieldtype=="Check" %}
<i class="{{ 'icon-check' if doc[df.fieldname] else 'icon-check-empty' }}"></i>
{% elif df.fieldtype=="Image" %}
<img src="{{ doc[doc.meta.get_field(df.fieldname).options] }}" class="img-responsive">
{% elif df.fieldtype=="HTML" %}
{{ frappe.render_template(df.options, {"doc":doc}) }}
{% else %}
{{ doc.get_formatted(df.fieldname, parent_doc or doc) }}
{% endif %}
{%- endmacro %}
{% macro get_width(df) -%}
{%- if df.print_width -%}{{ (df.print_width|str).replace("px", "") }}
{%- elif df.fieldtype in ("Int", "Check", "Float", "Currency") -%}{{ 80 }}
{%- else -%}{{ 150 }}{% endif -%}
{%- endmacro %}
{% macro get_align_class(fieldtype) %}
{%- if fieldtype in ("Int", "Check", "Float", "Currency") -%}{{ "text-right" }}
{%- else -%}{{ "" }}
{%- endif -%}
{% endmacro %}
{%- macro add_header(page_num, max_pages, doc, letter_head, no_letterhead) -%}
{% if letter_head and not no_letterhead %}
<div class="letter-head">{{ letter_head }}</div>
{% endif %}
{% if doc.print_heading_template %}
{{ frappe.render_template(doc.print_heading_template, {"doc":doc}) }}
{% else %}
<div class="print-heading">
<h2>{{ doc.select_print_heading or (doc.print_heading if doc.print_heading != None
else _(doc.doctype)) }}<br>
<small>{{ doc.sub_heading if doc.sub_heading != None
else doc.name }}</small>
</h2>
</div>
{% endif %}
{%- if doc.meta.is_submittable and doc.docstatus==0-%}
<div class="text-center">
<h4 style="margin: 0px;">{{ _("DRAFT") }}</h4>
</div>
{%- endif -%}
{%- if doc.meta.is_submittable and doc.docstatus==2-%}
<div class="text-center">
<h4 style="margin: 0px;">{{ _("CANCELLED") }}</h4>
</div>
{%- endif -%}
{% if max_pages > 1 %}
<p class="text-right">{{ _("Page #{0} of {1}").format(page_num, max_pages) }}</p>
{% endif %}
{%- endmacro -%}