diff --git a/src/accounting/account/forms.py b/src/accounting/account/forms.py index cee24a2..15b39fc 100644 --- a/src/accounting/account/forms.py +++ b/src/accounting/account/forms.py @@ -131,11 +131,11 @@ def sort_accounts_in(base_code: str, exclude: int) -> None: accounts[i].no = i + 1 -class AccountSortForm: - """The form to sort the accounts.""" +class AccountReorderForm: + """The form to reorder the accounts.""" def __init__(self, base: BaseAccount): - """Constructs the form to sort the accounts under a base account. + """Constructs the form to reorder the accounts under a base account. :param base: The base account. """ diff --git a/src/accounting/account/views.py b/src/accounting/account/views.py index 942c20d..8c5de72 100644 --- a/src/accounting/account/views.py +++ b/src/accounting/account/views.py @@ -29,7 +29,7 @@ from accounting.models import Account, BaseAccount from accounting.utils.next_url import inherit_next, or_next from accounting.utils.pagination import Pagination from accounting.utils.permission import can_view, has_permission, can_edit -from .forms import AccountForm, sort_accounts_in, AccountSortForm +from .forms import AccountForm, sort_accounts_in, AccountReorderForm bp: Blueprint = Blueprint("account", __name__) """The view blueprint for the account management.""" @@ -168,28 +168,27 @@ def delete_account(account: Account) -> redirect: return redirect(or_next(url_for("accounting.account.list"))) -@bp.get("/sort/", endpoint="sort-form") +@bp.get("/base/", endpoint="order") @has_permission(can_edit) -def show_sort_form(base: BaseAccount) -> str: - """Shows the form to sort the accounts under a base account. +def show_account_order(base: BaseAccount) -> str: + """Shows the order of the accounts under a same base account. :param base: The base account. - :return: The form to sort the accounts under the base account. + :return: The order of the accounts under the base account. """ - return render_template("accounting/account/sort.html", - base=base) + return render_template("accounting/account/order.html", base=base) -@bp.post("/sort/", endpoint="sort") +@bp.post("/base/", endpoint="sort") @has_permission(can_edit) def sort_accounts(base: BaseAccount) -> redirect: - """Sorts the accounts under a base account. + """Reorders the accounts under a base account. :param base: The base account. :return: The redirection to the incoming account or the account list. The - sorting operation does not fail. + reordering operation does not fail. """ - form: AccountSortForm = AccountSortForm(base) + form: AccountReorderForm = AccountReorderForm(base) form.save_order() if not form.is_modified: flash(lazy_gettext("The order was not modified."), "success") diff --git a/src/accounting/static/js/account-sort.js b/src/accounting/static/js/account-order.js similarity index 71% rename from src/accounting/static/js/account-sort.js rename to src/accounting/static/js/account-order.js index 9a56e53..bc76e43 100644 --- a/src/accounting/static/js/account-sort.js +++ b/src/accounting/static/js/account-order.js @@ -1,5 +1,5 @@ /* The Mia! Accounting Flask Project - * account-sort.js: The JavaScript for the account sorting form + * account-order.js: The JavaScript for the account order */ /* Copyright (c) 2023 imacat. @@ -23,15 +23,15 @@ // Initializes the page JavaScript. document.addEventListener("DOMContentLoaded", function () { - const list = document.getElementById("sort-account-list"); + const list = document.getElementById("account-order-list"); const onReorder = function () { const accounts = Array.from(list.children); for (let i = 0; i < accounts.length; i++) { - const input = document.getElementById("sort-" + accounts[i].dataset.id + "-no"); - const code = document.getElementById("sort-" + accounts[i].dataset.id + "-code"); - input.value = i + 1; + const no = document.getElementById("account-order-" + accounts[i].dataset.id + "-no"); + const code = document.getElementById("account-order-" + accounts[i].dataset.id + "-code"); + no.value = String(i + 1); code.innerText = list.dataset.baseCode + "-" + ("000" + (i + 1)).slice(-3); } }; - initializeDragAndDropSorting(list, onReorder); + initializeDragAndDropReordering(list, onReorder); }); diff --git a/src/accounting/static/js/drag-and-drop-sorting.js b/src/accounting/static/js/drag-and-drop-reorder.js similarity index 79% rename from src/accounting/static/js/drag-and-drop-sorting.js rename to src/accounting/static/js/drag-and-drop-reorder.js index c90b9e7..10f5106 100644 --- a/src/accounting/static/js/drag-and-drop-sorting.js +++ b/src/accounting/static/js/drag-and-drop-reorder.js @@ -1,5 +1,5 @@ /* The Mia! Accounting Flask Project - * drag-and-drop-sorting.js: The JavaScript for the sorting with drag-and-drop + * drag-and-drop-reorder.js: The JavaScript for the reorder a list with drag-and-drop */ /* Copyright (c) 2023 imacat. @@ -22,24 +22,24 @@ */ /** - * Initializes the drag-and-drop sorting on a list. + * Initializes the drag-and-drop reordering on a list. * - * @param list {HTMLElement} the list to be sorted + * @param list {HTMLElement} the list to be reordered * @param onReorder {(function())|*} The callback to reorder the items */ -function initializeDragAndDropSorting(list, onReorder) { - initializeMouseDragAndDropSorting(list, onReorder); - initializeTouchDragAndDropSorting(list, onReorder); +function initializeDragAndDropReordering(list, onReorder) { + initializeMouseDragAndDropReordering(list, onReorder); + initializeTouchDragAndDropReordering(list, onReorder); } /** - * Initializes the drag-and-drop sorting with mouse. + * Initializes the drag-and-drop reordering with mouse. * - * @param list {HTMLElement} the list to be sorted + * @param list {HTMLElement} the list to be reordered * @param onReorder {(function())|*} The callback to reorder the items * @private */ -function initializeMouseDragAndDropSorting(list, onReorder) { +function initializeMouseDragAndDropReordering(list, onReorder) { const items = Array.from(list.children); let dragged = null; items.forEach(function (item) { @@ -60,13 +60,13 @@ function initializeMouseDragAndDropSorting(list, onReorder) { } /** - * Initializes the drag-and-drop sorting with touch devices. + * Initializes the drag-and-drop reordering with touch devices. * - * @param list {HTMLElement} the list to be sorted + * @param list {HTMLElement} the list to be reordered * @param onReorder {(function())|*} The callback to reorder the items * @private */ -function initializeTouchDragAndDropSorting(list, onReorder) { +function initializeTouchDragAndDropReordering(list, onReorder) { const items = Array.from(list.children); items.forEach(function (item) { item.addEventListener("touchstart", function () { diff --git a/src/accounting/templates/accounting/account/detail.html b/src/accounting/templates/accounting/account/detail.html index 874ce42..d6ffcec 100644 --- a/src/accounting/templates/accounting/account/detail.html +++ b/src/accounting/templates/accounting/account/detail.html @@ -35,9 +35,9 @@ First written: 2023/1/31 {{ A_("Settings") }} - - - {{ A_("Sort") }} + + + {{ A_("Order") }}