Merge branch 'master' of git.curoverse.com:arvados #2751
[arvados.git] / apps / workbench / app / assets / javascripts / selection.js
index ef1c59230bf4ac8f2756d89446040da789fafba6..1e32c635642ef3fd9f109df931aebc23f8a8013b 100644 (file)
@@ -48,22 +48,27 @@ jQuery(function($){
         update_count();
     }
 
-    var combine_selected_files_into_collection = 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) {
-            $('#selection-form-content').html('<li><input type="submit" name="combine_selected_files_into_collection" id="combine_selected_files_into_collection" value="Combine selected collections and files into a new collection"/></li>'
-                                                 + '<li><a href="#" id="clear_selections_button">Clear selections</a></li>'
-                                                 + '<li class="notification"><table style="width: 100%"></table></li>');
+            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>';
+            if (this_object_uuid.match('-j7d0g-'))
+                html += '<li><button class="btn btn-xs btn-info" type="submit" name="copy_selections_into_folder" id="copy_selections_into_folder"><i class="fa fa-fw fa-folder-open"></i> Copy selections into this folder</button></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++) {
                 $('#selection-form-content > li > table').append("<tr>"
                                                        + "<td>"
-                                                       + "<input class='remove-selection' name='selection[]' type='checkbox' value='" + lst[i].uuid + "' checked='true'></input>"
+                                                       + "<input class='remove-selection' name='selection[]' type='checkbox' value='" + lst[i].uuid + "' checked='true' data-stoppropagation='true' />"
                                                        + "</td>"
 
                                                        + "<td>"
@@ -77,7 +82,7 @@ jQuery(function($){
                                                        + "</tr>");
             }
         } else {
-            $('#persistent-selection-list').html("<li class='notification empty'>No selections.</li>");
+            $('#selection-form-content').html("<li class='notification empty'>No selections.</li>");
         }
 
         var checkboxes = $('.persistent-selection:checkbox');
@@ -92,17 +97,16 @@ jQuery(function($){
                 checkboxes[i].checked = false;
             }
         }
-        
+
         $('.remove-selection').on('click', remove_selection_click);
         $('#clear_selections_button').on('click', clear_selections);
-        $('#combine_selected_files_into_collection').on('click', combine_selected_files_into_collection);
     };
 
     $(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'));
@@ -114,10 +118,14 @@ 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 = {};
@@ -139,16 +147,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 = "&horbar; Selections &horbar;";
+                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(/<span[^>]*>/i, "[");
+                        n = n.replace(/<\/span>/i, "]");
+                        ret.push({text: n, value: lst[i].uuid})
                     }
                 }
             }
         }
-        ret.push({text: "--- Recent ---", value: ""});
+
+        var text = "&horbar; Recent &horbar;";
+        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) {
@@ -160,4 +178,3 @@ select_form_sources  = null;
         return ret;
     };
 })();
-