From 6153ca426f9f880c70564ecb2d5346d64c2802eb Mon Sep 17 00:00:00 2001 From: Javier Hernandez Date: Mon, 5 Feb 2024 10:48:12 +0100 Subject: improve delete confirmation Make delete confirmations show information in a manner that is easier to read. This includes delete confirmations for centers, room and folder. Messages are now more clear. Also, content table shows the type of the items (folder, room, etc.) --- ogcp/forms/action_forms.py | 6 ++---- ogcp/templates/actions/delete_center.html | 30 ++++++++++++++++-------------- ogcp/templates/actions/delete_room.html | 18 +++++++++++------- ogcp/templates/actions/folder_delete.html | 30 ++++++++++++++++-------------- ogcp/views.py | 26 +++++++++----------------- 5 files changed, 54 insertions(+), 56 deletions(-) diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index 3c53d0c..8586665 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -175,8 +175,7 @@ class CenterForm(FlaskForm): class DeleteCenterForm(FlaskForm): server = HiddenField() - center = SelectField(label=_l('Center'), - validators=[InputRequired()]) + center = HiddenField() submit = SubmitField(label=_l('Submit')) class RoomForm(FlaskForm): @@ -194,8 +193,7 @@ class RoomForm(FlaskForm): class DeleteRoomForm(FlaskForm): server = HiddenField() - room = SelectField(label=_l('Room'), - validators=[InputRequired()]) + room = HiddenField() submit = SubmitField(label=_l('Submit')) class ImageDetailsForm(FlaskForm): diff --git a/ogcp/templates/actions/delete_center.html b/ogcp/templates/actions/delete_center.html index af89364..5379a58 100644 --- a/ogcp/templates/actions/delete_center.html +++ b/ogcp/templates/actions/delete_center.html @@ -9,12 +9,11 @@ {% block content %}

{{_('Delete center')}}

-{% if children %} -

The following items will be deleted

+

The following center and its content will be deleted

- -{% for c in children %} - - - -{% endfor %} +{% if children %} + {% for type, elements in children.items() %} + + + + + {% endfor %} +{% else %} + +{% endif %}
+ {% for x in ancestors %} {{x}} {% if not loop.last %} @@ -25,19 +24,22 @@
- {% if c['type'] == 'folder' %} - 📁 - {% endif %} - {{c['name']}} -
{{ type }} + {% for e in elements %} + {{e}} + {% endfor %} +
This center is empty
-{% endif %} {{ wtf.quick_form(form, action=url_for('action_center_delete'), diff --git a/ogcp/templates/actions/delete_room.html b/ogcp/templates/actions/delete_room.html index 3fa24cf..b4c3601 100644 --- a/ogcp/templates/actions/delete_room.html +++ b/ogcp/templates/actions/delete_room.html @@ -11,11 +11,11 @@

{{_('Delete room')}}

{% if children %} -

The following items will be deleted

+

The following room and its content will be deleted

- -{% for c in children %} +{% if children %} +{% for type, elements in children.items() %} + {% endfor %} +{% else %} + +{% endif %}
+ {% for x in ancestors %} {{x}} {% if not loop.last %} @@ -26,16 +26,20 @@
{{ type }} - {% if c['type'] == 'folder' %} - 📁 - {% endif %} - {{c['name']}} + {% for e in elements %} + {{e}} + {% endfor %}
This room is empty
{% endif %} diff --git a/ogcp/templates/actions/folder_delete.html b/ogcp/templates/actions/folder_delete.html index 8d497e8..0f58026 100644 --- a/ogcp/templates/actions/folder_delete.html +++ b/ogcp/templates/actions/folder_delete.html @@ -10,12 +10,11 @@

{{_('Delete folder')}}

-{% if children %} -

The following items will be deleted

+

The following folder and its content will be deleted

- -{% for c in children %} - - - -{% endfor %} +{% if children %} + {% for type, elements in children.items() %} + + + + + {% endfor %} +{% else %} + +{% endif %}
+ {% for x in ancestors %} {{x}} {% if not loop.last %} @@ -26,19 +25,22 @@
- {% if c['type'] == 'folder' %} - 📁 - {% endif %} - {{c['name']}} -
{{ type }} + {% for e in elements %} + {{e}} + {% endfor %} +
This folder is empty
-{% endif %} {{ wtf.quick_form(form, method='post', diff --git a/ogcp/views.py b/ogcp/views.py index cdb1582..572b784 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1222,10 +1222,9 @@ def action_folder_delete(): form.submit.render_kw = {"formaction": url_for('action_folder_delete')} scopes, unused = get_scopes() - form.name.render_kw = {'readonly': True} ancestors, children = get_scope_context(int(folder_id), 'folder', scopes) - form.name.data = ancestors[len(ancestors)-1] + del form.name return render_template('actions/folder_delete.html', form=form, parent="scopes.html", scopes=scopes, ancestors=ancestors, children=children) @@ -1885,9 +1884,11 @@ def get_scope_context_rec(elem_id, elem_type, scopes, ancestors): def get_scope_context(elem_id, elem_type, scopes): ancestors, elem = get_scope_context_rec(elem_id, elem_type, scopes['scope'], []) - children = [] + children = {} for c in elem['scope']: - children.append({'name':c['name'], 'type':c['type']}) + if c['type'] not in children: + children[c['type']] = [] + children[c['type']].append(c['name']) return (ancestors, children) @app.route('/action/center/delete', methods=['GET', 'POST']) @@ -1916,15 +1917,10 @@ def action_center_delete(): if r.status_code != requests.codes.ok: return ogserver_error('scopes') - selected_center_id = params['scope-center'] - centers = parse_scopes_from_tree(r.json(), 'center') - selected_center = [(center['id'], center['name']) for center in centers - if center['id'] == int(selected_center_id)] - form.center.choices = selected_center - form.center.render_kw = {'readonly': True} + form.center.data = params['scope-center'] form.server.data = params['scope-server'] scopes, clients = get_scopes() - ancestors, children = get_scope_context(int(selected_center_id), 'center', scopes) + ancestors, children = get_scope_context(int(params['scope-center']), 'center', scopes) return render_template('actions/delete_center.html', form=form, scopes=scopes, ancestors=ancestors, children=children) @@ -2000,15 +1996,11 @@ def action_room_delete(): if r.status_code != requests.codes.ok: return ogserver_error('scopes') - rooms = parse_scopes_from_tree(r.json(), 'room') - selected_room_id = params['scope-room'] - selected_room = [(room['id'], room['name'] + " (" + room['parent'] + ")") - for room in rooms if room['id'] == int(selected_room_id)] - form.room.choices = selected_room + form.room.data = params['scope-room'] form.room.render_kw = {'readonly': True} form.server.data = params['scope-server'] scopes, clients = get_scopes() - ancestors, children = get_scope_context(int(selected_room_id), 'room', scopes) + ancestors, children = get_scope_context(int(params['scope-room']), 'room', scopes) return render_template('actions/delete_room.html', form=form, scopes=scopes, ancestors=ancestors, children=children) -- cgit v1.2.3-18-g5258