2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 12:06:44 +00:00

Part image delete (#3963)

* Add button to remove an associated image from a part

- Also fixes some issues with onclick event propagation

* Similar feature for company image
This commit is contained in:
Oliver 2022-11-19 21:53:48 +11:00 committed by GitHub
parent 9ce2f4f4d3
commit bc8a6ae4b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 17 deletions

View File

@ -458,7 +458,7 @@ main {
} }
.part-thumb-container:hover .part-thumb-overlay { .part-thumb-container:hover .part-thumb-overlay {
opacity: 1; opacity: 0.75;
} }
.part-thumb-overlay { .part-thumb-overlay {
@ -467,8 +467,6 @@ main {
left: 0; left: 0;
opacity: 0; opacity: 0;
transition: .25s ease; transition: .25s ease;
padding-top: 10px;
padding-left: 25px;
margin: 5px; margin: 5px;
} }

View File

@ -58,6 +58,9 @@
{% if allow_download %} {% if allow_download %}
<button type='button' class='btn btn-outline-secondary' title="{% trans 'Download image from URL' %}" id='company-image-url'><span class='fas fa-cloud-download-alt'></span></button> <button type='button' class='btn btn-outline-secondary' title="{% trans 'Download image from URL' %}" id='company-image-url'><span class='fas fa-cloud-download-alt'></span></button>
{% endif %} {% endif %}
{% if company.image %}
<button type='button' class='btn btn-outline-secondary' title='{% trans "Delete image" %}' id='company-image-delete'><span class='fas fa-trash-alt icon-red'></span></button>
{% endif %}
</div> </div>
</div> </div>
</div> </div>
@ -194,10 +197,37 @@
$('#company-image').click(function() { $('#company-image').click(function() {
showModalImage('{{ company.image.url }}'); showModalImage('{{ company.image.url }}');
}); });
$('#company-image-delete').click(function(event) {
event.stopPropagation();
showQuestionDialog(
'{% trans "Remove Image" %}',
'{% trans "Remove associated image from this company" %}',
{
accept_text: '{% trans "Remove" %}',
submitClass: 'danger',
accept: function() {
inventreePut(
'{% url "api-company-detail" company.pk %}',
{
'image': null,
},
{
method: 'PATCH',
success: function() {
location.reload();
}
}
);
}
}
);
});
{% endif %} {% endif %}
$("#company-image-upload").click(function() { $("#company-image-upload").click(function(event) {
event.stopPropagation();
constructForm( constructForm(
'{% url "api-company-detail" company.pk %}', '{% url "api-company-detail" company.pk %}',
{ {

View File

@ -502,8 +502,34 @@
}); });
}); });
$("#part-image-upload").click(function() { $('#part-image-delete').click(function(event) {
event.stopPropagation();
showQuestionDialog(
'{% trans "Remove Image" %}',
'{% trans "Remove associated image from this part" %}',
{
accept_text: '{% trans "Remove" %}',
submitClass: 'danger',
accept: function() {
inventreePut(
'{% url "api-part-detail" part.pk %}',
{
'image': null,
},
{
method: 'PATCH',
success: function(data) {
location.reload();
}
}
);
}
}
);
});
$("#part-image-upload").click(function(event) {
event.stopPropagation();
constructForm( constructForm(
'{% url "api-part-detail" part.pk %}', '{% url "api-part-detail" part.pk %}',
{ {
@ -576,9 +602,9 @@
}); });
} }
$("#part-image-select").click(function() { $("#part-image-select").click(function(event) {
launchModalForm("{% url 'part-image-select' part.id %}", event.stopPropagation();
{ launchModalForm("{% url 'part-image-select' part.id %}", {
reload: true, reload: true,
after_render: onSelectImage after_render: onSelectImage
}); });

View File

@ -13,6 +13,9 @@
{% if allow_download %} {% if allow_download %}
<button type='button' class='btn btn-outline-secondary' title="{% trans 'Download image from URL' %}" id='part-image-url'><span class='fas fa-cloud-download-alt'></span></button> <button type='button' class='btn btn-outline-secondary' title="{% trans 'Download image from URL' %}" id='part-image-url'><span class='fas fa-cloud-download-alt'></span></button>
{% endif %} {% endif %}
{% if part.image %}
<button type='button' class='btn btn-outline-secondary' title='{% trans "Delete image" %}' id='part-image-delete'><span class='fas fa-trash-alt icon-red'></span></button>
{% endif %}
</div> </div>
</div> </div>
{% endif %} {% endif %}

View File

@ -621,11 +621,11 @@ function showQuestionDialog(title, content, options={}) {
* cancel - Functino to run if the user presses 'Cancel' * cancel - Functino to run if the user presses 'Cancel'
*/ */
var modal = createNewModal({ options.title = title;
title: title, options.submitText = options.accept_text || '{% trans "Accept" %}';
submitText: options.accept_text || '{% trans "Accept" %}', options.closeText = options.cancel_text || '{% trans "Cancel" %}';
closeText: options.cancel_text || '{% trans "Cancel" %}',
}); var modal = createNewModal(options);
modalSetContent(modal, content); modalSetContent(modal, content);