refactor(web): move common TDBMS functions to tdbms.js

This commit is contained in:
2023-02-09 18:49:25 +03:00
parent a1e6f3e9e1
commit 87404e34d3
5 changed files with 91 additions and 90 deletions
+86
View File
@@ -1,3 +1,32 @@
var sasahyou = null, sappyou = null, shoppyou = null;
var sort_files = localStorage["sort_files"],
sort_tags = localStorage["sort_tags"];
if (localStorage["sasahyou"] != null) {
sasahyou = JSON.parse(localStorage["sasahyou"]);
}
if (localStorage["sappyou"] != null) {
sappyou = JSON.parse(localStorage["sappyou"]);
}
if (localStorage["shoppyou"] != null) {
shoppyou = JSON.parse(localStorage["shoppyou"]);
}
var sasahyou_mts = 0, sappyou_mts = 0, shoppyou_mts = 0;
if (localStorage["sasahyou_mts"] != null) {
sasahyou_mts = parseInt(localStorage["sasahyou_mts"]);
}
if (localStorage["sappyou_mts"] != null) {
sappyou_mts = parseInt(localStorage["sappyou_mts"]);
}
if (localStorage["shoppyou_mts"] != null) {
shoppyou_mts = parseInt(localStorage["shoppyou_mts"]);
}
if (sort_files == null) {
sort_files = "id";
}
if (sort_tags == null) {
sort_tags = "id";
}
function tdb_query(trdb, trc, trb) {
let output = null;
$.ajax({
@@ -22,3 +51,60 @@ function tdb_query(trdb, trc, trb) {
});
return output;
}
function sasahyou_load(tdb) {
let db_info = tdb_query(tdb, 0, "");
if (db_info == null || !db_info.status) {
alert("Failed to fetch database");
throw new Error("Failed to fetch database");
}
if (sasahyou == null || sasahyou_mts !== db_info.data[0].sasahyou.mts) {
let resp = tdb_query(tdb, 16, "");
if (resp == null || !resp.status) {
alert("Failed to get sasahyou");
throw new Error("Failed to get sasahyou");
}
sasahyou = resp.data;
sasahyou_mts = db_info.data[0].sasahyou.mts;
localStorage["sasahyou"] = JSON.stringify(sasahyou);
localStorage["sasahyou_mts"] = sasahyou_mts;
}
}
function sappyou_load(tdb) {
let db_info = tdb_query(tdb, 0, "");
if (db_info == null || !db_info.status) {
alert("Failed to fetch database");
throw new Error("Failed to fetch database");
}
if (sappyou == null || sappyou_mts !== db_info.data[0].sappyou.mts) {
let resp = tdb_query(tdb, 32, "");
if (resp == null || !resp.status) {
alert("Failed to get sappyou");
throw new Error("Failed to get sappyou");
}
sappyou = resp.data;
sappyou_mts = db_info.data[0].sappyou.mts;
localStorage["sappyou"] = JSON.stringify(sappyou);
localStorage["sappyou_mts"] = sappyou_mts;
}
}
function shoppyou_load(tdb) {
let db_info = tdb_query(tdb, 0, "");
if (db_info == null || !db_info.status) {
alert("Failed to fetch database");
throw new Error("Failed to fetch database");
}
if (shoppyou == null || shoppyou_mts !== db_info.data[0].shoppyou.mts) {
let resp = tdb_query(tdb, 8, "");
if (resp == null || !resp.status) {
alert("Failed to get shoppyou");
throw new Error("Failed to get shoppyou");
}
shoppyou = resp.data;
shoppyou_mts = db_info.data[0].shoppyou.mts;
localStorage["shoppyou"] = JSON.stringify(shoppyou);
localStorage["shoppyou_mts"] = shoppyou_mts;
}
}