[htdig] PATCH: enhanced build_select_lists attribute


Subject: [htdig] PATCH: enhanced build_select_lists attribute
From: Gilles Detillieux (grdetil@scrc.umanitoba.ca)
Date: Mon Jul 31 2000 - 10:23:38 PDT


OK, there have been a few requests for this, and it's been gnawing away
in the back of my mind for a while, so I took a bit of time to implement
this.

This patch extends the functionality of the build_select_lists attribute
to build not only single-choice select lists, but also select multiple
lists, radio button lists and checkbox lists. It's for version 3.1.5
of htsearch, and includes documentation additions to describe the
enhancements. Please read that for instructions and examples, rather
than asking the author. :-) You can point your web browser to the
htdoc directory in your source tree.

You can apply the patch by saving this e-mail message as-is (provided
your mail program doesn't clobber it), and going to the main source
directory of htdig-3.1.5 to run this command:

        patch -p0 < /path/to/saved/patch/file

--- htsearch/Display.cc.oldbuild Sat May 13 21:40:09 2000
+++ htsearch/Display.cc Mon Jul 31 09:48:59 2000
@@ -498,27 +498,96 @@ Display::setVariables(int pageNumber, Li
         int ivalue = atoi(builds[b+4]);
         int ilabel = atoi(builds[b+5]);
         int nsel = 0;
+ int mult = 0, asinput = 0;
+ char *cp;
+ char sepc = '\001';
+ String currval;
+ String pre, post;
+ QuotedStringList nameopt(builds[b], ",", 1);
         QuotedStringList namelist(config[builds[b+2]], " \t\r\n");
         if (ntuple > 0 && ivalue > 0 && ivalue <= ntuple
- && ilabel > 0 && ilabel <= ntuple && namelist.Count() % ntuple == 0)
+ && ilabel > 0 && ilabel <= ntuple && namelist.Count() % ntuple == 0
+ && nameopt.Count() > 0)
         {
+ if (strcmp(builds[b+1], "restrict") == 0
+ || strcmp(builds[b+1], "exclude") == 0)
+ sepc = '|';
+ if (nameopt.Count() == 1)
+ ; // default is single select
+ else if (mystrcasecmp(nameopt[1], "multiple") == 0)
+ mult = 1;
+ else if (mystrcasecmp(nameopt[1], "radio") == 0)
+ asinput = 1;
+ else if (mystrcasecmp(nameopt[1], "checkbox") == 0)
+ {
+ mult = 1;
+ asinput = 1;
+ }
+ if (nameopt.Count() > 2)
+ pre = nameopt[2];
+ else
+ pre = "";
+ if (nameopt.Count() > 3)
+ post = nameopt[3];
+ else
+ post = "";
+
             str = new String();
- *str << "<select name=\"" << builds[b+1] << "\">\n";
+ if (!asinput)
+ {
+ *str << "<select ";
+ if (mult)
+ *str << "multiple ";
+ *str << "name=\"" << builds[b+1] << "\">\n";
+ }
             for (i = 0; i < namelist.Count(); i += ntuple)
             {
- *str << "<option value=\"" << namelist[i+ivalue-1] << '"';
- if (mystrcasecmp(namelist[i+ivalue-1],config[builds[b+6]]) == 0)
+ if (*builds[b+6])
+ currval = config[builds[b+6]];
+ else if (input->exists(builds[b+1]))
+ currval = input->get(builds[b+1]);
+ else
+ currval = 0;
+ if (!asinput)
+ *str << pre << "<option value=\"" << namelist[i+ivalue-1] << '"';
+ else if (mult)
+ *str << pre << "<input type=\"checkbox\" name=\"" << builds[b+1]
+ << "\" value=\"" << namelist[i+ivalue-1] << '"';
+ else
+ *str << pre << "<input type=\"radio\" name=\"" << builds[b+1]
+ << "\" value=\"" << namelist[i+ivalue-1] << '"';
+ if (!mult && mystrcasecmp(namelist[i+ivalue-1], currval) == 0
+ || mult &&
+ (cp = mystrcasestr(currval, namelist[i+ivalue-1])) != NULL
+ && (cp == currval.get() || cp[-1] == sepc)
+ && (*(cp += strlen(namelist[i+ivalue-1])) == '\0'
+ || *cp == sepc))
                 {
- *str << " selected";
+ if (!asinput)
+ *str << " selected";
+ else
+ *str << " checked";
                     ++nsel;
                 }
- *str << '>' << namelist[i+ilabel-1] << '\n';
+ *str << '>' << namelist[i+ilabel-1] << post << '\n';
             }
             if (!nsel && builds[b+7][0] && input->exists(builds[b+1]))
- *str << "<option value=\"" << input->get(builds[b+1])
- << "\" selected>" << builds[b+7] << '\n';
- *str << "</select>\n";
- vars.Add(builds[b], str);
+ {
+ if (!asinput)
+ *str << pre << "<option value=\"" << input->get(builds[b+1])
+ << "\" selected>" << builds[b+7] << post << '\n';
+ else if (mult)
+ *str << pre << "<input type=\"checkbox\" name=\"" << builds[b+1]
+ << "\" value=\"" << input->get(builds[b+1])
+ << "\" checked>" << builds[b+7] << post << '\n';
+ else
+ *str << pre << "<input type=\"radio\" name=\"" << builds[b+1]
+ << "\" value=\"" << input->get(builds[b+1])
+ << "\" checked>" << builds[b+7] << post << '\n';
+ }
+ if (!asinput)
+ *str << "</select>\n";
+ vars.Add(nameopt[0], str);
         }
     }
         
