class Script { static main () { const self = this; self.paramAsc = null; self.paramStart = null; self.paramEnd = null; self.paramQ = null; self.paramP = null; self.fetchData (); const dateOptions = {dateFormat: 'yy-mm-dd', firstDay: 6}; $ ('#filter-date-start').datepicker (dateOptions); $ ('#filter-date-end').datepicker (dateOptions); const orderAsc = document.getElementById ('order-asc'); const filterKeyword = document.getElementById ('filter-keyword'); const btnFilter = document.getElementById ('btn-filter'); const filter = function (e) { let dateStart = $ ('#filter-date-start').val (); let dateEnd = $ ('#filter-date-end').val (); if ((dateStart !== '') && (dateEnd !== '') && (dateStart > dateEnd)) [dateStart, dateEnd] = [dateEnd, dateStart]; self.paramAsc = orderAsc.checked ? '1' : '0'; self.paramQ = filterKeyword.value; if (dateStart !== '') self.paramStart = dateStart; if (dateEnd !== '') self.paramEnd = dateEnd; self.paramP = null; self.fetchData (); }; const resetFilter = function () { self.paramAsc = null; self.paramStart = null; self.paramEnd = null; self.paramQ = null; self.paramP = null; self.fetchData (); }; filterKeyword.addEventListener ('keydown', function (e) { if (e.key === 'Enter') filter (e); }); btnFilter.addEventListener ('click', filter); $ ('#btn-reset').on ('click', resetFilter); $ (window).resize (this.setPagination); $ ('#accordion-filter').on ('shown.bs.collapse', function () { $.cookie ('expand-filter', '1'); }); $ ('#accordion-filter').on ('hidden.bs.collapse', function () { $.cookie ('expand-filter', '0'); }); if ($.cookie ('expand-filter') === '0') { $ ('#collapse-filter').removeClass ('show'); $ ('#accordion-filter .accordion-button').addClass ('collapsed'); } window.setInterval (function () { self.fetchData (); }, 60000); } static jumpTo (page) { this.paramP = page; this.fetchData (); } static setPagination () { for (let i = 1; i <= 20; ++i) $ (`.page-${i}`).removeClass ('d-none'); for (let i = 20; i > 1; --i) { if (($ ('.pagination').width () < $ ('body').width () * .8) && ($ ('.page-item:not(.d-none)').length / 2 % 2 != 0)) break; $ (`.page-${i}`).addClass ('d-none'); } } static fetchData () { const self = this; const postData = {} if (this.paramAsc != null) postData.asc = this.paramAsc; if (this.paramStart != null) postData.start = this.paramStart; if (this.paramEnd != null) postData.end = this.paramEnd; if (this.paramQ != null) postData.q = this.paramQ; if (this.paramP != null) postData.p = this.paramP; const done = function (data) { $ ('.pagination').empty (); if (data.page > 1) { ($ ('.pagination') .append ($ ('