From 267b3bb0cc89632207fb3e5810f41f4cd19dc206 Mon Sep 17 00:00:00 2001 From: KanchanChauhan Date: Tue, 25 Oct 2016 11:26:04 +0530 Subject: [PATCH] [WIP] Option to align field in Print Format Builder (#2109) --- .../print_format_builder.js | 56 +++++++++++++++++++ .../print_format_builder_field.html | 9 ++- .../print_format_builder_section.html | 2 +- .../print_formats/standard_macros.html | 19 ++++--- 4 files changed, 76 insertions(+), 10 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 0574dfa184..998f643f67 100644 --- a/frappe/print/page/print_format_builder/print_format_builder.js +++ b/frappe/print/page/print_format_builder/print_format_builder.js @@ -198,6 +198,7 @@ frappe.PrintFormatBuilder = Class.extend({ this.setup_sortable(); this.setup_add_section(); this.setup_edit_heading(); + this.setup_field_settings(); }, prepare_data: function() { this.print_heading_template = null; @@ -423,6 +424,50 @@ frappe.PrintFormatBuilder = Class.extend({ return false; }); }, + setup_field_settings: function() { + var me = this; + this.page.main.on("click", ".field-settings", function() { + var field = $(this).parent(); + + // new dialog + var d = new frappe.ui.Dialog({ + title: "Set Properties", + fields: [ + { + label:__("Label"), + fieldname:"label", + fieldtype:"Data" + }, + { + label: __("Align Value"), + fieldname: "align", + fieldtype: "Select", + options: [{'label': __('Left'), 'value': 'left'}, {'label': __('Right'), 'value': 'right'}] + }, + ], + }); + + d.set_value('label', field.attr("data-label")); + + d.set_primary_action(__("Update"), function() { + field.attr('data-align', d.get_value('align')); + field.attr('data-label', d.get_value('label')); + field.find('.field-label').html(d.get_value('label')); + d.hide(); + }); + + // set current value + if(field.attr('data-align')) { + d.set_value('align', field.attr('data-align')); + } else { + d.set_value('align', 'left'); + } + + d.show(); + + return false; + }); + }, update_columns_in_section: function(section, no_of_columns, new_no_of_columns) { var col_size = 12 / new_no_of_columns, me = this, @@ -645,10 +690,21 @@ frappe.PrintFormatBuilder = Class.extend({ $(this).find(".print-format-builder-field").each(function() { var $this = $(this), fieldtype = $this.attr("data-fieldtype"), + align = $this.attr('data-align'), + label = $this.attr('data-label'), df = { fieldname: $this.attr("data-fieldname"), print_hide: 0 }; + + if(align) { + df.align = align; + } + + if(label) { + df.label = label; + } + if(fieldtype==="Table") { // append the user selected columns to visible_columns var columns = $this.attr("data-columns").split(","); 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 299cfa2a39..67988bf842 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 @@ -2,12 +2,17 @@ {% if(field.print_hide) { %}style="background-color: #F7FAFC; color: #8D99A6;" title="{{ __("Hidden") }}"{% } %} data-fieldname="{%= field.fieldname %}" - data-label="{%= field.label %}" + data-label="{{ field.label }}" + + {% if field.align %}data-align="{{ field.align }}"{% endif %} data-fieldtype="{%= field.fieldtype %}" {% if(field.fieldtype==="Table") { %} data-columns="{%= me.get_visible_columns_string(field) %}" data-doctype="{%= field.options %}" {% } %}> + + {% if(field.fieldtype==="Custom HTML") { %}
@@ -15,7 +20,7 @@
{%= field.options || me.get_no_content() %}
{% } else { %} - {%= field.label %} + {{ field.label }} {% if(field.fieldtype==="Table") { %} ({%= __("Table") %})
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 d3aa7cff75..f5a96faede 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,7 +1,7 @@