fix(web): fix tdb response checking in js

This commit is contained in:
Masahiko AMANO 2023-02-17 23:51:45 +03:00
parent 880d4df453
commit c9b921becf
9 changed files with 53 additions and 49 deletions

View File

@ -4,11 +4,11 @@ $(document).on("click", "#btn-save", function (e) {
return;
}
let resp = tdb_query(db_name, 4);
if (resp.status) {
alert("Successfully saved!");
} else {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}
alert("Successfully saved!");
});
$(document).on("click", "#btn-reload", function (e) {
@ -20,14 +20,14 @@ $(document).on("click", "#btn-reload", function (e) {
return;
}
let resp = tdb_query(db_name, 2);
if (resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}
localStorage["sasahyou_mts"] = sasahyou_mts = 0;
localStorage["sappyou_mts"] = sappyou_mts = 0;
localStorage["shoppyou_mts"] = shoppyou_mts = 0;
alert("Successfully reloaded database!");
} else {
alert("Something went wrong!");
}
});
$(document).on("click", "#btn-remove", function (e) {
@ -39,14 +39,14 @@ $(document).on("click", "#btn-remove", function (e) {
return;
}
let resp = tdb_query(db_name, 1);
if (resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}
localStorage.removeItem("db_name");
db_name = null;
localStorage["sasahyou_mts"] = sasahyou_mts = 0;
localStorage["sappyou_mts"] = sappyou_mts = 0;
localStorage["shoppyou_mts"] = shoppyou_mts = 0;
alert("Successfully removed database!");
} else {
alert("Something went wrong!");
}
});

View File

@ -2,17 +2,17 @@ $(document).on("submit", "#newdb", function (e) {
e.preventDefault();
let newdb_name = $("#newdb-name").val(), newdb_path = $("#newdb-path").val();
let resp = tdb_query(newdb_name, 3);
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Failed to initialize database!");
return;
}
resp = tdb_query(newdb_name, 4, newdb_path);
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Failed to save database!");
return;
}
resp = tdb_query(newdb_name, 6, "path=" + newdb_path);
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Failed to finalize database!");
return;
}

View File

@ -30,7 +30,7 @@ function settings_load() {
$(window).on("load", function () {
let resp = tdb_query();
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Failed to fetch databases");
throw new Error("Failed to fetch databases");
}

View File

@ -1,6 +1,6 @@
$(window).on("load", function (e) {
let resp = tdb_query(db_name);
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Failed to fetch database");
throw new Error("Failed to fetch database");
}

View File

@ -9,11 +9,11 @@ $(document).on("click", "#btn-save", function (e) {
return;
}
let resp = tdb_query(db_name, 4);
if (resp.status) {
alert("Successfully saved!");
} else {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}
alert("Successfully saved!");
});
$(document).on("click", "#btn-reload", function (e) {
@ -25,12 +25,12 @@ $(document).on("click", "#btn-reload", function (e) {
return;
}
let resp = tdb_query(db_name, 2);
if (resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}
localStorage["sasahyou_mts"] = sasahyou_mts = 0;
localStorage["sappyou_mts"] = sappyou_mts = 0;
localStorage["shoppyou_mts"] = shoppyou_mts = 0;
alert("Successfully reloaded database!");
} else {
alert("Something went wrong!");
}
});

View File

@ -21,7 +21,7 @@ $(window).on("load", function () {
$(document).on("submit", "#menu-add form", function (e) {
e.preventDefault();
let resp = tdb_query(db_name, 18, $("#new-name").val());
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}

View File

@ -26,7 +26,7 @@ function menu_view_file_open() {
$("#menu-file-view .list-item").css("display", "");
$("#btn-full").attr("href", "/files/" + current_sasa.path);
let resp = tdb_query(db_name, 24, '' + current_sasa.id);
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}
@ -59,7 +59,7 @@ function menu_view_tag_open() {
$("#tag-name").val(decodeURI(current_tanzaku.name));
$("#description").val(current_tanzaku.desc);
let resp = tdb_query(db_name, 40, '' + current_tanzaku.id);
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}
@ -262,7 +262,7 @@ $(document).on("reset", "#menu-add form", function (e) {
$(document).on("submit", "#menu-file-view form", function (e) {
e.preventDefault();
let resp = tdb_query(db_name, 24, '' + current_sasa.id);
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}
@ -280,11 +280,13 @@ $(document).on("submit", "#menu-file-view form", function (e) {
}
});
let status = true;
if (toadd !== "" && !tdb_query(db_name, 26, '' + current_sasa.id + toadd).status) {
status = false;
if (toadd !== "") {
resp = tdb_query(db_name, 26, '' + current_sasa.id + toadd);
status = (resp != null && resp.status);
}
if (toremove !== "" && !tdb_query(db_name, 25, '' + current_sasa.id + toremove).status) {
status = false;
if (toremove !== "") {
resp = tdb_query(db_name, 25, '' + current_sasa.id + toremove);
status = (resp != null && resp.status);
}
if (status) {
alert("Saved changes!");
@ -300,7 +302,7 @@ $(document).on("submit", "#menu-tag-view form", function (e) {
desc = $("#description").val();
if (name !== current_tanzaku.name || desc !== current_tanzaku.desc) {
resp = tdb_query(db_name, 36, '' + current_tanzaku.id + ' ' + name + '\n' + desc);
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}
@ -309,7 +311,7 @@ $(document).on("submit", "#menu-tag-view form", function (e) {
$(`.tanzaku[tid=${current_tanzaku.id}]`).text(name);
}
resp = tdb_query(db_name, 40, '' + current_tanzaku.id);
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}
@ -327,11 +329,13 @@ $(document).on("submit", "#menu-tag-view form", function (e) {
}
});
let status = true;
if (toadd !== "" && !tdb_query(db_name, 42, '' + current_tanzaku.id + toadd).status) {
status = false;
if (toadd !== "") {
resp = tdb_query(db_name, 42, '' + current_tanzaku.id + toadd);
status = (resp != null && resp.status);
}
if (toremove !== "" && !tdb_query(db_name, 41, '' + current_tanzaku.id + toremove).status) {
status = false;
if (toremove !== "") {
resp = tdb_query(db_name, 41, '' + current_tanzaku.id + toremove);
status = (resp != null && resp.status);
}
if (status) {
alert("Saved changes!");
@ -346,7 +350,7 @@ $(document).on("click", "#btn-remove", function (e) {
return;
}
let resp = tdb_query(db_name, 33, '' + current_tanzaku.id);
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}

View File

@ -40,7 +40,7 @@ function settings_load() {
$(window).on("load", function () {
let resp = tdb_query();
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Failed to fetch databases");
throw new Error("Failed to fetch databases");
}
@ -65,7 +65,7 @@ $(document).on("submit", "#settings", function (e) {
let db_name_val = db_name_input.val();
if (db_name_val !== db_name) {
let resp = tdb_query();
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Failed to fetch databases");
return;
}

View File

@ -30,7 +30,7 @@ $(document).on("input", "#text-filter-all", function (e) {
$(document).on("submit", "#menu-add form", function (e) {
e.preventDefault();
let resp = tdb_query(db_name, 34, $("#new-name").val() + '\n' + $("#new-description").val());
if (!resp.status) {
if (resp == null || !resp.status) {
alert("Something went wrong!");
return;
}