SymphoniaFilter = function(filtersForm) { var form = document.getElementById(filtersForm); $(document).ready(function() { var n = form.querySelector(".symphonia-query-column-selector"); if (n) { new Sortable(n, { animation: 0, draggable: "div.column", scroll: false }) } initDatepicker(filtersForm + ' .filter-custom-date > .datepicker'); }); this.submit = function() { var cols = document.querySelectorAll("#" + form.id + " .column input:checked"); var params = []; for (var i=0;i < cols.length; i++) { params.push(cols[i].name.replace(/\[|\]/g, "")) } var uri = form.action.replace(/[\?&]column_names=.*&?/, ""); if (!uri.includes("?")) { uri = uri + "?" } if (params.length > 0) { uri = uri + "&column_names=" + params.join("|") } var $filters = $("#"+form.id+" .symphonia-query-filters-selector").find("input, select"); $filters.each(function(_index, item) { if (item.value && item.value !== "" && (item.type !== 'checkbox' || item.checked)) { uri = uri + "&" + item.name + "=" + item.value; } }); window.location = uri } }; SymphoniaFilter.prototype.dateFilterCallback = function(element) { if (element.value === 'custom') { window.Symphonia.toggle(element.nextElementSibling) } else { window.Symphonia.toggle(element.nextElementSibling, false) } }; window.Symphonia || (window.Symphonia = {}); window.Symphonia.filters = { search: function (el) { if (!!el.value) { if (el.dataset.remote) { var data = {}; data[el.name] = el.value; $.get(window.location.pathname, data, function (response) { document.getElementById("main").innerHTML = response; }) } else { window.location.search = "?" + el.name + "=" + encodeURIComponent(el.value); } } }, resetSearch: function (el) { if (el.dataset.remote) { $.get(window.location.pathname, {}, function (response) { document.getElementById("main").innerHTML = response; }) } else { window.location.search = ''; } }, removeRow: function (id) { var el = document.getElementById(id); el.remove(); } }