mirror of
https://github.com/frappe/frappe.git
synced 2024-06-13 05:22:21 +00:00
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
This commit is contained in:
parent
9ad376a579
commit
c4492cc378
|
@ -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 = $(
|
||||
`<button
|
||||
class="btn icon-btn"
|
||||
style="position: absolute; top: 32px; right: 5px;"
|
||||
onmouseover="this.classList.add('btn-default')"
|
||||
onmouseout="this.classList.remove('btn-default')"
|
||||
>
|
||||
<svg class="es-icon es-line icon-sm" style="" aria-hidden="true">
|
||||
<use class="" href="#es-line-copy-light"></use>
|
||||
</svg>
|
||||
</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 = $(
|
||||
`<button
|
||||
class="btn icon-btn"
|
||||
style="position: absolute; top: 32px; right: 5px;"
|
||||
onmouseover="this.classList.add('btn-default')"
|
||||
onmouseout="this.classList.remove('btn-default')"
|
||||
>
|
||||
<svg class="es-icon es-line icon-sm" style="" aria-hidden="true">
|
||||
<use class="" href="#es-line-copy-light"></use>
|
||||
</svg>
|
||||
</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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user