--- htdoc/attrs.html.oldbuild Thu Feb 24 20:29:10 2000
+++ htdoc/attrs.html Mon Jul 31 09:56:56 2000
@@ -564,7 +564,8 @@
                         the elements have the following meaning:
                         <ol>
                            <li>the name of the template variable to be
- defined as a list
+ defined as a list, optionally followed by a
+ comma and the type of list
                            <li>the input parameter name that the select
                            list will set
                            <li>the name of the user-defined attribute
@@ -599,8 +600,8 @@
                                 <td nowrap>
                 MATCH_LIST matchesperpage matches_per_page_list \<br>
                                 1 1 1 matches_per_page "Previous Amount" \<br>
- RESTRICT_LIST restrict restrict_names 2 1 2 restrict "" \<br>
- FORMAT_LIST format template_map 3 2 1 template_name ""
+ RESTRICT_LIST,multiple restrict restrict_names 2 1 2 restrict "" \<br>
+ FORMAT_LIST,radio format template_map 3 2 1 template_name ""
                                 </td>
                           </tr>
                         </table>
@@ -7440,7 +7441,7 @@
           <a href="author.html">Andrew Scherpbier &lt;andrew@contigo.com&gt;</a>
         </address>
 <!-- hhmts start -->
-Last modified: $Date: 2000/02/24 16:42:52 $
+Last modified: $Date: 2000/07/31 09:56:49 $
 <!-- hhmts end -->
   </body>
 </html>
--- htdoc/hts_selectors.html.oldbuild Thu Feb 24 20:29:10 2000
+++ htdoc/hts_selectors.html Mon Jul 31 10:44:34 2000
@@ -133,7 +133,9 @@
         </p>
         <ol>
           <li>
- the name of the template variable to be defined as a list
+ the name of the template variable to be defined as a list,
+ optionally followed by a comma and the type of list, and
+ optional formatting codes
           </li>
           <li>
                 the input parameter name that the select list will set
@@ -167,6 +169,28 @@
           </li>
         </ol>
         <p>
+ The first element in an entry is actually a comma separated
+ list. The first item within this list is the name of the
+ template variable to be created. The next item, if specified,
+ is the type of select list or input list to be created in this
+ template variable. Choices are <strong>select</strong>,
+ <strong>multiple</strong>, <strong>radio</strong>,
+ and <strong>checkbox</strong>, with the default being
+ <strong>select</strong>. The word <strong>multiple</strong>
+ refers to a &lt;select multiple&gt; type of select list,
+ where more than one option can be selected. The choices
+ <strong>radio</strong> and <strong>checkbox</strong> will build
+ lists of &lt;input&gt; tags of these types, rather than a select
+ list with &lt;option&gt; tags. The optional third and fourth
+ items in this comma separated list are text or formatting tags
+ that will be prepended and appended, respectively, to each item
+ in the built list, before the &lt;option&gt; or &lt;input&gt;
+ tag and after the label for that tag. This first element is
+ parsed as a quoted string list within a quoted string list,
+ so you can embed quotes and commas within elements of this
+ inner list if you use correct quoting. See examples below.
+ </p>
+ <p>
           The name list that you define will most commonly consist
           of pairs of values, and therefore you'd use a tuple size of
           2. The method_names and sort_names attributes are samples of
