3016: prefill input search with value configured in the template
[arvados.git] / apps / workbench / app / assets / javascripts / select_modal.js
index fc158bff79f4415590a538a1eb67b29b5482e2a0..c1267d1d3da8b5587a585ef95c662de187d33531 100644 (file)
@@ -71,10 +71,21 @@ $(document).on('click', '.selectable', function() {
                                 [data, status, jqxhr, this.action_data]);
         });
 }).on('click', '.chooser-show-project', function() {
-    $(this).attr('href', '#');
+    var params = {};
+    $(this).attr('href', '#');  // Skip normal click handler
+    if ($(this).attr('data-project-uuid')) {
+        params = {'filters[]': JSON.stringify(['owner_uuid',
+                                               '=',
+                                               $(this).attr('data-project-uuid')])};
+    }
+    // Use current selection as dropdown button label
+    $(this).
+        closest('.dropdown-menu').
+        prev('button').
+        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',
-             {'filters[]': JSON.stringify(['owner_uuid', '=', $(this).attr('data-project-uuid')])}).
+        data('infinite-content-params', params).
         trigger('refresh-content');
 });
 $(document).on('page-refresh', function(event, data, status, jqxhr, action_data) {