thedesk/app/js/tl/directory.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-08-30 02:46:04 +10:00
//ディレクトリ
//ディレクトリトグル
function dirMenu() {
2020-08-02 17:08:07 +10:00
$("#dir-contents").html("")
directory()
$("#left-menu a").removeClass("active")
$("#dirMenu").addClass("active")
$(".menu-content").addClass("hide")
$("#dir-box").removeClass("hide")
2019-08-30 02:46:04 +10:00
}
function dirselCk() {
2020-08-02 17:08:07 +10:00
var acct = $("#dir-acct-sel").val()
2019-11-04 03:10:06 +11:00
if (acct == "noauth") {
2020-08-02 17:08:07 +10:00
$("#dirNoAuth").removeClass("hide")
2019-11-04 03:10:06 +11:00
} else {
2020-08-02 17:08:07 +10:00
$("#dirNoAuth").addClass("hide")
directory()
2019-11-04 03:10:06 +11:00
}
2019-08-30 02:46:04 +10:00
}
function directory(isMore) {
2020-08-02 17:08:07 +10:00
var order = $("[name=sort]:checked").val()
2019-11-04 03:10:06 +11:00
if (!order) {
2020-08-02 17:08:07 +10:00
order = "active"
2019-11-04 03:10:06 +11:00
}
2020-08-02 17:08:07 +10:00
var local_only = $("#local_only:checked").val()
2019-11-04 03:10:06 +11:00
if (local_only) {
2020-08-02 17:08:07 +10:00
local_only = "true"
2019-11-04 03:10:06 +11:00
} else {
2020-08-02 17:08:07 +10:00
local_only = "false"
2019-11-04 03:10:06 +11:00
}
2020-08-02 17:08:07 +10:00
var acct_id = $("#dir-acct-sel").val()
2019-11-04 03:10:06 +11:00
if (acct_id == "noauth") {
2020-08-02 17:08:07 +10:00
var domain = $("#dirNoAuth-url").val()
var at = ""
2019-11-04 03:10:06 +11:00
} else {
2020-08-02 17:08:07 +10:00
var domain = localStorage.getItem("domain_" + acct_id)
var at = localStorage.getItem("acct_" + acct_id + "_at")
2019-11-04 03:10:06 +11:00
}
if (isMore) {
2020-08-02 17:08:07 +10:00
var addOffset = $("#dir-contents .cvo").length
2019-11-04 03:10:06 +11:00
} else {
2020-08-02 17:08:07 +10:00
var addOffset = 0
$("#dir-contents").html("")
2019-11-04 03:10:06 +11:00
}
2020-08-02 17:08:07 +10:00
var start = "https://" + domain + "/api/v1/directory?order=" + order + "&local=" + local_only + "&offset=" + addOffset
console.log(start)
2019-11-04 03:10:06 +11:00
fetch(start, {
method: "GET",
headers: {
"content-type": "application/json",
Authorization: "Bearer " + at
2019-10-31 02:30:26 +11:00
}
2019-11-04 03:10:06 +11:00
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
2020-08-02 17:08:07 +10:00
setLog(response.url, response.status, text)
})
2019-11-04 03:10:06 +11:00
}
2020-08-02 17:08:07 +10:00
return response.json()
2019-11-04 03:10:06 +11:00
})
.catch(function(error) {
2020-08-02 17:08:07 +10:00
setLog(start, "JSON", error)
console.error(error)
2019-11-04 03:10:06 +11:00
})
.then(function(json) {
if (json) {
2020-08-02 17:08:07 +10:00
$("#moreDir").removeClass("disabled")
var html = userparse(json, null, acct_id, "dir", null)
$("#dir-contents").append(html)
jQuery("time.timeago").timeago()
2019-11-04 03:10:06 +11:00
} else {
2020-08-02 17:08:07 +10:00
$("#moreDir").addClass("disabled")
2019-11-04 03:10:06 +11:00
}
2020-08-02 17:08:07 +10:00
})
2019-11-04 03:10:06 +11:00
}