a3fe2462440781ba92b9fb1ef95bec0359028325
angie
  Mon Jul 20 09:28:59 2015 -0700
Adding Data Integrator to list of destinations from the Manage Custom Tracks
page.  Since there are now 4 destinations, instead of having one button for
each, use a menu to select the destination and a single 'go' button.
Align the 'add custom tracks' button with the new menu.
refs #15517

diff --git src/hg/hgCustom/hgCustom.c src/hg/hgCustom/hgCustom.c
index f56033c..f9afdcd 100644
--- src/hg/hgCustom/hgCustom.c
+++ src/hg/hgCustom/hgCustom.c
@@ -630,30 +630,63 @@
 /* Get list of assemblies with custom tracks */
 struct hashEl *hels = cartFindPrefix(cart, CT_FILE_VAR_PREFIX);
 struct hashEl *hel = NULL;
 for (hel = hels; hel != NULL; hel = hel->next)
     {
     /* TODO: chop actual prefix */
     db = chopPrefixAt(cloneString(hel->name), '_');
         /* TODO: check if file exists, if not remove ctfile_ var */
     dbDb = hDbDb(db);
     if (dbDb)
         slAddTail(&dbList, dbDb);
     }
 return dbList;
 }
 
+static struct slPair *makeOtherCgiValsAndLabels()
+/* Return {value, label} pairs with other CGIs the user might wish to jump to. */
+{
+struct slPair *valsAndLabels = slPairNew(hgTracksName(), "Genome Browser");
+slAddHead(&valsAndLabels, slPairNew(hgTablesName(), "Table Browser"));
+slAddHead(&valsAndLabels, slPairNew(hgVaiName(), "Variant Annotation Integrator"));
+slAddHead(&valsAndLabels, slPairNew(hgIntegratorName(), "Data Integrator"));
+slReverse(&valsAndLabels);
+return valsAndLabels;
+}
+
+static void makeOtherCgiForm(char *pos)
+/* Make a form for navigating to other CGIs. */
+{
+struct slPair *valsAndLabels = makeOtherCgiValsAndLabels();
+// Default to the first CGI in the menu.
+char *defaultCgi = valsAndLabels->name;
+printf("<FORM STYLE=\"margin-bottom:0;\" METHOD=\"GET\" NAME=\"navForm\" ID=\"navForm\""
+       " ACTION=\"%s\">\n", defaultCgi);
+cartSaveSession(cart);
+if (pos)
+    cgiMakeHiddenVar("position", pos);
+printf("view in ");
+// Construct a menu of destination CGIs
+#define hgCtNavDest "hgct_navDest"
+char *selected = cartUsualString(cart, hgCtNavDest, defaultCgi);
+char *extraHtml = "id=\"navSelect\" "
+    "onChange=\"var newVal = $('#navSelect').val(); $('#navForm').attr('action', newVal);\"";
+puts(cgiMakeSingleSelectDropList(hgCtNavDest, valsAndLabels, selected, NULL, NULL, extraHtml));
+cgiMakeButton("submit", "go");
+puts("</FORM>");
+}
+
 static void manageCustomForm(char *warn)
 /* list custom tracks and display checkboxes so user can select for delete */
 {
 
 struct dbDb *dbList = getCustomTrackDatabases();
 struct dbDb *dbDb = NULL;
 /* add this database to the list, as it may have no custom
  * tracks, but we still want to see it in the menu */
 slAddTail(&dbList, hDbDb(database));
 slReverse(&dbList);
 /* remove duplicate entry for this database, if any */
 for (dbDb = dbList->next; dbDb != NULL; dbDb = dbDb->next)
     if (sameString(dbDb->name, database))
         slRemoveEl(&dbList, dbDb);
 
@@ -714,88 +747,80 @@
 
 /* count up number of custom tracks for this genome */
 int numCts = slCount(ctList);
 
 cgiSimpleTableStart();
 cgiSimpleTableRowStart();
 if (numCts)
     {
     puts("<TD VALIGN=\"TOP\">");
     showCustomTrackList(ctList, numCts);
     }
 else
     puts("<TD VALIGN=\"TOP\"><B><EM>No custom tracks for this genome:<B></EM>&nbsp;&nbsp;");
 puts("</TD>");
 
-/* navigation  buttons */
-puts("<TD VALIGN=\"TOP\">");
-puts("<TABLE BORDER=0>");
+/* end mainForm; navigation menu has its own form. */
 
-/* button to add custom tracks */
-int buttonWidth = 18;
-puts("<TR><TD>");
-printf("<INPUT TYPE=SUBMIT NAME=\"%s\" VALUE=\"%s\" STYLE=\"width:%dem\">",
-                hgCtDoAdd, "add custom tracks", buttonWidth);
-puts("</TD></TR>");
 puts("</FORM>");
 
+puts("<TD VALIGN=\"TOP\">");
+puts("<TABLE BORDER=0>");
+
 /* determine if there's a navigation position for this screen */
 char *pos = NULL;
 if (ctList)
     {
     pos = ctInitialPosition(ctList);
     if (!pos)
         pos = ctFirstItemPos(ctList);
     }
 
-/* button for GB navigation */
-puts("<TR><TD>");
-printf("<FORM STYLE=\"margin-bottom:0;\" ACTION=\"%s\" METHOD=\"GET\" NAME=\"tracksForm\">\n",
-           hgTracksName());
-cartSaveSession(cart);
-printf("<INPUT TYPE=SUBMIT NAME=\"Submit\" VALUE=\"%s\" STYLE=\"width:%dem\">",
-        "go to genome browser", buttonWidth);
-if (pos)
-    cgiMakeHiddenVar("position", pos);
-puts("</FORM>");
-puts("</TD></TR>");
-
-/* button for TB navigation */
 puts("<TR><TD>");
-printf("<FORM STYLE=\"margin-bottom:0;\" ACTION=\"%s\" METHOD=\"GET\" NAME=\"tablesForm\">\n",
-           hgTablesName());
-cartSaveSession(cart);
-printf("<INPUT TYPE=SUBMIT NAME=\"Submit\" VALUE=\"%s\" STYLE=\"width:%dem\">",
-        "go to table browser", buttonWidth);
-puts("</FORM>");
+makeOtherCgiForm(pos);
 puts("</TD></TR>");
 
-/* button for VAI navigation */
+/* button to add custom tracks */
 puts("<TR><TD>");
-printf("<FORM STYLE=\"margin-bottom:0;\" ACTION=\"%s\" METHOD=\"GET\" NAME=\"vaiForm\">\n",
-           hgVaiName());
-cartSaveSession(cart);
-printf("<INPUT TYPE=SUBMIT NAME=\"Submit\" VALUE=\"%s\" STYLE=\"width:%dem\">",
-        "go to variant annotation integrator", buttonWidth);
-puts("</FORM>");
+printf("<INPUT TYPE=SUBMIT NAME=\"addTracksButton\" ID=\"addTracksButton\" VALUE=\"%s\" "
+       "STYLE=\"margin-top: 5px\" "
+       // This submits mainForm with a hidden input that tells hgCustom to show add tracks page:
+       "onClick='var $form = $(form[name=\"mainForm\"]); "
+                "$form.append(\"<input name=\\\"%s\\\" type=\\\"hidden\\\">\"); "
+                "$form.submit();' >\n",
+       "add custom tracks", hgCtDoAdd);
 puts("</TD></TR>");
 
 puts("</TABLE>");
 puts("</TD>");
 
 cgiTableRowEnd();
 cgiTableEnd();
+
+
+// This vertically aligns the 'add tracks' button with the other-CGI select
+puts("<SCRIPT>");
+puts("function fitUnder($el1, $el2) { "
+     "  var off1 = $el1.offset(); "
+     "  var off2 = $el2.offset(); "
+     "  off2.left = off1.left; "
+     "  $el2.offset(off2);"
+     "  $el2.width($el1.width()); "
+     "};");
+puts("$(document).ready(function () { fitUnder($('#navSelect'), $('#addTracksButton')); });");
+puts("</SCRIPT>");
+
 cartSetString(cart, "hgta_group", "user");
 }
 
 void helpCustom()
 /* display documentation */
 {
 webNewSection("Loading Custom Tracks");
 char *browserVersion;
 if (btIE == cgiClientBrowser(&browserVersion, NULL, NULL) && *browserVersion < '8')
     puts("<span>");
 else
     puts("<span style='position:relative; top:-1em;'>");
 webIncludeHelpFile("customTrackLoad", FALSE);
 
 puts("</span>");