diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index d35284135c..dea46a7e54 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -54,6 +54,8 @@ class AjaxCreateView(AjaxView, CreateView): # Return the PK of the newly-created object data['pk'] = obj.pk + data['url'] = obj.get_absolute_url() + return self.renderJsonResponse(request, form, data) else: @@ -84,6 +86,9 @@ class AjaxUpdateView(AjaxView, UpdateView): if form.is_valid(): obj = form.save() + data['pk'] = obj.id + data['url'] = obj.get_absolute_url() + return self.renderJsonResponse(request, form, data) else: diff --git a/InvenTree/company/forms.py b/InvenTree/company/forms.py index 8ef2f14c51..c7a4066ccd 100644 --- a/InvenTree/company/forms.py +++ b/InvenTree/company/forms.py @@ -34,12 +34,7 @@ class EditCompanyForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(EditCompanyForm, self).__init__(*args, **kwargs) self.helper = FormHelper() - - self.helper.form_id = 'id-edit-part-form' - self.helper.form_class = 'blueForms' - self.helper.form_method = 'post' - - self.helper.add_input(Submit('submit', 'Submit')) + self.helper.form_tag = False class Meta: model = Company diff --git a/InvenTree/company/templates/company/index.html b/InvenTree/company/templates/company/index.html index 78e83a2dde..4b27676c9f 100644 --- a/InvenTree/company/templates/company/index.html +++ b/InvenTree/company/templates/company/index.html @@ -6,23 +6,30 @@

Companies

-
-
- - - - -
-
- -
+ + + + + + + + + {% for company in companies %} + + + + + {% endfor %} + +
NameDescription
+ + {{ company.name }} + + {{ company.description }}
- - - +
{% include 'modals.html' %} @@ -31,8 +38,19 @@ {% block javascript %} - - + + + {% endblock %} \ No newline at end of file diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index e06a6fba53..864f7b97fe 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -6,6 +6,8 @@ from django.http import HttpResponseRedirect from django.views.generic import DetailView, ListView from django.views.generic.edit import UpdateView, DeleteView, CreateView +from InvenTree.views import AjaxCreateView, AjaxUpdateView, AjaxDeleteView + from .models import Company from .forms import EditCompanyForm @@ -43,11 +45,13 @@ class CompanyEdit(UpdateView): context_object_name = 'company' -class CompanyCreate(CreateView): +class CompanyCreate(AjaxCreateView): model = Company context_object_name = 'company' form_class = EditCompanyForm template_name = "company/create.html" + ajax_template_name = 'modal_form.html' + ajax_form_title = "Create new Company" class CompanyDelete(DeleteView): diff --git a/InvenTree/static/script/modal_form.js b/InvenTree/static/script/modal_form.js index 98840d3998..efe4801f07 100644 --- a/InvenTree/static/script/modal_form.js +++ b/InvenTree/static/script/modal_form.js @@ -129,12 +129,19 @@ function launchModalForm(modal, url, options = {}) { $(modal).modal('hide'); + // Form success callback if (options.success) { options.success(); } + // Follow the URL returned by the JSON response + else if (options.follow && response.url) { + window.location.href = response.url; + } + // Redirect to a specific URL else if (options.redirect) { window.location.href = options.redirect; } + // Reload the current page else if (options.reload) { location.reload(); }