This commit is contained in:
Jojo144 2024-11-16 11:55:10 +01:00 committed by GitHub
commit 3dc708f175
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View file

@ -10,6 +10,7 @@
{% block title %} - {{ g.project.name }}{% endblock %}
{% block js %}
{% if add_bill %} $('#new-bill > a').click(); {% endif %}
{% if edit_bill is not none %} $('#edit-bill > a').click(); {% endif %}
// focus on first field when adding a bill
$("#bill-form").on('shown.bs.modal', function(){
@ -91,6 +92,25 @@
</div>
</div>
</div>
{% if edit_bill is not none %}
<div id="bill-edit-form" class="modal fade show" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">{{ _('Edit this bill') }}</h3>
<a href="#" class="close" data-dismiss="modal">&times;</a>
</div>
<form action="{{ url_for(".edit_bill", bill_id=edit_bill) }}" method="post" class="modal-body container">
{{ forms.add_bill(bill_edit_form, edit=True, title=False) }}
</form>
</div>
</div>
</div>
<span id="edit-bill" class="hidden">
<a href="#" data-toggle="modal" data-keyboard="false" data-target="#bill-edit-form"></a>
</span>
{% endif %}
<div class="d-flex flex-wrap w-100 pt-2 mt-2" id="bill-toolbar">
{% if bills.pages > 1 %}
<ul class="pagination mr-2 mb-0 pb-2 flex-wrap" id="pagination-top">
@ -148,7 +168,7 @@
</span>
</td>
<td class="bill-actions d-flex align-items-center">
<a class="edit" href="{{ url_for(".edit_bill", bill_id=bill.id) }}" title="{{ _("edit") }}">{{ _('edit') }}</a>
<a class="edit" href="{{ url_for(".list_bills", edit_bill=bill.id) }}" title="{{ _("edit") }}">{{ _('edit') }}</a>
<form class="delete-bill" action="{{ url_for(".delete_bill", bill_id=bill.id) }}" method="POST">
{{ csrf_form.csrf_token }}
<button class="action delete" type="submit" title="{{ _("delete") }}"></button>

View file

@ -663,6 +663,14 @@ def list_bills():
):
bill_form.payed_for.data = session["last_selected_payed_for"][g.project.id]
edit_bill = request.values.get("edit_bill", type=int)
bill_edit_form = get_billform_for(g.project)
if edit_bill is not None:
bill = Bill.query.get(g.project, edit_bill)
if not bill:
raise NotFound()
bill_edit_form.fill(bill, g.project)
# Each item will be a (weight_sum, Bill) tuple.
# TODO: improve this awkward result using column_property:
# https://docs.sqlalchemy.org/en/14/orm/mapped_sql_expr.html.
@ -675,6 +683,8 @@ def list_bills():
bills=weighted_bills,
member_form=MemberForm(g.project),
bill_form=bill_form,
edit_bill=edit_bill,
bill_edit_form=bill_edit_form,
csrf_form=csrf_form,
add_bill=request.values.get("add_bill", False),
current_view="list_bills",