c5a827f8f0c4094c20ff333acb191ded2bf86744
braney
  Wed Dec 20 11:36:10 2017 -0800
ongoing work on hgCollection

diff --git src/hg/js/hgCollection.js src/hg/js/hgCollection.js
index 536f06f..3f24679 100644
--- src/hg/js/hgCollection.js
+++ src/hg/js/hgCollection.js
@@ -41,32 +41,32 @@
 
     function currentCollectionItems(node) {
         // populate the menu for the currentCollection tree
         var items = {
             deleteItem: { // The "delete" menu item
                 label: "Delete",
                 action: function () {
                     var nodes = $(selectedTree).jstree( "get_selected");
                     isDirty = true;
                     $(selectedTree).jstree( "delete_node", nodes);
                 }
             }
         };
 
         // can't delete root
-        if ($(node).attr('parent') === '#')
-            delete items.deleteItem;
+        //if ($(node).attr('parent') === '#')
+            //delete items.deleteItem;
 
         return items;
         }
 
     function changeCollection() {
         $( "#newCollectionDialog" ).dialog("close");
         selectedNode.li_attr.class = "folder";
         selectedNode.li_attr.shortlabel = $("#customName").val();
         selectedNode.li_attr.longlabel = $("#customDescription").val();
         selectedNode.li_attr.visibility = $("#customVis").val();
         selectedNode.li_attr.color = $("#customColorInput").val();
         selectedNode.li_attr.missingMethod = $("input:radio[name ='missingData']:checked").val();
         selectedNode.li_attr.viewfunc = $("#viewFunc").val();
         //newNode.li_attr.viewtype = "view";
         rebuildLabel();
@@ -149,34 +149,35 @@
         var newDescription = $("#customDescription").val();
         var parent = $(selectedTree).find("li").first();
 
         var newId = $(selectedTree).jstree("create_node", "#", newName + " (" + newDescription + ")");
         var newNode = $(selectedTree).jstree("get_node", newId);
         isDirty = true;
         newNode.li_attr.class = "folder";
         newNode.li_attr.name = ourCollectionName;
         newNode.li_attr.shortlabel = $("#customName").val();
         newNode.li_attr.longlabel = $("#customDescription").val();
         newNode.li_attr.visibility = $("#customVis").val();
         newNode.li_attr.color = $("#customColorInput").val();
         newNode.li_attr.missingMethod = $("input:radio[name ='missingData']:checked").val();
         newNode.li_attr.viewfunc = $("#viewFunc").val();
         newNode.li_attr.viewtype = "collection";
-        rebuildLabel();
+        //selectedNode = newNode;
         $(selectedTree).jstree("set_icon", newNode, '../images/folderC.png');
         $(selectedTree).jstree("deselect_node", selectedNode);
         $(selectedTree).jstree("select_node", newNode.id);
+        rebuildLabel();
     }
 
     function addCollection(trees, list) {
         // called when outputting JSON of all the collectionList
         var collectTree = trees[list.id];
         var v = collectTree.jstree(true).get_json('#', {flat:true, no_data:true, no_state:true, no_a_attr:true});
         var mytext = JSON.stringify(v);
         return mytext;
     }
 
     function saveCollections(trees) {
        // called when the "Save" button is pressed
        var json = "[";
         var v = $(selectedTree).jstree(true).get_json('#', {flat:true, no_data:true, no_state:true, no_a_attr:true});
         var children;
@@ -264,31 +265,31 @@
     function init() {
         // called at initialization time
         $body = $("body");
 
         // block user input when ajax is running
         $(document).on({
             ajaxStart: function() { $body.addClass("loading");    },
             ajaxStop: function() { $body.removeClass("loading"); }    
         });
 
         $('.gbButtonGoContainer').click(submitForm);
        
         window.addEventListener("beforeunload", function (e) {
             if (isDirty) {
                 doAjaxAsync = false;
-                //saveCollections(trees);
+                saveCollections(trees);
             }
 
             return undefined;
         });
 
         $("#saveCollections").click ( function() { saveCollections(trees); } );
         $("#discardChanges").click ( function () { isDirty = false; window.location.reload(); });
 
         $( "#newCollectionDialog" ).dialog({ modal: true, 
             width: "50%", 
             autoOpen: false,
             });
         $("#newCollection").click ( dialogCollection );
         $("#doNewCollection").click ( newCollection );
 
@@ -365,31 +366,31 @@
     // Show a spinner -- sometimes it takes a while for hgTracks to start displaying.
         $('.gbIconGo').removeClass('fa-play').addClass('fa-spinner fa-spin');
         goTracks = true;
         saveCollections(trees);
     }
 
     function updatePage(responseJson) {
         // called after AJAX call
         isDirty = false;
         if (!responseJson) {
             return;
         }
 
         if (goTracks) {
             // we go straight to hgTracks after save
-            $form = $('form');
+            $form = $('#redirectForm');
             $form.submit();
         }
     }
 
     function getUniqueName(root) {
         // make sure name is unique in track hub
         if (!names[root]) {
             names[root] = true;
             return root;
         } else {
             var counter = 1;
 
             for(; ; counter++) {
                 var name  = root + counter;
                 if (!names[name]) {