fix(web): fix settings handling
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
var db_name = localStorage["db_name"];
|
||||
|
||||
$(window).on("load", function (e) {
|
||||
if (db_name != null) {
|
||||
$(".db_name").text(db_name);
|
||||
}
|
||||
});
|
||||
@@ -1,32 +1,34 @@
|
||||
var db_name = localStorage["db_name"];
|
||||
|
||||
function settings_load() {
|
||||
if (db_name != null) {
|
||||
$("#db_name").val(db_name);
|
||||
$(`#db_name option[value="${db_name}"]`).prop("selected", true);
|
||||
} else {
|
||||
$("#db_name").val("");
|
||||
$("#db_name option[value=\"\"]").prop("selected", true);
|
||||
}
|
||||
if (sort_sasa != null) {
|
||||
if (sort_sasa[0] === '-') {
|
||||
$("#sasa-reverse").prop("checked", true);
|
||||
sort_sasa = sort_sasa.slice(1);
|
||||
let sort_s = sort_sasa;
|
||||
if (sort_s[0] === '!') {
|
||||
sort_s = sort_s.slice(1);
|
||||
}
|
||||
$(`#sasa-by-${sort_sasa}`).prop("checked", true);
|
||||
if (sort_s[0] === '-') {
|
||||
$("#sasa-reverse").prop("checked", true);
|
||||
sort_s = sort_s.slice(1);
|
||||
}
|
||||
$(`#sasa-by-${sort_s}`).prop("checked", true);
|
||||
}
|
||||
if (sort_tanzaku != null) {
|
||||
if (sort_tanzaku[0] === '-') {
|
||||
$("#tanzaku-reverse").prop("checked", true);
|
||||
sort_tanzaku = sort_tanzaku.slice(1);
|
||||
let sort_t = sort_tanzaku;
|
||||
if (sort_t[0] === '!') {
|
||||
sort_t = sort_t.slice(1);
|
||||
}
|
||||
$(`#tanzaku-by-${sort_tanzaku}`).prop("checked", true);
|
||||
if (sort_t[0] === '-') {
|
||||
$("#tanzaku-reverse").prop("checked", true);
|
||||
sort_t = sort_t.slice(1);
|
||||
}
|
||||
$(`#tanzaku-by-${sort_t}`).prop("checked", true);
|
||||
}
|
||||
}
|
||||
|
||||
$(window).on("load", function () {
|
||||
settings_load();
|
||||
if (db_name != null) {
|
||||
$(".db_name").text(db_name);
|
||||
}
|
||||
let resp = tdb_query();
|
||||
if (!resp.status) {
|
||||
alert("Failed to fetch databases");
|
||||
@@ -39,6 +41,7 @@ $(window).on("load", function () {
|
||||
}));
|
||||
return true;
|
||||
});
|
||||
settings_load();
|
||||
});
|
||||
|
||||
$(document).on("reset", "#settings", function (e) {
|
||||
|
||||
@@ -2,6 +2,14 @@ db_name = localStorage["tfm_db_name"];
|
||||
if (db_name == null) {
|
||||
location.href = "/tfm/settings";
|
||||
}
|
||||
sort_sasa = localStorage["sort_files"];
|
||||
sort_tanzaku = localStorage["sort_tags"];
|
||||
if (sort_sasa == null) {
|
||||
localStorage["sort_files"] = sort_sasa = "id";
|
||||
}
|
||||
if (sort_tanzaku == null) {
|
||||
localStorage["sort_tags"] = sort_tanzaku = "id";
|
||||
}
|
||||
var current_sasa = null, current_tanzaku = null;
|
||||
var current_sasa_index = -1;
|
||||
var menu_count = 0;
|
||||
|
||||
@@ -10,27 +10,47 @@ if (sort_tanzaku == null) {
|
||||
|
||||
function settings_load() {
|
||||
if (db_name != null) {
|
||||
$("#db_name").val(db_name);
|
||||
$(`#db_name option[value="${db_name}"]`).prop("selected", true);
|
||||
} else {
|
||||
$("#db_name").val("");
|
||||
$("#db_name option[value=\"\"]").prop("selected", true);
|
||||
}
|
||||
if (sort_sasa != null) {
|
||||
if (sort_sasa[0] === '-') {
|
||||
$("#files-reverse").prop("checked", true);
|
||||
sort_sasa = sort_sasa.slice(1);
|
||||
let sort_s = sort_sasa;
|
||||
if (sort_s[0] === '!') {
|
||||
sort_s = sort_s.slice(1);
|
||||
}
|
||||
$(`#files-by-${sort_sasa}`).prop("checked", true);
|
||||
if (sort_s[0] === '-') {
|
||||
$("#files-reverse").prop("checked", true);
|
||||
sort_s = sort_s.slice(1);
|
||||
}
|
||||
$(`#files-by-${sort_s}`).prop("checked", true);
|
||||
}
|
||||
if (sort_tanzaku != null) {
|
||||
if (sort_tanzaku[0] === '-') {
|
||||
$("#tags-reverse").prop("checked", true);
|
||||
sort_tanzaku = sort_tanzaku.slice(1);
|
||||
let sort_t = sort_tanzaku;
|
||||
if (sort_t[0] === '!') {
|
||||
sort_t = sort_t.slice(1);
|
||||
}
|
||||
$(`#tags-by-${sort_tanzaku}`).prop("checked", true);
|
||||
if (sort_t[0] === '-') {
|
||||
$("#tags-reverse").prop("checked", true);
|
||||
sort_t = sort_t.slice(1);
|
||||
}
|
||||
$(`#tags-by-${sort_t}`).prop("checked", true);
|
||||
}
|
||||
}
|
||||
|
||||
$(window).on("load", function () {
|
||||
let resp = tdb_query();
|
||||
if (!resp.status) {
|
||||
alert("Failed to fetch databases");
|
||||
throw new Error("Failed to fetch databases");
|
||||
}
|
||||
resp.data.every(tdb => {
|
||||
$("#db_name").append($("<option>", {
|
||||
value: tdb.name,
|
||||
text: tdb.name
|
||||
}));
|
||||
return true;
|
||||
});
|
||||
settings_load();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user