import { escape, whenReady } from './dom'; import { DataTable, dumbFilterCallback } from './data_tables'; import { tagsToHtml } from "./utils"; import { globalSetup } from './main'; const getUserInfo = () => { const elem = document.getElementById('js-data-holder'); if (!elem) { return { userId: null, csrfToken: null }; } return { userId: elem.dataset.userId, csrfToken: elem.dataset.csrfToken }; }; const parsePasteInfo = (elem) => { if (!elem.dataset.pasteInfo) { return null; } return JSON.parse(elem.dataset.pasteInfo); }; whenReady(() => { globalSetup(); const urlParams = new URLSearchParams(window.location.search); const myParam = urlParams.get('q'); const myPastesElem = document.getElementById('archive'); const apiUrl = '/api/user_pastes.php?user_id=' + myPastesElem.dataset.userId; console.log('myPastesElem', myPastesElem); const table = new DataTable(myPastesElem, { ajaxCallback: (resolve) => { fetch(apiUrl) .then(r => r.json()) .then(resolve); }, rowCallback: (rowData) => { console.log('rowData', rowData); const userData = getUserInfo(); const ownedByUser = (parseInt(rowData.author_id) === parseInt(userData.userId)); console.log(ownedByUser); const deleteElem = ownedByUser ? `