81f240f86b16d599cafde436527c5a6a6b87e456
kent
Thu Jan 28 20:59:17 2021 -0800
getting rid of a lot of hard coded cdwBrowseFiles where prefixVar should be used. Making it not need a submit button for paging to work.
diff --git src/hg/lib/tablesTables.c src/hg/lib/tablesTables.c
index 8fffdb5..ad19bd7 100644
--- src/hg/lib/tablesTables.c
+++ src/hg/lib/tablesTables.c
@@ -57,47 +57,49 @@
{
if ((i >= offset) && (i < offset+limit))
fieldedTableAdd(table, row, fieldCount, ++id);
++i;
}
}
facetFieldsFromSqlTableFinish(ffList, facetValCmpSelectCountDesc);
sqlFreeResult(&sr);
*pFfArray = ffArray;
*pResultCount = i;
return table;
}
static void showTableFilterInstructionsEtc(struct fieldedTable *table,
char *pluralInstructions, struct fieldedTableSegment *largerContext, void (*addFunc)(int),
- char *visibleFacetList)
+ char *visibleFacetList, char *varPrefix)
/* Print instructional text, and basic summary info on who passes filter, and a submit
* button just in case user needs it */
{
/* Print info on matching */
int matchCount = slCount(table->rowList);
if (largerContext != NULL) // Need to page?
matchCount = largerContext->tableSize;
printf("");
printf("  ");
printf("");
-jsOnEventById("click", "clearButton",
+char jsText[1024];
+safef(jsText, sizeof(jsText),
"$(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');\n"
- "$('[name=cdwBrowseFiles_page]').val('1');\n"
- "$('#submit').click();\n");
+ "$('[name=%s_page]').val('1');\n"
+ "$('#submit').click();\n", varPrefix);
+jsOnEventById("click", "clearButton", jsText);
printf(" ");
printf("%d %s found. ", matchCount, pluralInstructions);
if (addFunc)
addFunc(matchCount);
if (!visibleFacetList)
{
printf(" \n");
printf("You can further filter search results field by field below. ");
printf("Wildcard * and ? characters are allowed in text fields. ");
printf(">min or <max are allowed in numerical fields. \n");
}
@@ -125,40 +127,40 @@
jsInline(dy->string);
dyStringFree(&dy);
}
#ifdef NOT_CURRENTLY_USED
static void printWatermark(char *id, char *watermark)
/* Print light text filter prompt as watermark. */
{
jsInlineF(
"$(function() {\n"
" $('#%s').watermark(\"%s\");\n"
"});\n", id, watermark);
}
#endif
-static void resetPageNumberOnChange(char *id)
+static void resetPageNumberOnChange(char *id, char *varPrefix)
/* On change, reset page number to 1. */
{
jsInlineF(
"$(function() {\n"
" $('form').delegate('#%s','change keyup paste',function(e){\n"
-" $('[name=cdwBrowseFiles_page]').val('1');\n"
+" $('[name=%s_page]').val('1');\n"
" });\n"
"});\n"
-, id);
+, id, varPrefix);
}
static void showTableFilterControlRow(struct fieldedTable *table, struct slName *visibleFields,
struct cart *cart, char *varPrefix, int maxLenField, struct hash *suggestHash)
/* Assuming we are in table already drow control row.
* The suggestHash is keyed by field name. If something is there we'll assume
* it's value is slName list of suggestion values */
{
/* Include javascript and style we need */
printf("\n");
printf("\n");
printf("
");
struct slName *el;
@@ -174,31 +176,31 @@
int size = fieldedTableMaxColChars(table, fieldIx);
if (size > maxLenField)
size = maxLenField;
/* Print input control getting previous value from cart. Set an id=
* so auto-suggest can find this control. */
char *oldVal = cartUsualString(cart, varName, "");
printf("\n");
else
printf(" value=\"%s\">\n", oldVal);
/* Write out javascript to reset page number to 1 if filter changes */
- resetPageNumberOnChange(varName);
+ resetPageNumberOnChange(varName, varPrefix);
/* Set up the auto-suggest list for this filter */
if (suggestHash != NULL)
{
struct slName *suggestList = hashFindVal(suggestHash, field);
if (suggestList != NULL)
{
printSuggestScript(varName, suggestList);
}
}
printf("\n");
}
printf("
");
@@ -340,96 +342,97 @@
{
if (pageSize < largerContext->tableSize)
{
int curPage = largerContext->tableOffset/pageSize;
int totalPages = (largerContext->tableSize + pageSize - 1)/pageSize;
char id[256];
if ((curPage + 1) > 1)
{
// first page
safef(id, sizeof id, "%s_first", varPrefix);
printf("⏮", id);
jsOnEventByIdF("click", id,
"$('[name=%s_page]').val('1');\n"
- "$('#submit').click();\n"
+ "event.target.closest('form').submit();\n"
, varPrefix);
printf(" ");
// prev page
safef(id, sizeof id, "%s_prev", varPrefix);
printf("⏪", id);
jsOnEventByIdF("click", id,
"$('[name=%s_page]').val('%d');\n"
- "$('#submit').click();\n"
+ "event.target.closest('form').submit();\n"
, varPrefix, (curPage+1)-1);
printf(" ");
}
printf("Displaying page ");
char pageVar[64];
safef(pageVar, sizeof(pageVar), "%s_page", varPrefix);
cgiMakeIntVar(pageVar, curPage+1, 3);
printf(" of %d", totalPages);
if ((curPage + 1) < totalPages)
{
// next page
printf(" ");
safef(id, sizeof id, "%s_next", varPrefix);
printf("⏩", id);
jsOnEventByIdF("click", id,
"$('[name=%s_page]').val('%d');\n"
- "$('#submit').click();\n"
+ "event.target.closest('form').submit();\n"
, varPrefix, (curPage+1)+1);
// last page
printf(" ");
safef(id, sizeof id, "%s_last", varPrefix);
printf("⏭", id);
jsOnEventByIdF("click", id,
"$('[name=%s_page]').val('%d');\n"
- "$('#submit').click();\n"
+ "event.target.closest('form').submit();\n"
, varPrefix, totalPages);
}
}
}
}
void webFilteredFieldedTable(struct cart *cart, struct fieldedTable *table,
char *visibleFieldList, char *returnUrl, char *varPrefix,
int maxLenField, struct hash *tagOutputWrappers, void *wrapperContext,
boolean withFilters, char *pluralInstructions,
int pageSize, int facetUsualSize,
struct fieldedTableSegment *largerContext, struct hash *suggestHash,
struct facetField **ffArray, char *visibleFacetList,
void (*addFunc)(int) )
/* Show a fielded table that can be sorted by clicking on column labels and optionally
* that includes a row of filter controls above the labels .
* The maxLenField is maximum character length of field before truncation with ...
* Pass in 0 for no max. */
{
if (strchr(returnUrl, '?') == NULL)
errAbort("Expecting returnUrl to include ? in showFieldedTable\nIt's %s", returnUrl);
if (pluralInstructions != NULL)
- showTableFilterInstructionsEtc(table, pluralInstructions, largerContext, addFunc, visibleFacetList);
+ showTableFilterInstructionsEtc(table, pluralInstructions, largerContext, addFunc,
+ visibleFacetList, varPrefix);
if (visibleFacetList)
{
// Show top bar with quick-deselects for selected facet values
// as well a clear restriction button that cleans out cdwFile_filter cart var.
struct dyString *facetBar = dyStringNew(1024);
char *where = cartUsualString(cart, "cdwFile_filter", "");
boolean gotSelected = FALSE;
struct slName *visList = slNameListFromComma(visibleFacetList);
@@ -450,84 +453,86 @@
// Sort values alphabetically
// Make a copy to not disturb the original order
struct facetVal *valListCopy = facetsClone(field->valList);
slSort(&valListCopy, facetValCmp);
for (val = valListCopy; val; val=val->next)
{
boolean specificallySelected = (val->selected && !field->allSelected);
if (specificallySelected)
{
char *op = "remove";
htmlDyStringPrintf(facetBar, "
\n");
}
else if (val->selectCount > 0)
{
++valuesNotShown;
}
}
// show "See More" link when facet has lots of values
if (valuesNotShown > 0)
{
char *op = "showAllValues";
- htmlPrintf("
\n");
// Clicking a checkbox is actually a click on the following link
jsInlineF(
"$(function () {\n"
" $('.cdwFSCheckBox').click(function() {\n"
" this.nextSibling.nextSibling.click();\n"
" });\n"
"});\n");
}