A website for my game dev stuff that supports chat, etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
1.1 KiB

class PaginateTable {
constructor(url) {
this.page = 0;
this.items = [];
this.url = url;
this.headers = [];
this.search_query=""
}
async contents() {
if(this.page < 0) this.page = 0;
let url = `${this.url}?page=${this.page}`;
if(this.search_query !== "") {
this.page = 0;
url += `&search=${this.search_query}`
}
const resp = await fetch(url);
console.assert(resp.status == 200, "failed to get it");
const items = await resp.json();
if(items) {
this.items = items;
this.headers = Object.keys(this.items[0]);
}
return this.items;
}
}
class GetJson {
constructor(url) {
this.item;
this.url = url;
}
async item() {
const resp = await fetch(`${this.url}`);
console.assert(resp.status == 200, "failed to get it");
this.item = await resp.json();
return this.item;
}
}
const ConfirmDelete = async (table, obj_id) => {
if(confirm("Are you sure?")) {
await fetch("/api/admin/table/" + table + "/" + obj_id + "/",
{ method: "DELETE" });
window.location = "/admin/table/" + table + "/";
} else {
return false;
}
}