Merge branch 'master' into 3177-collection-choose-files
[arvados.git] / apps / workbench / app / assets / javascripts / select_modal.js
index ee33b54a62173e03138bf72aad92f2bf93933a02..d84037763c77b8a33e0478511c0e92c4f8e84170 100644 (file)
@@ -8,8 +8,11 @@ $(document).on('click', '.selectable', function() {
             removeClass('active');
     }
     $this.toggleClass('active');
-    any = ($container.
+
+    if (!$this.hasClass('use-checkbox-selection')) {
+      any = ($container.
            find('.selectable.active').length > 0)
+    }
     $this.
         closest('.modal').
         find('[data-enable-if-selection]').
@@ -31,26 +34,57 @@ $(document).on('click', '.selectable', function() {
                 $(".modal-dialog-preview-pane").html(no_preview_available);
             });
     }
+}).on('click', '.persistent-selection', function() {
+    var checked_status = this.checked;
+    var $modal = $(this).closest('.modal');
+    $checked_selections = $modal.find('.persistent-selection:checked');
+
+    if (checked_status && ($checked_selections.length > 1)) {
+      $(this).prop('checked', false);
+    }
 
+    any = ($checked_selections.length > 0);
+    $(this).
+        closest('.modal').
+        find('[data-enable-if-selection]').
+        prop('disabled', !any);
 }).on('click', '.modal button[data-action-href]', function() {
     var selection = [];
     var data = [];
     var $modal = $(this).closest('.modal');
     var action_data = $(this).data('action-data');
+    var action_data_from_params = $(this).data('action-data-from-params');
     var selection_param = action_data.selection_param;
     $modal.find('.modal-error').removeClass('hide').hide();
-    $modal.find('.selectable.active[data-object-uuid]').each(function() {
+
+    $checked_selections = $modal.find('.persistent-selection:checked');
+    if ($checked_selections) {
+      $checked_selections.each(function() {
+          data.push({name: selection_param, value: $(this).attr('value')});
+      });
+    }
+
+    if (data.length == 0) {   // no checked persistent selection
+      $modal.find('.selectable.active[data-object-uuid]').each(function() {
         var val = $(this).attr('data-object-uuid');
         data.push({name: selection_param, value: val});
-    });
-    $.each(action_data, function(key, value) {
-        data.push({name: key, value: value});
-    });
+      });
+    }
+    $.each($.extend({}, action_data, action_data_from_params),
+           function(key, value) {
+               if (value instanceof Array && key[-1] != ']') {
+                   for (var i in value) {
+                       data.push({name: key + '[]', value: value[i]});
+                   }
+               } else {
+                   data.push({name: key, value: value});
+               }
+           });
     $.ajax($(this).attr('data-action-href'),
            {dataType: 'json',
             type: $(this).attr('data-method'),
             data: data,
-            traditional: true,
+            traditional: false,
             context: {modal: $modal, action_data: action_data}}).
         fail(function(jqxhr, status, error) {
             if (jqxhr.readyState == 0 || jqxhr.status == 0) {
@@ -72,11 +106,14 @@ $(document).on('click', '.selectable', function() {
         });
 }).on('click', '.chooser-show-project', function() {
     var params = {};
+    var project_uuid = $(this).attr('data-project-uuid');
     $(this).attr('href', '#');  // Skip normal click handler
-    if ($(this).attr('data-project-uuid')) {
-        params = {'filters[]': JSON.stringify(['owner_uuid',
-                                               '=',
-                                               $(this).attr('data-project-uuid')])};
+    if (project_uuid) {
+        params = {'filters': [['owner_uuid',
+                               '=',
+                               project_uuid]],
+                  'project_uuid': project_uuid
+                 };
     }
     // Use current selection as dropdown button label
     $(this).
@@ -85,7 +122,7 @@ $(document).on('click', '.selectable', function() {
         html($(this).text() + ' <span class="caret"></span>');
     // Set (or unset) filter params and refresh filterable rows
     $($(this).closest('[data-filterable-target]').attr('data-filterable-target')).
-        data('infinite-content-params', params).
+        data('infinite-content-params-from-project-dropdown', params).
         trigger('refresh-content');
 }).on('ready', function() {
     $('form[data-search-modal] a').on('click', function() {