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 { &.btn-red {
background-color: #fc8181; background-color: #fc8181;
color: black; color: black;
border: #fc8181 1px solid; &:not(:disabled):hover {
background-color: darken(#fc8181, 15%);
}
&:disabled {
background-color: lighten(#fc8181, 15%);
color: grey;
}
} }
i { i {

View File

@ -49,11 +49,14 @@
{%- if form[field_name] -%} {%- if form[field_name] -%}
<div> <div>
{{ form[field_name] }} {{ form[field_name] }}
{%- if user.is_root and form.instance[field_name] -%} <button class="btn btn-red" @click.prevent="delete_picture()"
<button class="btn btn-red" @click.prevent="window.open('{{ url('core:file_delete', file_id=form.instance[field_name].id, popup='') }}', '_self')"> {%- if not (user.is_root and form.instance[field_name]) -%}
:disabled="picture == null"
{%- endif -%}
x-cloak
>
{%- trans -%}Delete{%- endtrans -%} {%- trans -%}Delete{%- endtrans -%}
</button> </button>
{%- endif -%}
</div> </div>
<p> <p>
{{ form[field_name].label }} {{ form[field_name].label }}
@ -107,6 +110,28 @@
{%- endif -%} {%- 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() { enable_camera() {
this.picture = null; this.picture = null;
this.loading = true; this.loading = true;