Browse Source

[fix] Custom HTML is now a Code field in Print Format Builder, fixes #2229 (#2320)

version-14
Rushabh Mehta 8 years ago
committed by GitHub
parent
commit
9fc234e63d
2 changed files with 18 additions and 13 deletions
  1. +12
    -11
      frappe/print/page/print_format_builder/print_format_builder.js
  2. +6
    -2
      frappe/print/page/print_format_builder/print_format_builder_field.html

+ 12
- 11
frappe/print/page/print_format_builder/print_format_builder.js View File

@@ -89,8 +89,7 @@ frappe.PrintFormatBuilder = Class.extend({
var name = me.print_format_input.get_value(); var name = me.print_format_input.get_value();
if(!name) return; if(!name) return;
frappe.model.with_doc("Print Format", name, function(doc) { frappe.model.with_doc("Print Format", name, function(doc) {
me.print_format = frappe.get_doc("Print Format", name);
me.refresh();
frappe.set_route('print-format-builder', name);
}); });
}); });
}, },
@@ -446,9 +445,9 @@ frappe.PrintFormatBuilder = Class.extend({
}, },
], ],
}); });
d.set_value('label', field.attr("data-label")); d.set_value('label', field.attr("data-label"));
d.set_primary_action(__("Update"), function() { d.set_primary_action(__("Update"), function() {
field.attr('data-align', d.get_value('align')); field.attr('data-align', d.get_value('align'));
field.attr('data-label', d.get_value('label')); field.attr('data-label', d.get_value('label'));
@@ -627,7 +626,7 @@ frappe.PrintFormatBuilder = Class.extend({
return $.map(f.visible_columns, function(v) { return v.fieldname + "|" + (v.print_width || "") }).join(","); return $.map(f.visible_columns, function(v) { return v.fieldname + "|" + (v.print_width || "") }).join(",");
}, },
get_no_content: function() { get_no_content: function() {
return '<div class="text-extra-muted" data-no-content>'+__("Edit to add content")+'</div>'
return __("Edit to add content")
}, },
setup_edit_custom_html: function() { setup_edit_custom_html: function() {
var me = this; var me = this;
@@ -637,12 +636,13 @@ frappe.PrintFormatBuilder = Class.extend({
}); });
}, },
get_edit_html_dialog: function(title, label, $content) { get_edit_html_dialog: function(title, label, $content) {
var me = this;
var d = new frappe.ui.Dialog({ var d = new frappe.ui.Dialog({
title: title, title: title,
fields: [ fields: [
{ {
fieldname: "content", fieldname: "content",
fieldtype: "Text Editor",
fieldtype: "Code",
label: label label: label
}, },
{ {
@@ -657,11 +657,12 @@ frappe.PrintFormatBuilder = Class.extend({
}); });


// set existing content in input // set existing content in input
content = $content.html();
if(content.indexOf("data-no-content")!==-1) content = "";
content = $content.attr('data-html-content');
if(content.indexOf(me.get_no_content())!==-1) content = "";
d.set_input("content", content); d.set_input("content", content);


d.set_primary_action(__("Update"), function() { d.set_primary_action(__("Update"), function() {
$content.attr('data-html-content', d.get_value("content"));
$content.html(d.get_value("content")); $content.html(d.get_value("content"));
d.hide(); d.hide();
}); });
@@ -696,11 +697,11 @@ frappe.PrintFormatBuilder = Class.extend({
fieldname: $this.attr("data-fieldname"), fieldname: $this.attr("data-fieldname"),
print_hide: 0 print_hide: 0
}; };
if(align) { if(align) {
df.align = align; df.align = align;
} }
if(label) { if(label) {
df.label = label; df.label = label;
} }
@@ -721,7 +722,7 @@ frappe.PrintFormatBuilder = Class.extend({
if(fieldtype==="Custom HTML") { if(fieldtype==="Custom HTML") {
// custom html as HTML field // custom html as HTML field
df.fieldtype = "HTML"; df.fieldtype = "HTML";
df.options = $this.find(".html-content").html();
df.options = $this.find(".html-content").attr('data-html-content');
} }
data.push(df); data.push(df);
}); });


+ 6
- 2
frappe/print/page/print_format_builder/print_format_builder_field.html View File

@@ -3,22 +3,26 @@
title="{{ __("Hidden") }}"{% } %} title="{{ __("Hidden") }}"{% } %}
data-fieldname="{%= field.fieldname %}" data-fieldname="{%= field.fieldname %}"
data-label="{{ field.label }}" data-label="{{ field.label }}"
{% if field.align %}data-align="{{ field.align }}"{% endif %} {% if field.align %}data-align="{{ field.align }}"{% endif %}
data-fieldtype="{%= field.fieldtype %}" data-fieldtype="{%= field.fieldtype %}"
{% if(field.fieldtype==="Table") { %} {% if(field.fieldtype==="Table") { %}
data-columns="{%= me.get_visible_columns_string(field) %}" data-columns="{%= me.get_visible_columns_string(field) %}"
data-doctype="{%= field.options %}" data-doctype="{%= field.options %}"
{% } %}> {% } %}>
{% if !in_list(["Table", "HTML", "Custom HTML"], field.fieldtype) %}
<a class="field-settings pull-right <a class="field-settings pull-right
btn-default btn-xs" style="padding-top: 3px"> btn-default btn-xs" style="padding-top: 3px">
<span class="octicon octicon-gear text-muted"></span></a> <span class="octicon octicon-gear text-muted"></span></a>
{% endif %}
{% if(field.fieldtype==="Custom HTML") { %} {% if(field.fieldtype==="Custom HTML") { %}
<div class="text-right"> <div class="text-right">
<a class="edit-html btn btn-default btn-xs"> <a class="edit-html btn btn-default btn-xs">
{%= __("Edit HTML") %}</a> {%= __("Edit HTML") %}</a>
</div> </div>
<div class="html-content">{%= field.options || me.get_no_content() %}</div>
<div class="html-content"
data-html-content="{{ field.options || me.get_no_content() }}">
{{ field.options || me.get_no_content() }}</div>
{% } else { %} {% } else { %}
<span class="field-label">{{ field.label }}</span> <span class="field-label">{{ field.label }}</span>
{% if(field.fieldtype==="Table") { %} {% if(field.fieldtype==="Table") { %}


Loading…
Cancel
Save