summaryrefslogtreecommitdiff
path: root/assets/create.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/create.js')
-rw-r--r--assets/create.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/assets/create.js b/assets/create.js
index cd787af..72d64be 100644
--- a/assets/create.js
+++ b/assets/create.js
@@ -25,4 +25,34 @@ async function createTransaction() {
document.getElementById('create-currency').value = '£';
document.getElementById('create-description').value = '';
document.getElementById('create-amount').value = '';
+}
+
+async function newCreate() {
+ if (!addAmount.valid || !addDescription.valid || document.querySelector(".mdc-add-dialog .mdc-text-field-add-amount > input").value.trim() === "" || document.querySelector(".mdc-add-dialog .mdc-text-field-add-description > input").value.length > 100) return;
+
+ document.getElementById("action-remove").disabled = true;
+ document.getElementById("action-add").disabled = true;
+ document.getElementById("currency-eur").disabled = true;
+ document.getElementById("currency-gbp").disabled = true;
+ document.querySelector(".mdc-add-dialog .mdc-text-field-add-amount > input").disabled = true;
+ document.querySelector(".mdc-add-dialog .mdc-text-field-add-description > input").disabled = true;
+ Array.from(document.querySelectorAll(".mdc-add-dialog .mdc-dialog__actions button")).map((e) => e.disabled = true);
+
+ await (await window.fetch("https://money-v1.equestria.dev/Application/AddTransaction/?Currency=" + (document.getElementById("currency-eur").checked ? "€" : "£") + "&Amount=" + document.querySelector(".mdc-add-dialog .mdc-text-field-add-amount > input").value + "&Operation=" + (document.getElementById("action-add").checked ? "+" : "-") + "&Description=" + btoa(document.querySelector(".mdc-add-dialog .mdc-text-field-add-description > input").value).replaceAll("+", "-").replaceAll("/", "_"))).text();
+
+ await refresh();
+
+ document.getElementById("action-remove").disabled = false;
+ document.getElementById("action-add").disabled = false;
+ document.getElementById("currency-eur").disabled = false;
+ document.getElementById("currency-gbp").disabled = false;
+ document.querySelector(".mdc-add-dialog .mdc-text-field-add-amount > input").disabled = false;
+ document.querySelector(".mdc-add-dialog .mdc-text-field-add-description > input").disabled = false;
+ Array.from(document.querySelectorAll(".mdc-add-dialog .mdc-dialog__actions button")).map((e) => e.disabled = false);
+ addDialog.close();
+
+ document.getElementById("action-add").checked = true;
+ document.getElementById("currency-gbp").checked = true;
+ document.querySelector(".mdc-add-dialog .mdc-text-field-add-amount > input").value = "";
+ document.querySelector(".mdc-add-dialog .mdc-text-field-add-description > input").value = "";
} \ No newline at end of file