4fa0e7161f5d0aa6068807e41c2bf935cdc6865f
braney
  Tue Jul 12 18:40:16 2011 -0700
make it so unlisted hubs don't disappear when you deselect them, and add the ability to disconnect them
diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c
index bf1e369..48c883f 100644
--- src/hg/hgHubConnect/hgHubConnect.c
+++ src/hg/hgHubConnect/hgHubConnect.c
@@ -13,30 +13,31 @@
 #include "hdb.h"
 #include "hui.h"
 #include "cart.h"
 #include "dbDb.h"
 #include "web.h"
 #include "trackHub.h"
 #include "hubConnect.h"
 #include "dystring.h"
 #include "hPrint.h"
 #include "jsHelper.h"
 #include "obscure.h"
 
 #define hgHub             "hgHub_"  /* prefix for all control variables */
 #define hgHubDo            hgHub   "do_"    /* prefix for all commands */
 #define hgHubDoClear       hgHubDo "clear"
+#define hgHubDoDisconnect  hgHubDo "disconnect"
 
 struct cart *cart;	/* The user's ui state. */
 struct hash *oldVars = NULL;
 
 static char *destUrl = "../cgi-bin/hgTracks";
 static char *pageTitle = "Import Tracks from Data Hubs";
 char *database = NULL;
 char *organism = NULL;
 
 static void ourCellStart()
 {
 puts("<TD>");
 }
 
 static void ourCellEnd()
@@ -58,55 +59,56 @@
 printf("<div id=\"unlistedHubs\" class=\"hubList\"> "
     "<table id=\"unlistedHubsTable\"> "
     "<thead><tr> "
 	"<th colspan=\"5\" id=\"addHubBar\"><label>URL:</label> "
 	"<input name=\"hubText\" id=\"hubUrl\" class=\"hubField\""
 	    "type=\"text\" size=\"65\"> "
 	"<input name=\"hubAddButton\""
 	    "onClick=\"document.addHubForm.elements['hubUrl'].value=hubText.value;"
 		"document.addHubForm.submit();return true;\" "
 		"class=\"hubField\" type=\"button\" value=\"Add Hub\">"
 	"</th> "
     "</tr></thead> ");
 
 // count up the number of unlisted hubs we currently have
 int count = 0;
-struct hubConnectStatus *hub, *hubList =  hubConnectStatusListFromCart(cart);
+struct hubConnectStatus *hub, *hubList =  hubConnectStatusListFromCartAll(cart);
 for(hub = hubList; hub; hub = hub->next)
     {
     if (isHubUnlisted(hub))
 	count++;
     }
 
 if (count == 0)
     {
     // nothing to see here
     printf(
 	"<tr><th>No Track Hubs for this genome assembly</th></tr>"
 	"</td></table>");
     cgiMakeButton("Submit", "Return to Genome Browser");
     printf("</div>");
     return;
     }
 
 // time to output the big table.  First the header
 printf(
     "<tr> "
 	"<th>Active?</th> "
 	"<th>Hub Name</th> "
 	"<th>Description</th> "
 	"<th>URL</th> "
+	"<th>Disconnect</th> "
     "</tr>\n");
 
 // start first row
 printf("<tbody><tr>");
 
 count = 0;
 for(hub = hubList; hub; hub = hub->next)
     {
     /* if the hub is public, then don't list it here */
     if (!isHubUnlisted(hub))
 	continue;
 
     if (count)
 	webPrintLinkTableNewRow();  // ends last row and starts a new one
     count++;
@@ -117,30 +119,42 @@
 	{
 	ourCellStart();
 	char hubName[32];
 	safef(hubName, sizeof(hubName), "%s%u", hgHubConnectHubVarPrefix, hub->id);
 	cartMakeCheckBox(cart, hubName, FALSE);
 	ourCellEnd();
 	}
     else
 	ourPrintCell("error");
     ourPrintCell(hub->shortLabel);
     if (isEmpty(hub->errorMessage))
 	ourPrintCell(hub->longLabel);
     else
 	ourPrintCell(hub->errorMessage);
     ourPrintCell(hub->hubUrl);
+
+    ourCellStart();
+    printf(
+    "<input name=\"hubDisconnectButton\""
+	"onClick=\"document.disconnectHubForm.elements['hubUrl'].value='%s';"
+	    "document.disconnectHubForm.submit();return true;\" "
+	    "class=\"hubField\" type=\"button\" value=\"X\">"
+	    , hub->hubUrl);
+    //cgiMakeButton("Submit", "X");
+    ourCellEnd();
+    //hPrintf("<input type='button' name='clear' value='clear' class='clear' style='font-size:.8em;' onclick='findTracksClear();'>\n");
+
     }
 
 printf("</TR></tbody></TABLE>\n");
 cgiMakeButton("Submit", "Display Selected Hubs");
 printf("</div>");
 }
 
 static void makeGenomePrint()
 /* print out the name of the current database etc. */
 {
 getDbAndGenome(cart, &database, &organism, oldVars);
 printf("<div id=\"assemblyInfo\"> \n");
 printf("<B>genome:</B> %s &nbsp;&nbsp;&nbsp;<B>assembly:</B> %s  ",
 	organism, hFreezeDate(database));
 printf("</div>\n");
@@ -233,93 +247,115 @@
 hDisconnectCentral(&conn);
 }
 
 static void doClearHub(struct cart *theCart)
 {
 char *url = cartOptionalString(cart, hgHubDataText);
 
 printf("<pre>clearing hub %s\n",url);
 if (url != NULL)
     hubClearStatus(url);
 else
     errAbort("must specify url in %s\n", hgHubDataText);
 printf("<pre>Completed\n");
 }
 
