/* eslint-disable */ ((global) => { class Todos { constructor({ el } = {}) { this.allDoneClicked = this.allDoneClicked.bind(this); this.doneClicked = this.doneClicked.bind(this); this.el = el || $('.js-todos-options'); this.perPage = this.el.data('perPage'); this.clearListeners(); this.initBtnListeners(); this.initFilters(); } clearListeners() { $('.done-todo').off('click'); $('.js-todos-mark-all').off('click'); return $('.todo').off('click'); } initBtnListeners() { $('.done-todo').on('click', this.doneClicked); $('.js-todos-mark-all').on('click', this.allDoneClicked); return $('.todo').on('click', this.goToTodoUrl); } initFilters() { new UsersSelect(); this.initFilterDropdown($('.js-project-search'), 'project_id', ['text']); this.initFilterDropdown($('.js-type-search'), 'type'); this.initFilterDropdown($('.js-action-search'), 'action_id'); $('form.filter-form').on('submit', function (event) { event.preventDefault(); Turbolinks.visit(this.action + '&' + $(this).serialize()); }); } initFilterDropdown($dropdown, fieldName, searchFields) { $dropdown.glDropdown({ fieldName, selectable: true, filterable: searchFields ? true : false, search: { fields: searchFields }, data: $dropdown.data('data'), clicked: function() { return $dropdown.closest('form.filter-form').submit(); } }) } doneClicked(e) { e.preventDefault(); e.stopImmediatePropagation(); const $target = $(e.currentTarget); $target.disable(); return $.ajax({ type: 'POST', url: $target.attr('href'), dataType: 'json', data: { '_method': 'delete' }, success: (data) => { this.redirectIfNeeded(data.count); this.clearDone($target.closest('li')); return this.updateBadges(data); } }); } allDoneClicked(e) { e.preventDefault(); e.stopImmediatePropagation(); $target = $(e.currentTarget); $target.disable(); return $.ajax({ type: 'POST', url: $target.attr('href'), dataType: 'json', data: { '_method': 'delete' }, success: (data) => { $target.remove(); $('.prepend-top-default').html('