a9ef87ba7d8b726b83b81adafb931e3e44c15998
braney
  Wed Dec 13 18:54:16 2017 -0800
ongoing work on hgCollection

diff --git src/hg/js/hgCollection.js src/hg/js/hgCollection.js
index 88b9574..536f06f 100644
--- src/hg/js/hgCollection.js
+++ src/hg/js/hgCollection.js
@@ -69,31 +69,31 @@
         selectedNode.li_attr.missingMethod = $("input:radio[name ='missingData']:checked").val();
         selectedNode.li_attr.viewfunc = $("#viewFunc").val();
         //newNode.li_attr.viewtype = "view";
         rebuildLabel();
     }
 
     function doubleClickNode(tree) {
         var node = $(selectedTree).jstree("get_node", tree.id);
         var color = node.li_attr.color;
         var name =  node.li_attr.shortlabel;
         var description = node.li_attr.longlabel;
         var visibility = node.li_attr.visibility;
         var type = node.li_attr.viewtype;
         var viewFunc = node.li_attr.viewfunc;
 
-        if (type == 'view') 
+        if (type == 'collection') 
             $("#viewFuncDiv").show();
         else
             $("#viewFuncDiv").hide();
 
         $("#CustomTrackOptions").show();
         $("#viewFunc").val(viewFunc);
         $("#customName").val(name);
         $("#customDescription").val(description);
         $("#customVis").val(visibility);
         $("#customColorInput").val(color);
         $("#customColorPicker").spectrum("set", color);
 
         $("#doNewCollection").off ( "click" );
         $("#doNewCollection").click ( changeCollection );
         $( "#newCollectionDialog" ).dialog("open");
@@ -105,79 +105,105 @@
         selectedTree = tree;
         $(selectedTree).jstree("toggle_node", selectedNode);
    }
 
     function doubleClickTreeNode(evt, data)             {
         doubleClickNode(evt.target);
     }
 
     function selectTreeNode(evt, data)             {
         selectNode(evt.target, data.node);
     }
 
     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.li_attr.class !== "folder")
+            if (node.li_attr.class === "folder") {
+                if (node_parent.id !== '#') {
                     return false;
                 }
-
+            }
+            else if (node_parent.li_attr.class !== "folder") {
+                return false;
+            }
+        }
         return true;
     }
 
     function dialogCollection() {
         $("#doNewCollection").off ( "click" );
         $("#doNewCollection").click ( newCollection );
+        $("#viewFuncDiv").show();
+        $("#customName").val("A New Collection");
+        $("#customDescription").val("A New Collection Description");
+        $("#customVis").val("full");
+        $("#customColorInput").val("#0");
+        //$("input:radio[name ='missingData']:checked").val();
+        $("#viewFunc").val("show all");
         $( "#newCollectionDialog" ).dialog("open");
     } 
 
     function newCollection() {
         $( "#newCollectionDialog" ).dialog("close");
         var ourCollectionName = getUniqueName("coll");
         var newName = $("#customName").val();
         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 = "view";
-        selectedNode = newNode;
+        newNode.li_attr.viewtype = "collection";
         rebuildLabel();
         $(selectedTree).jstree("set_icon", newNode, '../images/folderC.png');
+        $(selectedTree).jstree("deselect_node", selectedNode);
+        $(selectedTree).jstree("select_node", newNode.id);
     }
 
     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;
+        var parents = {};
+        for(ii=0; ii < v.length; ii++) {
+            if (v[ii].parent !== '#') {
+                parents[v[ii].parent] = 1;
+            }
+        }
+        for(ii=0; ii < v.length; ii++) { 
+            if (v[ii].li_attr.class === "folder") {
+                if (parents[v[ii].id] !== 1)
+                    alert(v[ii].text + " does not have any wiggles.  Not saved");
+            }
+        }
         json += JSON.stringify(v);
         json += ']';
         var requestData = 'jsonp=' + json;
         $.ajax({
             data:  requestData ,
             async: doAjaxAsync,
             dataType: "JSON",
             type: "PUT",
             url: "hgCollection?cmd=saveCollection",
             trueSuccess: updatePage,
             success: catchErrorOrDispatch,
             error: errorHandler,
         });
     }
 
@@ -289,30 +315,34 @@
                'contextmenu': { "items" : currentCollectionItems},
                'dnd': {
                 "check_callback" : checkCallback,
                 }
             });
             recordNames(newTree);
             trees[this.id] = $(newTree);
             $(newTree).on("select_node.jstree", selectTreeNode);
             $(newTree).on("dblclick.jstree", doubleClickTreeNode);
 
             $(newTree).on("copy_node.jstree", function (evt, data)  {
                 $(evt.target).jstree("open_node", data.parent);
                 $(evt.target).jstree("set_icon", data.node, 'fa fa-minus-square');
             });
             $(newTree).on('click', '.jstree-themeicon ', minusHit);
+
+            // select the first cild
+            var firstChild = $(newTree).find("li").first();
+            $(newTree).jstree("select_node", $(firstChild).attr("id"));
             selectedTree = newTree;
         });
 
         if (!addedOne) {
             dialogCollection();
         }
 
         treeDiv=$('#tracks');
         treeDiv.jstree({
                'plugins' : ['dnd', 'conditionalselect', 'contextmenu'],
                'contextmenu': { "items" : currentTrackItems},
                'dnd': {
                 "check_callback" : checkCallback,
                'always_copy' : true,
                 is_draggable: isDraggable,