Added more confirmation dialogs to delete forms

This commit is contained in:
Xu 2023-11-05 16:29:07 +01:00 committed by Igor Scheller
parent ff179360cc
commit 93270a10fd
12 changed files with 74 additions and 50 deletions

View File

@ -316,7 +316,9 @@ ready(() => {
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="${element.className}" <button type="button" class="${element.className}"
title="${element.title}" data-submit="">${element.innerHTML}</button> title="${element.title}" data-submit="">
${element.dataset.confirm_button_text ?? element.innerHTML}
</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -57,7 +57,7 @@
<div class="btn-group"> <div class="btn-group">
{{ f.submit(__('form.save'), {'icon_left': 'save'}) }} {{ f.submit(__('form.save'), {'icon_left': 'save'}) }}
{% if location %} {% if location %}
{{ f.submit(__('form.delete'), {'name': 'delete', 'btn_type': 'danger', 'icon_left': 'trash'}) }} {{ f.delete(__('form.delete'), {'confirm_title': location.name|e}) }}
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@ -265,6 +265,8 @@ Renders a button.
@param {string} [opt.confirm_text] - Optional value for the confirmation text. @param {string} [opt.confirm_text] - Optional value for the confirmation text.
#} #}
{% macro button(label, opt) %} {% macro button(label, opt) %}
{%- set icon_left = opt.icon_left is defined ? '<span class="bi bi-' ~ opt.icon_left ~ '"></span>' : '' %}
{%- set icon_right = opt.icon_right is defined ? '<span class="bi bi-' ~ opt.icon_right ~ '"></span>' : '' %}
<button <button
class="btn btn-{{ opt.btn_type|default('secondary') }} class="btn btn-{{ opt.btn_type|default('secondary') }}
{%- if opt.size is defined %} btn-{{ opt.size }}{% endif %}" {%- if opt.size is defined %} btn-{{ opt.size }}{% endif %}"
@ -274,10 +276,13 @@ Renders a button.
{%- if opt.value is defined or opt.name is defined %} value="{{ opt.value|default('1') }}"{% endif -%} {%- if opt.value is defined or opt.name is defined %} value="{{ opt.value|default('1') }}"{% endif -%}
{%- if opt.confirm_title is defined %} data-confirm_submit_title="{{ opt.confirm_title }}"{% endif -%} {%- if opt.confirm_title is defined %} data-confirm_submit_title="{{ opt.confirm_title }}"{% endif -%}
{%- if opt.confirm_text is defined %} data-confirm_submit_text="{{ opt.confirm_text }}"{% endif -%} {%- if opt.confirm_text is defined %} data-confirm_submit_text="{{ opt.confirm_text }}"{% endif -%}
{%- if opt.confirm_button_text is defined %}
data-confirm_button_text="{{ icon_left ~ ' ' ~ opt.confirm_button_text ~ ' ' ~ icon_right }}"
{%- endif -%}
> >
{%- if opt.icon_left is defined %}<span class="bi bi-{{ opt.icon_left }}"></span>{% endif %} {{ icon_left|raw }}
{{ label }} {{ label }}
{%- if opt.icon_right is defined %}<span class="bi bi-{{ opt.icon_right }}"></span>{% endif %} {{ icon_right|raw }}
</button> </button>
{%- endmacro %} {%- endmacro %}

View File

@ -46,12 +46,12 @@
'value': faq ? faq.text : '', 'value': faq ? faq.text : '',
}) }} }) }}
{{ f.submit() }} {{ f.submit(__('form.save'), {'icon_left': 'save'}) }}
{{ f.submit(m.icon('eye'), {'name': 'preview', 'btn_type': 'info', 'title': __('form.preview')}) }} {{ f.submit(m.icon('eye'), {'name': 'preview', 'btn_type': 'info', 'title': __('form.preview')}) }}
{% if faq and faq.id %} {% if faq and faq.id %}
{{ f.submit(m.icon('trash'), {'name': 'delete', 'btn_type': 'danger', 'title': __('form.delete')}) }} {{ f.delete(__('form.delete'), {'confirm_title': faq.question[:40]|e})}}
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@ -58,6 +58,18 @@
<span class="ms-auto"> <span class="ms-auto">
{{ m.button(m.icon('pencil'), url('/admin/faq/' ~ item.id), 'secondary', 'sm') }} {{ m.button(m.icon('pencil'), url('/admin/faq/' ~ item.id), 'secondary', 'sm') }}
</span> </span>
<form class="ps-1"
action="{{ url('/admin/faq/' ~ item.id) }}"
enctype="multipart/form-data"
method="post">
{{ csrf() }}
{{ f.delete(null, {
'size': 'sm',
'confirm_title': item.question[:40]|e,
'confirm_button_text': __('form.delete')
}) }}
</form>
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@ -70,12 +70,12 @@
<p>{{ m.info(__('news.edit.hint')) }}</p> <p>{{ m.info(__('news.edit.hint')) }}</p>
{{ f.submit() }} {{ f.submit(__('form.save'), {'icon_left': 'save'}) }}
{{ f.submit(m.icon('eye'), {'name': 'preview', 'btn_type': 'info', 'title': __('form.preview')}) }} {{ f.submit(m.icon('eye'), {'name': 'preview', 'btn_type': 'info', 'title': __('form.preview')}) }}
{% if news and news.id %} {% if news and news.id %}
{{ f.submit(m.icon('trash'), {'name': 'delete', 'btn_type': 'danger', 'title': __('form.delete')}) }} {{ f.delete(__('form.delete'), {'confirm_title': news.title[:40]|e}) }}
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@ -1,5 +1,6 @@
{% extends 'layouts/app.twig' %} {% extends 'layouts/app.twig' %}
{% import 'macros/base.twig' as m %} {% import 'macros/base.twig' as m %}
{% import 'macros/form.twig' as f %}
{% set only_meetings = only_meetings|default(false) %} {% set only_meetings = only_meetings|default(false) %}
{% block title %}{{ not only_meetings ? __('news.title') : __('news.title.meetings') }}{% endblock %} {% block title %}{{ not only_meetings ? __('news.title') : __('news.title.meetings') }}{% endblock %}
@ -94,8 +95,19 @@
{% endif %} {% endif %}
{% if has_permission_to('admin_news') %} {% if has_permission_to('admin_news') %}
<div> <div class="d-flex ms-auto">
{{ m.button(m.icon('pencil'), url('/admin/news/' ~ news.id), 'secondary', 'sm') }} {{ m.button(m.icon('pencil'), url('/admin/news/' ~ news.id), 'secondary', 'sm') }}
<form class="ps-1"
action="{{ url('/admin/news/' ~ news.id) }}" enctype="multipart/form-data"
method="post">
{{ csrf() }}
{{ f.delete(null, {
'size': 'sm',
'confirm_title': news.title[:40]|e,
'confirm_button_text': __('form.delete')
}) }}
</form>
</div> </div>
{% endif %} {% endif %}
</div> </div>

