{"version":3,"file":"home-4cbCStjG.js","sources":["../../../app/frontend/entrypoints/controllers/admin/home.ts"],"sourcesContent":["import * as bootstrap from 'bootstrap'\nimport Utils from '../../utils'\nimport DefaultController from \"../defaultController\";\nimport Swal from \"sweetalert2\";\n\nexport default class AdminHome extends DefaultController {\n tableElem: any;\n datatable: any;\n private editModal: any;\n\n async init() {\n this.entity = \"sites\"\n this.editModal = new bootstrap.Modal((document.querySelector(\"#editSite\") as HTMLElement));\n this.tableElem = jQuery('.datatables-users')\n this.createTable();\n await super.init();\n }\n\n getEntityData(elem: any) {\n return {}\n }\n\n bindListeners() {\n this.tableElem.delegate(\".edit-record\", \"click\", async (e: any) => {\n const id = e.currentTarget.getAttribute(\"data-id\")\n const requestData = await Utils.entity.get(id, this.entity)\n if (requestData.status === 200) {\n const data = requestData.data[0]\n const form = (document.querySelector(\"#editSiteForm\") as HTMLFormElement);\n form.reset()\n await Utils.updateElements(data, '', form)\n // @ts-ignore\n this.editModal.show();\n }\n\n });\n\n this.tableElem.delegate(\".delete-record\", \"click\", async (e: any) => {\n const id = e.currentTarget.getAttribute(\"data-id\");const confirm = await Swal.fire({\n title: 'Are you sure?',\n text: \"You won't be able to revert this!\",\n icon: 'warning',\n showCancelButton: true,\n confirmButtonText: 'Yes, delete it!',\n customClass: {\n confirmButton: 'btn btn-primary me-3',\n cancelButton: 'btn btn-label-secondary'\n },\n buttonsStyling: false\n })\n if(confirm.value === true) {\n const r = await Utils.entity.destroy(id, this.entity);\n if (r.status === 200) {\n this.toastr.success(`${Utils.translate('site.name')} ${Utils.translate('generic.deleted')}`, `${Utils.translate('generic.success')}`)\n } else {\n this.toastr.error(`${Utils.translate('site.name')} ${Utils.translate('generic.messages.not_deleted')}`, `${Utils.translate('generic.error')}`)\n }\n this.datatable.ajax.reload();\n }\n });\n\n }\n createTable() {\n this.datatable = new DataTable(\".datatables-users\", {\n initComplete: () => {\n this.tableElem.closest(\".card\").find(\".loading-body\").addClass(\"d-none\")\n this.tableElem.closest(\".card\").find(\".card-datatable\").removeClass(\"d-none\")\n },\n ajax: `/api/v1/sites`,\n columns: [\n {data: 'name'},\n {data: 'urls'},\n {data: 'uuid'},\n {data: 'uuid'},\n ],\n columnDefs: [\n {\n targets: 0,\n render: (data: any, type: any, full: any, meta: any) => {\n return data;\n },\n },\n {\n targets: 1,\n render: (data: any, type: any, full: any, meta: any) => {\n return `${data.join(\", \")}`;\n },\n },\n {\n targets: 2,\n render: (data: any, type: any, full: any, meta: any) => {\n let html: string[] = [];\n Object.keys(full.features).forEach((key) => {\n const v = full.features[key];\n html.push(`${key} - ${v ? \"Ja\" : \"Nein\"}`)\n })\n return html.join(\"
\");\n },\n },\n {\n targets: 3,\n searchable: false,\n orderable: false,\n render: (data: any, type: any, full: any, meta: any) => {\n return `