From c4492cc37809d25697996b7f4e66c3d201d418b7 Mon Sep 17 00:00:00 2001 From: Corentin Flr <10946971+cogk@users.noreply.github.com> Date: Mon, 20 May 2024 08:17:06 +0200 Subject: [PATCH] refactor(code): Fix "copy text" button in dialogs and read_only_depends_on (#26467) * refactor(code): Use get_status for "copy text" button * refactor(code): Rename method to setup_copy_button * refactor(code): Toggle "copy text" button on refresh * refactor(code): Use get_model_value when copying to clipboard --- frappe/public/js/frappe/form/controls/code.js | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/frappe/public/js/frappe/form/controls/code.js b/frappe/public/js/frappe/form/controls/code.js index f547c4c7e3..e710144b00 100644 --- a/frappe/public/js/frappe/form/controls/code.js +++ b/frappe/public/js/frappe/form/controls/code.js @@ -4,37 +4,37 @@ frappe.ui.form.ControlCode = class ControlCode extends frappe.ui.form.ControlTex this.load_lib().then(() => this.make_ace_editor()); } - make_wrapper() { - super.make_wrapper(); - this.set_copy_button(); + refresh() { + super.refresh(); + if (this.df.fieldtype === "Code") { + // Don't show for derived classes + this.setup_copy_button(); + } } - set_copy_button() { - if (!this.frm?.doc) { - return; + setup_copy_button() { + if (this.get_status() === "Write") { + this.copy_button?.remove(); + this.copy_button = null; + return; // Don't show copy button in write mode } - const codeField = this.df.fieldtype === "Code"; - if ((codeField && this.df.read_only === 1) || (codeField && this.frm.doc.docstatus > 0)) { - this.button = $( - `` - ); - this.button.on("click", () => { - frappe.utils.copy_to_clipboard( - frappe.model.get_value(this.doctype, this.docname, this.df.fieldname) - ); - }); - this.button.appendTo(this.$wrapper); - } + this.copy_button = $( + `` + ); + this.copy_button.on("click", () => { + frappe.utils.copy_to_clipboard(this.get_model_value() || this.get_value()); + }); + this.copy_button.appendTo(this.$wrapper); } make_ace_editor() {