Skip to content

Commit

Permalink
feat: toggle HTML (LAN-779)
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Sep 22, 2023
1 parent 163f1cc commit ff34e20
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions landa/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"Contact": "address_and_contact.js",
"User": "organization_management/user/user.js",
"Customer": "landa_sales/customer/customer.js",
"Water Body Rules": "public/js/beautify_1.14.9.min.js",
}
doctype_list_js = {
"Report": "scripts/report_list.js",
Expand Down
3 changes: 3 additions & 0 deletions landa/public/js/beautify_1.14.9.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions landa/translations/de.csv
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Create Stocking Targets,Besatzplanungen erstellen,
Water Body Rules,Gewässerordnung,
Privacy Policy,Datenschutzerklärung,
Imprint,Impressum,
Toggle HTML,HTML umschalten,
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
// Copyright (c) 2023, ALYF GmbH and contributors
// For license information, please see license.txt

frappe.ui.form.on('Water Body Rules', {
// refresh: function(frm) {
frappe.ui.form.on("Water Body Rules", {
refresh: function (frm) {
frm.add_custom_button(__("Toggle HTML"), function () {
frm.trigger("toggle_html");
});
},
toggle_html: function (frm) {
for (let fieldname of ["water_body_rules", "privacy_policy", "imprint"]) {
let df = frm.fields_dict[fieldname].df;

// }
// overwrites Code formatter defined in apps/frappe/frappe/public/js/frappe/form/formatters.js
df.formatter = df.read_only ? undefined : format_html;
frm.set_df_property(fieldname, "fieldtype", df.read_only ? "HTML Editor" : "Code");
frm.set_df_property(fieldname, "options", df.read_only ? "" : "HTML");
frm.set_df_property(fieldname, "read_only", !df.read_only);
}
}
});

// modifies Code formatter defined in apps/frappe/frappe/public/js/frappe/form/formatters.js
// to pretty print HTML
function format_html(value, df) {
const _value = df.options == "HTML" ? html_beautify(value) : value;
return "<pre>" + (_value == null ? "" : $("<div>").text(_value).html()) + "</pre>";
}

0 comments on commit ff34e20

Please sign in to comment.