mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Replace CompanyCreate and CompanyEdit forms with AJAX form
- Adds the ability to specify an "icon" for each field
This commit is contained in:
@ -1,5 +1,52 @@
|
||||
{% load i18n %}
|
||||
|
||||
|
||||
// Returns a default form-set for creating / editing a Company object
|
||||
function companyFormFields(options={}) {
|
||||
|
||||
return {
|
||||
name: {},
|
||||
description: {},
|
||||
website: {
|
||||
icon: 'fa-globe',
|
||||
},
|
||||
address: {
|
||||
icon: 'fa-envelope',
|
||||
},
|
||||
currency: {
|
||||
icon: 'fa-dollar-sign',
|
||||
},
|
||||
phone: {
|
||||
icon: 'fa-phone',
|
||||
},
|
||||
email: {
|
||||
icon: 'fa-at',
|
||||
},
|
||||
contact: {
|
||||
icon: 'fa-address-card',
|
||||
},
|
||||
is_supplier: {},
|
||||
is_manufacturer: {},
|
||||
is_customer: {}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function editCompany(pk, options={}) {
|
||||
|
||||
var fields = options.fields || companyFormFields();
|
||||
|
||||
constructForm(
|
||||
`/api/company/${pk}/`,
|
||||
{
|
||||
method: 'PATCH',
|
||||
fields: fields,
|
||||
reload: true,
|
||||
title: '{% trans "Edit Company" %}',
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/*
|
||||
* Launches a form to create a new company.
|
||||
* As this can be called from many different contexts,
|
||||
@ -8,22 +55,7 @@
|
||||
function createCompany(options={}) {
|
||||
|
||||
// Default field set
|
||||
var fields = {
|
||||
name: {},
|
||||
description: {},
|
||||
website: {},
|
||||
address: {},
|
||||
currency: {},
|
||||
phone: {},
|
||||
email: {},
|
||||
contact: {},
|
||||
is_supplier: {},
|
||||
is_manufacturer: {},
|
||||
is_customer: {}
|
||||
};
|
||||
|
||||
// Override / update default fields as required
|
||||
fields = Object.assign(fields, options.fields || {});
|
||||
var fields = options.fields || companyFormFields();
|
||||
|
||||
constructForm(
|
||||
'{% url "api-company-list" %}',
|
||||
|
@ -287,7 +287,12 @@ function constructFormBody(fields, options) {
|
||||
fields[field].onEdit = field_options.onEdit;
|
||||
|
||||
// Field prefix
|
||||
fields[field].prefix = field_options.prefix;
|
||||
if (field_options.prefix) {
|
||||
fields[field].prefix = field_options.prefix;
|
||||
} else if (field_options.icon) {
|
||||
// Specify icon like 'fa-user'
|
||||
fields[field].prefix = `<span class='fas ${field_options.icon}'></span>`;
|
||||
}
|
||||
|
||||
// // Field value?
|
||||
// if (fields[field].value == null) {
|
||||
|
Reference in New Issue
Block a user