feat: Copy DocType / Documents without boundaries
This commit is contained in:
parent
23f9f0b1d2
commit
f974294484
2 changed files with 37 additions and 1 deletions
|
|
@ -51,6 +51,7 @@ frappe.Application = Class.extend({
|
|||
this.set_fullwidth_if_enabled();
|
||||
this.add_browser_class();
|
||||
this.setup_energy_point_listeners();
|
||||
this.copy_doc_listeners();
|
||||
|
||||
frappe.ui.keys.setup();
|
||||
|
||||
|
|
@ -605,6 +606,36 @@ frappe.Application = Class.extend({
|
|||
frappe.show_alert(message);
|
||||
});
|
||||
},
|
||||
|
||||
copy_doc_listeners() {
|
||||
$('body').on('paste', (e) => {
|
||||
try {
|
||||
let clipboard_data = e.clipboardData || window.clipboardData || e.originalEvent.clipboardData;
|
||||
let pasted_data = clipboard_data.getData('Text');
|
||||
let doc = JSON.parse(pasted_data);
|
||||
if (doc.doctype) {
|
||||
e.preventDefault();
|
||||
let sleep = (time) => {
|
||||
return new Promise((resolve) => setTimeout(resolve, time));
|
||||
};
|
||||
frappe.dom.freeze(__('Copying {0}', [doc.doctype]));
|
||||
|
||||
sleep(500).then(() => {
|
||||
frappe.model.with_doctype(doc.doctype, () => {
|
||||
let newdoc = frappe.model.copy_doc(doc);
|
||||
newdoc.__newname = doc.name;
|
||||
newdoc.idx = null;
|
||||
newdoc.__run_link_triggers = false;
|
||||
frappe.set_route('Form', newdoc.doctype, newdoc.name);
|
||||
frappe.dom.unfreeze();
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
frappe.get_module = function(m, default_module) {
|
||||
|
|
|
|||
|
|
@ -278,13 +278,18 @@ frappe.ui.form.Toolbar = class Toolbar {
|
|||
}, true)
|
||||
}
|
||||
|
||||
// copy
|
||||
// duplicate
|
||||
if(in_list(frappe.boot.user.can_create, me.frm.doctype) && !me.frm.meta.allow_copy) {
|
||||
this.page.add_menu_item(__("Duplicate"), function() {
|
||||
me.frm.copy_doc();
|
||||
}, true);
|
||||
}
|
||||
|
||||
// copy doc to clipboard
|
||||
this.page.add_menu_item(__("Copy {0}", [me.frm.doc.doctype]), function() {
|
||||
frappe.utils.copy_to_clipboard(JSON.stringify(me.frm.doc));
|
||||
}, true);
|
||||
|
||||
// rename
|
||||
if(this.can_rename()) {
|
||||
this.page.add_menu_item(__("Rename"), function() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue