Handle hostnames with upper-case letters
[webmin.git] / ui-lib.pl
index 1ab71fa..178677f 100755 (executable)
--- a/ui-lib.pl
+++ b/ui-lib.pl
@@ -264,7 +264,7 @@ $rv .= "</tr>\n";
 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. The parameters are :
@@ -281,15 +281,17 @@ contains a checkbox. The parameters are :
 
 =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++) {
@@ -308,7 +310,7 @@ $rv .= "</tr>\n";
 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. The parameters are :
@@ -325,11 +327,13 @@ column is a radio button. The parameters are :
 
 =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].">".
@@ -441,13 +445,15 @@ foreach my $r (@$data) {
                        # 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
@@ -475,12 +481,14 @@ foreach my $r (@$data) {
        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'});
                }
        }
 
@@ -710,12 +718,17 @@ options. May truncate values to 2 decimal points! The parameters are :
 
 =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, $tags) = @_;
+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) {
@@ -908,13 +921,13 @@ if (defined($opts_title)) {
        }
 $rv .= "<tr class='ui_multi_select_row'>";
 $rv .= "<td>".&ui_select($name."_opts", [ ], $leftover,
-                        $size, 0, 0, $dis, $wstyle)."</td>\n";
+                        $size, 1, 0, $dis, $wstyle)."</td>\n";
 $rv .= "<td>".&ui_button("->", $name."_add", $dis,
                 "onClick='multi_select_move(\"$name\", form, 1)'")."<br>".
              &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;
@@ -940,15 +953,27 @@ var opts_idx = opts.selectedIndex;
 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];
@@ -1836,8 +1861,8 @@ if (!$main::ui_hidden_start_donejs++) {
        }
 
 # 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 { "\"".&quote_escape($_->[0])."\"" } @$tabs)."]";
+my $tabtitles = "[".join(",", map { "\"".&quote_escape($_->[1])."\"" } @$tabs)."]";
 $rv .= "<script>\n";
 $rv .= "document.${name}_tabnames = $tabnames;\n";
 $rv .= "document.${name}_tabtitles = $tabtitles;\n";
@@ -2397,6 +2422,10 @@ 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 = '".&quote_escape($url)."';</script>\n";
 }