From 87b3816cf4150c4d7df52439296b9a9d829e498d Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 10 Oct 2016 16:16:52 +0530 Subject: [PATCH] [fixes] print format cleanup, options for alignment and print from web form (#2159) * [fixes] print format cleanup, options for alignment and print from web form * [print-format] select module for export --- .../doctype/print_format/print_format.js | 21 ++-- .../doctype/print_format/print_format.json | 115 +++++++++++++++++- .../doctype/print_format/print_format.py | 6 +- .../print_format_builder.js | 51 +++++--- .../print_format_builder_section.html | 3 +- frappe/public/css/common.css | 3 + frappe/public/js/frappe/form/print.js | 3 +- frappe/public/js/frappe/ui/messages.js | 17 ++- frappe/public/less/common.less | 4 + frappe/templates/generators/web_form.html | 7 ++ frappe/templates/print_formats/standard.html | 12 +- .../print_formats/standard_macros.html | 8 +- frappe/website/doctype/web_form/web_form.json | 30 ++++- frappe/www/print.py | 34 ++++-- 14 files changed, 258 insertions(+), 56 deletions(-) diff --git a/frappe/print/doctype/print_format/print_format.js b/frappe/print/doctype/print_format/print_format.js index e6a99f146f..aba08102c7 100644 --- a/frappe/print/doctype/print_format/print_format.js +++ b/frappe/print/doctype/print_format/print_format.js @@ -15,6 +15,14 @@ frappe.ui.form.on("Print Format", "refresh", function(frm) { } if(!frm.is_new()) { + frm.add_custom_button(__("Edit Format"), function() { + if(!frm.doc.doc_type) { + msgprint(__("Please select DocType first")); + return; + } + frappe.set_route("print-format-builder", frm.doc.name); + }); + frm.add_custom_button(__("Make Default"), function() { frappe.call({ method: "frappe.print.doctype.print_format.print_format.make_default", @@ -22,17 +30,6 @@ frappe.ui.form.on("Print Format", "refresh", function(frm) { name: frm.doc.name } }) - }) - } -}); - -frappe.ui.form.on("Print Format", "edit_format", function(frm) { - if(!frm.doc.doc_type) { - msgprint(__("Please select DocType first")); - return; + }); } - frappe.route_options = { - print_format: frm - }; - frappe.set_route("print-format-builder"); }); diff --git a/frappe/print/doctype/print_format/print_format.json b/frappe/print/doctype/print_format/print_format.json index f4338d525a..a8e202f71e 100644 --- a/frappe/print/doctype/print_format/print_format.json +++ b/frappe/print/doctype/print_format/print_format.json @@ -8,11 +8,14 @@ "custom": 0, "docstatus": 0, "doctype": "DocType", + "editable_grid": 0, + "engine": "InnoDB", "fields": [ { "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "description": "", "fieldname": "doc_type", "fieldtype": "Link", @@ -39,6 +42,34 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, + "fieldname": "module", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Module", + "length": 0, + "no_copy": 0, + "options": "Module Def", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, "fieldname": "disabled", "fieldtype": "Check", "hidden": 0, @@ -63,6 +94,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "column_break_3", "fieldtype": "Column Break", "hidden": 0, @@ -86,6 +118,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "default": "No", "fieldname": "standard", "fieldtype": "Select", @@ -114,6 +147,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "custom_format", "fieldtype": "Check", "hidden": 0, @@ -139,6 +173,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "depends_on": "custom_format", "fieldname": "section_break_6", "fieldtype": "Section Break", @@ -163,6 +198,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "default": "Server", "depends_on": "custom_format", "description": "", @@ -191,6 +227,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "depends_on": "custom_format", "fieldname": "html", "fieldtype": "Code", @@ -219,6 +256,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "depends_on": "eval:!doc.custom_format", "fieldname": "section_break_9", "fieldtype": "Section Break", @@ -227,6 +265,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, + "label": "Style Settings", "length": 0, "no_copy": 0, "permlevel": 0, @@ -244,15 +283,70 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "depends_on": "eval:!doc.custom_format", - "fieldname": "edit_format", - "fieldtype": "Button", + "columns": 0, + "default": "1", + "fieldname": "align_labels_left", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Align Labels to the Left", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "1", + "fieldname": "show_section_headings", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Show Section Headings", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "1", + "fieldname": "line_breaks", + "fieldtype": "Check", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, - "label": "Edit Format", + "label": "Show Line Breaks after Sections", "length": 0, "no_copy": 0, "permlevel": 0, @@ -270,6 +364,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "column_break_11", "fieldtype": "Column Break", "hidden": 0, @@ -294,6 +389,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "default": "Default", "depends_on": "eval:!doc.custom_format", "fieldname": "font", @@ -322,6 +418,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "css_section", "fieldtype": "Section Break", "hidden": 0, @@ -346,6 +443,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "css", "fieldtype": "Code", "hidden": 0, @@ -371,6 +469,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "custom_html_help", "fieldtype": "HTML", "hidden": 0, @@ -397,6 +496,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "depends_on": "custom_format", "fieldname": "section_break_13", "fieldtype": "Section Break", @@ -422,6 +522,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "depends_on": "custom_format", "fieldname": "print_format_help", "fieldtype": "HTML", @@ -448,6 +549,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "format_data", "fieldtype": "Code", "hidden": 1, @@ -473,6 +575,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "print_format_builder", "fieldtype": "Check", "hidden": 1, @@ -499,13 +602,14 @@ "hide_toolbar": 0, "icon": "icon-print", "idx": 1, + "image_view": 0, "in_create": 0, "in_dialog": 0, "is_submittable": 0, "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-05-05 17:15:45.522931", + "modified": "2016-10-10 06:06:34.530193", "modified_by": "Administrator", "module": "Print", "name": "Print Format", @@ -521,6 +625,7 @@ "export": 0, "if_owner": 0, "import": 0, + "is_custom": 0, "permlevel": 0, "print": 1, "read": 1, diff --git a/frappe/print/doctype/print_format/print_format.py b/frappe/print/doctype/print_format/print_format.py index 195659b5f7..2eb2af5285 100644 --- a/frappe/print/doctype/print_format/print_format.py +++ b/frappe/print/doctype/print_format/print_format.py @@ -23,6 +23,9 @@ class PrintFormat(Document): self.extract_images() + if not self.module: + self.module = frappe.db.get_value('DocType', self.doc_type, 'module') + if self.html: validate_template(self.html) @@ -46,8 +49,7 @@ class PrintFormat(Document): def export_doc(self): # export from frappe.modules.utils import export_module_json - export_module_json(self, self.standard == 'Yes', - frappe.db.get_value("DocType", self.doc_type, "module")) + export_module_json(self, self.standard == 'Yes', self.module) def on_trash(self): if self.doc_type: 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 21fc6e8fc3..b74b335d7a 100644 --- a/frappe/print/page/print_format_builder/print_format_builder.js +++ b/frappe/print/page/print_format_builder/print_format_builder.js @@ -4,7 +4,13 @@ frappe.pages['print-format-builder'].on_page_load = function(wrapper) { } frappe.pages['print-format-builder'].on_page_show = function(wrapper) { - if(frappe.route_options) { + var route = frappe.get_route(); + if(route.length>1) { + frappe.model.with_doc('Print Format', route[1], function() { + frappe.print_format_builder.print_format = frappe.get_doc('Print Format', route[1]); + frappe.print_format_builder.refresh(); + }); + } else if(frappe.route_options) { if(frappe.route_options.make_new) { var doctype = frappe.route_options.doctype; var name = frappe.route_options.name; @@ -157,9 +163,10 @@ frappe.PrintFormatBuilder = Class.extend({ me.print_format = null; me.refresh(); }, true); - me.page.add_menu_item(__("Edit Properties"), function() { + me.page.clear_inner_toolbar(); + me.page.add_inner_button(__("Edit Properties"), function() { frappe.set_route("Form", "Print Format", me.print_format.name); - }, true); + }); }); }, setup_sidebar: function() { @@ -217,8 +224,9 @@ frappe.PrintFormatBuilder = Class.extend({ section.no_of_columns += 1; } - var set_section = function() { + var set_section = function(label) { section = me.get_new_section(); + if(label) section.label = label; column = null; me.layout_data.push(section); } @@ -239,7 +247,7 @@ frappe.PrintFormatBuilder = Class.extend({ } if(f.fieldtype==="Section Break") { - set_section(); + set_section(f.label); } else if(f.fieldtype==="Column Break") { set_column(); @@ -265,7 +273,7 @@ frappe.PrintFormatBuilder = Class.extend({ }); }, get_new_section: function() { - return {columns: [], no_of_columns: 0}; + return {columns: [], no_of_columns: 0, label:''}; }, get_new_column: function() { return {fields: []} @@ -330,7 +338,8 @@ frappe.PrintFormatBuilder = Class.extend({ if(fieldname==="_custom_html") { var field = me.get_custom_html_field(); } else { - var field = frappe.meta.get_docfield(me.print_format.doc_type, fieldname); + var field = frappe.meta.get_docfield(me.print_format.doc_type, + fieldname); } $item.replaceWith(frappe.render_template("print_format_builder_field", @@ -355,6 +364,7 @@ frappe.PrintFormatBuilder = Class.extend({ this.page.main.on("click", ".section-settings", function() { var section = $(this).parent().parent(); var no_of_columns = section.find(".section-column").length; + var label = section.attr('data-label'); // new dialog var d = new frappe.ui.Dialog({ @@ -364,7 +374,13 @@ frappe.PrintFormatBuilder = Class.extend({ label:__("No of Columns"), fieldname:"no_of_columns", fieldtype:"Select", - options: ["1", "2", "3"], + options: ["1", "2", "3", "4"], + }, + { + label:__("Section Heading"), + fieldname:"label", + fieldtype:"Data", + description: __('Will only be shown if section headings are enabled') }, { label: __("Remove Section"), @@ -383,12 +399,16 @@ frappe.PrintFormatBuilder = Class.extend({ }); d.set_input("no_of_columns", no_of_columns + ""); + d.set_input("label", label || ""); d.set_primary_action(__("Update"), function() { // resize number of columns me.update_columns_in_section(section, no_of_columns, cint(d.get_value("no_of_columns"))); + section.attr('data-label', d.get_value('label') || ''); + section.find('.section-label').html(d.get_value('label') || ''); + d.hide(); }); @@ -486,16 +506,16 @@ frappe.PrintFormatBuilder = Class.extend({ }); var $body = $(d.body); - - + + var doc_fields = frappe.get_meta(doctype).fields; var docfields_by_name = {}; - + // docfields by fieldname $.each(doc_fields, function(j, f) { if(f) docfields_by_name[f.fieldname] = f; }) - + // add field which are in column_names first to preserve order var fields = []; $.each(column_names, function(i, v) { @@ -505,7 +525,7 @@ frappe.PrintFormatBuilder = Class.extend({ }) // add remaining fields $.each(doc_fields, function(j, f) { - if (f && !in_list(column_names, f.fieldname) + if (f && !in_list(column_names, f.fieldname) && !in_list(["Section Break", "Column Break"], f.fieldtype) && f.label) { fields.push(f); } @@ -612,7 +632,8 @@ frappe.PrintFormatBuilder = Class.extend({ // add pages this.page.main.find(".print-format-builder-section").each(function() { - data.push({"fieldtype": "Section Break"}); + var section = {"fieldtype": "Section Break", 'label': $(this).attr('data-label') || '' }; + data.push(section); $(this).find(".print-format-builder-column").each(function() { data.push({"fieldtype": "Column Break"}); $(this).find(".print-format-builder-field").each(function() { @@ -656,7 +677,7 @@ frappe.PrintFormatBuilder = Class.extend({ }, callback: function(r) { me.print_format = r.message; - msgprint(__("Saved")); + frappe.show_alert({message: __("Saved"), indicator: 'green'}); } }); } diff --git a/frappe/print/page/print_format_builder/print_format_builder_section.html b/frappe/print/page/print_format_builder/print_format_builder_section.html index 43e5da221a..d3aa7cff75 100644 --- a/frappe/print/page/print_format_builder/print_format_builder_section.html +++ b/frappe/print/page/print_format_builder/print_format_builder_section.html @@ -1,9 +1,10 @@ -