1
htmx.on('htmx:wsBeforeMessage', (e) => {
2
console.log('wsBeforeMessage')
3
const message = JSON.parse(e.detail.message)
5
if (message.message_type === 'COMPANY_CHANGED') {
6
document.location.reload()
7
} else if (message.tag === 'LOGOUT') {
9
document.cookie = "token={{token}};expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;"
10
document.cookie = "refresh_token={{refresh_token}};expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;"
11
document.location.replace('/basic/user/login?/')
13
} else if (message.tag === 'MODEL') {
14
var elements = htmx.findAll(`[ui_key="${message.vars.model}--${message.vars.id}"]`)
15
if (message.vars.method === 'create') {
16
let elements = htmx.findAll('[id^="table--"]');
17
elements.forEach(element => {
18
htmx.trigger(element, 'update')
21
} else if (message.vars.method === 'update') {
25
for (var i = elements.length - 1; i >= 0; i--) {
27
console.log(el.attributes.lsn)
28
var elLsn = Number(el.attributes.lsn.nodeValue)
29
el.attributes.lsn.nodeValue = message.vars.lsn
30
htmx.trigger(el, 'backend_update')
31
var myToast = Toastify({
32
text: message.message,
40
} else if (message.vars.method === 'delete') {
41
elements.forEach(element => {
44
var myToast = Toastify({
45
text: 'Object deleted',
49
} else if (message.tag === 'REFRESH') {