//= require rails-ujs //= require turbolinks //= require jquery3 //= require popper //= require bootstrap-sprockets //= require symphonia/_core //= require symphonia/Sortable //= require bootstrap-datepicker/core //= require bootstrap-datepicker/locales/bootstrap-datepicker.cs.js //= require_self //= require symphonia/symphonia_bootstrap_dialog //= require symphonia/filters document.addEventListener("turbolinks:load", initDatepicker); $(document).on("ready turbolinks:load", function () { var item = document.getElementsByTagName("body")[0].dataset.menuItem; var menuItem = document.querySelector("header ul.nav li." + item); if (menuItem) { $("header ul.nav li").removeClass('active'); menuItem.className += ' active'; } if (typeof($.colorbox) === "function") { $.colorbox.remove(); $('a.symphonia-lightbox[data-lightbox="true"]').colorbox({rel: 'gallery', maxHeight: '80%', photo: true}); } var images = document.getElementById("editable_images"); if (images) { new Sortable(images, { animation: 0, draggable: ".entity-edit-image", scroll: true, onUpdate: function (event) { $.ajax({ url: Symphonia.routes.reorderImagesPath, data: { position: event.newIndex + 1, id: event.item.dataset.id }, type: 'PATCH' }); } }) } }); $(document).on('click', '.share-buttons a', function (event) { event.preventDefault(); window.open(this.href, this.title, 'toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=no,width=620,height=320px'); }); function toggleMultiSelect(select) { var $select = $(select); $select.prop("multiple", !$select.prop("multiple")); } function initDatepicker(input) { var selector = 'input[type=text].datepicker'; if (typeof input === 'string') { selector = input; } $(selector).each(function (index, item) { var $item = $(item); $item.datepicker({ 'language': (item.dataset.datepickerLocale || 'cs'), format: 'yyyy-mm-dd', autoclose: true }); var c = item.nextElementSibling; if (c) { c.onclick = function () { $item.datepicker('show') } } }) } $(document).on('click', 'input.symphonia-query-submit-button', function (event) { event.preventDefault(); var form = $(event.target).closest('form'); form.find('input, select').each(function (index, i) { if (i.value.length === 0) { i.disabled = true; } }); form.submit(); }); 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(); } } function submitSymphoniaForm(formId) { console.debug('submitSymphoniaForm in window will remove'); SymphoniaFilters.submit(formId); } function submitSymphoniaQueryQ(el) { console.debug('submitSymphoniaQueryQ in window will remove'); Symphonia.filters.search(el); } $(document).on("change", "#query_data input:checkbox", function (event) { SymphoniaCheckboxes.toggle(event.target, !event.target.checked) }); SymphoniaCheckboxes = { toggleAll: function (toggler) { var isChecked = toggler.dataset.checked == 'true'; var inputs = toggler.querySelectorAll("input[type=checkbox]"); for (var i = 0; i < inputs.length; i++) { this.toggle(inputs[i], isChecked) } toggler.dataset.checked = !isChecked; }, toggle: function (input, isChecked) { if (typeof(isChecked) === "undefined") isChecked = input.checked; input.checked = !isChecked; var tr = input.closest("tr"); tr && tr.classList.toggle("info", !isChecked); return input; } };