From a5b7bff45a3e563113309e79c5af6625c07438bf Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 22 Nov 2016 11:53:11 +0530 Subject: [PATCH 1/3] [fix] check for column field dict before appending child table data field --- frappe/www/print.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frappe/www/print.py b/frappe/www/print.py index 3db4a5cf81..d9a0121df4 100644 --- a/frappe/www/print.py +++ b/frappe/www/print.py @@ -232,6 +232,11 @@ def make_layout(doc, meta, format_data=None): def get_new_section(): return {'columns': [], 'has_data': False} + def append_empty_field_dict_to_page_column(page): + """ append empty columns dict to page layout """ + if not page[-1]['columns']: + page[-1]['columns'].append({'fields': []}) + for df in format_data or meta.fields: if format_data: # embellish df with original properties @@ -263,16 +268,13 @@ def make_layout(doc, meta, format_data=None): else: # add a column if not yet added - if not page[-1]['columns']: - page[-1]['columns'].append({'fields': []}) + append_empty_field_dict_to_page_column(page) if df.fieldtype=="HTML" and df.options: doc.set(df.fieldname, True) # show this field if is_visible(df, doc) and has_value(df, doc): - if page[-1]['columns'] == []: - # if no column, add one - page[-1]['columns'].append({'fields': []}) + append_empty_field_dict_to_page_column(page) page[-1]['columns'][-1]['fields'].append(df) @@ -293,6 +295,7 @@ def make_layout(doc, meta, format_data=None): # new page, with empty section and column page = [get_new_section()] layout.append(page) + append_empty_field_dict_to_page_column(page) # continue the table in a new page df = copy.copy(df) From 8d67b991666713df3734013b8cf9e430d05558eb Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 22 Nov 2016 13:29:26 +0530 Subject: [PATCH 2/3] [hot] [fix] editing multiple CUSTOM HTML values in field --- .../print_format_builder.js | 29 ++++++++++++++----- .../print_format_builder_field.html | 4 ++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/frappe/print/page/print_format_builder/print_format_builder.js b/frappe/print/page/print_format_builder/print_format_builder.js index fac5e38589..b13ce659af 100644 --- a/frappe/print/page/print_format_builder/print_format_builder.js +++ b/frappe/print/page/print_format_builder/print_format_builder.js @@ -31,6 +31,7 @@ frappe.PrintFormatBuilder = Class.extend({ this.refresh(); }, refresh: function() { + this.custom_html_count = 0; if(!this.print_format) { this.show_start(); } else { @@ -203,7 +204,6 @@ frappe.PrintFormatBuilder = Class.extend({ prepare_data: function() { this.print_heading_template = null; this.data = JSON.parse(this.print_format.format_data || "[]"); - this.fields_dict = {}; if(!this.data.length) { // new layout this.data = this.meta.fields; @@ -224,7 +224,9 @@ frappe.PrintFormatBuilder = Class.extend({ } this.layout_data = []; - var section = null, column = null, me = this; + this.fields_dict = {}; + this.custom_html_dict = {}; + var section = null, column = null, me = this, custom_html_count = 0; // create a new placeholder for column and set // it as "column" @@ -251,7 +253,12 @@ frappe.PrintFormatBuilder = Class.extend({ // print_hide should always be false if(f.fieldname==="_custom_html") { f.label = "Custom HTML"; - f.fieldtype = "Custom HTML" + f.fieldtype = "Custom HTML"; + + // set custom html id to map data properties later + custom_html_count++; + f.custom_html_id = custom_html_count; + me.custom_html_dict[f.custom_html_id] = f } else { f = $.extend(frappe.meta.get_docfield(me.print_format.doc_type, f.fieldname) || {}, f); @@ -480,11 +487,17 @@ frappe.PrintFormatBuilder = Class.extend({ }); }, setup_html_data: function() { - // set `data` for Custom HTML fields + // set JQuery `data` for Custom HTML fields, since editing the HTML + // directly causes problem becuase of HTML reformatting + // + // this is based on a dummy attribute custom_html_id, since all custom html + // fields have the same fieldname `_custom_html` var me = this; this.page.main.find('[data-fieldtype="Custom HTML"]').each(function() { - $(this).find('.html-content') - .data('content', me.fields_dict[$(this).attr('data-fieldname')].options); + var fieldname = $(this).attr('data-fieldname'); + var content = $($(this).find('.html-content')[0]); + var html = me.custom_html_dict[parseInt(content.attr('data-custom-html-id'))].options; + content.data('content', html); }) }, update_columns_in_section: function(section, no_of_columns, new_no_of_columns) { @@ -682,7 +695,7 @@ frappe.PrintFormatBuilder = Class.extend({ d.set_input("content", content); d.set_primary_action(__("Update"), function() { - $content.data('content', d.get_value("content")); + $($content[0]).data('content', d.get_value("content")); $content.html(d.get_value("content")); d.hide(); }); @@ -744,7 +757,7 @@ frappe.PrintFormatBuilder = Class.extend({ if(fieldtype==="Custom HTML") { // custom html as HTML field df.fieldtype = "HTML"; - df.options = $this.find(".html-content").data('content'); + df.options = $($this.find(".html-content")[0]).data('content'); } data.push(df); }); diff --git a/frappe/print/page/print_format_builder/print_format_builder_field.html b/frappe/print/page/print_format_builder/print_format_builder_field.html index 33bfd0a9c6..b59c76a16d 100644 --- a/frappe/print/page/print_format_builder/print_format_builder_field.html +++ b/frappe/print/page/print_format_builder/print_format_builder_field.html @@ -20,7 +20,9 @@ {%= __("Edit HTML") %} -
+
{{ field.options || me.get_no_content() }}
{% } else { %} {{ field.label }} From fc69d03dc81e1b807c4a77ad64090097b3026f8b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 22 Nov 2016 17:46:39 +0600 Subject: [PATCH 3/3] bumped to version 7.1.18 --- frappe/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index 08ef75073b..495b94a846 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -13,7 +13,7 @@ import os, sys, importlib, inspect, json from .exceptions import * from .utils.jinja import get_jenv, get_template, render_template -__version__ = '7.1.17' +__version__ = '7.1.18' __title__ = "Frappe Framework" local = Local()