mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-04 20:51:00 +00:00
Allow override of values from calling function
This commit is contained in:
@ -1,5 +1,75 @@
|
||||
{% load i18n %}
|
||||
|
||||
/*
|
||||
* Launches a form to create a new company.
|
||||
* As this can be called from many different contexts,
|
||||
* we abstract it here!
|
||||
*/
|
||||
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 || {});
|
||||
|
||||
constructForm(
|
||||
'{% url "api-company-list" %}',
|
||||
{
|
||||
method: 'POST',
|
||||
fields: fields,
|
||||
follow: true,
|
||||
title: '{% trans "Add new Company" %}',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Launch form to create a new manufacturer part
|
||||
function createManufacturerPart(options={}) {
|
||||
|
||||
var fields = {
|
||||
'part': {
|
||||
secondary: {
|
||||
label: '{% trans "New Part" %}',
|
||||
}
|
||||
},
|
||||
'manufacturer': {
|
||||
secondary: {
|
||||
label: '{% trans "New Manufacturer" %}',
|
||||
}
|
||||
},
|
||||
'MPN': {},
|
||||
'description': {},
|
||||
'link': {},
|
||||
};
|
||||
|
||||
fields = Object.assign(fields, options.fields || {});
|
||||
|
||||
constructForm(
|
||||
'{% url "api-manufacturer-part-list" %}',
|
||||
{
|
||||
fields: fields,
|
||||
method: 'POST',
|
||||
follow: true,
|
||||
title: '{% trans "Add new Manufacturer Part" %}',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function loadCompanyTable(table, url, options={}) {
|
||||
/*
|
||||
* Load company listing data into specified table.
|
||||
|
@ -109,14 +109,24 @@ function getApiEndpointOptions(url, callback, options) {
|
||||
* -
|
||||
*/
|
||||
function constructCreateForm(fields, options) {
|
||||
|
||||
|
||||
// Check if default values were provided for any fields
|
||||
for (const name in fields) {
|
||||
|
||||
var field = fields[name];
|
||||
|
||||
if (field.default != null) {
|
||||
field.value = field.default;
|
||||
var field_options = options.fields[name] || {};
|
||||
|
||||
// If a 'value' is not provided for the field,
|
||||
if (field.value == null) {
|
||||
|
||||
if ('value' in field_options) {
|
||||
// Client has specified the default value for the field
|
||||
field.value = field_options.value;
|
||||
} else if (field.default != null) {
|
||||
// OPTIONS endpoint provided default value for this field
|
||||
field.value = field.default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,6 +288,11 @@ function constructFormBody(fields, options) {
|
||||
|
||||
// Field prefix
|
||||
fields[field].prefix = field_options.prefix;
|
||||
|
||||
// // Field value?
|
||||
// if (fields[field].value == null) {
|
||||
// fields[field].value = field_options.value;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user