src/hg/lib/hui.c 1.241

1.241 2009/10/20 23:23:44 tdreszer
Changes to support the matrix 3-way CBs. Requires hui.js to be uptodate as well.
Index: src/hg/lib/hui.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/hui.c,v
retrieving revision 1.240
retrieving revision 1.241
diff -b -B -U 4 -r1.240 -r1.241
--- src/hg/lib/hui.c	24 Sep 2009 23:15:44 -0000	1.240
+++ src/hg/lib/hui.c	20 Oct 2009 23:23:44 -0000	1.241
@@ -30,13 +30,18 @@
 #define ADD_BUTTON_LABEL        "add"
 #define CLEAR_BUTTON_LABEL      "clear"
 #define JBUFSIZE 2048
 
-#define PM_BUTTON "<A NAME=\"%s\"></A><A HREF=\"#%s\"><IMG height=18 width=18 onclick=\"return (setCheckBoxesThatContain('%s',%s,true,'%s','','%s') == false);\" id=\"btn_%s\" src=\"../images/%s\" alt=\"%s\"></A>\n"
-#define DEF_BUTTON "<A NAME=\"%s\"></A><A HREF=\"#%s\"><IMG onclick=\"setCheckBoxesThatContain('%s',true,false,'%s','','%s'); return (setCheckBoxesThatContain('%s',false,false,'%s','_defOff','%s') == false);\" id=\"btn_%s\" src=\"../images/%s\" alt=\"%s\"></A>\n"
-#define DEFAULT_BUTTON(nameOrId,anc,beg,contains) printf(DEF_BUTTON,(anc),(anc),(nameOrId),        (beg),(contains),(nameOrId),(beg),(contains),(anc),"defaults_sm.png","default")
-#define    PLUS_BUTTON(nameOrId,anc,beg,contains) printf(PM_BUTTON, (anc),(anc),(nameOrId),"true", (beg),(contains),(anc),"add_sm.gif",   "+")
-#define   MINUS_BUTTON(nameOrId,anc,beg,contains) printf(PM_BUTTON, (anc),(anc),(nameOrId),"false",(beg),(contains),(anc),"remove_sm.gif","-")
+//#define PM_BUTTON "<A NAME=\"%s\"></A><A HREF=\"#%s\"><IMG height=18 width=18 onclick=\"return (setCheckBoxesThatContain('%s',%s,true,'%s','','%s') == false);\" id=\"btn_%s\" src=\"../images/%s\" alt=\"%s\"></A>\n"
+//#define DEF_BUTTON "<A NAME=\"%s\"></A><A HREF=\"#%s\"><IMG onclick=\"setCheckBoxesThatContain('%s',true,false,'%s','','%s'); return (setCheckBoxesThatContain('%s',false,false,'%s','_defOff','%s') == false);\" id=\"btn_%s\" src=\"../images/%s\" alt=\"%s\"></A>\n"
+//#define DEFAULT_BUTTON(nameOrId,anc,beg,contains) printf(DEF_BUTTON,(anc),(anc),(nameOrId),        (beg),(contains),(nameOrId),(beg),(contains),(anc),"defaults_sm.png","default")
+//#define    PLUS_BUTTON(nameOrId,anc,beg,contains) printf(PM_BUTTON, (anc),(anc),(nameOrId),"true", (beg),(contains),(anc),"add_sm.gif",   "+")
+//#define   MINUS_BUTTON(nameOrId,anc,beg,contains) printf(PM_BUTTON, (anc),(anc),(nameOrId),"false",(beg),(contains),(anc),"remove_sm.gif","-")
+#define PM_BUTTON  "<IMG height=18 width=18 onclick=\"setCheckBoxesThatContain('%s',%s,true,'%s','','%s');\" id=\"btn_%s\" src=\"../images/%s\" alt=\"%s\">\n"
+#define DEF_BUTTON "<IMG onclick=\"setCheckBoxesThatContain('%s',true,false,'%s','','%s'); setCheckBoxesThatContain('%s',false,false,'%s','_defOff','%s');\" id=\"btn_%s\" src=\"../images/%s\" alt=\"%s\">\n"
+#define DEFAULT_BUTTON(nameOrId,anc,beg,contains) printf(DEF_BUTTON,(nameOrId),        (beg),(contains),(nameOrId),(beg),(contains),(anc),"defaults_sm.png","default")
+#define    PLUS_BUTTON(nameOrId,anc,beg,contains) printf(PM_BUTTON, (nameOrId),"true", (beg),(contains),(anc),"add_sm.gif",   "+")
+#define   MINUS_BUTTON(nameOrId,anc,beg,contains) printf(PM_BUTTON, (nameOrId),"false",(beg),(contains),(anc),"remove_sm.gif","-")
 
 #define ENCODE_DCC_DOWNLOADS "encodeDCC"
 
 
