brotherton-erpnext/erpnext/public/js/hub/components/profile_dialog.js
2018-08-31 20:42:48 +05:30

94 lines
2.0 KiB
JavaScript

const ProfileDialog = (title = __('Edit Profile'), action={}) => {
const fields = [
{
// TODO: add hub check for taken
fieldname: 'username',
label: __('Username'),
fieldtype: 'Data'
},
{
fieldtype: 'Link',
fieldname: 'company',
label: __('Company'),
options: 'Company',
onchange: () => {
const value = dialog.get_value('company');
if (value) {
frappe.db.get_doc('Company', value)
.then(company => {
dialog.set_values({
country: company.country,
currency: company.default_currency
});
});
}
}
},
{
fieldname: 'company_email',
label: __('Email'),
fieldtype: 'Read Only'
},
{
fieldname: 'users',
label: __('Users'),
fieldtype: 'MultiSelect'
},
{
fieldname: 'country',
label: __('Country'),
fieldtype: 'Read Only'
},
{
fieldname: 'currency',
label: __('Currency'),
fieldtype: 'Read Only'
},
{
fieldtype: 'Text',
label: __('About your Company'),
fieldname: 'company_description'
}
];
let dialog = new frappe.ui.Dialog({
title: title,
fields: fields,
primary_action_label: action.label || __('Update'),
primary_action: () => {
const form_values = dialog.get_values();
let values_filled = true;
const mandatory_fields = ['company', 'company_email', 'company_description'];
mandatory_fields.forEach(field => {
const value = form_values[field];
if (!value) {
dialog.set_df_property(field, 'reqd', 1);
values_filled = false;
}
});
if (!values_filled) return;
action.on_submit(form_values);
}
});
frappe.db.get_list('User')
.then(result => {
const users = result.map(result => result.name)
.filter(user => !['Guest', 'Administrator', frappe.session.user].includes(user));
dialog.fields_dict.users.set_data(users);
});
// Post create
const default_company = frappe.defaults.get_default('company');
dialog.set_value('company', default_company);
dialog.set_value('company_email', frappe.session.user);
return dialog;
}
export {
ProfileDialog
}