{
- dbg!(&trans);
let record = translate(trans);
record.insert(conn.into_inner()).await.unwrap();
@@ -174,5 +217,5 @@ async fn rocket() -> _ {
.attach(Db::init())
.attach(AdHoc::try_on_ignite("Migrations", run_migrations))
.attach(Template::fairing())
- .mount("/", routes![index, add, get_add])
+ .mount("/", routes![index, add, get_add, get_tx, post_tx, delete_tx])
}
diff --git a/bookkeeper/templates/index.html.j2 b/bookkeeper/templates/index.html.j2
index 2f5690b..427be94 100644
--- a/bookkeeper/templates/index.html.j2
+++ b/bookkeeper/templates/index.html.j2
@@ -39,7 +39,7 @@
| {{ (r.gain or 0)|float|round(4) }}% |
{{ (r.net_gain or 0)|float|round(4) }}% |
- 修改
+ 改 删
|
{% else %}
{{ p.date or "" }} |
@@ -63,7 +63,8 @@
|
- |
- |
- 修改 |
+ 改 删
+ |
{% endif %}
{% endfor %}
@@ -109,6 +110,33 @@
openModal($target);
});
+ (document.querySelectorAll('.modify-row') || []).forEach(($cl) => {
+ $cl.addEventListener('click', async () => {
+ const rowId = $cl.attributes.getNamedItem("row-id").value;
+ const $target = document.getElementById("modal");
+ const response = await fetch(`/tx/${rowId}`);
+ if (!response.ok) {
+ return;
+ }
+ document.getElementById('modal-content').innerHTML = await response.text();
+ openModal($target);
+ });
+ });
+
+ (document.querySelectorAll('.delete-row') || []).forEach(($cl) => {
+ $cl.addEventListener('click', async () => {
+ const rowId = $cl.attributes.getNamedItem("row-id").value;
+ if (confirm(`删除${$cl.parentElement.parentElement.innerText}吗?`) !== true) {
+ return;
+ }
+ const response = await fetch(`/tx/${rowId}`, {method: 'DELETE'});
+ alert(`${response.ok ? "OK" : "Fail"}: ${response.status}`);
+ if (response.ok) {
+ $cl.parentElement.parentElement.remove();
+ }
+ });
+ });
+
// Add a click event on various child elements to close the parent modal
(document.querySelectorAll('.modal-background, .modal-close, .modal-card-head .delete, .modal-card-foot .button') || []).forEach(($close) => {
const $target = $close.closest('.modal');
@@ -148,6 +176,8 @@
this_row.parentElement.removeChild(this_row);
}
}
+
+
{% endblock container %}
diff --git a/bookkeeper/templates/tx.html.j2 b/bookkeeper/templates/tx.html.j2
index 12dd47e..32fc726 100644
--- a/bookkeeper/templates/tx.html.j2
+++ b/bookkeeper/templates/tx.html.j2
@@ -34,30 +34,32 @@
|
- |
+ |
|
- |
+ |
操作 |
+ {% if r.split_pieces %}
+ {% for split in r.split_pieces %}
- {% if r.split_pieces %}
- {% for split in r.split_pieces %}
- |
- |
- |
- |
+ |
+ |
+ |
+ |
删除 |
- {% endfor %}
- {% else %}
- |
- |
- |
- |
- 删除 |
- {% endif %}
+ {% endfor %}
+ {% else %}
+
+ |
+ |
+ |
+ |
+ 删除 |
+
+ {% endif %}
| 添加 |
@@ -67,9 +69,6 @@
-
-
-