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 {
opacity: 1;
opacity: 0.75;
}
.part-thumb-overlay {
@ -467,8 +467,6 @@ main {
left: 0;
opacity: 0;
transition: .25s ease;
padding-top: 10px;
padding-left: 25px;
margin: 5px;
}

View File

@ -58,6 +58,9 @@
{% 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>
{% 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>
@ -194,10 +197,37 @@
$('#company-image').click(function() {
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 %}
$("#company-image-upload").click(function() {
$("#company-image-upload").click(function(event) {
event.stopPropagation();
constructForm(
'{% 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(
'{% url "api-part-detail" part.pk %}',
{
@ -576,12 +602,12 @@
});
}
$("#part-image-select").click(function() {
launchModalForm("{% url 'part-image-select' part.id %}",
{
reload: true,
after_render: onSelectImage
});
$("#part-image-select").click(function(event) {
event.stopPropagation();
launchModalForm("{% url 'part-image-select' part.id %}", {
reload: true,
after_render: onSelectImage
});
});
$("#part-edit").click(function() {

View File

@ -13,6 +13,9 @@
{% 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>
{% 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>
{% endif %}

View File

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