+static void doDisconnectHub(struct cart *theCart)
+{
+char *url = cartOptionalString(cart, hgHubDataText);
+
+if (url != NULL)
+    hubDisconnect(theCart, url);
+
+cartRemove(theCart, hgHubDataText);
+}
+
 void doMiddle(struct cart *theCart)
 /* Write header and body of html page. */
 {
 cart = theCart;
 setUdcCacheDir();
 if (cartVarExists(cart, hgHubDoClear))
     {
     doClearHub(cart);
     cartWebEnd();
     return;
     }
 
+if (cartVarExists(cart, hgHubDoDisconnect))
+    doDisconnectHub(cart);
+
 cartWebStart(cart, NULL, "%s", pageTitle);
 jsIncludeFile("jquery.js", NULL);
 jsIncludeFile("utils.js", NULL);
 jsIncludeFile("jquery-ui.js", NULL);
 
 webIncludeResourceFile("jquery-ui.css");
 
 jsIncludeFile("ajax.js", NULL);
 jsIncludeFile("hgHubConnect.js", NULL);
 webIncludeResourceFile("hgHubConnect.css");
 
 printf("<div id=\"hgHubConnectUI\"> <div id=\"description\"> \n");
 printf(
    "<P>Track data hubs are collections of tracks from outside of UCSC that "
    "can be imported into the Genome Browser.  To import a public hub check "
    "the box in the list below. "
    "After import the hub will show up as a group of tracks with its own blue "
    "bar and label underneath the main browser graphic, and in the "
    "configure page. </P>\n"
    );
 printf("</div>\n");
 
 // figure out and print out genome name
 makeGenomePrint();
 
 // check to see if we have any new hubs
 hubCheckForNew(database, cart);
 
 // here's a little form for the add new hub button
 printf("<FORM ACTION=\"%s\" NAME=\"addHubForm\">\n",  "../cgi-bin/hgHubConnect");
-cgiMakeHiddenVar("hubUrl", "foo");
+cgiMakeHiddenVar("hubUrl", "");
+cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
+puts("</FORM>");
+
+// this the form for the disconnect hub button
+printf("<FORM ACTION=\"%s\" NAME=\"disconnectHubForm\">\n",  "../cgi-bin/hgHubConnect");
+cgiMakeHiddenVar("hubUrl", "");
+cgiMakeHiddenVar(hgHubDoDisconnect, "on");
 cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
 puts("</FORM>");
 
 // ... and now the main form
 printf("<FORM ACTION=\"%s\" METHOD=\"POST\" NAME=\"mainForm\">\n", destUrl);
 cartSaveSession(cart);
 
 // we have two tabs for the public and unlisted hubs
 printf("<div id=\"tabs\">"
        "<ul> <li><a href=\"#publicHubs\">Public Hubs</a></li>"
        "<li><a href=\"#unlistedHubs\">My Hubs</a></li> "
        "</ul> ");
 			     
 hgHubConnectPublic();
 hgHubConnectUnlisted();
 printf("</div>");
 
 cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
 
 printf("</div>\n");
 puts("</FORM>");
 cartWebEnd();
 }
 
-char *excludeVars[] = {"Submit", "submit", "hc_one_url", hgHubConnectCgiDestUrl,  hgHubDoClear, hgHubDataText, NULL};
+char *excludeVars[] = {"Submit", "submit", "hc_one_url", 
+    hgHubConnectCgiDestUrl,  hgHubDoClear, hgHubDoDisconnect, hgHubDataText, 
+    hgHubConnectRemakeTrackHub, NULL};
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 oldVars = hashNew(10);
 cgiSpoof(&argc, argv);
 cartEmptyShell(doMiddle, hUserCookie(), excludeVars, oldVars);
 return 0;
 }