X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a2b994514a6743a055116f9362c303db66f480b5..0561bd0c3c07257fd58ded6c7cfa5feeae97af57:/apps/workbench/app/assets/javascripts/selection.js.erb diff --git a/apps/workbench/app/assets/javascripts/selection.js.erb b/apps/workbench/app/assets/javascripts/selection.js.erb index 0eb1fb16f9..e8f21eefd5 100644 --- a/apps/workbench/app/assets/javascripts/selection.js.erb +++ b/apps/workbench/app/assets/javascripts/selection.js.erb @@ -1,3 +1,7 @@ +<%# Copyright (C) The Arvados Authors. All rights reserved. + +SPDX-License-Identifier: AGPL-3.0 %> + //= require jquery //= require jquery_ujs @@ -8,96 +12,53 @@ jQuery(function($){ on('change', '.persistent-selection:checkbox', function(e) { $(document).trigger('selections-updated'); }); - - $('#selection-form-content').on("click", function(e) { - e.stopPropagation(); - }); }); -add_form_selection_sources = null; -select_form_sources = null; - -(function() { - var form_selection_sources = {}; - add_form_selection_sources = function (src) { - for (var i = 0; i < src.length; i++) { - var t = form_selection_sources[src[i].type]; - if (!t) { - t = form_selection_sources[src[i].type] = {}; - } - if (!t[src[i].uuid]) { - t[src[i].uuid] = src[i]; - } - } - }; - - select_form_sources = function(type) { - var ret = []; - - if (get_selection_list) { - var lst = get_selection_list(); - if (lst.length > 0) { - var text = "― Selections ―"; - var span = document.createElement('span'); - span.innerHTML = text; - ret.push({text: span.innerHTML, value: "***invalid***"}); - - for (var i = 0; i < lst.length; i++) { - if (lst[i].type == type) { - var n = lst[i].name; - n = n.replace(/]*>/i, "["); - n = n.replace(/<\/span>/i, "]"); - ret.push({text: n, value: lst[i].uuid}) - } - } - } - } - - var text = "― Recent ―"; - var span = document.createElement('span'); - span.innerHTML = text; - ret.push({text: span.innerHTML, value: "***invalid***"}); - - var t = form_selection_sources[type]; - for (var key in t) { - if (t.hasOwnProperty(key)) { - var obj = t[key]; - ret.push({text: obj.name, value: obj.uuid}) - } - } - return ret; - }; -})(); - 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) { + /* When the user clicks a selection action link, build a form to perform + the action on the selected data, and submit it. + This is based on handleMethod from rails-ujs, extended to add the + selections to the submitted form. + Copyright (c) 2007-2010 Contributors at http://github.com/rails/jquery-ujs/contributors + */ + var $container = $(this); + if ($container.closest('.disabled').length) { return false; } - $(this). + $container.closest('.dropdown-menu').dropdown('toggle'); + + var href = $container.data('href'), + method = $container.data('method') || 'GET', + paramName = $container.data('selection-param-name'), + csrfToken = $('meta[name=csrf-token]').attr('content'), + csrfParam = $('meta[name=csrf-param]').attr('content'), + form = $('
'), + metadataInput = (''); + + if (csrfParam !== undefined && csrfToken !== undefined) { + metadataInput += (''); + } + $container. closest('.selection-action-container'). find(':checkbox:checked:visible'). - each(function() { - data.push({name: param_name, value: $(this).val()}); + each(function(index, elem) { + metadataInput += (''); }); - if (href.indexOf('?') >= 0) - href += '&'; - else - href += '?'; - href += $.param(data, true); - $(this).attr('href', href); - return true; + + form.data('remote', $container.data('remote')); + form.hide().append(metadataInput).appendTo('body'); + form.submit(); + return false; } function enable_disable_selection_actions() { var $container = $(this); var $checked = $('.persistent-selection:checkbox:checked', $container); + var collection_lock_classes = $('.lock-collection-btn').attr('class') + $('[data-selection-action]', $container). closest('div.btn-group-sm'). find('ul li'). @@ -119,6 +80,15 @@ function enable_disable_selection_actions() { toggleClass('disabled', ($checked.filter('[value*=-4zz18-]').length < 1) || ($checked.length != $checked.filter('[value*=-4zz18-]').length)); + $('[data-selection-action=remove-selected-files]', $container). + closest('li'). + toggleClass('disabled', + ($checked.length < 0) || + !($checked.length > 0 && collection_lock_classes && collection_lock_classes.indexOf("fa-unlock") !=-1)); + $('[data-selection-action=untrash-selected-items]', $container). + closest('li'). + toggleClass('disabled', + ($checked.length < 1)); } $(document). @@ -131,3 +101,11 @@ $(document). on('click', dispatch_selection_action); $(this).trigger('selections-updated'); }); + +function select_all_items() { + $(".arv-selectable-items :checkbox").filter(":visible").prop("checked", true).trigger("change"); +} + +function unselect_all_items() { + $(".arv-selectable-items :checkbox").filter(":visible").prop("checked", false).trigger("change"); +}