refactor: move copy to clipboard btn to code.js (#26061)
- ref: https://github.com/frappe/frappe/pull/26049
This commit is contained in:
parent
5d51320462
commit
c5c7a0ecfe
2 changed files with 33 additions and 19 deletions
|
|
@ -153,25 +153,6 @@ frappe.ui.form.ControlInput = class ControlInput extends frappe.ui.form.Control
|
|||
let display_value = frappe.format(value, this.df, { no_icon: true, inline: true }, doc);
|
||||
// This is used to display formatted output AND showing values in read only fields
|
||||
this.disp_area && $(this.disp_area).html(display_value);
|
||||
|
||||
if (this.df.fieldtype === "Code") {
|
||||
this.button = $(
|
||||
`<button
|
||||
class="btn icon-btn"
|
||||
style="position: absolute; top: 5px; 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.appendTo($(this.disp_area));
|
||||
this.button.on("click", () => {
|
||||
frappe.utils.copy_to_clipboard(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
set_label(label) {
|
||||
if (label) this.df.label = label;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,39 @@ 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();
|
||||
}
|
||||
|
||||
set_copy_button() {
|
||||
if (!this.frm?.doc) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
make_ace_editor() {
|
||||
if (this.editor) return;
|
||||
this.ace_editor_target = $('<div class="ace-editor-target"></div>').appendTo(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue