Set modal form title

This commit is contained in:
Oliver 2021-06-26 14:30:14 +10:00
parent 565631ef87
commit 949c7dd81b
2 changed files with 15 additions and 9 deletions

View File

@ -337,8 +337,9 @@ class PartDetail(generics.RetrieveUpdateDestroyAPIView):
def get_serializer(self, *args, **kwargs): def get_serializer(self, *args, **kwargs):
# By default, include 'category_detail' information in the detail view
try: try:
kwargs['category_detail'] = str2bool(self.request.query_params.get('category_detail', False)) kwargs['category_detail'] = str2bool(self.request.query_params.get('category_detail', True))
except AttributeError: except AttributeError:
pass pass

View File

@ -161,17 +161,18 @@ function constructChangeForm(url, fields, options={}) {
* and construct a modal form based on the response. * and construct a modal form based on the response.
* *
* arguments: * arguments:
* - method: The HTTP method e.g. 'PUT', 'POST', 'DELETE', * - url: API URL
* *
* options: * options:
* - method: * - method: The HTTP method e.g. 'PUT', 'POST', 'DELETE',
* - title: The form title
* - fields: list of fields to display
* - exclude: List of fields to exclude
*/ */
function constructForm(url, method, options={}) { function constructForm(url, options={}) {
method = method.toUpperCase(); // Default HTTP method
options.method = options.method || 'PATCH';
// Store the method in the options struct
options.method = method;
// Request OPTIONS endpoint from the API // Request OPTIONS endpoint from the API
getApiEndpointOptions(url, function(OPTIONS) { getApiEndpointOptions(url, function(OPTIONS) {
@ -183,7 +184,7 @@ function constructForm(url, method, options={}) {
* First we must determine if the user has the correct permissions! * First we must determine if the user has the correct permissions!
*/ */
switch (method) { switch (options.method) {
case 'POST': case 'POST':
if (canCreate(OPTIONS)) { if (canCreate(OPTIONS)) {
constructCreateForm(url, OPTIONS.actions.POST, options); constructCreateForm(url, OPTIONS.actions.POST, options);
@ -322,6 +323,10 @@ function constructFormBody(url, fields, options={}) {
$(modal + ' .select2-container').css('width', '100%'); $(modal + ' .select2-container').css('width', '100%');
modalShowSubmitButton(modal, true); modalShowSubmitButton(modal, true);
var title = options.title || '{% trans "Form Title" %}';
modalSetTitle(modal, title);
} }