Improve delete button behavior

This commit is contained in:
Antoine Bartuccio 2024-08-26 16:14:12 +02:00 committed by Bartuccio Antoine
parent 93b66d980d
commit 85d9816aaa
2 changed files with 37 additions and 6 deletions

View File

@ -263,7 +263,13 @@ a:not(.button) {
&.btn-red {
background-color: #fc8181;
color: black;
border: #fc8181 1px solid;
&:not(:disabled):hover {
background-color: darken(#fc8181, 15%);
}
&:disabled {
background-color: lighten(#fc8181, 15%);
color: grey;
}
}
i {

View File

@ -49,11 +49,14 @@
{%- if form[field_name] -%}
<div>
{{ form[field_name] }}
{%- if user.is_root and form.instance[field_name] -%}
<button class="btn btn-red" @click.prevent="window.open('{{ url('core:file_delete', file_id=form.instance[field_name].id, popup='') }}', '_self')">
{%- trans -%}Delete{%- endtrans -%}
</button>
{%- endif -%}
<button class="btn btn-red" @click.prevent="delete_picture()"
{%- if not (user.is_root and form.instance[field_name]) -%}
:disabled="picture == null"
{%- endif -%}
x-cloak
>
{%- trans -%}Delete{%- endtrans -%}
</button>
</div>
<p>
{{ form[field_name].label }}
@ -107,6 +110,28 @@
{%- endif -%}
},
delete_picture() {
{# Only remove currently displayed picture #}
if (this.picture != null){
let list = new DataTransfer();
this.picture_form.files = list.files;
this.picture_form.dispatchEvent(new Event("change"));
return;
}
{# Remove user picture if correct rights are available #}
{%- if user.is_root and form.instance[field_name] -%}
window.open(
'{{ url(
'core:file_delete',
file_id=form.instance[field_name].id,
popup=''
) }}',
'_self');
{%- endif -%}
},
enable_camera() {
this.picture = null;
this.loading = true;