//= require jquery //= require jquery_ujs /** Javascript for selection. */ jQuery(function($){ $(document). on('change', '.persistent-selection:checkbox', function(e) { $(document).trigger('selections-updated'); }); $('#selection-form-content').on("click", function(e) { e.stopPropagation(); }); }); function dispatch_selection_action() { // Build a new "href" attribute for this link by starting with the // "data-href" attribute and appending ?foo[]=bar&foo[]=baz (or // &foo=... as appropriate) to reflect the current object // selections. var data = []; var param_name = $(this).attr('data-selection-param-name'); var href = $(this).attr('data-href'); if ($(this).closest('.disabled').length > 0) { return false; } $(this). closest('.selection-action-container'). find(':checkbox:checked:visible'). each(function() { data.push({name: param_name, value: $(this).val()}); }); if (href.indexOf('?') >= 0) href += '&'; else href += '?'; href += $.param(data, true); $(this).attr('href', href); return true; } function enable_disable_selection_actions() { var $container = $(this); var $checked = $('.persistent-selection:checkbox:checked', $container); $('[data-selection-action]', $container). closest('div.btn-group-sm'). find('ul li'). toggleClass('disabled', ($checked.length == 0)); $('[data-selection-action=compare]', $container). closest('li'). toggleClass('disabled', ($checked.filter('[value*=-d1hrv-]').length < 2) || ($checked.not('[value*=-d1hrv-]').length > 0)); <% unless Group.copies_to_projects? %> $('[data-selection-action=copy]', $container). closest('li'). toggleClass('disabled', ($checked.filter('[value*=-j7d0g-]').length > 0) || ($checked.length < 1)); <% end %> $('[data-selection-action=combine-project-contents]', $container). closest('li'). toggleClass('disabled', ($checked.filter('[value*=-4zz18-]').length < 1) || ($checked.length != $checked.filter('[value*=-4zz18-]').length)); } $(document). on('selections-updated', function() { $('.selection-action-container').each(enable_disable_selection_actions); }). on('ready ajax:complete', function() { $('[data-selection-action]'). off('click', dispatch_selection_action). on('click', dispatch_selection_action); $(this).trigger('selections-updated'); });