1 <%# Copyright (C) The Arvados Authors. All rights reserved.
3 SPDX-License-Identifier: AGPL-3.0 %>
8 /** Javascript for selection. */
12 on('change', '.persistent-selection:checkbox', function(e) {
13 $(document).trigger('selections-updated');
17 function dispatch_selection_action() {
18 /* When the user clicks a selection action link, build a form to perform
19 the action on the selected data, and submit it.
20 This is based on handleMethod from rails-ujs, extended to add the
21 selections to the submitted form.
22 Copyright (c) 2007-2010 Contributors at http://github.com/rails/jquery-ujs/contributors
24 var $container = $(this);
25 if ($container.closest('.disabled').length) {
28 $container.closest('.dropdown-menu').dropdown('toggle');
30 var href = $container.data('href'),
31 method = $container.data('method') || 'GET',
32 paramName = $container.data('selection-param-name'),
33 csrfToken = $('meta[name=csrf-token]').attr('content'),
34 csrfParam = $('meta[name=csrf-param]').attr('content'),
35 form = $('<form method="post" action="' + href + '"></form>'),
36 metadataInput = ('<input name="_method" value="' + method +
37 '" type="hidden" />');
39 if (csrfParam !== undefined && csrfToken !== undefined) {
40 metadataInput += ('<input type="hidden" name="' + csrfParam +
41 '" value="' + csrfToken + '" />');
44 closest('.selection-action-container').
45 find(':checkbox:checked:visible').
46 each(function(index, elem) {
47 metadataInput += ('<input type="hidden" name="' + paramName +
48 '" value="' + elem.value + '" />');
51 form.data('remote', $container.data('remote'));
52 form.hide().append(metadataInput).appendTo('body');
57 function enable_disable_selection_actions() {
58 var $container = $(this);
59 var $checked = $('.persistent-selection:checkbox:checked', $container);
60 var collection_lock_classes = $('.lock-collection-btn').attr('class')
62 $('[data-selection-action]', $container).
63 closest('div.btn-group-sm').
65 toggleClass('disabled', ($checked.length == 0));
66 $('[data-selection-action=compare]', $container).
68 toggleClass('disabled',
69 ($checked.filter('[value*=-d1hrv-]').length < 2) ||
70 ($checked.not('[value*=-d1hrv-]').length > 0));
71 <% unless Group.copies_to_projects? %>
72 $('[data-selection-action=copy]', $container).
74 toggleClass('disabled',
75 ($checked.filter('[value*=-j7d0g-]').length > 0) ||
76 ($checked.length < 1));
78 $('[data-selection-action=combine-project-contents]', $container).
80 toggleClass('disabled',
81 ($checked.filter('[value*=-4zz18-]').length < 1) ||
82 ($checked.length != $checked.filter('[value*=-4zz18-]').length));
83 $('[data-selection-action=remove-selected-files]', $container).
85 toggleClass('disabled',
86 ($checked.length < 0) ||
87 !($checked.length > 0 && collection_lock_classes && collection_lock_classes.indexOf("fa-unlock") !=-1));
88 $('[data-selection-action=untrash-selected-items]', $container).
90 toggleClass('disabled',
91 ($checked.length < 1));
95 on('selections-updated', function() {
96 $('.selection-action-container').each(enable_disable_selection_actions);
98 on('ready ajax:complete', function() {
99 $('[data-selection-action]').
100 off('click', dispatch_selection_action).
101 on('click', dispatch_selection_action);
102 $(this).trigger('selections-updated');
105 function select_all_items() {
106 $(".arv-selectable-items :checkbox").filter(":visible").prop("checked", true).trigger("change");
109 function unselect_all_items() {
110 $(".arv-selectable-items :checkbox").filter(":visible").prop("checked", false).trigger("change");