Skip to content

Commit

Permalink
Make editing a bill into a modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Jojo144 committed Aug 28, 2023
1 parent 04c375e commit d5f7ecb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ihatemoney/templates/list_bills.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

// ask for confirmation before removing an user
$('.action.delete').each(function(){
Expand Down Expand Up @@ -86,6 +87,25 @@ <h3 class="modal-title">{{ _('Add a bill') }}</h3>
</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">
Expand Down Expand Up @@ -143,7 +163,7 @@ <h3 class="modal-title">{{ _('Add a bill') }}</h3>
</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>
Expand Down
10 changes: 10 additions & 0 deletions ihatemoney/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,14 @@ def list_bills():
if "last_selected_payer" in session:
bill_form.payer.data = session["last_selected_payer"]

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.
Expand All @@ -661,6 +669,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",
Expand Down

0 comments on commit d5f7ecb

Please sign in to comment.