0bd11409624970f87f46089c184f38bc9360f136
braney
  Sat Mar 10 11:18:22 2018 -0800
make sure auto-generated short labels are unique within the collection

diff --git src/hg/js/hgCollection.js src/hg/js/hgCollection.js
index 3a7ada2..c2d05c2 100644
--- src/hg/js/hgCollection.js
+++ src/hg/js/hgCollection.js
@@ -163,36 +163,39 @@
     }
 
     function checkCallback( operation, node, node_parent, node_position, more) {
         // called during a drag and drop action to see if the target is droppable
         if ((operation === "copy_node") ||  (operation === "move_node")) {
             if ((node.parent != '#') && (node_parent.parent === '#')) {
                 if (node.icon === true) // empty stub
                     return false;
                 return true;
             }
             return false;
         }
         return true;
     }
 
+
     function dialogCollection() {
         $("#doNewCollection").off ( "click" );
         $("#doNewCollection").click ( newCollection );
         $("#viewFuncDiv").show();
-        $("#customName").val("New Collection");
-        $("#customDescription").val("New Collection description");
+
+        var collectionLabel = getUniqueLabel();
+        $("#customName").val(collectionLabel);
+        $("#customDescription").val(collectionLabel + " description");
         $("#customVis").val("full");
         $("#customColorInput").val("#0");
         $("#customColorPicker").spectrum("set", "#0");
         $("#viewFunc").val("show all");
         $( "#customName" ).select();
         $('#collectionDialogHelp').show();
         $('#trackDialogHelp').hide();
         $( "#newCollectionDialog" ).dialog( 'option', 'title', 'Create New Collection');
         $( "#newCollectionDialog" ).dialog("open");
     } 
 
     function newCollection() {
         var newName = $("#customName").val().trim();
         if (!validateLabel(newName))
             return;
@@ -507,30 +510,48 @@
 
     function updatePage(responseJson) {
         // called after AJAX call
         isDirty = false;
         if (!responseJson) {
             return;
         }
 
         if (goTracks) {
             // we go straight to hgTracks after save
             $form = $('#redirectForm');
             $form.submit();
         }
     }
 
+    function getUniqueLabel() {
+        var root = "New Collection";
+        if (!collectionLabels[root]) {
+            collectionLabels[root] = 1;
+            return root;
+        } else {
+            var counter = 1;
+
+            for(; ; counter++) {
+                var label  = root + ' (' + counter + ')';
+                if (!collectionLabels[label]) {
+                    collectionLabels[label] = 1;
+                    return label;
+                }
+            }
+        }
+    }
+
     function getUniqueName() {
         // make sure name is unique in track hub
         var seconds =  Math.floor( Date.now() / 1000 ) - 1520631071;
         var root = "coll" + seconds;
         if (!collectionNames[root]) {
             collectionNames[root] = 1;
             return root;
         } else {
             var counter = 1;
 
             for(; ; counter++) {
                 var name  = root + counter;
                 if (!collectionNames[name]) {
                     collectionNames[name] = 1;
                     return name;