+use vars qw($theme_no_table $ui_radio_selector_donejs $module_name
+ $ui_multi_select_donejs);
+
=head1 ui-lib.pl
Common functions for generating HTML for Webmin user interface elements.
Some example code :
- require '../ui-lib.pl';
+ use WebminCore;
+ init_config();
ui_print_header(undef, 'My Module', '');
print ui_form_start('save.cgi');
return $rv;
}
-=head2 ui_checked_columns_row(&columns, &tdtags, checkname, checkvalue, [checked?], [disabled])
+=head2 ui_checked_columns_row(&columns, &tdtags, checkname, checkvalue, [checked?], [disabled], [tags])
Returns HTML for a row in a multi-column table, in which the first column
-contains a checkbox.
-XXX
+contains a checkbox. The parameters are :
+
+=item columns - Reference to an array containing the HTML to show in the columns for this row.
+
+=item tdtags - An optional array reference containing HTML attributes for the row's <td> tags.
+
+=item checkname - Name for the checkbox input. Should be the same for all rows.
+
+=item checkvalue - Value for this checkbox input.
+
+=item checked - Set to 1 if it should be checked by default.
+
+=item disabled - Set to 1 if the checkbox should be disabled and thus un-clickable.
+
+=item tags - Extra HTML tags to include in the radio button.
=cut
sub ui_checked_columns_row
{
return &theme_ui_checked_columns_row(@_) if (defined(&theme_ui_checked_columns_row));
-my ($cols, $tdtags, $checkname, $checkvalue, $checked, $disabled) = @_;
+my ($cols, $tdtags, $checkname, $checkvalue, $checked, $disabled, $tags) = @_;
my $rv;
$rv .= "<tr $cb class='ui_checked_columns'>\n";
$rv .= "<td class='ui_checked_checkbox' ".$tdtags->[0].">".
- &ui_checkbox($checkname, $checkvalue, undef, $checked, undef, $disabled).
+ &ui_checkbox($checkname, $checkvalue, undef, $checked, $tags, $disabled).
"</td>\n";
my $i;
for($i=0; $i<@$cols; $i++) {
return $rv;
}
-=head2 ui_radio_columns_row(&columns, &tdtags, checkname, checkvalue, [checked], [disabled])
+=head2 ui_radio_columns_row(&columns, &tdtags, checkname, checkvalue, [checked], [disabled], [tags])
Returns HTML for a row in a multi-column table, in which the first
-column is a radio button
+column is a radio button. The parameters are :
+
+=item columns - Reference to an array containing the HTML to show in the columns for this row.
+
+=item tdtags - An optional array reference containing HTML attributes for the row's <td> tags.
+
+=item checkname - Name for the radio button input. Should be the same for all rows.
+
+=item checkvalue - Value for this radio button option.
+
+=item checked - Set to 1 if it should be checked by default.
+
+=item disabled - Set to 1 if the radio button should be disabled and thus un-clickable.
+
+=item tags - Extra HTML tags to include in the radio button.
=cut
sub ui_radio_columns_row
{
return &theme_ui_radio_columns_row(@_) if (defined(&theme_ui_radio_columns_row));
-my ($cols, $tdtags, $checkname, $checkvalue, $checked, $dis) = @_;
+my ($cols, $tdtags, $checkname, $checkvalue, $checked, $dis, $tags) = @_;
my $rv;
$rv .= "<tr $cb class='ui_radio_columns'>\n";
$rv .= "<td class='ui_radio_radio' ".$tdtags->[0].">".
=head2 ui_columns_end
-Returns HTML to end a table started by ui_columns_start
+Returns HTML to end a table started by ui_columns_start.
=cut
sub ui_columns_end
=head2 ui_columns_table(&headings, width-percent, &data, &types, no-sort, title, empty-msg)
-Returns HTML for a complete table.
-headings - An array ref of heading HTML
-width-percent - Preferred total width
-data - A 2x2 array ref of table contents. Each can either be a simple string,
-or a hash ref like :
-{ 'type' => 'group', 'desc' => 'Some section title' }
-{ 'type' => 'string', 'value' => 'Foo', 'colums' => 3,
-'nowrap' => 1 }
-{ 'type' => 'checkbox', 'name' => 'd', 'value' => 'foo',
-'label' => 'Yes', 'checked' => 1, 'disabled' => 1 }
-{ 'type' => 'radio', 'name' => 'd', 'value' => 'foo', ... }
-types - An array ref of data types, such as 'string', 'number', 'bytes'
-or 'date'
-no-sort - Set to 1 to disable sorting by theme
-title - Text to appear above the table
-empty-msg - Message to display if no data
+Returns HTML for a complete table, typically generated internally by
+ui_columns_start, ui_columns_row and ui_columns_end. The parameters are :
+
+=item headings - An array ref of heading HTML.
+
+=item width-percent - Preferred total width
+
+=item data - A 2x2 array ref of table contents. Each can either be a simple string, or a hash ref like :
+
+ { 'type' => 'group', 'desc' => 'Some section title' }
+ { 'type' => 'string', 'value' => 'Foo', 'colums' => 3,
+ 'nowrap' => 1 }
+ { 'type' => 'checkbox', 'name' => 'd', 'value' => 'foo',
+ 'label' => 'Yes', 'checked' => 1, 'disabled' => 1 }
+ { 'type' => 'radio', 'name' => 'd', 'value' => 'foo', ... }
+
+=item types - An array ref of data types, such as 'string', 'number', 'bytes' or 'date'
+
+=item no-sort - Set to 1 to disable sorting by theme.
+
+=item title - Text to appear above the table.
+
+=item empty-msg - Message to display if no data.
=cut
sub ui_columns_table
# Checkbox in non-first column
push(@cols, &ui_checkbox($c->{'name'}, $c->{'value'},
$c->{'label'}, $c->{'checked'},
- undef, $c->{'disabled'}));
+ $c->{'tags'},
+ $c->{'disabled'}));
}
elsif ($c->{'type'} eq 'radio') {
# Radio button in non-first column
push(@cols, &ui_oneradio($c->{'name'}, $c->{'value'},
$c->{'label'}, $c->{'checked'},
- undef, $c->{'disabled'}));
+ $c->{'tags'},
+ $c->{'disabled'}));
}
elsif ($c->{'type'} eq 'group') {
# Header row that spans whole table
elsif ($c0->{'type'} eq 'checkbox') {
$rv .= &ui_checked_columns_row(\@cols, \@rtds, $c0->{'name'},
$c0->{'value'}, $c0->{'checked'},
- $c0->{'disabled'});
+ $c0->{'disabled'},
+ $c0->{'tags'});
}
elsif ($c0->{'type'} eq 'radio') {
$rv .= &ui_radio_columns_row(\@cols, \@rtds, $c0->{'name'},
$c0->{'value'}, $c0->{'checked'},
- $c0->{'disabled'});
+ $c0->{'disabled'},
+ $c0->{'tags'});
}
}
return $rv;
}
-=head2 ui_form_columns_table(cgi, &buttons, select-all, &otherlinks, &hiddens, &headings, width-percent, &data, &types, no-sort, title, empty-msg)
+=head2 ui_form_columns_table(cgi, &buttons, select-all, &otherlinks, &hiddens, &headings, width-percent, &data, &types, no-sort, title, empty-msg, form-no)
+
+Similar to ui_columns_table, but wrapped in a form. Parameters are :
+
+=item cgi - URL to submit the form to.
+
+=item buttons - An array ref of buttons at the end of the form, similar to that taken by ui_form_end.
-Similar to ui_columns_table, but wrapped in a form. Args are :
-cgi - URL to submit the form to
-buttons - An array ref of buttons at the end of the form, similar to
-that taken by ui_form_end
-select-all - If set to 1, include select all / invert links
-otherslinks - An array ref of other links to put at the top of the table,
-each of which is a 3-element hash ref of url, text and
-alignment (left or right)
-hiddens - An array ref of hidden fields, each of which is a 2-element array
-ref containing the name and value
-All other parameters are the same as ui_columns_table
+=item select-all - If set to 1, include select all / invert links.
+
+=item otherslinks - An array ref of other links to put at the top of the table, each of which is a 3-element hash ref of url, text and alignment (left or right).
+
+=item hiddens - An array ref of hidden fields, each of which is a 2-element array ref containing the name and value.
+
+All other parameters are the same as ui_columns_table.
=cut
sub ui_form_columns_table
return &theme_ui_form_columns_table(@_)
if (defined(&theme_ui_form_columns_table));
my ($cgi, $buttons, $selectall, $others, $hiddens,
- $heads, $width, $data, $types, $nosort, $title, $emptymsg) = @_;
+ $heads, $width, $data, $types, $nosort, $title, $emptymsg, $formno) = @_;
my $rv;
# Build links
}
}
if ($cbname) {
- unshift(@leftlinks, &select_all_link($cbname),
- &select_invert_link($cbname));
+ unshift(@leftlinks, &select_all_link($cbname, $formno),
+ &select_invert_link($cbname, $formno));
}
}
}
=head2 ui_form_start(script, method, [target], [tags])
-Returns HTML for a form that submits to some script
+Returns HTML for the start of a a form that submits to some script. The
+parameters are :
+
+=item script - CGI script to submit to, like save.cgi.
+
+=item method - HTTP method, which must be one of 'get', 'post' or 'form-data'. If form-data is used, the target CGI must call ReadParseMime to parse parameters.
+
+=item target - Optional target window or frame for the form.
+
+=item tags - Additional HTML attributes for the form tag.
=cut
sub ui_form_start
=head2 ui_form_end([&buttons], [width])
-Returns HTML for the end of a form, optionally with a row of submit buttons
+Returns HTML for the end of a form, optionally with a row of submit buttons.
+These are specified by the buttons parameter, which is an array reference
+of array refs, with the following elements :
+
+=item HTML value for the submit input for the button, or undef for none.
+
+=item Text to appear on the button.
+
+=item HTML or other inputs to appear after the button.
+
+=item Set to 1 if the button should be disabled.
+
+=item Additional HTML attributes to appear inside the button's input tag.
=cut
sub ui_form_end
=head2 ui_textbox(name, value, size, [disabled?], [maxlength], [tags])
-Returns HTML for a text input
+Returns HTML for a text input box. The parameters are :
+
+=item name - Name for this input.
+
+=item value - Initial contents for the text box.
+
+=item size - Desired width in characters.
+
+=item disabled - Set to 1 if this text box should be disabled by default.
+
+=item maxlength - Maximum length of the string the user is allowed to input.
+
+=item tags - Additional HTML attributes for the <input> tag.
=cut
sub ui_textbox
=head2 ui_filebox(name, value, size, [disabled?], [maxlength], [tags], [dir-only])
-Returns HTML for a text box for choosing a file
+Returns HTML for a text box for choosing a file. Parameters are the same
+as ui_textbox, except for the extra dir-only option which limits the chooser
+to directories.
=cut
sub ui_filebox
=head2 ui_bytesbox(name, bytes, [size], [disabled?])
Returns HTML for entering a number of bytes, but with friendly kB/MB/GB
-options. May truncate values to 2 decimal points!
+options. May truncate values to 2 decimal points! The parameters are :
+
+=item name - Name for this input.
+
+=item bytes - Initial number of bytes to show.
+
+=item size - Desired width of the text box part.
+
+=item disabled - Set to 1 if this text box should be disabled by default.
+
+=item tags - Additional HTML attributes for the <input> tag.
+
+=item defaultunits - Units mode selected by default
=cut
sub ui_bytesbox
{
-my ($name, $bytes, $size, $dis) = @_;
+my ($name, $bytes, $size, $dis, $tags, $defaultunits) = @_;
my $units = 1;
-if ($bytes >= 10*1024*1024*1024*1024) {
+if ($bytes eq '' && $defaultunits) {
+ $units = $defaultunits;
+ }
+elsif ($bytes >= 10*1024*1024*1024*1024) {
$units = 1024*1024*1024*1024;
}
elsif ($bytes >= 10*1024*1024*1024) {
$bytes =~ s/\.00$//;
}
$size = &ui_max_text_width($size || 8);
-return &ui_textbox($name, $bytes, $size, $dis)." ".
+return &ui_textbox($name, $bytes, $size, $dis, undef, $tags)." ".
&ui_select($name."_units", $units,
[ [ 1, "bytes" ],
[ 1024, "kB" ],
=head2 ui_upload(name, size, [disabled?], [tags])
-Returns HTML for a file upload input
+Returns HTML for a file upload input, for use in a form with the form-data
+method. The parameters are :
+
+=item name - Name for this input.
+
+=item size - Desired width in characters.
+
+=item disabled - Set to 1 if this text box should be disabled by default.
+
+=item tags - Additional HTML attributes for the <input> tag.
=cut
sub ui_upload
($tags ? " ".$tags : "").">";
}
-=head2 ui_password(name, value, size, [disabled?], [maxlength])
+=head2 ui_password(name, value, size, [disabled?], [maxlength], [tags])
-Returns HTML for a password text input
+Returns HTML for a password text input. Parameters are the same as ui_textbox,
+and behaviour is identical except that the user's input is not visible.
=cut
sub ui_password
{
return &theme_ui_password(@_) if (defined(&theme_ui_password));
-my ($name, $value, $size, $dis, $max) = @_;
+my ($name, $value, $size, $dis, $max, $tags) = @_;
$size = &ui_max_text_width($size);
return "<input class='ui_password' ".
"type=password name=\""."e_escape($name)."\" ".
"value=\""."e_escape($value)."\" ".
"size=$size ".($dis ? "disabled=true" : "").
($max ? " maxlength=$max" : "").
+ " ".$tags.
">";
}
=head2 ui_hidden(name, value)
-Returns HTML for a hidden field
+Returns HTML for a hidden field with the given name and value.
=cut
sub ui_hidden
=head2 ui_select(name, value|&values, &options, [size], [multiple], [add-if-missing], [disabled?], [javascript])
-Returns HTML for a drop-down menu or multiple selection list
+Returns HTML for a drop-down menu or multiple selection list. The parameters
+are :
+
+=item name - Name for this input.
+
+=item value - Either a single initial value, or an array reference of values if this is a multi-select list.
+
+=item options - An array reference of possible options. Each element can either be a scalar, or a two-element array ref containing a submitted value and displayed text.
+
+=item size - Desired vertical size in rows, which defaults to 1. For multi-select lists, this must be set to something larger.
+
+=item multiple - Set to 1 for a multi-select list, 0 for single.
+
+=item add-if-missing - If set to 1, any value that is not in the list of options will be automatically added (and selected).
+
+=item disabled - Set to 1 to disable this input.
+
+=item javascript - Additional HTML attributes for the <select> input.
=cut
sub ui_select
implemented using two <select> lists and Javascript buttons to move elements
between them. The resulting input value is \n separated.
+Parameters are :
+
+=item name - HTML name for this input.
+
+=item values - An array reference of two-element array refs, containing the submitted values and descriptions of items that are selected by default.
+
+=item options - An array reference of two-element array refs, containing the submitted values and descriptions of items that the user can select from.
+
+=item size - Vertical size in rows.
+
+=item add-if-missing - If set to 1, any entries that are in values but not in options will be added automatically.
+
+=item disabled - Set to 1 to disable this input by default.
+
+=item options-title - Optional text to appear above the list of options.
+
+=item values-title - Optional text to appear above the list of selected values.
+
+=item width - Optional width of the two lists in pixels.
+
=cut
sub ui_multi_select
{
}
$rv .= "<tr class='ui_multi_select_row'>";
$rv .= "<td>".&ui_select($name."_opts", [ ], $leftover,
- $size, 0, 0, $dis, $wstyle)."</td>\n";
-$rv .= "<td>".&ui_button("->", undef, $dis,
+ $size, 1, 0, $dis, $wstyle)."</td>\n";
+$rv .= "<td>".&ui_button("->", $name."_add", $dis,
"onClick='multi_select_move(\"$name\", form, 1)'")."<br>".
- &ui_button("<-", undef, $dis,
+ &ui_button("<-", $name."_remove", $dis,
"onClick='multi_select_move(\"$name\", form, 0)'")."</td>\n";
$rv .= "<td>".&ui_select($name."_vals", [ ], $values,
- $size, 0, 0, $dis, $wstyle)."</td>\n";
+ $size, 1, 0, $dis, $wstyle)."</td>\n";
$rv .= "</tr></table>\n";
$rv .= &ui_hidden($name, join("\n", map { $_->[0] } @$values));
return $rv;
=head2 ui_multi_select_javascript
-Returns <script> section for left/right select boxes
+Returns <script> section for left/right select boxes. For internal use only.
=cut
sub ui_multi_select_javascript
var vals_idx = vals.selectedIndex;
if (dir == 1 && opts_idx >= 0) {
// Moving from options to selected list
- var o = opts.options[opts_idx];
- vals.options[vals.options.length] = new Option(o.text, o.value);
- opts.remove(opts_idx);
+ for(var i=0; i<opts.options.length; i++) {
+ var o = opts.options[i];
+ if (o.selected) {
+ vals.options[vals.options.length] =
+ new Option(o.text, o.value);
+ opts.remove(i);
+ i--;
+ }
+ }
}
else if (dir == 0 && vals_idx >= 0) {
// Moving the other way
- var o = vals.options[vals_idx];
- opts.options[opts.options.length] = new Option(o.text, o.value);
- vals.remove(vals_idx);
+ for(var i=0; i<vals.options.length; i++) {
+ var o = vals.options[i];
+ if (o.selected) {
+ opts.options[opts.options.length] =
+ new Option(o.text, o.value);
+ vals.remove(i);
+ i--;
+ }
+ }
}
// Fill in hidden field
var hid = f.elements[name];
=head2 ui_radio(name, value, &options, [disabled?])
-Returns HTML for a series of radio buttons
+Returns HTML for a series of radio buttons, of which one can be selected. The
+parameters are :
+
+=item name - HTML name for the radio buttons.
+
+=item value - Value of the button that is selected by default.
+
+=item options - Array ref of radio button options, each of which is an array ref containing the submitted value and description for each button.
+
+=item disabled - Set to 1 to disable all radio buttons by default.
=cut
sub ui_radio
=head2 ui_yesno_radio(name, value, [yes], [no], [disabled?])
-Like ui_yesno, but always displays just two inputs (yes and no)
+Like ui_radio, but always displays just two inputs (yes and no). The parameters
+are :
+
+=item name - HTML name of the inputs.
+
+=item value - Option selected by default, typically 1 or 0.
+
+=item yes - The value for the yes option, defaulting to 1.
+
+=item no - The value for the no option, defaulting to 0.
+
+=item disabled - Set to 1 to disable all radio buttons by default.
=cut
sub ui_yesno_radio
=head2 ui_checkbox(name, value, label, selected?, [tags], [disabled?])
-Returns HTML for a single checkbox
+Returns HTML for a single checkbox. Parameters are :
+
+=item name - HTML name of the checkbox.
+
+=item value - Value that will be submitted if it is checked.
+
+=item label - Text to appear next to the checkbox.
+
+=item selected - Set to 1 for it to be checked by default.
+
+=item tags - Additional HTML attributes for the <input> tag.
+
+=item disabled - Set to 1 to disable the checkbox by default.
=cut
sub ui_checkbox
=head2 ui_oneradio(name, value, label, selected?, [tags], [disabled?])
-Returns HTML for a single radio button
+Returns HTML for a single radio button. The parameters are :
+
+=item name - HTML name of the radio button.
+
+=item value - Value that will be submitted if it is selected.
+
+=item label - Text to appear next to the button.
+
+=item selected - Set to 1 for it to be selected by default.
+
+=item tags - Additional HTML attributes for the <input> tag.
+
+=item disabled - Set to 1 to disable the radio button by default.
=cut
sub ui_oneradio
=head2 ui_textarea(name, value, rows, cols, [wrap], [disabled?], [tags])
-Returns HTML for a multi-line text input
+Returns HTML for a multi-line text input. The function parameters are :
+
+=item name - Name for this HTML <textarea>.
+
+=item value - Default value. Multiple lines must be separated by \n.
+
+=item rows - Number of rows, in lines.
+
+=item cols - Number of columns, in characters.
+
+=item wrap - Wrapping mode. Can be one of soft, hard or off.
+
+=item disabled - Set to 1 to disable this text area by default.
+
+=item tags - Additional HTML attributes for the <textarea> tag.
=cut
sub ui_textarea
=head2 ui_user_textbox(name, value, [form], [disabled?], [tags])
-Returns HTML for a Unix user input
+Returns HTML for an input for selecting a Unix user. Parameters are the
+same as ui_textbox.
=cut
sub ui_user_textbox
=head2 ui_group_textbox(name, value, [form], [disabled?], [tags])
-Returns HTML for a Unix group input
+Returns HTML for an input for selecting a Unix group. Parameters are the
+same as ui_textbox.
=cut
sub ui_group_textbox
=head2 ui_opt_textbox(name, value, size, option1, [option2], [disabled?], [&extra-fields], [max])
-Returns HTML for a text field that is optional
+Returns HTML for a text field that is optional, implemented by default as
+a field with radio buttons next to it. The parameters are :
+
+=item name - HTML name for the text box. The radio buttons will have the same name, but with _def appended.
+
+=item value - Initial value, or undef if you want the default radio button selected initially.
+
+=item size - Width of the text box in characters.
+
+=item option1 - Text for the radio button for selecting that no input is being given, such as 'Default'.
+
+=item option2 - Text for the radio button for selecting that you will provide input.
+
+=item disabled - Set to 1 to disable this input by default.
+
+=item extra-fields - An optional array ref of field names that should be disabled by Javascript when this field is disabled.
+
+=item max - Optional maximum allowed input length, in characters.
+
+=item tags - Additional HTML attributes for the text box
=cut
sub ui_opt_textbox
{
return &theme_ui_opt_textbox(@_) if (defined(&theme_ui_opt_textbox));
-my ($name, $value, $size, $opt1, $opt2, $dis, $extra, $max) = @_;
+my ($name, $value, $size, $opt1, $opt2, $dis, $extra, $max, $tags) = @_;
my $dis1 = &js_disable_inputs([ $name, @$extra ], [ ]);
my $dis2 = &js_disable_inputs([ ], [ $name, @$extra ]);
my $rv;
$rv .= "<input class='ui_opt_textbox' name=\""."e_escape($name)."\" ".
"size=$size value=\""."e_escape($value)."\" ".
($value eq "" || $dis ? "disabled=true" : "").
- ($max ? " maxlength=$max" : "").">\n";
+ ($max ? " maxlength=$max" : "").
+ " ".$tags.
+ ">\n";
return $rv;
}
=head2 ui_submit(label, [name], [disabled?], [tags])
-Returns HTML for a form submit button
+Returns HTML for a form submit button. Parameters are :
+
+=item label - Text to appear on the button.
+
+=item name - Optional HTML name for the button. Useful if the CGI it submits to needs to know which of several buttons was clicked.
+
+=item disabled - Set to 1 if this button should be disabled by default.
+
+=item tags - Additional HTML attributes for the <input> tag.
=cut
sub ui_submit
=head2 ui_reset(label, [disabled?])
-Returns HTML for a form reset button
+Returns HTML for a form reset button, which clears all fields when clicked.
+Parameters are :
+
+=item label - Text to appear on the button.
+
+=item disabled - Set to 1 if this button should be disabled by default.
=cut
sub ui_reset
=head2 ui_button(label, [name], [disabled?], [tags])
-Returns HTML for a form button
+Returns HTML for a form button, which doesn't do anything when clicked unless
+you add some Javascript to it. The parameters are :
+
+=item label - Text to appear on the button.
+
+=item name - HTML name for this input.
+
+=item disabled - Set to 1 if this button should be disabled by default.
+
+=item tags - Additional HTML attributes for the <input> tag, typically Javascript inside an onClick attribute.
=cut
sub ui_button
=head2 ui_date_input(day, month, year, day-name, month-name, year-name, [disabled?])
-Returns HTML for a date-selection field
+Returns HTML for a date-selection field, with day, month and year inputs.
+The parameters are :
+
+=item day - Initial day of the month.
+
+=item month - Initial month of the year, indexed from 1.
+
+=item year - Initial year, four-digit.
+
+=item day-name - Name of the day input field.
+
+=item month-name - Name of the month select field.
+
+=item year-name - Name of the year input field.
+
+=item disabled - Set to 1 to disable all fields by default.
=cut
sub ui_date_input
return $rv;
}
+=head2 ui_buttons_start
+
+Returns HTML for the start of a block of action buttoms with descriptions, as
+generated by ui_buttons_row. Some example code :
+
+ print ui_buttons_start();
+ print ui_buttons_row('start.cgi', 'Start server',
+ 'Click this button to start the server process');
+ print ui_buttons_row('stop.cgi', 'Stop server',
+ 'Click this button to stop the server process');
+ print ui_buttons_end();
+
+=cut
sub ui_buttons_start
{
return &theme_ui_buttons_start(@_) if (defined(&theme_ui_buttons_start));
return "<table width=100% class='ui_buttons_table'>\n";
}
+=head2 ui_buttons_end
+
+Returns HTML for the end of a block started by ui_buttons_start.
+
+=cut
sub ui_buttons_end
{
return &theme_ui_buttons_end(@_) if (defined(&theme_ui_buttons_end));
=head2 ui_buttons_row(script, button-label, description, [hiddens], [after-submit], [before-submit])
-MISSING DOCUMENTATION
+Returns HTML for a button with a description next to it, and perhaps other
+inputs. The parameters are :
+
+=item script - CGI script that this button submits to, like start.cgi.
+
+=item button-label - Text to appear on the button.
+
+=item description - Text to appear next to the button, describing in more detail what it does.
+
+=item hiddens - HTML for hidden fields to include in the form this function generates.
+
+=item after-submit - HTML for text or inputs to appear after the submit button.
+
+=item before-submit - HTML for text or inputs to appear before the submit button.
=cut
sub ui_buttons_row
=head2 ui_buttons_hr([title])
-MISSING DOCUMENTATION
+Returns HTML for a separator row, for use inside a ui_buttons_start block.
=cut
sub ui_buttons_hr
=head2 ui_post_header([subtext])
-Returns HTML to appear directly after a standard header() call
+Returns HTML to appear directly after a standard header() call. This is never
+called directly - instead, ui_print_header calls it. But it can be overridden
+by themes.
=cut
sub ui_post_header
=head2 ui_pre_footer
-Returns HTML to appear directly before a standard footer() call
+Returns HTML to appear directly before a standard footer() call. This is never
+called directly - instead, ui_print_footer calls it. But it can be overridden
+by themes.
=cut
sub ui_pre_footer
return $rv;
}
-=head2 ui_print_header(subtext, args...)
+=head2 ui_print_header(subtext, image, [help], [config], [nomodule], [nowebmin], [rightside], [head-stuff], [body-stuff], [below])
Print HTML for a header with the post-header line. The args are the same
-as those passed to header()
+as those passed to header(), defined in web-lib-funcs.pl, with the addition
+of the subtext parameter :
+
+=item subtext - Text to display below the title
+
+=item title - The text to show at the top of the page
+
+=item image - An image to show instead of the title text. This is typically left blank.
+
+=item help - If set, this is the name of a help page that will be linked to in the title.
+
+=item config - If set to 1, the title will contain a link to the module's config page.
+
+=item nomodule - If set to 1, there will be no link in the title section to the module's index.
+
+=item nowebmin - If set to 1, there will be no link in the title section to the Webmin index.
+
+=item rightside - HTML to be shown on the right-hand side of the title. Can contain multiple lines, separated by <br>. Typically this is used for links to stop, start or restart servers.
+
+=item head-stuff - HTML to be included in the <head> section of the page.
+
+=item body-stuff - HTML attributes to be include in the <body> tag.
+
+=item below - HTML to be displayed below the title. Typically this is used for application or server version information.
+
+
=cut
sub ui_print_header
=head2 ui_print_unbuffered_header(subtext, args...)
Like ui_print_header, but ensures that output for this page is not buffered
-or contained in a table.
+or contained in a table. This should be called by scripts that are producing
+output while performing some long-running process.
=cut
sub ui_print_unbuffered_header
=head2 ui_print_footer(args...)
Print HTML for a footer with the pre-footer line. Args are the same as those
-passed to footer()
+passed to footer().
=cut
sub ui_print_footer
=head2 ui_config_link(text, &subs)
Returns HTML for a module config link. The first non-null sub will be
-replaced with the appropriate URL.
+replaced with the appropriate URL for the module's config page.
=cut
sub ui_config_link
=head2 ui_subheading(text, ...)
-Returns HTML for a section heading
+Returns HTML for a section heading whose message is the given text strings.
=cut
sub ui_subheading
=head2 ui_links_row(&links)
Returns HTML for a row of links, like select all / invert selection / add..
+Each element of the links array ref should be an HTML fragment like :
+
+ <a href='user_form.cgi'>Create new user</a>
=cut
sub ui_links_row
=head2 ui_hidden_javascript
-Returns <script> and <style> sections for hiding functions and CSS
+Returns <script> and <style> sections for hiding functions and CSS. For
+internal use only.
=cut
sub ui_hidden_javascript
=head2 ui_hidden_start(title, name, status, thisurl)
Returns HTML for the start of a collapsible hidden section, such as for
-advanced options.
+advanced options. When clicked on, the section header will expand to display
+whatever is between this function and ui_hidden_end. The parameters are :
+
+=item title - Text for the start of this hidden section.
+
+=item name - A unique name for this section.
+
+=item status - 1 if it should be initially open, 0 if not.
+
+=item thisurl - URL of the current page. This is used by themes on devices that don't support Javascript to implement the opening and closing.
=cut
sub ui_hidden_start
=head2 ui_hidden_end(name)
-Returns HTML for the end of a hidden section
+Returns HTML for the end of a hidden section, started by ui_hidden_start.
=cut
sub ui_hidden_end
=head2 ui_hidden_table_row_start(title, name, status, thisurl)
Similar to ui_hidden_start, but for use within a table started with
-ui_table_start
+ui_table_start. I recommend against using this where possible, as it can
+be difficult for some themes to implement.
=cut
sub ui_hidden_table_row_start
=head2 ui_hidden_table_row_end(name)
-MISSING DOCUMENTATION
+Returns HTML to end a block started by ui_hidden_table_start.
=cut
sub ui_hidden_table_row_end
=head2 ui_hidden_table_start(heading, [tabletags], [cols], name, status, [&default-tds], [rightheading])
-A table with a heading and table inside, and which is collapsible
+Returns HTML for the start of a form block into which labelled inputs can
+be placed, which is collapsible by clicking on the header. Basically the same
+as ui_table_start, and must contain HTML generated by ui_table_row.
+
+The parameters are :
+
+=item heading - Text to show at the top of the form.
+
+=item tabletags - HTML attributes to put in the outer <table>, typically something like width=100%.
+
+=item cols - Desired number of columns for labels and fields. Defaults to 4, but can be 2 for forms with lots of wide inputs.
+
+=item name - A unique name for this table.
+
+=item status - Set to 1 if initially open, 0 if initially closed.
+
+=item default-tds - An optional array reference of HTML attributes for the <td> tags in each row of the table.
+
+=item right-heading - HTML to appear in the heading, aligned to the right.
=cut
sub ui_hidden_table_start
=head2 ui_hidden_table_end(name)
-Returns HTML for the end of table with hiding, as started by
-ui_hidden_table_start
+Returns HTML for the end of a form block with hiding, as started by
+ui_hidden_table_start.
=cut
sub ui_hidden_table_end
=head2 ui_tabs_start(&tabs, name, selected, show-border)
-Render a row of tabs from which one can be selected. Each tab is an array
-ref containing a name, title and link.
+Returns a row of tabs from which one can be selected, displaying HTML
+associated with that tab. The parameters are :
+
+=item tabs - An array reference of array refs, each of which contains the value and user-visible text for a tab.
+
+=item name - Name of the HTML field into which the selected tab will be placed.
+
+=item selected - Value for the tab selected by default.
+
+=item show-border - Set to 1 if there should be a border around the contents of the tabs.
+
+Example code :
+
+ @tabs = ( [ 'list', 'List services' ],
+ [ 'install', 'Install new service' ] );
+ print ui_tabs_start(\@tabs, 'mode', 'list');
+
+ print ui_tabs_start_tab('mode', 'list');
+ generate_service_list();
+ print ui_tabs_end_tab('mode', 'list');
+
+ print ui_tabs_start_tab('mode', 'install');
+ generate_install_form();
+ print ui_tabs_end_tab('mode', 'install);
+
+ print ui_tabs_end();
=cut
sub ui_tabs_start
}
# Build list of tab titles and names
-my $tabnames = "[".join(",", map { "\"".&html_escape($_->[0])."\"" } @$tabs)."]";
-my $tabtitles = "[".join(",", map { "\"".&html_escape($_->[1])."\"" } @$tabs)."]";
+my $tabnames = "[".join(",", map { "\""."e_escape($_->[0])."\"" } @$tabs)."]";
+my $tabtitles = "[".join(",", map { "\""."e_escape($_->[1])."\"" } @$tabs)."]";
$rv .= "<script>\n";
$rv .= "document.${name}_tabnames = $tabnames;\n";
$rv .= "document.${name}_tabtitles = $tabtitles;\n";
$rv .= "<tr>\n";
$rv .= "<td bgcolor=#ffffff width=1><img src=$imgdir/1x1.gif></td>\n";
foreach my $t (@$tabs) {
- if ($t ne $tabs[0]) {
+ if ($t ne $$tabs[0]) {
# Spacer
$rv .= "<td width=2 bgcolor=#ffffff class='ui_tab_spacer'>".
"<img src=$imgdir/1x1.gif></td>\n";
return $rv;
}
-=head2 ui_tabs_end(border)
+=head2 ui_tabs_end(show-border)
-MISSING DOCUMENTATION
+Returns HTML to end a block started by ui_tabs_start. The show-border parameter
+must match the parameter with the same name in the start function.
=cut
sub ui_tabs_end
=head2 ui_tabs_start_tab(name, tab)
-Must be called before outputting the HTML for the named tab
+Must be called before outputting the HTML for the named tab, and returns HTML
+for the required <div> block.
=cut
sub ui_tabs_start_tab
=head2 ui_tabs_start_tabletab(name, tab)
-Behaves like ui_tabs_start_tab, but for use within a ui_table_start block
+Behaves like ui_tabs_start_tab, but for use within a ui_table_start block.
+I recommend against using this where possible, as it is difficult for themes
+to implement.
=cut
sub ui_tabs_start_tabletab
return "</table>\n".$div."<table width=100%>\n";
}
+=head2 ui_tabs_end_tab
+
+Returns HTML for the end of a block started by ui_tabs_start_tab.
+
+=cut
sub ui_tabs_end_tab
{
return &theme_ui_tabs_end_tab(@_) if (defined(&theme_ui_tabs_end_tab));
return "</div>\n";
}
+=head2 ui_tabs_end_tabletab
+
+Returns HTML for the end of a block started by ui_tabs_start_tabletab.
+
+=cut
sub ui_tabs_end_tabletab
{
return &theme_ui_tabs_end_tabletab(@_)
=head2 ui_max_text_width(width, [text-area?])
-Returns a new width for a text field, based on theme settings
+Returns a new width for a text field, based on theme settings. For internal
+use only.
=cut
sub ui_max_text_width
=head2 ui_radio_selector(&opts, name, selected)
Returns HTML for a set of radio buttons, each of which shows a different
-block of HTML when selected. &opts is an array ref to arrays containing
-[ value, label, html ]
+block of HTML when selected. The parameters are :
+
+=item opts - An array ref to arrays containing [ value, label, html ]
+
+=item name - HTML name for the radio buttons
+
+=item selected - Value for the initially selected button.
=cut
sub ui_radio_selector
####################### grid layout functions
-=head2 ui_grid_table(&elements, columns, [width-percent], [tds], [tabletags], [title])
+=head2 ui_grid_table(&elements, columns, [width-percent], [&tds], [tabletags], [title])
Given a list of HTML elements, formats them into a table with the given
number of columns. However, themes are free to override this to use fewer
-columns where space is limited.
+columns where space is limited. Parameters are :
+
+=item elements - An array reference of table elements, each of which can be any HTML you like.
+
+=item columns - Desired number of columns in the grid.
+
+=item width-percent - Optional desired width as a percentage.
+
+=item tds - Array ref of HTML attributes for <td> tags in the tables.
+
+=item tabletags - HTML attributes for the <table> tag.
+
+=item title - Optional title to add to the top of the grid.
=cut
sub ui_grid_table
return $rv;
}
-=head2 ui_radio_table(name, selected, &rows)
+=head2 ui_radio_table(name, selected, &rows, [no-bold])
Returns HTML for a table of radio buttons, each of which has a label and
-some associated inputs to the right.
+some associated inputs to the right. The parameters are :
+
+=item name - Unique name for this table, which is also the radio buttons' name.
+
+=item selected - Value for the initially selected radio button.
+
+=item rows - Array ref of array refs, one per button. The elements of each are the value for this option, a label, and option additional HTML to appear next to it.
+
+=item no-bold - When set to 1, labels in the table will not be bolded
=cut
sub ui_radio_table
{
return &theme_ui_radio_table(@_) if (defined(&theme_ui_radio_table));
-my ($name, $sel, $rows) = @_;
+my ($name, $sel, $rows, $nobold) = @_;
return "" if (!@$rows);
my $rv = "<table class='ui_radio_table'>\n";
foreach my $r (@$rows) {
$rv .= "<tr>\n";
- $rv .= "<td valign=top".(defined($r->[2]) ? "" : " colspan=2").
- "><b>".
- &ui_oneradio($name, $r->[0], $r->[1], $r->[0] eq $sel).
- "</b></td>\n";
+ $rv .= "<td valign=top".(defined($r->[2]) ? "" : " colspan=2").">".
+ ($nobold ? "" : "<b>").
+ &ui_oneradio($name, $r->[0], $r->[1], $r->[0] eq $sel, $r->[3]).
+ ($nobold ? "" : "</b>").
+ "</td>\n";
if (defined($r->[2])) {
$rv .= "<td valign=top>".$r->[2]."</td>\n";
}
=head2 ui_up_down_arrows(uplink, downlink, up-show, down-show)
-Returns HTML for moving some objects in a table up or down
+Returns HTML for moving some objects in a table up or down. The parameters are :
+
+=item uplink - URL for the up-arrow link.
+
+=item downlink - URL for the down-arrow link.
+
+=item up-show - Set to 1 if the up-arrow should be shown, 0 if not.
+
+=item down-show - Set to 1 if the down-arrow should be shown, 0 if not.
=cut
sub ui_up_down_arrows
=head2 ui_hr
-Returns a horizontal row tag
+Returns a horizontal row tag, typically just an <hr>
=cut
sub ui_hr
=head2 ui_nav_link(direction, url, disabled)
-Returns an arrow icon linking to provided url
+Returns an arrow icon linking to the provided url.
=cut
sub ui_nav_link
}
}
-=head2 ui_confirmation_form(cgi, message, &hiddens, [&buttons], [&otherinputs], [extra-warning])
+=head2 ui_confirmation_form(cgi, message, &hiddens, [&buttons], [otherinputs], [extra-warning])
Returns HTML for a form asking for confirmation before performing some
-action, such as deleting a user.
+action, such as deleting a user. The parameters are :
+
+=item cgi - Script to which the confirmation form submits, like delete.cgi.
+
+=item message - Warning message for the user to see.
+
+=item hiddens - Array ref of two-element array refs, containing hidden form field names and values.
+
+=item buttons - Array ref of two-element array refs, containing form button names and labels.
+
+=item otherinputs - HTML for extra inputs to include in ther form.
+
+=item extra-warning - An additional separate warning message to show.
=cut
sub ui_confirmation_form
####################### javascript functions
-=head2 js_disable_inputs
+=head2 js_disable_inputs(&disable-inputs, &enable-inputs, [tag])
-js_disable_input(&disable-inputs, &enable-inputs, [tag])
-Returns Javascript to disable some form elements and enable others
+Returns Javascript to disable some form elements and enable others. Mainly
+for internal use.
=cut
sub js_disable_inputs
Returns HTML for moving left and right in some large list, such as an inbox
or database table. If only 5 parameters are given, no far links are included.
-If any link is undef, that array will be greyed out.
+If any link is undef, that array will be greyed out. The parameters are :
+
+=item message - Text or display between arrows.
+
+=item inputs - Additional HTML inputs to show after message.
+
+=item cgi - Optional CGI for form wrapping arrows to submit to.
+
+=item left-link - Link for left-facing arrow.
+
+=item right-link - Link for right-facing arrow.
+
+=item far-left-link - Link for far left-facing arrow, optional.
+
+=item far-right-link - Link for far right-facing arrow, optional.
+
+=item below - HTML to display below the arrows.
=cut
sub ui_page_flipper
# Far left link, if needed
if (@_ > 5) {
if ($farleft) {
- $rv .= "<a href='$farleft'><img src=/images/first.gif ".
+ $rv .= "<a href='$farleft'>".
+ "<img src=$gconfig{'webprefix'}/images/first.gif ".
"border=0 align=middle></a>\n";
}
else {
- $rv .= "<img src=/images/first-grey.gif ".
+ $rv .= "<img src=$gconfig{'webprefix'}/images/first-grey.gif ".
"border=0 align=middle></a>\n";
}
}
# Left link
if ($left) {
- $rv .= "<a href='$left'><img src=/images/left.gif ".
+ $rv .= "<a href='$left'>".
+ "<img src=$gconfig{'webprefix'}/images/left.gif ".
"border=0 align=middle></a>\n";
}
else {
- $rv .= "<img src=/images/left-grey.gif ".
+ $rv .= "<img src=$gconfig{'webprefix'}/images/left-grey.gif ".
"border=0 align=middle></a>\n";
}
# Right link
if ($right) {
- $rv .= "<a href='$right'><img src=/images/right.gif ".
+ $rv .= "<a href='$right'>".
+ "<img src=$gconfig{'webprefix'}/images/right.gif ".
"border=0 align=middle></a>\n";
}
else {
- $rv .= "<img src=/images/right-grey.gif ".
+ $rv .= "<img src=$gconfig{'webprefix'}/images/right-grey.gif ".
"border=0 align=middle></a>\n";
}
# Far right link, if needed
if (@_ > 5) {
if ($farright) {
- $rv .= "<a href='$farright'><img src=/images/last.gif ".
+ $rv .= "<a href='$farright'>".
+ "<img src=$gconfig{'webprefix'}/images/last.gif ".
"border=0 align=middle></a>\n";
}
else {
- $rv .= "<img src=/images/last-grey.gif ".
+ $rv .= "<img src=$gconfig{'webprefix'}/images/last-grey.gif ".
"border=0 align=middle></a>\n";
}
}
=head2 js_checkbox_disable(name, &checked-disable, &checked-enable, [tag])
-MISSING DOCUMENTATION
+For internal use only.
=cut
sub js_checkbox_disable
=head2 js_redirect(url, [window-object])
-Returns HTML to trigger a redirect to some URL
+Returns HTML to trigger a redirect to some URL.
=cut
sub js_redirect
if (defined(&theme_js_redirect)) {
return &theme_js_redirect(@_);
}
+$window ||= "window";
+if ($url =~ /^\//) {
+ # If the URL is like /foo , add webprefix
+ $url = $gconfig{'webprefix'}.$url;
+ }
return "<script>${window}.location = '"."e_escape($url)."';</script>\n";
}