e5179bc8d5f2500ff7c51e74f6b5529dcea17612
braney
  Mon Jan 29 20:45:15 2018 -0800
tweaks to hgCollection to renable drag and drop in collections

diff --git src/hg/js/hgCollection.js src/hg/js/hgCollection.js
index 0b248ce..a85e44c 100644
--- src/hg/js/hgCollection.js
+++ src/hg/js/hgCollection.js
@@ -39,38 +39,43 @@
         if ($(node).attr('children').length > 0)
             delete items.addItem;
 
         return items;
     }
 
     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");
                     var parentNode = $(selectedTree).jstree("get_node", node.parent);
                     isDirty = true;
-                    if (parentNode.children.length === nodes.length) {
+                    if ((parentNode.id !== '#') && (parentNode.children.length === nodes.length) ){
                         $(selectedTree).jstree("create_node", node.parent, emptyCollectionText);
                         parentNode.li_attr.class = "folder empty";
                     }
                     $(selectedTree).jstree( "delete_node", nodes);
+                    if (parentNode.id === '#') {
+                        var firstChild = $(selectedTree).find("li").first();
+                        $(selectedTree).jstree("select_node", $(firstChild).attr("id"));
+                    } else {
                         $(selectedTree).jstree( "select_node", parentNode.id);
                     }
                 }
+            }
         };
 
         return items;
         }
 
     function changeCollection() {
         $( "#newCollectionDialog" ).dialog("close");
         selectedNode.li_attr.class = "folder";
         selectedNode.li_attr.shortlabel = $("#customName").val().trim();
         selectedNode.li_attr.longlabel = $("#customDescription").val().trim();
         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();
         rebuildLabel();
@@ -126,39 +131,34 @@
         selectedTree = tree;
         $(selectedTree).jstree("open_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.li_attr.class.includes("folder")) {
-                if (node_parent.id !== '#') {
-                    return false;
-                }
-            }
-            else if (!node_parent.li_attr.class.includes("folder")) {
+            if (node_parent.parent === '#')
+                return true;
             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");
         $("#viewFunc").val("show all");
         $( "#customName" ).select();
         $('#collectionDialogHelp').show();
         $('#trackDialogHelp').hide();
@@ -356,32 +356,32 @@
             change: colorChange,
         };
 
         $("#customColorPicker").spectrum(trackOpt);
         $.jstree.defaults.core.check_callback = checkCallback;
         $.jstree.defaults.core.themes.dots = true;
         $.jstree.defaults.contextmenu.show_at_node = false;
         var addedOne = false;
         if ( $("#currentCollection ul").length !== 0) {
             addedOne = true;
         }
         $("#currentCollection div").each(function(index) {
             var newTree = this;
 
             $(newTree).jstree({
-               //'plugins' : ['dnd', 'conditionalselect', 'contextmenu'],
-               'plugins' : [ 'conditionalselect', 'contextmenu'],
+               'plugins' : ['dnd', 'conditionalselect', 'contextmenu'],
+               //'plugins' : [ 'conditionalselect', 'contextmenu'],
                'contextmenu': { "items" : currentCollectionItems},
                'core': {
                    "dblclick_toggle" : false,
                 },
                '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);