@@ -3165,9 +3170,9 @@
                 printf(" class='trDraggable' title='Drag to Reorder'");
 
             printf(" id=\"tr_%s\" nowrap%s>\n<TD>",id,(selectedOnly?" style='display:none'":""));
             dyStringClear(dyHtml);
-            dyStringPrintf(dyHtml, "onclick='matSubtrackCbClick(this);' onmouseover=\"this.style.cursor='default';\" class=\"subtrackCB");
+            dyStringPrintf(dyHtml, "onclick='matSubCbClick(this);' onmouseover=\"this.style.cursor='default';\" class=\"subCB");
             for(di=0;di<dimMax;di++)
                 {
                 if(dimensions[di] && -1 != (ix = stringArrayIx(dimensions[di]->tag, membership->subgroups, membership->count)))
                     dyStringPrintf(dyHtml, " %s",membership->membership[ix]);
@@ -4685,8 +4690,9 @@
 {
 int ix;
 struct trackDb *subtrack;
 char objName[SMALLBUF];
+char classes[SMALLBUF];
 char javascript[JBUFSIZE];
 #define CFG_LINK  "<B><A NAME=\"a_cfg_%s\"></A><A id='a_cfg_%s' HREF=\"#a_cfg_%s\" onclick=\"return (showConfigControls('%s') == false);\" title=\"%s Configuration\">%s</A><INPUT TYPE=HIDDEN NAME='%s.%s.showCfg' value='%s'></B>\n"
 #define MAKE_CFG_LINK(name,title,tbl,open) printf(CFG_LINK, (name),(name),(name),(name),(title),(title),(tbl),(name),((open)?"on":"off"))
 
@@ -4752,9 +4758,10 @@
 
         safef(javascript, sizeof(javascript), "onchange=\"matSelectViewForSubTracks(this,'%s');\"", membersOfView->names[ix]);
 
         printf("<TD>");
-        hTvDropDownClassWithJavascript(objName, tv, parentTdb->canPack,"viewDd normalText",javascript);
+        safef(classes, sizeof(classes), "viewDD normalText %s", membersOfView->names[ix]);
+        hTvDropDownClassWithJavascript(objName, tv, parentTdb->canPack,classes,javascript);
         puts(" &nbsp; &nbsp; &nbsp;</TD>");
         // Until the cfg boxes are inserted here, this divorces the relationship
         //if(membersOfView->count > 6 && ix == ((membersOfView->count+1)/2)-1)  // An attempt at 2 rows of cfg's No good!
         //    puts("</tr><tr><td>&nbsp;</td></tr><tr>");
@@ -4841,18 +4848,18 @@
 freeMem(words[0]);
 return cloneString(label);
 }
 
-#define PM_BUTTON_UC "<A NAME='%s'></A><A HREF='#%s'><IMG height=18 width=18 onclick=\"return (matSetMatrixCheckBoxes(%s%s%s%s%s%s) == false);\" id='btn_%s' src='../images/%s'></A>"
+#define PM_BUTTON_UC "<IMG height=18 width=18 onclick=\"return (matSetMatrixCheckBoxes(%s%s%s%s%s%s) == false);\" id='btn_%s' src='../images/%s'>"
 static void buttonsForAll()
 {
-printf(PM_BUTTON_UC, "plus_all", "plus_all", "true",  "", "", "", "", "",  "plus_all",    "add_sm.gif");
-printf(PM_BUTTON_UC,"minus_all","minus_all","false",  "", "", "", "", "", "minus_all", "remove_sm.gif");
+printf(PM_BUTTON_UC,"true", "", "", "", "", "",  "plus_all",    "add_sm.gif");
+printf(PM_BUTTON_UC,"false","", "", "", "", "", "minus_all", "remove_sm.gif");
 }
 static void buttonsForOne(char *name,char *class)
 {
-printf(PM_BUTTON_UC, name, name,  "true", ",'", class, "'", "", "", name,    "add_sm.gif");
-printf(PM_BUTTON_UC, name, name, "false", ",'", class, "'", "", "", name, "remove_sm.gif");
+printf(PM_BUTTON_UC, "true",  ",'", class, "'", "", "", name,    "add_sm.gif");
+printf(PM_BUTTON_UC, "false", ",'", class, "'", "", "", name, "remove_sm.gif");
 }
 
 #define MATRIX_RIGHT_BUTTONS_AFTER 8
 #define MATRIX_BOTTOM_BUTTONS_AFTER 20
@@ -4980,9 +4986,8 @@
 {
 //int ix;
 char objName[SMALLBUF];
 char javascript[JBUFSIZE];
-boolean alreadySet = TRUE;
 struct trackDb *subtrack;
 
 if(!dimensionsExist(parentTdb))
     return FALSE;
@@ -5070,8 +5075,10 @@
         printf("<TR ALIGN=CENTER BGCOLOR=\"#FFF9D2\">");
 
         matrixYheadings(parentTdb, dimensionX,dimensionY,ixY,tdbsY[ixY],TRUE);
 
+#define MAT_CB_SETUP "<INPUT TYPE=CHECKBOX NAME='%s' VALUE=on %s>"
+#define MAT_CB(name,js) printf(MAT_CB_SETUP,(name),(js));
         for (ixX = 0; ixX < sizeOfX; ixX++)
             {
             if(tdbsX[ixX] != NULL || dimensionX == NULL)
                 {
@@ -5082,31 +5089,25 @@
                 if(dimensionX && ixX == dimensionX->count)
                     break;
                 if(cells[ixX][ixY] > 0)
                     {
+                    struct dyString *dyJS = dyStringCreate("onclick='matCbClick(this);'");
                     if(dimensionX && dimensionY)
                         {
                         safef(objName, sizeof(objName), "mat_%s_%s_cb", dimensionX->names[ixX],dimensionY->names[ixY]);
-                        safef(javascript, sizeof(javascript), "onclick='matSetSubtrackCheckBoxes(this.checked,\"%s\",\"%s\");'",
-                            dimensionX->names[ixX],dimensionY->names[ixY]);
                         }
                     else
                         {
                         safef(objName, sizeof(objName), "mat_%s_cb", (dimensionX ? dimensionX->names[ixX] : dimensionY->names[ixY]));
-                        safef(javascript, sizeof(javascript), "onclick='matSetSubtrackCheckBoxes(this.checked,\"%s\");'",
-                            (dimensionX ? dimensionX->names[ixX] : dimensionY->names[ixY]));
                         }
-                    alreadySet = cartUsualBoolean(cart, objName, FALSE);
                     puts("<TD>");
-                    struct dyString *dyJS = newDyString(100);
-                    dyStringAppend(dyJS, javascript);
-                    dyStringPrintf(dyJS, " class=\"matrixCB");
+                    dyStringPrintf(dyJS, " class=\"matCB");
                     if(dimensionX)
                         dyStringPrintf(dyJS, " %s",dimensionX->names[ixX]);
                     if(dimensionY)
                         dyStringPrintf(dyJS, " %s",dimensionY->names[ixY]);
                     dyStringAppendC(dyJS,'"');
-                    cgiMakeCheckBoxJS(objName,alreadySet,dyStringCannibalize(&dyJS));
+                    MAT_CB(objName,dyStringCannibalize(&dyJS)); // X&Y are set by javascript page load
                     puts("</TD>");
                     }
                 else
                     puts("<TD>&nbsp;</TD>");
@@ -5126,22 +5127,23 @@
     printf("<TH class='greenRoof' STYLE='font-size: 2' colspan=50>&nbsp;</TH>");
     printf("<TR BGCOLOR='%s'><TH valign=top align=left colspan=2 rowspan=20><B><EM>%s</EM></B>:",
             COLOR_BG_ALTDEFAULT,dimensionZ->title);
     int cntZ=0;
+    char *dimZdefaults = trackDbSettingOrDefault(parentTdb,"dimensionZchecked","");
+    boolean alreadySet=FALSE;
     for(ixZ=0;ixZ<sizeOfZ;ixZ++)
         {
         if(tdbsZ[ixZ] != NULL && cellsZ[ixZ]>0)
             {
             if(cntZ > 0 && (cntZ % cntX) == 0)
                 printf("</TR><TR BGCOLOR='%s'>",COLOR_BG_ALTDEFAULT);
             printf("<TH align=left nowrap>");
-            safef(objName, sizeof(objName), "mat_%s_dimZ_cb",dimensionZ->names[ixZ]);
-            safef(javascript, sizeof(javascript), "onclick='matSetSubtrackCheckBoxes(this.checked,\"%s\");'",dimensionZ->names[ixZ]);
-            alreadySet = cartUsualBoolean(cart, objName, FALSE);
-            struct dyString *dyJS = newDyString(100);
-            dyStringAppend(dyJS, javascript);
-            dyStringPrintf(dyJS, " class=\"matrixCB dimZ %s\"",dimensionZ->names[ixZ]);
-            cgiMakeCheckBoxJS(objName,alreadySet,dyStringCannibalize(&dyJS));
+            safef(objName, sizeof(objName), "%s.mat_%s_dimZ_cb",parentTdb->tableName,dimensionZ->names[ixZ]);
+            alreadySet=(NULL!=findWordByDelimiter(dimensionZ->names[ixZ],',',dimZdefaults));
+            alreadySet=cartUsualBoolean(cart,objName,alreadySet);
+            struct dyString *dyJS = dyStringCreate("onclick='matCbClick(this);'");
+            dyStringPrintf(dyJS, " class=\"matCB dimZ %s\"",dimensionZ->names[ixZ]);
+            cgiMakeCheckBoxJS(objName,alreadySet,dyStringCannibalize(&dyJS));// dimZ is set by cart variable, while X and Y are set by subtrack sets
             printf("%s",labelWithVocabLink(parentTdb,tdbsZ[ixZ],dimensionZ->tag,dimensionZ->values[ixZ]));
             puts("</TH>");
             cntZ++;
             }
@@ -5167,11 +5169,11 @@
 
 if(dimensionsExist(parentTdb))
     return FALSE;
 
-#define PM_BUTTON_GLOBAL "<A NAME='%s'></A><A HREF='#%s'><IMG height=18 width=18 onclick=\"return (subtrackCBsSetAll(%s) == false);\" id='btn_%s' src='../images/%s'></A>"
-#define    BUTTON_PLUS_ALL_GLOBAL()  printf(PM_BUTTON_GLOBAL, "plus_all", "plus_all", "true", "plus_all",   "add_sm.gif")
-#define    BUTTON_MINUS_ALL_GLOBAL() printf(PM_BUTTON_GLOBAL,"minus_all","minus_all","false","minus_all","remove_sm.gif")
+#define PM_BUTTON_GLOBAL "<IMG height=18 width=18 onclick=\"subtrackCBsSetAll(%s);\" id='btn_%s' src='../images/%s'>"
+#define    BUTTON_PLUS_ALL_GLOBAL()  printf(PM_BUTTON_GLOBAL,"true",  "plus_all",   "add_sm.gif")
+#define    BUTTON_MINUS_ALL_GLOBAL() printf(PM_BUTTON_GLOBAL,"false","minus_all","remove_sm.gif")
 printf("<P><B>Select subtracks:</B><P>All:&nbsp;");
 BUTTON_PLUS_ALL_GLOBAL();
 BUTTON_MINUS_ALL_GLOBAL();
 puts("</P>");