Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make editing a bill into a modal #1220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about having multiple different IDs for each of the modals here rather than sharing the same id?

<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
Loading