af76ebc56040c96025f9d5eba0ef0add4e26177f braney Fri Oct 27 10:31:41 2017 -0700 dialog for calculation track. diff --git src/hg/js/hgCollection.js src/hg/js/hgCollection.js index aafb290..99b005e 100644 --- src/hg/js/hgCollection.js +++ src/hg/js/hgCollection.js @@ -7,33 +7,37 @@ var selectedNode = "collectionList"; // keep track of id of selected row var selectedTree = "collectionList"; // keep track of id of selected row var $tracks; // the #tracks object var trees = []; var isDirty = false; function currentTrackItems(node) { // populate the menu for the currentCollection tree var items = { addItem: { // The "add" menu item label: "Add", action: function () { var nodeIds = $("#tracks").jstree( "get_selected"); isDirty = true; var nodes = []; - for(ii=0; ii < nodeIds.length;ii++) - nodes.push($("#tracks").jstree('get_node', nodeIds[ii])); - var parentId = $(selectedTree).jstree("get_node", "ul > li:first").id; + var node; + for(ii=0; ii < nodeIds.length;ii++) { + node = $("#tracks").jstree('get_node', nodeIds[ii]); + if (node.children.length === 0) + nodes.push(node); + } + var parentId = $(selectedNode).attr('id'); $(selectedTree).jstree("copy_node", nodes, parentId,'last'); } } }; 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 @@ -93,49 +97,75 @@ 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") return false; } return true; } + function dialogCalcTrack() { + $( "#newCalcTrackDialog" ).dialog("open"); + } + function newCalcTrack() { // create a new view under a collection + $( "#newCalcTrackDialog" ).dialog("close"); var ourCalcName = getUniqueName("calc"); var newName = "Calc Track"; var newDescription = "Description of Calculated Track"; var parent = $(selectedTree).find("li").first(); + var children = $(selectedTree).jstree("get_children_dom",$(selectedTree).jstree("get_node", $(parent).attr('id'))); var newId = $(selectedTree).jstree("create_node", parent, newName + " (" + newDescription + ")"); var newNode = $(selectedTree).jstree("get_node", newId); isDirty = true; newNode.li_attr.class = "folder"; newNode.li_attr.name = ourCalcName; newNode.li_attr.shortlabel = newName; newNode.li_attr.longlabel = newDescription; newNode.li_attr.visibility = "full"; newNode.li_attr.color = "#0"; + newNode.li_attr.missing = $("input:radio[name ='missingData']:checked").val(); newNode.li_attr.viewfunc = "add all"; newNode.li_attr.viewtype = "view"; $(selectedTree).jstree("set_icon", newNode, '../images/folderC.png'); + + var nodes = []; + for(ii=0; ii < children.length;ii++) { + if (!$(children[ii]).hasClass('folder')) + nodes.push(children[ii]); + } + + switch($("input:radio[name ='defaultContents']:checked").val()) { + case "move": + // move_node causes havoc + $(selectedTree).jstree('copy_node', nodes, newNode, 'last'); + $(selectedTree).jstree('delete_node', nodes); + break; + case "copy": + $(selectedTree).jstree('copy_node', nodes, newNode); + break; + case "empty": + break; + } } function newCollection() { isDirty = true; // called when the "New Collection" button is pressed var ourCollectionName = getUniqueName("coll"); var ourTreeName = getUniqueName("tree"); var newName = "A New Collection"; var newDescription = "Description of New Collection"; var attributes = "shortLabel='" + newName + "' "; attributes += "longLabel='" + newDescription + "' "; attributes += "color='" + "#0" + "' "; attributes += "viewType='" + "track" + "' "; attributes += "visibility='" + "full" + "' "; attributes += "name='" + ourCollectionName + "' "; @@ -276,31 +306,31 @@ 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 plusHit(event, data) { // called with the plus icon is hit var treeObject = $(event.currentTarget).parent().parent(); var id = treeObject.attr('id'); var node = treeObject.jstree("get_node", id); if (node.children.length === 0) { - var parentId = $(selectedTree).jstree("get_node", "ul > li:first").id; + var parentId = $(selectedNode).attr('id'); isDirty = true; $(selectedTree).jstree("copy_node", node, parentId,'last'); } } function minusHit (event, data) { // called with the minus icon is hit var treeObject = $(event.currentTarget).parent().parent(); var id = treeObject.attr('id'); var node = treeObject.jstree("get_node", id); if (node.children.length === 0) { isDirty = true; $(selectedTree).jstree( "delete_node", node); } } @@ -322,30 +352,35 @@ (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); //$("#customColorInput").change(colorChange); $("#saveCollections").click ( function() {saveCollections(trees);} ); $("#discardChanges").click ( function () { window.location.reload(); }); $("#newCollection").click ( newCollection ); + $( "#newCalcTrackDialog" ).dialog({ modal: true, + width: "50%", + autoOpen: false, + }); + $("#newCalcTrackButton").click ( dialogCalcTrack ); $("#newCalcTrack").click ( newCalcTrack ); $('#collectionList').selectable({selected : selectCollection}); $( "#collectionList" ).contextmenu(collectionListRightClick); $(document).bind("mousedown", function (e) { // If the clicked element is not the menu if ($(e.target).parents(".collectionList-menu").length === 0) { // Hide it $(".collectionList-menu").hide(100); } }); $(".collectionList-menu li").click(function(){ // This is the triggered action name