fix(minor): setting default doctype in customize form
This commit is contained in:
parent
53099b40de
commit
62cb5d7793
2 changed files with 61 additions and 41 deletions
|
|
@ -4,6 +4,15 @@
|
|||
frappe.provide("frappe.customize_form");
|
||||
|
||||
frappe.ui.form.on("Customize Form", {
|
||||
setup: function(frm) {
|
||||
// save the last setting if refreshing
|
||||
window.addEventListener('beforeunload', (event) => {
|
||||
if (frm.doc.doc_type && frm.doc.doc_type!='undefined') {
|
||||
localStorage['customize_doctype'] = frm.doc.doc_type;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onload: function(frm) {
|
||||
frm.disable_save();
|
||||
frm.set_query("doc_type", function() {
|
||||
|
|
@ -40,12 +49,6 @@ frappe.ui.form.on("Customize Form", {
|
|||
$(frm.wrapper).on("grid-move-row", function(e, frm) {
|
||||
frm.trigger("setup_sortable");
|
||||
});
|
||||
|
||||
if (localStorage['customize_doctype']) {
|
||||
// set default value from customize form
|
||||
frm.set_value('doc_type', localStorage['customize_doctype']);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
doc_type: function(frm) {
|
||||
|
|
@ -59,7 +62,6 @@ frappe.ui.form.on("Customize Form", {
|
|||
if (r._server_messages && r._server_messages.length) {
|
||||
frm.set_value("doc_type", "");
|
||||
} else {
|
||||
localStorage['customize_doctype'] = frm.doc.doc_type;
|
||||
frm.refresh();
|
||||
frm.trigger("setup_sortable");
|
||||
}
|
||||
|
|
@ -113,33 +115,58 @@ frappe.ui.form.on("Customize Form", {
|
|||
frappe.set_route('permission-manager', frm.doc.doc_type);
|
||||
}, __('Actions'));
|
||||
|
||||
if (frappe.boot.developer_mode) {
|
||||
frm.add_custom_button(__('Export Customizations'), function() {
|
||||
frappe.prompt(
|
||||
[
|
||||
{fieldtype:'Link', fieldname:'module', options:'Module Def',
|
||||
label: __('Module to Export')},
|
||||
{fieldtype:'Check', fieldname:'sync_on_migrate',
|
||||
label: __('Sync on Migrate'), 'default': 1},
|
||||
{fieldtype:'Check', fieldname:'with_permissions',
|
||||
label: __('Export Custom Permissions'), 'default': 1},
|
||||
],
|
||||
function(data) {
|
||||
frappe.call({
|
||||
method: 'frappe.modules.utils.export_customizations',
|
||||
args: {
|
||||
doctype: frm.doc.doc_type,
|
||||
module: data.module,
|
||||
sync_on_migrate: data.sync_on_migrate,
|
||||
with_permissions: data.with_permissions
|
||||
}
|
||||
});
|
||||
},
|
||||
__("Select Module"));
|
||||
}, __('Actions'));
|
||||
}
|
||||
}
|
||||
|
||||
frm.events.setup_export(frm);
|
||||
frm.events.setup_sort_order(frm);
|
||||
frm.events.set_default_doc_type(frm);
|
||||
|
||||
},
|
||||
|
||||
set_default_doc_type(frm) {
|
||||
let doc_type;
|
||||
if (frappe.route_options && frappe.route_options.doc_type) {
|
||||
doc_type = frappe.route_options.doc_type;
|
||||
frappe.route_options = null;
|
||||
localStorage.removeItem('customize_doctype');
|
||||
}
|
||||
if (!doc_type) {
|
||||
doc_type = localStorage.getItem('customize_doctype');
|
||||
}
|
||||
if (doc_type) {
|
||||
setTimeout(() => frm.set_value("doc_type", doc_type), 1000);
|
||||
}
|
||||
},
|
||||
|
||||
setup_export(frm) {
|
||||
if (frappe.boot.developer_mode) {
|
||||
frm.add_custom_button(__('Export Customizations'), function() {
|
||||
frappe.prompt(
|
||||
[
|
||||
{fieldtype:'Link', fieldname:'module', options:'Module Def',
|
||||
label: __('Module to Export')},
|
||||
{fieldtype:'Check', fieldname:'sync_on_migrate',
|
||||
label: __('Sync on Migrate'), 'default': 1},
|
||||
{fieldtype:'Check', fieldname:'with_permissions',
|
||||
label: __('Export Custom Permissions'), 'default': 1},
|
||||
],
|
||||
function(data) {
|
||||
frappe.call({
|
||||
method: 'frappe.modules.utils.export_customizations',
|
||||
args: {
|
||||
doctype: frm.doc.doc_type,
|
||||
module: data.module,
|
||||
sync_on_migrate: data.sync_on_migrate,
|
||||
with_permissions: data.with_permissions
|
||||
}
|
||||
});
|
||||
},
|
||||
__("Select Module"));
|
||||
}, __('Actions'));
|
||||
}
|
||||
},
|
||||
|
||||
setup_sort_order(frm) {
|
||||
// sort order select
|
||||
if (frm.doc.doc_type) {
|
||||
var fields = $.map(frm.doc.fields,
|
||||
|
|
@ -149,13 +176,6 @@ frappe.ui.form.on("Customize Form", {
|
|||
fields = ["", "name", "modified"].concat(fields);
|
||||
frm.set_df_property("sort_field", "options", fields);
|
||||
}
|
||||
|
||||
if (frappe.route_options && frappe.route_options.doc_type) {
|
||||
setTimeout(function() {
|
||||
frm.set_value("doc_type", frappe.route_options.doc_type);
|
||||
frappe.route_options = null;
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ frappe.socketio = {
|
|||
frappe.socketio.form_stopped_typing(frm.doctype, frm.docname);
|
||||
});
|
||||
|
||||
window.onbeforeunload = function() {
|
||||
window.addEventListener('beforeunload', (event) => {
|
||||
if (!cur_frm || cur_frm.is_new()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ frappe.socketio = {
|
|||
if (cur_frm.doc) {
|
||||
frappe.socketio.doc_close(cur_frm.doctype, cur_frm.docname);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
get_host: function(port = 3000) {
|
||||
var host = window.location.origin;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue