diff --git a/InvenTree/company/templates/company/company_base.html b/InvenTree/company/templates/company/company_base.html index a276f5df4f..197ddbf75e 100644 --- a/InvenTree/company/templates/company/company_base.html +++ b/InvenTree/company/templates/company/company_base.html @@ -111,11 +111,7 @@ }); $('#company-edit').click(function() { - launchModalForm( - "{% url 'company-edit' company.id %}", - { - reload: true - }); + editCompany({{ company.id }}); }); $("#company-order-2").click(function() { diff --git a/InvenTree/company/templates/company/index.html b/InvenTree/company/templates/company/index.html index 025251c883..672d82fdb7 100644 --- a/InvenTree/company/templates/company/index.html +++ b/InvenTree/company/templates/company/index.html @@ -32,49 +32,16 @@ $('#new-company').click(function() { + var fields = companyFormFields(); + + // Field overrides + fields.is_supplier.value = {% if pagetype == 'suppliers' %}true{% else %}false{% endif %}; + fields.is_manufacturer.value = {% if pagetype == 'manufacturers' %}true{% else %}false{% endif %}; + fields.is_customer.value = {% if pagetype == 'customers' %}true{% else %}false{% endif %}; + createCompany({ - fields: { - is_supplier: { - value: {% if pagetype == 'suppliers' %}true{% else %}false{% endif %}, - }, - is_manufacturer: { - value: {% if pagetype == 'manufacturers' %}true{% else %}false{% endif %}, - }, - is_customer: { - value: {% if pagetype == 'customers' %}true{% else %}false{% endif %}, - }, - } + fields: fields, }); - - return; - - constructForm( - '{% url "api-company-list" %}', - { - method: 'POST', - title: '{% trans "Create new Company" %}', - follow: true, - fields: { - name: {}, - description: {}, - website: {}, - address: {}, - currency: {}, - phone: {}, - email: {}, - contact: {}, - is_supplier: { - value: {% if pagetype == 'suppliers' %}true{% else %}false{% endif %}, - }, - is_manufacturer: { - value: {% if pagetype == 'manufacturers' %}true{% else %}false{% endif %}, - }, - is_customer: { - value: {% if pagetype == 'customers' %}true{% else %}false{% endif %}, - }, - } - } - ); }); loadCompanyTable("#company-table", "{% url 'api-company-list' %}", diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index a5cdcd00a0..c42e3e2465 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -246,23 +246,11 @@ class CompanyImage(AjaxUpdateView): } -class CompanyEdit(AjaxUpdateView): - """ View for editing a Company object """ - model = Company - form_class = EditCompanyForm - context_object_name = 'company' - ajax_template_name = 'modal_form.html' - ajax_form_title = _('Edit Company') - permission_required = 'company.change_company' - - def get_data(self): - return { - 'info': _('Edited company information'), - } - - class CompanyCreate(AjaxCreateView): - """ View for creating a new Company object """ + """ + View for creating a new Company object + """ + model = Company context_object_name = 'company' form_class = EditCompanyForm diff --git a/InvenTree/templates/js/company.js b/InvenTree/templates/js/company.js index bd9c1cf458..b069901ce1 100644 --- a/InvenTree/templates/js/company.js +++ b/InvenTree/templates/js/company.js @@ -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" %}', diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index e2ccb096b3..e96f9dee2a 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -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 = ``; + } // // Field value? // if (fields[field].value == null) {