4 /** Javascript for selection. */
8 on('change', '.persistent-selection:checkbox', function(e) {
9 $(document).trigger('selections-updated');
13 function dispatch_selection_action() {
14 /* When the user clicks a selection action link, build a form to perform
15 the action on the selected data, and submit it.
16 This is based on handleMethod from rails-ujs, extended to add the
17 selections to the submitted form.
18 Copyright (c) 2007-2010 Contributors at http://github.com/rails/jquery-ujs/contributors
20 var $container = $(this);
21 if ($container.closest('.disabled').length) {
24 $container.closest('.dropdown-menu').dropdown('toggle');
26 var href = $container.data('href'),
27 method = $container.data('method') || 'GET',
28 paramName = $container.data('selection-param-name'),
29 csrfToken = $('meta[name=csrf-token]').attr('content'),
30 csrfParam = $('meta[name=csrf-param]').attr('content'),
31 form = $('<form method="post" action="' + href + '"></form>'),
32 metadataInput = ('<input name="_method" value="' + method +
33 '" type="hidden" />');
35 if (csrfParam !== undefined && csrfToken !== undefined) {
36 metadataInput += ('<input type="hidden" name="' + csrfParam +
37 '" value="' + csrfToken + '" />');
40 closest('.selection-action-container').
41 find(':checkbox:checked:visible').
42 each(function(index, elem) {
43 metadataInput += ('<input type="hidden" name="' + paramName +
44 '" value="' + elem.value + '" />');
47 form.data('remote', $container.data('remote'));
48 form.hide().append(metadataInput).appendTo('body');
53 function enable_disable_selection_actions() {
54 var $container = $(this);
55 var $checked = $('.persistent-selection:checkbox:checked', $container);
56 $('[data-selection-action]', $container).
57 closest('div.btn-group-sm').
59 toggleClass('disabled', ($checked.length == 0));
60 $('[data-selection-action=compare]', $container).
62 toggleClass('disabled',
63 ($checked.filter('[value*=-d1hrv-]').length < 2) ||
64 ($checked.not('[value*=-d1hrv-]').length > 0));
65 <% unless Group.copies_to_projects? %>
66 $('[data-selection-action=copy]', $container).
68 toggleClass('disabled',
69 ($checked.filter('[value*=-j7d0g-]').length > 0) ||
70 ($checked.length < 1));
72 $('[data-selection-action=combine-project-contents]', $container).
74 toggleClass('disabled',
75 ($checked.filter('[value*=-4zz18-]').length < 1) ||
76 ($checked.length != $checked.filter('[value*=-4zz18-]').length));
80 on('selections-updated', function() {
81 $('.selection-action-container').each(enable_disable_selection_actions);
83 on('ready ajax:complete', function() {
84 $('[data-selection-action]').
85 off('click', dispatch_selection_action).
86 on('click', dispatch_selection_action);
87 $(this).trigger('selections-updated');
90 function select_all_items() {
91 $(".arv-selectable-items :checkbox").filter(":visible").prop("checked", true).trigger("change");
94 function unselect_all_items() {
95 $(".arv-selectable-items :checkbox").filter(":visible").prop("checked", false).trigger("change");