mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-12-23 03:31:07 +00:00
create append_table_row js function
This commit is contained in:
parent
ad17fb64f1
commit
31f5decc4a
|
@ -27,6 +27,24 @@ function get_date_string(date) {
|
|||
}
|
||||
|
||||
|
||||
function append_table_row(table, row_name, row) {
|
||||
var table_row = table.insertRow(-1);
|
||||
table_row.id = row_name;
|
||||
|
||||
index = 0;
|
||||
|
||||
for (var prop in row) {
|
||||
if (Object.prototype.hasOwnProperty.call(row, prop)) {
|
||||
var cell = table_row.insertCell(index);
|
||||
cell.className = prop;
|
||||
cell.innerHTML = row[prop];
|
||||
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Client {
|
||||
constructor() {
|
||||
this.token = get_cookie("user-token");
|
||||
|
|
|
@ -40,20 +40,11 @@ async function ban() {
|
|||
return
|
||||
}
|
||||
|
||||
var row = table.insertRow(-1);
|
||||
row.id = ban.domain;
|
||||
|
||||
var new_domain = row.insertCell(0);
|
||||
var new_date = row.insertCell(1);
|
||||
var new_remove = row.insertCell(2);
|
||||
|
||||
new_domain.className = "domain";
|
||||
new_date.className = "date";
|
||||
new_remove.className = "remove";
|
||||
|
||||
new_domain.innerHTML = create_ban_object(ban.domain, ban.reason, ban.note);
|
||||
new_date.innerHTML = get_date_string(ban.created);
|
||||
new_remove.innerHTML = `<a href="#" onclick="unban('${ban.domain}')" title="Unban domain">✖</a>`;
|
||||
append_table_row(document.getElementById("instances"), ban.domain, {
|
||||
domain: create_ban_object(ban.domain, ban.reason, ban.note),
|
||||
date: get_date_string(ban.created),
|
||||
remove: `<a href="#" onclick="unban('${ban.domain}')" title="Unban domain">✖</a>`
|
||||
});
|
||||
|
||||
elems.domain.value = null;
|
||||
elems.reason.value = null;
|
||||
|
|
|
@ -1,25 +1,3 @@
|
|||
function append_table_row(table, instance) {
|
||||
var row = table.insertRow(-1);
|
||||
row.id = instance.domain;
|
||||
|
||||
var domain = row.insertCell(0);
|
||||
domain.className = "domain";
|
||||
domain.innerHTML = `<a href="https://${instance.domain}/" target="_new">${instance.domain}</a>`;
|
||||
|
||||
var software = row.insertCell(1);
|
||||
software.className = "software";
|
||||
software.innerHTML = instance.software
|
||||
|
||||
var date = row.insertCell(2);
|
||||
date.className = "date";
|
||||
date.innerHTML = get_date_string(instance.created);
|
||||
|
||||
var remove = row.insertCell(3);
|
||||
remove.className = "remove";
|
||||
remove.innerHTML = `<a href="#" onclick="del_instance('${instance.domain}')" title="Remove Instance">✖</a>`;
|
||||
}
|
||||
|
||||
|
||||
async function add_instance() {
|
||||
var elems = {
|
||||
actor: document.getElementById("new-actor"),
|
||||
|
@ -48,7 +26,12 @@ async function add_instance() {
|
|||
return
|
||||
}
|
||||
|
||||
append_table_row(document.getElementById("instances"), instance);
|
||||
append_table_row(document.getElementById("instances"), instance.domain, {
|
||||
domain: `<a href="https://${instance.domain}/" target="_new">${instance.domain}</a>`,
|
||||
software: instance.software,
|
||||
date: get_date_string(instance.created),
|
||||
remove: `<a href="#" onclick="del_instance('${instance.domain}')" title="Remove Instance">✖</a>`
|
||||
});
|
||||
|
||||
elems.actor.value = null;
|
||||
elems.inbox.value = null;
|
||||
|
@ -99,7 +82,12 @@ async function req_response(domain, accept) {
|
|||
instances = await client.request("GET", `v1/instance`, null);
|
||||
instances.forEach((instance) => {
|
||||
if (instance.domain === domain) {
|
||||
append_table_row(document.getElementById("instances"), instance);
|
||||
append_table_row(document.getElementById("instances"), instance.domain, {
|
||||
domain: `<a href="https://${instance.domain}/" target="_new">${instance.domain}</a>`,
|
||||
software: instance.software,
|
||||
date: get_date_string(instance.created),
|
||||
remove: `<a href="#" onclick="del_instance('${instance.domain}')" title="Remove Instance">✖</a>`
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -42,18 +42,11 @@ async function ban() {
|
|||
return
|
||||
}
|
||||
|
||||
row.id = ban.name;
|
||||
var new_name = row.insertCell(0);
|
||||
var new_date = row.insertCell(1);
|
||||
var new_remove = row.insertCell(2);
|
||||
|
||||
new_name.className = "name";
|
||||
new_date.className = "date";
|
||||
new_remove.className = "remove";
|
||||
|
||||
new_name.innerHTML = create_ban_object(ban.name, ban.reason, ban.note);
|
||||
new_date.innerHTML = get_date_string(ban.created);
|
||||
new_remove.innerHTML = `<a href="#" onclick="unban('${ban.name}')" title="Unban name">✖</a>`;
|
||||
append_table_row(document.getElementById("instances"), ban.name, {
|
||||
name: create_ban_object(ban.name, ban.reason, ban.note),
|
||||
date: get_date_string(ban.created),
|
||||
remove: `<a href="#" onclick="unban('${ban.domain}')" title="Unban software">✖</a>`
|
||||
});
|
||||
|
||||
elems.name.value = null;
|
||||
elems.reason.value = null;
|
||||
|
|
|
@ -15,21 +15,11 @@ async function add_whitelist() {
|
|||
return
|
||||
}
|
||||
|
||||
var table = document.getElementById("whitelist");
|
||||
var row = table.insertRow(-1);
|
||||
row.id = item.domain;
|
||||
|
||||
var domain = row.insertCell(0);
|
||||
domain.className = "domain";
|
||||
domain.innerHTML = item.domain;
|
||||
|
||||
var date = row.insertCell(1);
|
||||
date.className = "date";
|
||||
date.innerHTML = get_date_string(item.created);
|
||||
|
||||
var remove = row.insertCell(2);
|
||||
remove.className = "remove";
|
||||
remove.innerHTML = `<a href="#" onclick="del_whitelist('${item.domain}')" title="Remove whitelisted domain">✖</a>`;
|
||||
append_table_row(document.getElementById("instances"), item.domain, {
|
||||
domain: item.domain,
|
||||
date: get_date_string(ban.created),
|
||||
remove: `<a href="#" onclick="del_whitelist('${item.domain}')" title="Remove whitelisted domain">✖</a>`
|
||||
});
|
||||
|
||||
domain_elem.value = null;
|
||||
document.querySelector("details.section").open = false;
|
||||
|
|
Loading…
Reference in a new issue