4 /** Javascript for selection. */
8 on('change', '.persistent-selection:checkbox', function(e) {
9 $(document).trigger('selections-updated');
13 function dispatch_selection_action() {
14 // Build a new "href" attribute for this link by starting with the
15 // "data-href" attribute and appending ?foo[]=bar&foo[]=baz (or
16 // &foo=... as appropriate) to reflect the current object
19 var param_name = $(this).attr('data-selection-param-name');
20 var href = $(this).attr('data-href');
21 if ($(this).closest('.disabled').length > 0) {
25 closest('.selection-action-container').
26 find(':checkbox:checked:visible').
28 data.push({name: param_name, value: $(this).val()});
30 if (href.indexOf('?') >= 0)
34 href += $.param(data, true);
35 $(this).attr('href', href);
39 function enable_disable_selection_actions() {
40 var $container = $(this);
41 var $checked = $('.persistent-selection:checkbox:checked', $container);
42 $('[data-selection-action]', $container).
43 closest('div.btn-group-sm').
45 toggleClass('disabled', ($checked.length == 0));
46 $('[data-selection-action=compare]', $container).
48 toggleClass('disabled',
49 ($checked.filter('[value*=-d1hrv-]').length < 2) ||
50 ($checked.not('[value*=-d1hrv-]').length > 0));
51 <% unless Group.copies_to_projects? %>
52 $('[data-selection-action=copy]', $container).
54 toggleClass('disabled',
55 ($checked.filter('[value*=-j7d0g-]').length > 0) ||
56 ($checked.length < 1));
58 $('[data-selection-action=combine-project-contents]', $container).
60 toggleClass('disabled',
61 ($checked.filter('[value*=-4zz18-]').length < 1) ||
62 ($checked.length != $checked.filter('[value*=-4zz18-]').length));
66 on('selections-updated', function() {
67 $('.selection-action-container').each(enable_disable_selection_actions);
69 on('ready ajax:complete', function() {
70 $('[data-selection-action]').
71 off('click', dispatch_selection_action).
72 on('click', dispatch_selection_action);
73 $(this).trigger('selections-updated');