View File

@ -48,13 +48,11 @@
}) }} }) }}
{% endif %} {% endif %}
{{ f.submit() }} {{ f.submit(__('form.save'), {'icon_left': 'save'}) }}
{% if is_admin|default(false) %} {% if is_admin|default(false) %}
{{ f.submit(m.icon('eye'), {'name': 'preview', 'btn_type': 'info', 'title': __('form.preview')}) }} {{ f.submit(m.icon('eye'), {'name': 'preview', 'btn_type': 'info', 'title': __('form.preview')}) }}
{% if question and question.id %} {% if question and question.id %}
{{ f.submit(m.icon('trash'), {'name': 'delete', 'btn_type': 'danger', 'title': __('form.delete')}) }} {{ f.delete(__('form.delete'), {'confirm_title': question.text[:40]|e}) }}
{% endif %} {% endif %}
{% endif %} {% endif %}
</div> </div>

View File

@ -42,26 +42,21 @@
{% if has_permission_to('question.edit') %} {% if has_permission_to('question.edit') %}
{{ m.user(question.user, {'pronoun': true}) }} {{ m.user(question.user, {'pronoun': true}) }}
<div class="d-flex ms-auto">
{% endif %} {% endif %}
{% if question.user.id == user.id or has_permission_to('question.edit') %} <div class="d-flex ms-auto">
<form {% if has_permission_to('question.edit') %}
class="pe-1" {{ m.button(m.icon('pencil'), url('/admin/questions/' ~ question.id), null, 'sm') }}
action="" {% endif %}
enctype="multipart/form-data"
method="post"
>
{{ csrf() }}
{{ f.hidden('id', question.id) }}
{{ f.delete(null, {'size': 'sm', 'confirm_title': question.text[:40]|e}) }}
</form>
{% endif %}
{% if has_permission_to('question.edit') %} {% if question.user.id == user.id or has_permission_to('question.edit') %}
{{ m.button(m.icon('pencil'), url('/admin/questions/' ~ question.id), null, 'sm') }} <form class="ps-1" method="post" action="">
</div> {{ csrf() }}
{% endif %} {{ f.hidden('id', question.id) }}
{{ f.delete(null, {'size': 'sm', 'confirm_title': question.text[:40]|e, 'confirm_button_text': __('form.delete')}) }}
</form>
{% endif %}
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -40,7 +40,7 @@
{{ csrf() }} {{ csrf() }}
{{ f.hidden('id', session.id[:15]) }} {{ f.hidden('id', session.id[:15]) }}
{{ f.submit( {{ f.submit(
__('form.delete'), ' ',
{'name': 'delete', 'btn_type': 'danger', 'size': 'sm', 'icon_left': 'trash'} {'name': 'delete', 'btn_type': 'danger', 'size': 'sm', 'icon_left': 'trash'}
) }} ) }}
</form> </form>