@@ -184,7 +208,7 @@
         <p>
           Any of the strings in an octuple may be quoted, and should be if
           you want to include spaces or define an empty string. If the
- the default label, the eight element in an entry, is an empty
+ default label, the eight element in an entry, is an empty
           string, the select list will not have a <i>selected</i> item
           if the current input parameter value doesn't match any value
           in the name list. If a default label is given, an additional
@@ -192,13 +216,22 @@
           current input parameter value doesn't match.
         </p>
         <p>
+ If the seventh element, the configuration attribute name, is
+ an empty string, the default value will be taken from from
+ the input parameter, the second element, instead. This is
+ especially useful for input parameters that don't get mapped
+ to a configuration attribute, or for checkboxes or multiple
+ selects, where the separation between individual choices may
+ get lost when the input parameter is mapped to an attribute.
+ </p>
+ <p>
           Here is an example of its usage, which illustrates different
           tuple sizes and orders:
         </p>
         <pre>
-build_select_lists: MATCH_LIST matchesperpage matches_per_page_list \
+build_select_lists: MATCH_LIST,radio matchesperpage matches_per_page_list \
                                 1 1 1 matches_per_page "Previous Amount" \
- RESTRICT_LIST restrict restrict_names 2 1 2 restrict "" \
+ RESTRICT_LIST,multiple restrict restrict_names 2 1 2 restrict "" \
                 FORMAT_LIST format template_map 3 2 1 template_name ""
 
 matches_per_page_list: 1 5 10 20 100 500
@@ -214,6 +247,27 @@ restrict_names: "http://www.myschool.edu
           an additional example of how to specify the tuple size and indices of
           values and labels in a tuple.
         </p>
+ <p>
+ Here is an example which illustrates additional formatting tags,
+ and the quoting that may be required:
+ </p>
+ <pre>
+build_select_lists: "RESTRICT_LIST,checkbox,'&lt;font face=\\"Arial,Helvetica\\" size=\\"+2\\"&gt;',&lt;/font&gt;&lt;br&gt;" restrict restrict_names 2 1 2 restrict ""
+ </pre>
+ <p>
+ In this example, the font tag will be inserted before each
+ checkbox input tag, and the closing font tag and line break will
+ be appended after each label that follows the input tag. Because
+ the font tag has an embeded comma, which is also the separator
+ for the list in the first element, the whole tag (i.e. the whole
+ third item in the comma separated list) is quoted, and it's
+ quoted with single quotes so as not to conflict with the double
+ quotes enclosing the whole element. Finally, to embed a double
+ quote in the font tag, it must be escaped with two backslashes -
+ the first of these is absorbed by the variable expansion phase
+ that all attribute values go through, and the second is used
+ to embed the double quote within a double quoted string.
+ </p>
         <h3>
           <a name="template_patterns"></a>
           Combining the format select list with template_patterns
@@ -266,7 +320,7 @@ template_patterns: .pdf ${common_dir}/${
           <a href="author.html">Andrew Scherpbier &lt;andrew@contigo.com&gt;</a>
         </address>
 
-Last modified: $Date: 2000/02/15 22:08:36 $
+Last modified: $Date: 2000/07/31 10:44:25 $
 
   </body>
 </html>

-- 
Gilles R. Detillieux              E-mail: <grdetil@scrc.umanitoba.ca>
Spinal Cord Research Centre       WWW:    http://www.scrc.umanitoba.ca/~grdetil
Dept. Physiology, U. of Manitoba  Phone:  (204)789-3766
Winnipeg, MB  R3E 3J7  (Canada)   Fax:    (204)789-3930

------------------------------------ To unsubscribe from the htdig mailing list, send a message to htdig-unsubscribe@htdig.org You will receive a message to confirm this.



This archive was generated by hypermail 2b28 : Mon Jul 31 2000 - 00:22:57 PDT