mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-10 17:28:50 +00:00
Extract context information from the OPTIONS request (forms.js)
This commit is contained in:
parent
4e7d1d8e7f
commit
e527ddcc86
@ -43,10 +43,7 @@ class InvenTreeMetadata(SimpleMetadata):
|
|||||||
Custom context information to pass through to the OPTIONS endpoint,
|
Custom context information to pass through to the OPTIONS endpoint,
|
||||||
if the "context=True" is supplied to the OPTIONS requst
|
if the "context=True" is supplied to the OPTIONS requst
|
||||||
|
|
||||||
Serializer class can supply either:
|
Serializer class can supply context data by defining a get_context_data() method (no arguments)
|
||||||
|
|
||||||
- get_context_data() (method)
|
|
||||||
- CONTEXT_DATA (dict)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
context = {}
|
context = {}
|
||||||
@ -55,8 +52,6 @@ class InvenTreeMetadata(SimpleMetadata):
|
|||||||
|
|
||||||
if hasattr(self.serializer, 'get_context_data'):
|
if hasattr(self.serializer, 'get_context_data'):
|
||||||
context = self.serializer.get_context_data()
|
context = self.serializer.get_context_data()
|
||||||
elif hasattr(self.erializer, 'CONTEXT_DATA'):
|
|
||||||
context = self.serializer.CONTEXT_DATA
|
|
||||||
|
|
||||||
metadata['context'] = context
|
metadata['context'] = context
|
||||||
|
|
||||||
|
@ -338,6 +338,9 @@ function constructForm(url, options) {
|
|||||||
// Request OPTIONS endpoint from the API
|
// Request OPTIONS endpoint from the API
|
||||||
getApiEndpointOptions(url, function(OPTIONS) {
|
getApiEndpointOptions(url, function(OPTIONS) {
|
||||||
|
|
||||||
|
// Extract any custom 'context' information from the OPTIONS data
|
||||||
|
options.context = OPTIONS.context || {};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine what "type" of form we want to construct,
|
* Determine what "type" of form we want to construct,
|
||||||
* based on the requested action.
|
* based on the requested action.
|
||||||
@ -530,7 +533,14 @@ function constructFormBody(fields, options) {
|
|||||||
$(modal).find('#form-content').html(html);
|
$(modal).find('#form-content').html(html);
|
||||||
|
|
||||||
if (options.preFormContent) {
|
if (options.preFormContent) {
|
||||||
$(modal).find('#pre-form-content').html(options.preFormContent);
|
|
||||||
|
if (typeof(options.preFormContent) === 'function') {
|
||||||
|
var content = options.preFormContent(options);
|
||||||
|
} else {
|
||||||
|
var content = options.preFormContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(modal).find('#pre-form-content').html(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.postFormContent) {
|
if (options.postFormContent) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user