.selector_shown {display:inline}
.selector_hidden {display:none}
EOF
}
####################### grid layout functions
=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. 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 tags in the tables.
=item tabletags - HTML attributes for the tag.
=item title - Optional title to add to the top of the grid.
=cut
sub ui_grid_table
{
return &theme_ui_grid_table(@_) if (defined(&theme_ui_grid_table));
my ($elements, $cols, $width, $tds, $tabletags, $title) = @_;
return "" if (!@$elements);
my $rv = "\n";
my $i;
for($i=0; $i<@$elements; $i++) {
$rv .= "" if ($i%$cols == 0);
$rv .= "[$i%$cols]." valign=top class='ui_grid_cell'>".
$elements->[$i]." | \n";
$rv .= " " if ($i%$cols == $cols-1);
}
if ($i%$cols) {
while($i%$cols) {
$rv .= "[$i%$cols]." class='ui_grid_cell'>".
"
| \n";
$i++;
}
$rv .= "\n";
}
$rv .= " \n";
if (defined($title)) {
$rv = "\n".
($title ? "$title | \n" : "").
"$rv | \n".
" ";
}
return $rv;
}
=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. 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, $nobold) = @_;
return "" if (!@$rows);
my $rv = "\n";
foreach my $r (@$rows) {
$rv .= "\n";
$rv .= "[2]) ? "" : " colspan=2").">".
($nobold ? "" : "").
&ui_oneradio($name, $r->[0], $r->[1], $r->[0] eq $sel, $r->[3]).
($nobold ? "" : "").
" | \n";
if (defined($r->[2])) {
$rv .= "".$r->[2]." | \n";
}
$rv .= " \n";
}
$rv .= " \n";
return $rv;
}
=head2 ui_up_down_arrows(uplink, downlink, up-show, down-show)
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.
=item up-icon - Optional path to icon for up link
=item down-icon - Optional path to icon for down link
=cut
sub ui_up_down_arrows
{
return &theme_ui_up_down_arrows(@_) if (defined(&theme_ui_up_down_arrows));
my ($uplink, $downlink, $upshow, $downshow, $upicon, $downicon) = @_;
my $mover;
my $imgdir = "$gconfig{'webprefix'}/images";
$upicon ||= "$imgdir/moveup.gif";
$downicon ||= "$imgdir/movedown.gif";
if ($downshow) {
$mover .= "".
" ";
}
else {
$mover .= " ";
}
if ($upshow) {
$mover .= "".
" ";
}
else {
$mover .= " ";
}
return $mover;
}
=head2 ui_hr
Returns a horizontal row tag, typically just an
=item tags - Additional HTML attributes for the tag.
=cut
sub ui_hr
{
return &theme_ui_hr(@_) if (defined(&theme_ui_hr));
my ($tags) = @_;
return " \n";
}
=head2 ui_nav_link(direction, url, disabled)
Returns an arrow icon linking to the provided url.
=cut
sub ui_nav_link
{
return &theme_ui_nav_link(@_) if (defined(&theme_ui_nav_link));
my ($direction, $url, $disabled) = @_;
my $alt = $direction eq "left" ? '<-' : '->';
if ($disabled) {
return " \n";
}
else {
return " \n";
}
}
=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. 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
{
my ($cgi, $message, $hiddens, $buttons, $others, $warning) = @_;
my $rv;
$rv .= "\n";
$rv .= &ui_form_start($cgi, "post");
foreach my $h (@$hiddens) {
$rv .= &ui_hidden(@$h);
}
$rv .= "$message\n";
if ($warning) {
$rv .= "$warning \n";
}
if ($others) {
$rv .= $others." \n";
}
$rv .= &ui_form_end($buttons);
$rv .= " \n";
return $rv;
}
=head2 ui_alert_box(msg, type)
Returns HTML for an alert box, with background color determined by $type.
$msg contains any text or HTML to be contained within the alert box, and
can include forms.
Type of alert:
=item success - green
=item info - blue
=item warning - yellow
=item danger - red
=cut
sub ui_alert_box
{
my ($msg, $type) = @_;
my ($rv, $color);
if (defined (&theme_ui_alert_box)) {
return &theme_ui_alert_box(@_);
}
if ($type eq "success") { $color = "DFF0D8"; }
elsif ($type eq "info") { $color = "D9EDF7"; }
elsif ($type eq "warn") { $color = "FCF8E3"; }
elsif ($type eq "danger") { $color = "F2DEDE"; }
$rv .= "\n";
$rv .= "$msg\n";
$rv .= " |
\n";
return $rv;
}
####################### javascript functions
=head2 js_disable_inputs(&disable-inputs, &enable-inputs, [tag])
Returns Javascript to disable some form elements and enable others. Mainly
for internal use.
=cut
sub js_disable_inputs
{
my $rv;
my $f;
foreach $f (@{$_[0]}) {
$rv .= "e = form.elements[\"$f\"]; e.disabled = true; ";
$rv .= "for(i=0; i= 0) {
# When enabling both a _def field and its associated text field,
# disable the text if the _def is set to 1
my $tf = $1;
$rv .= "e = form.elements[\"$f\"]; for(i=0; i";
$rv .= &ui_form_start($cgi) if ($cgi);
# Far left link, if needed
if (@_ > 5) {
if ($farleft) {
$rv .= "".
" \n";
}
else {
$rv .= " \n";
}
}
# Left link
if ($left) {
$rv .= "".
" \n";
}
else {
$rv .= " \n";
}
# Message and inputs
$rv .= $msg;
$rv .= " ".$inputs if ($inputs);
# Right link
if ($right) {
$rv .= "".
" \n";
}
else {
$rv .= " \n";
}
# Far right link, if needed
if (@_ > 5) {
if ($farright) {
$rv .= "".
" \n";
}
else {
$rv .= " \n";
}
}
$rv .= " ".$below if ($below);
$rv .= &ui_form_end() if ($cgi);
$rv .= "\n";
return $rv;
}
=head2 js_checkbox_disable(name, &checked-disable, &checked-enable, [tag])
For internal use only.
=cut
sub js_checkbox_disable
{
my $rv;
my $f;
foreach $f (@{$_[1]}) {
$rv .= "form.elements[\"$f\"].disabled = $_[0].checked; ";
}
foreach $f (@{$_[2]}) {
$rv .= "form.elements[\"$f\"].disabled = !$_[0].checked; ";
}
return $_[3] ? "$_[3]='$rv'" : $rv;
}
=head2 js_redirect(url, [window-object])
Returns HTML to trigger a redirect to some URL.
=cut
sub js_redirect
{
my ($url, $window) = @_;
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 "\n";
}
1;
|