X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/8e60aa5c834a1a2a741a87a8155b8db9b4c46da3..bf43b9c625657fa745bbb237248f7d33ccb4cd2b:/apps/workbench/app/assets/javascripts/selection.js diff --git a/apps/workbench/app/assets/javascripts/selection.js b/apps/workbench/app/assets/javascripts/selection.js index 1e32c63564..a313c8b78e 100644 --- a/apps/workbench/app/assets/javascripts/selection.js +++ b/apps/workbench/app/assets/javascripts/selection.js @@ -57,8 +57,10 @@ jQuery(function($){ $("#persistent-selection-count").text(lst.length); if (lst.length > 0) { html = '
  • Clear selections
  • '; - if (this_object_uuid.match('-j7d0g-')) - html += '
  • '; + if (this_object_uuid.match('-j7d0g-')) { + html += '
  • '; + html += '
  • '; + } html += '
  • ' @@ -100,13 +102,11 @@ jQuery(function($){ $('.remove-selection').on('click', remove_selection_click); $('#clear_selections_button').on('click', clear_selections); + $(document).trigger('selections-updated', [lst]); }; $(document). on('change', '.persistent-selection:checkbox', function(e) { - //console.log($(this)); - //console.log($(this).val()); - var inc = 0; if ($(this).is(":checked")) { add_selection($(this).val(), $(this).attr('friendly_name'), $(this).attr('href'), $(this).attr('friendly_type')); @@ -116,7 +116,6 @@ jQuery(function($){ } }); - $(window).on('load storage', update_count); $('#selection-form-content').on("click", function(e) { @@ -178,3 +177,45 @@ select_form_sources = null; 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) { + return false; + } + $('.persistent-selection:checkbox:checked').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 $checked = $('.persistent-selection:checkbox:checked'); + $('[data-selection-action]'). + closest('div.btn-group-sm'). + find('ul li'). + toggleClass('disabled', ($checked.length == 0)); + $('[data-selection-action=compare]'). + closest('li'). + toggleClass('disabled', + ($checked.filter('[value*=-d1hrv-]').length < 2) || + ($checked.not('[value*=-d1hrv-]').length > 0)); +} + +$(document). + on('selections-updated ready ajax:complete', function() { + $('[data-selection-action]').click(dispatch_selection_action); + enable_disable_selection_actions(); + });