X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/da5ff6947c567dfb391af544473475c029a78ece..8dcb4daaa7e740f5957043321ccf2c1a7bd2ccb6:/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 c8ec8100ac..a313c8b78e 100644 --- a/apps/workbench/app/assets/javascripts/selection.js +++ b/apps/workbench/app/assets/javascripts/selection.js @@ -40,7 +40,6 @@ jQuery(function($){ }; var remove_selection_click = function(e) { - //remove_selection($(this).attr('name')); remove_selection($(this).val()); }; @@ -50,22 +49,32 @@ jQuery(function($){ } var update_count = function(e) { + var html; + var this_object_uuid = $('#selection-form-content'). + closest('form'). + find('input[name=uuid]').val(); var lst = get_selection_list(); $("#persistent-selection-count").text(lst.length); - if (lst.length > 0) { - $('#persistent-selection-list').html('
  • Clear selections
  • ' - +'
  • '); + html = '
  • Clear selections
  • '; + if (this_object_uuid.match('-j7d0g-')) { + html += '
  • '; + html += '
  • '; + } + html += '
  • ' + + '
  • '; + $('#selection-form-content').html(html); + for (var i = 0; i < lst.length; i++) { - $('#persistent-selection-list > li > table').append("" + $('#selection-form-content > li > table').append("" + "" - + "
    " - + "" - + "
    " + + "" + "" + "" - + "" + lst[i].name + "" + + "
    " + lst[i].name + "
    " + "" + "" @@ -75,7 +84,7 @@ jQuery(function($){ + ""); } } else { - $('#persistent-selection-list').html("
  • No selections.
  • "); + $('#selection-form-content').html("
  • No selections.
  • "); } var checkboxes = $('.persistent-selection:checkbox'); @@ -90,16 +99,14 @@ jQuery(function($){ checkboxes[i].checked = false; } } - + $('.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')); @@ -109,12 +116,15 @@ jQuery(function($){ } }); - $(window).on('load storage', update_count); + + $('#selection-form-content').on("click", function(e) { + e.stopPropagation(); + }); }); add_form_selection_sources = null; -select_form_sources = null; +select_form_sources = null; (function() { var form_selection_sources = {}; @@ -136,16 +146,26 @@ select_form_sources = null; if (get_selection_list) { var lst = get_selection_list(); if (lst.length > 0) { - ret.push({text: "--- Selections ---", value: ""}); + 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) { - ret.push({text: lst[i].name, value: lst[i].uuid}) + var n = lst[i].name; + n = n.replace(/]*>/i, "["); + n = n.replace(/<\/span>/i, "]"); + ret.push({text: n, value: lst[i].uuid}) } } } } - ret.push({text: "--- Recent ---", value: ""}); + + 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) { @@ -158,3 +178,44 @@ select_form_sources = null; }; })(); +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(); + });