Click on company image to edit it

This commit is contained in:
Oliver 2018-05-03 23:57:00 +10:00
parent e9be3e9e06
commit 17e6147c47
6 changed files with 43 additions and 5 deletions

View File

@ -23,3 +23,12 @@ class EditCompanyForm(HelperForm):
'is_supplier', 'is_supplier',
'notes' 'notes'
] ]
class CompanyImageForm(HelperForm):
class Meta:
model = Company
fields = [
'image'
]

View File

@ -8,7 +8,7 @@
<div class="col-sm-6"> <div class="col-sm-6">
<div class="media"> <div class="media">
<div class="media-left"> <div class="media-left">
<img class="part-thumb" <img class="part-thumb" id='company-thumb'
{% if company.image %} {% if company.image %}
src="{{ company.image.url }}" src="{{ company.image.url }}"
{% else %} {% else %}
@ -62,4 +62,19 @@
</div> </div>
{% include 'modals.html' %}
{% endblock %}
{% block js_ready %}
$("#company-thumb").click(function() {
launchModalForm("#modal-form",
"{% url 'company-image' company.id %}",
{
reload: true
}
);
});
{% endblock %} {% endblock %}

View File

@ -29,14 +29,13 @@
<button class="btn btn-danger" id='delete-company'>Delete Company</button> <button class="btn btn-danger" id='delete-company'>Delete Company</button>
</div> </div>
{% include 'modals.html' %}
{% endblock %} {% endblock %}
{% block js_load %} {% block js_load %}
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script> <script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
{% endblock %} {% endblock %}
{% block js_ready %} {% block js_ready %}
{{ block.super }}
$('#edit-company').click(function() { $('#edit-company').click(function() {
launchModalForm("#modal-form", launchModalForm("#modal-form",
"{% url 'company-edit' company.id %}", "{% url 'company-edit' company.id %}",

View File

@ -13,8 +13,6 @@
<button class="btn btn-success" id='part-create'>New Supplier Part</button> <button class="btn btn-success" id='part-create'>New Supplier Part</button>
</div> </div>
{% include 'modals.html' %}
{% endblock %} {% endblock %}
{% block js_load %} {% block js_load %}
@ -22,6 +20,8 @@
{% endblock %} {% endblock %}
{% block js_ready %} {% block js_ready %}
{{ block.super }}
$("#part-create").click(function () { $("#part-create").click(function () {
launchModalForm("#modal-form", launchModalForm("#modal-form",
"{% url 'supplier-part-create' %}", "{% url 'supplier-part-create' %}",

View File

@ -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'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 # Any other URL
url(r'^.*$', views.CompanyDetail.as_view(), name='company-detail'), url(r'^.*$', views.CompanyDetail.as_view(), name='company-detail'),
] ]

View File

@ -8,6 +8,7 @@ from InvenTree.views import AjaxCreateView, AjaxUpdateView, AjaxDeleteView
from .models import Company from .models import Company
from .forms import EditCompanyForm from .forms import EditCompanyForm
from .forms import CompanyImageForm
class CompanyIndex(ListView): class CompanyIndex(ListView):
@ -35,6 +36,18 @@ class CompanyDetail(DetailView):
model = Company 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): class CompanyEdit(AjaxUpdateView):
model = Company model = Company
form_class = EditCompanyForm form_class = EditCompanyForm