From 17e6147c47f79f62b731cc8a30cee97841fb60a7 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 3 May 2018 23:57:00 +1000 Subject: [PATCH] Click on company image to edit it --- InvenTree/company/forms.py | 9 +++++++++ .../company/templates/company/company_base.html | 17 ++++++++++++++++- InvenTree/company/templates/company/detail.html | 3 +-- .../company/templates/company/detail_part.html | 4 ++-- InvenTree/company/urls.py | 2 ++ InvenTree/company/views.py | 13 +++++++++++++ 6 files changed, 43 insertions(+), 5 deletions(-) diff --git a/InvenTree/company/forms.py b/InvenTree/company/forms.py index a8d833ce13..ccbbea85e6 100644 --- a/InvenTree/company/forms.py +++ b/InvenTree/company/forms.py @@ -23,3 +23,12 @@ class EditCompanyForm(HelperForm): 'is_supplier', 'notes' ] + + +class CompanyImageForm(HelperForm): + + class Meta: + model = Company + fields = [ + 'image' + ] \ No newline at end of file diff --git a/InvenTree/company/templates/company/company_base.html b/InvenTree/company/templates/company/company_base.html index c7fffec1e0..368d7665e9 100644 --- a/InvenTree/company/templates/company/company_base.html +++ b/InvenTree/company/templates/company/company_base.html @@ -8,7 +8,7 @@
- +{% include 'modals.html' %} + +{% endblock %} + +{% block js_ready %} + + $("#company-thumb").click(function() { + launchModalForm("#modal-form", + "{% url 'company-image' company.id %}", + { + reload: true + } + ); + }); + {% endblock %} \ No newline at end of file diff --git a/InvenTree/company/templates/company/detail.html b/InvenTree/company/templates/company/detail.html index b8fb3deea4..70254b1aaf 100644 --- a/InvenTree/company/templates/company/detail.html +++ b/InvenTree/company/templates/company/detail.html @@ -29,14 +29,13 @@
-{% include 'modals.html' %} - {% endblock %} {% block js_load %} {% endblock %} {% block js_ready %} +{{ block.super }} $('#edit-company').click(function() { launchModalForm("#modal-form", "{% url 'company-edit' company.id %}", diff --git a/InvenTree/company/templates/company/detail_part.html b/InvenTree/company/templates/company/detail_part.html index 71ebd41386..dfd8842132 100644 --- a/InvenTree/company/templates/company/detail_part.html +++ b/InvenTree/company/templates/company/detail_part.html @@ -13,8 +13,6 @@
-{% include 'modals.html' %} - {% endblock %} {% block js_load %} @@ -22,6 +20,8 @@ {% endblock %} {% block js_ready %} +{{ block.super }} + $("#part-create").click(function () { launchModalForm("#modal-form", "{% url 'supplier-part-create' %}", diff --git a/InvenTree/company/urls.py b/InvenTree/company/urls.py index 5defa50568..13c478f28a 100644 --- a/InvenTree/company/urls.py +++ b/InvenTree/company/urls.py @@ -12,6 +12,8 @@ company_detail_urls = [ url(r'parts/?', views.CompanyDetail.as_view(template_name='company/detail_part.html'), name='company-detail-parts'), + url(r'thumbnail/?', views.CompanyImage.as_view(), name='company-image'), + # Any other URL url(r'^.*$', views.CompanyDetail.as_view(), name='company-detail'), ] diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index bef157af70..9042578baf 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -8,6 +8,7 @@ from InvenTree.views import AjaxCreateView, AjaxUpdateView, AjaxDeleteView from .models import Company from .forms import EditCompanyForm +from .forms import CompanyImageForm class CompanyIndex(ListView): @@ -35,6 +36,18 @@ class CompanyDetail(DetailView): model = Company +class CompanyImage(AjaxUpdateView): + model = Company + ajax_template_name = 'modal_form.html' + ajax_form_title = 'Update Company Image' + form_class = CompanyImageForm + + def get_data(self): + return { + 'success': 'Updated company image', + } + + class CompanyEdit(AjaxUpdateView): model = Company form_class = EditCompanyForm