Merge branch 'master' into 3654-combine-selections
[arvados.git] / apps / workbench / app / assets / javascripts / selection.js
index 4ab0295c043b00ad4c30cd627d58f3774ecf06f9..bcc33c46bc1b1b67a355b96361b9b9ff30874697 100644 (file)
@@ -57,10 +57,6 @@ jQuery(function($){
         $("#persistent-selection-count").text(lst.length);
         if (lst.length > 0) {
             html = '<li><a href="#" class="btn btn-xs btn-info" id="clear_selections_button"><i class="fa fa-fw fa-ban"></i> Clear selections</a></li>';
-            html += '<li><button class="btn btn-xs btn-info" type="submit" name="combine_selected_files_into_collection" '
-                + ' id="combine_selected_files_into_collection">'
-                + '<i class="fa fa-fw fa-archive"></i> Combine selected collections and files into a new collection</button></li>'
-                + '<li class="notification"><table style="width: 100%"></table></li>';
             $('#selection-form-content').html(html);
 
             for (var i = 0; i < lst.length; i++) {
@@ -185,9 +181,12 @@ function dispatch_selection_action() {
     if ($(this).closest('.disabled').length > 0) {
        return false;
     }
-    $('.persistent-selection:checkbox:checked').each(function() {
-        data.push({name: param_name, value: $(this).val()});
-    });
+    $(this).
+        closest('.selection-action-container').
+        find(':checkbox:checked').
+        each(function() {
+            data.push({name: param_name, value: $(this).val()});
+        });
     if (href.indexOf('?') >= 0)
         href += '&';
     else
@@ -198,7 +197,8 @@ function dispatch_selection_action() {
 }
 
 function enable_disable_selection_actions() {
-    var $checked = $('.persistent-selection:checkbox:checked');
+    var $container = $(this).closest('.selection-action-container');
+    var $checked = $('.persistent-selection:checkbox:checked', $container);
     $('[data-selection-action]').
         closest('div.btn-group-sm').
         find('ul li').
@@ -212,11 +212,17 @@ function enable_disable_selection_actions() {
         closest('li').
         toggleClass('disabled',
                     ($checked.filter('[value*=-j7d0g-]').length > 0) ||
-                    (($checked.not('[value*=-d1hrv-]').length > 0) && ($checked.filter('[value*=-]').length < 0)));
+                    ($checked.length < 1));
+    $('[data-selection-action=combine-project-contents]').
+        closest('li').
+        toggleClass('disabled',
+                    ($checked.filter('[value*=-4zz18-]').length < 1) ||
+                    ($checked.length != $checked.filter('[value*=-4zz18-]').length));
 }
 
 $(document).
     on('selections-updated ready ajax:complete', function() {
-        $('[data-selection-action]').click(dispatch_selection_action);
-        enable_disable_selection_actions();
+        var $btn = $('[data-selection-action]');
+        $btn.click(dispatch_selection_action);
+        enable_disable_selection_actions.call($btn);
     });