d0f4fbf2ddcecf0f8b1d49575ab4c3ac10617b0d
braney
  Wed Oct 11 14:39:06 2017 -0700
change "Save" into Go button that saves and goes to hgTracks.  Add wait
screen for AJAX updates

diff --git src/hg/js/hgCollection.js src/hg/js/hgCollection.js
index 73dbf26..a340881 100644
--- src/hg/js/hgCollection.js
+++ src/hg/js/hgCollection.js
@@ -182,43 +182,41 @@
         // 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 = "[";
        $('#collectionList li').each(function() {
             json += addCollection(trees, this ) + ',';
         });
         json = json.slice(0, -1);
         json += ']';
-        console.log(json);
         var requestData = 'jsonp=' + json;
         $.ajax({
             data:  requestData ,
-            async: false,
+            async: true,
             dataType: "JSON",
             type: "PUT",
             url: "hgCollection?cmd=saveCollection",
             trueSuccess: updatePage,
             success: catchErrorOrDispatch,
             error: errorHandler,
         });
-        isDirty = false;
     }
 
     function rebuildLabel() {
         // rebuild the label for tree item
         var newText = selectedNode.li_attr.shortlabel + "   (" + selectedNode.li_attr.longlabel + ")";
         $(selectedTree).jstree('rename_node', selectedNode, newText);
     }
 
     function descriptionChange() {
         // change the description (longLabel) for a track
         selectedNode.li_attr.longlabel = $("#customDescription").val();
         isDirty = true;
         rebuildLabel();
     }
 
@@ -268,30 +266,38 @@
             left: event.pageX + "px"
         });
         return false;
     }
 
     function recordNames(tree) {
         // keep an accounting of track names that have been used
         var v = $(tree).jstree(true).get_json('#', {'flat': true});
         for (i = 0; i < v.length; i++) {
             var z = v[i];
             names[z.li_attr.name] = 1;
         }
     }
 
     function init() {
+        $body = $("body");
+
+        $(document).on({
+            ajaxStart: function() { $body.addClass("loading");    },
+            ajaxStop: function() { $body.removeClass("loading"); }    
+        });
+        $('.gbButtonGoContainer').click(submitForm);
+       
         window.addEventListener("beforeunload", function (e) {
             if (!isDirty)
                 return undefined;
 
             var confirmationMessage = 'Do you want to leave this page without saving?';
 
             (e || window.event).returnValue = confirmationMessage; //Gecko + IE
             return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
         });
 
         // called at initialization time
         $("#viewFunc").change(viewFuncChange);
         $("#customName").change(nameChange);
         $("#customDescription").change(descriptionChange);
         $("#customVis").change(visChange);
@@ -366,39 +372,47 @@
                'always_copy' : true,
                 is_draggable: isDraggable,
                },
                'core' :  {
                 "check_callback" : checkCallback
             }
         });
         $(treeDiv).on("select_node.jstree", function (evt, data)  {
             $(evt.target).jstree("toggle_node", data.node);
         });
 
         var firstElement = $("#collectionList li").first();
         selectElements($("#collectionList"), firstElement) ;
     }
 
+   function submitForm() {
+    // Submit the form (from GO button -- as in hgGateway.js)
+    // Show a spinner -- sometimes it takes a while for hgTracks to start displaying.
+        $('.gbIconGo').removeClass('fa-play').addClass('fa-spinner fa-spin');
+        saveCollections(trees);
+    }
+
     function updatePage(responseJson) {
         // called after AJAX call
+        isDirty = false;
         if (!responseJson) {
             return;
         }
-        var message = responseJson.serverSays;
-        if (message) {
-            alert(message);
-        }
+
+        // we go straight to hgTracks after save
+        $form = $('form');
+        $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]) {
                     names[name] = true;
                     return name;