iommirocks / iommi

Your first pick for a django power cord
http://iommi.rocks
BSD 3-Clause "New" or "Revised" License
718 stars 47 forks source link

JS refactoring #424

Closed berycz closed 1 year ago

berycz commented 1 year ago

this fixes https://github.com/iommirocks/iommi/issues/418

berycz commented 1 year ago

iommi.js // TODO should this be somehow conditioned? so people can create their own extended instance? I'd like to hear your opinion, I think it might be good for an inherited class maybe by a "global" variable, or a data attribute on <html>, or something

berycz commented 1 year ago

events iommi.init.start and iommi.init.end arent exactly "inits", or they are, but not constructor-init, they are on DOMContentLoaded inits if you have any better name, fire away

berycz commented 1 year ago

notice // deprecated, also it doesn't make sense to start spinner here imo I have no idea why spinner should be there ?

berycz commented 1 year ago

short info

I made two js classes - IommiBase and IommiSelect2 instance of the first one is in window.iommi, second as window.iommi.select2 I made all old functions deprecated, but left them there. If someone calls them, they get console.warn(...)

custom events iommi.init.start before functions/dependencies are being bound on elements iommi.init.end after -||- iommi.error when error occurs (only ajax errors for now, e.g. someone got logged out and receives html 403 instead of json, or when they're offline), good for popping up error messages to the user, triggered on any related elements, but probably better to listen on document iommi.element.populated - (for now only) table got loaded on filtering or paginating or reloaded, triggered on container; e.g. I use that for an "export csv" link, which I have above container and I want it to take in account filters iommi.loading.start - ajax loading started - good for showing spinners, triggered on container, or form for filter-form ajax validation iommi.loading.end - ajax loading ended - good for hiding spinners, triggered on the same element

element objects of filter form and table container get now iommi object with specific functions/attributes useful may be container.iommi.reload(), e.g. if user was afk for a long time and you want to reload the table, or based on websocket messages, or anything

ad 10) iommi_validate_form throwing JS errors on field errors (fields) you can test it if you have a select in a filter form: you change option value in the debugger and then select that option, you get now html5 validation error on the select

IommiBase.addLiveEventListener is kinda like simple version of live $(selector).on() in jquery, I didnt want to be dependent on jquery

file-inputs in filter-forms are as "todo" for now, I hardly think anybody will need it anytime soon

I got rid of axios and used fetch instead, with AbortController per container/form, not global

I switched from snake_case to camelCase for variables and function names

MAIN NEWS pagination is via ajax now