View File

@ -46,14 +46,7 @@ class FaqController extends BaseController
/** @var Faq $faq */ /** @var Faq $faq */
$faq = $this->faq->findOrNew($faqId); $faq = $this->faq->findOrNew($faqId);
$data = $this->validate($request, [ if ($request->request->has('delete')) {
'question' => 'required',
'text' => 'required',
'delete' => 'optional|checked',
'preview' => 'optional|checked',
]);
if (!is_null($data['delete'])) {
$faq->delete(); $faq->delete();
$this->log->info('Deleted faq "{question}"', ['question' => $faq->question]); $this->log->info('Deleted faq "{question}"', ['question' => $faq->question]);
@ -63,6 +56,13 @@ class FaqController extends BaseController
return $this->redirect->to('/faq'); return $this->redirect->to('/faq');
} }
$data = $this->validate($request, [
'question' => 'required',
'text' => 'required',
'delete' => 'optional|checked',
'preview' => 'optional|checked',
]);
$faq->question = $data['question']; $faq->question = $data['question'];
$faq->text = $data['text']; $faq->text = $data['text'];

View File

@ -62,17 +62,7 @@ class NewsController extends BaseController
/** @var News $news */ /** @var News $news */
$news = $this->news->findOrNew($newsId); $news = $this->news->findOrNew($newsId);
$data = $this->validate($request, [ if ($request->request->has('delete')) {
'title' => 'required',
'text' => 'required',
'is_meeting' => 'optional|checked',
'is_pinned' => 'optional|checked',
'is_highlighted' => 'optional|checked',
'delete' => 'optional|checked',
'preview' => 'optional|checked',
]);
if (!is_null($data['delete'])) {
$news->delete(); $news->delete();
$this->log->info( $this->log->info(
@ -88,6 +78,16 @@ class NewsController extends BaseController
return $this->redirect->to('/news'); return $this->redirect->to('/news');
} }
$data = $this->validate($request, [
'title' => 'required',
'text' => 'required',
'is_meeting' => 'optional|checked',
'is_pinned' => 'optional|checked',
'is_highlighted' => 'optional|checked',
'delete' => 'optional|checked',
'preview' => 'optional|checked',
]);
if (!$news->user) { if (!$news->user) {
$news->user()->associate($this->auth->user()); $news->user()->associate($this->auth->user());
} }