mirror of
https://github.com/webmin/webmin.git
synced 2026-03-20 16:50:24 +00:00
ui-lib conversion of map editing pages
This commit is contained in:
@@ -20,16 +20,14 @@ if (@files > 1) {
|
||||
}
|
||||
|
||||
# Show the file contents
|
||||
&open_readfile(FILE, $file);
|
||||
while(<FILE>) {
|
||||
$data .= $_;
|
||||
}
|
||||
close(FILE);
|
||||
$data = &read_file_contents($file);
|
||||
print &ui_form_start("save_manual.cgi", "form-data");
|
||||
print &ui_hidden("map_name", $in{'map_name'});
|
||||
print &ui_hidden("file", $file);
|
||||
print &text('manual_editing', "<tt>$file</tt>"),"<br>\n";
|
||||
print &ui_textarea("data", $data, 20, 80);
|
||||
print &ui_table_start();
|
||||
print &ui_table_row(undef, &ui_textarea("data", $data, 20, 80), 2);
|
||||
print &ui_table_end();
|
||||
print &ui_form_end([ [ "save", $text{'save'} ] ] );
|
||||
|
||||
&ui_print_footer("", $text{'index_return'});
|
||||
|
||||
@@ -355,7 +355,7 @@ mapping_value=Maps to...
|
||||
mapping_delete=Delete Selected
|
||||
mapping_cmt=Description
|
||||
mapping_ecannot=You are only allowed to edit maps under $1
|
||||
new_mapping=New Mapping
|
||||
new_mapping=Add a new mapping.
|
||||
new_mappingmsg=Click this button to create a new mapping
|
||||
new_manual=Edit Map Manually
|
||||
new_manualmsg=Click this button to manually edit the files from which this map is built.
|
||||
|
||||
@@ -303,14 +303,11 @@ sub option_radios_freefield
|
||||
my $check_free_field = 1;
|
||||
|
||||
my $help = -r &help_file($module_name, "opt_".$name) ?
|
||||
&hlink("<b>$text{$key}</b>", "opt_".$name) :
|
||||
"<b>$text{$key}</b>";
|
||||
printf "<td>$help</td> <td %s nowrap>\n",
|
||||
$length > 20 ? "colspan=3" : "";
|
||||
&hlink($text{$key}, "opt_".$name) : $text{$key};
|
||||
my $rv;
|
||||
|
||||
# first radio button (must be default value!!)
|
||||
|
||||
print &ui_oneradio($name."_def", "__DEFAULT_VALUE_IE_NOT_IN_CONFIG_FILE__",
|
||||
$rv .= &ui_oneradio($name."_def", "__DEFAULT_VALUE_IE_NOT_IN_CONFIG_FILE__",
|
||||
$_[2], &if_default_value($name));
|
||||
|
||||
$check_free_field = 0 if &if_default_value($name);
|
||||
@@ -319,17 +316,17 @@ sub option_radios_freefield
|
||||
# other radio buttons
|
||||
while (defined($_[2]))
|
||||
{
|
||||
print &ui_oneradio($name."_def", $_[2], $_[3], $v eq $_[2]);
|
||||
$rv .= &ui_oneradio($name."_def", $_[2], $_[3], $v eq $_[2]);
|
||||
if ($v eq $_[2]) { $check_free_field = 0; }
|
||||
shift;
|
||||
shift;
|
||||
}
|
||||
|
||||
# the free field
|
||||
print &ui_oneradio($name."_def", "__USE_FREE_FIELD__", undef,
|
||||
$rv .= &ui_oneradio($name."_def", "__USE_FREE_FIELD__", undef,
|
||||
$check_free_field == 1);
|
||||
print &ui_textbox($name, $check_free_field == 1 ? $v : undef, $length);
|
||||
print "</td>\n";
|
||||
$rv .= &ui_textbox($name, $check_free_field == 1 ? $v : undef, $length);
|
||||
print &ui_table_row($help, $rv, $length > 20 ? 3 : 1);
|
||||
}
|
||||
|
||||
# option_mapfield(name_of_option, length_of_free_field, defaulttext)
|
||||
@@ -344,23 +341,20 @@ sub option_mapfield
|
||||
my $check_free_field = 1;
|
||||
|
||||
my $help = -r &help_file($module_name, "opt_".$name) ?
|
||||
&hlink("<b>$text{$key}</b>", "opt_".$name) :
|
||||
"<b>$text{$key}</b>";
|
||||
printf "<td>$help</td> <td %s nowrap>\n",
|
||||
$length > 20 ? "colspan=3" : "";
|
||||
|
||||
print &ui_oneradio($name."_def", "__DEFAULT_VALUE_IE_NOT_IN_CONFIG_FILE__",
|
||||
&hlink($text{$key}, "opt_".$name) : $text{$key};
|
||||
my $rv;
|
||||
$rv .= &ui_oneradio($name."_def", "__DEFAULT_VALUE_IE_NOT_IN_CONFIG_FILE__",
|
||||
$_[2], &if_default_value($name));
|
||||
|
||||
$check_free_field = 0 if &if_default_value($name);
|
||||
shift;
|
||||
|
||||
# the free field
|
||||
print &ui_oneradio($name."_def", "__USE_FREE_FIELD__", undef,
|
||||
$rv .= &ui_oneradio($name."_def", "__USE_FREE_FIELD__", undef,
|
||||
$check_free_field == 1);
|
||||
print &ui_textbox($name, $check_free_field == 1 ? $v : undef, $length);
|
||||
print &map_chooser_button($name, $name);
|
||||
print "</td>\n";
|
||||
$rv .= &ui_textbox($name, $check_free_field == 1 ? $v : undef, $length);
|
||||
$rv .= &map_chooser_button($name, $name);
|
||||
print &ui_table_row($help, $rv, $length > 20 ? 3 : 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -833,6 +827,7 @@ sub get_maps
|
||||
|
||||
|
||||
# generate_map_edit(name, desc, [wide], [nametitle], [valuetitle])
|
||||
# Prints a table showing map contents, with links to edit and add
|
||||
sub generate_map_edit
|
||||
{
|
||||
# Check if map is set
|
||||
@@ -865,23 +860,10 @@ sub generate_map_edit
|
||||
|
||||
if ($#{$mappings} ne -1)
|
||||
{
|
||||
print $_[1];
|
||||
|
||||
print &ui_form_start("delete_mappings.cgi", "post");
|
||||
print &ui_hidden("map_name", $_[0]),"\n";
|
||||
local @links = ( &select_all_link("d", 1),
|
||||
&select_invert_link("d", 1) );
|
||||
print &ui_links_row(\@links);
|
||||
print "<table width=100%> <tr><td width=50% valign=top>\n";
|
||||
|
||||
local @tds = ( "width=5" );
|
||||
print &ui_columns_start(
|
||||
[ "", $nt, $vt,
|
||||
$config{'show_cmts'} ? ( $text{'mapping_cmt'} ) : ( )
|
||||
], 100, 0, \@tds);
|
||||
my $split_index = int(($#{$mappings})/2);
|
||||
my $i = -1;
|
||||
|
||||
# Map description
|
||||
print $_[1],"<p>\n";
|
||||
|
||||
# Sort the map
|
||||
if ($config{'sort_mode'} == 1) {
|
||||
if ($_[0] eq $virtual_maps) {
|
||||
@{$mappings} = sort sort_by_domain @{$mappings};
|
||||
@@ -891,46 +873,75 @@ sub generate_map_edit
|
||||
@{$mappings};
|
||||
}
|
||||
}
|
||||
foreach $map (@{$mappings})
|
||||
{
|
||||
local @cols = ( "<a href=\"edit_mapping.cgi?num=$map->{'number'}&map_name=$_[0]\">$map->{'name'}</a>",
|
||||
$map->{'value'} );
|
||||
push(@cols, &html_escape($map->{'cmt'})) if ($config{'show_cmts'});
|
||||
print &ui_checked_columns_row(\@cols, \@tds, "d", $map->{'name'});
|
||||
$i++;
|
||||
if ($i == $split_index && !$_[2] && $config{'columns'} == 2)
|
||||
{
|
||||
# Switch to second table
|
||||
print &ui_columns_end();
|
||||
print "</td><td width=50% valign=top>\n";
|
||||
if ($i == @$mappings -1) {
|
||||
# No more to show!
|
||||
print &ui_columns_start([ ]);
|
||||
}
|
||||
else {
|
||||
print &ui_columns_start([ "", $nt, $vt ], 100, 0,\@tds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Split into two columns, if needed
|
||||
my @parts;
|
||||
my $split_index = int(($#{$mappings})/2);
|
||||
if ($config{'columns'} == 2) {
|
||||
@parts = ( [ @{$mappings}[0 .. $split_index] ],
|
||||
[ @{$mappings}[$split_index+1 .. $#{$mappings} ] ] );
|
||||
}
|
||||
else {
|
||||
@parts = ( $mappings );
|
||||
}
|
||||
|
||||
print &ui_columns_end();
|
||||
print "</td></tr></table>\n";
|
||||
# Start of the overall form
|
||||
print &ui_form_start("delete_mappings.cgi", "post");
|
||||
print &ui_hidden("map_name", $_[0]),"\n";
|
||||
local @links = ( &select_all_link("d", 1),
|
||||
&select_invert_link("d", 1),
|
||||
"<a href='edit_mapping.cgi?map_name=$_[0]'>".
|
||||
$text{'new_mapping'}."</a>",
|
||||
);
|
||||
print &ui_links_row(\@links);
|
||||
|
||||
my @grid;
|
||||
foreach my $p (@parts) {
|
||||
# Build one table
|
||||
my @table;
|
||||
foreach my $map (@$p) {
|
||||
push(@table, [
|
||||
{ 'type' => 'checkbox', 'name' => 'd',
|
||||
'value' => $map->{'name'} },
|
||||
"<a href=\"edit_mapping.cgi?num=$map->{'number'}&".
|
||||
"map_name=$_[0]\">".&html_escape($map->{'name'}).
|
||||
"</a>",
|
||||
&html_escape($map->{'value'}),
|
||||
$config{'show_cmts'} ?
|
||||
( &html_escape($map->{'cmt'}) ) : ( ),
|
||||
]);
|
||||
}
|
||||
|
||||
# Add a table to the grid
|
||||
push(@grid, &ui_columns_table(
|
||||
[ "", $nt, $vt,
|
||||
$config{'show_cmts'} ? ( $text{'mapping_cmt'} ) : ( ),
|
||||
],
|
||||
100,
|
||||
\@table));
|
||||
}
|
||||
if (@grid == 1) {
|
||||
print $grid[0];
|
||||
}
|
||||
else {
|
||||
print &ui_grid_table(\@grid, 2, 100,
|
||||
[ "width=50%", "width=50%" ]);
|
||||
}
|
||||
|
||||
# Main form end
|
||||
print &ui_links_row(\@links);
|
||||
print &ui_form_end([ [ "delete", $text{'mapping_delete'} ] ]);
|
||||
}
|
||||
|
||||
|
||||
# new form
|
||||
print &ui_buttons_start();
|
||||
print &ui_buttons_row("edit_mapping.cgi", $text{'new_mapping'},
|
||||
$text{'new_mappingmsg'},
|
||||
&ui_hidden("map_name", $_[0]));
|
||||
# Manual edit button
|
||||
if ($access{'manual'} && &can_map_manual($_[0])) {
|
||||
print &ui_hr();
|
||||
print &ui_buttons_start();
|
||||
print &ui_buttons_row("edit_manual.cgi", $text{'new_manual'},
|
||||
$text{'new_manualmsg'},
|
||||
&ui_hidden("map_name", $_[0]));
|
||||
print &ui_buttons_end();
|
||||
}
|
||||
print &ui_buttons_end();
|
||||
|
||||
}
|
||||
|
||||
@@ -1699,13 +1710,13 @@ sub unlock_postfix_files
|
||||
&unlock_file($config{'postfix_master'});
|
||||
}
|
||||
|
||||
# map_chooser_button(field, mapname, [form])
|
||||
# map_chooser_button(field, mapname)
|
||||
# Returns HTML for a button for popping up a map file chooser
|
||||
sub map_chooser_button
|
||||
{
|
||||
local ($name, $mapname, $form) = @_;
|
||||
$form ||= 0;
|
||||
return "<input type=button onClick='ifield = form.$name; map = window.open(\"map_chooser.cgi?map=\"+escape(ifield.value)+\"&mapname=$mapname\", \"map\", \"toolbar=no,menubar=no,scrollbars=yes,width=1024,height=600\"); map.ifield = ifield; window.ifield = ifield;' value=\"...\">\n";
|
||||
local ($name, $mapname) = @_;
|
||||
return &popup_window_button("map_chooser.cgi?mapname=$mapname", 1024, 600, 1,
|
||||
[ [ "ifield", $name, "map" ] ]);
|
||||
}
|
||||
|
||||
# get_maps_types_files(value)
|
||||
|
||||
@@ -24,31 +24,22 @@ $access{'virtual'} || &error($text{'virtual_ecannot'});
|
||||
|
||||
|
||||
# alias general options
|
||||
|
||||
print "<form action=save_opts_virtual.cgi>\n";
|
||||
print "<table border width=100%>\n";
|
||||
print "<tr $tb> <td><b>$text{'virtual_title'}</b></td></tr>\n";
|
||||
print "<tr $cb> <td><table width=100%>\n";
|
||||
print &ui_form_start("save_opts_virtual.cgi");
|
||||
print &ui_table_start($text{'virtual_title'}, "width=100%", 2);
|
||||
|
||||
$none = $text{'opts_none'};
|
||||
|
||||
print "<tr>\n";
|
||||
&option_mapfield($virtual_maps, 60, $none);
|
||||
print "</tr>\n";
|
||||
&option_mapfield($virtual_maps, 40, $none);
|
||||
|
||||
if ($postfix_version >= 2) {
|
||||
print "<tr>\n";
|
||||
&option_radios_freefield("virtual_alias_domains", 60,
|
||||
&option_radios_freefield("virtual_alias_domains", 40,
|
||||
$text{'virtual_same'});
|
||||
print "</tr>\n";
|
||||
}
|
||||
|
||||
print "</table></td></tr></table><p>\n";
|
||||
print "<input type=submit value=\"$text{'opts_save'}\"></form>\n";
|
||||
print &ui_table_end();
|
||||
print &ui_form_end([ [ undef, $text{'opts_save'} ] ]);
|
||||
|
||||
# Current map contents
|
||||
print &ui_hr();
|
||||
print "<br>\n";
|
||||
|
||||
|
||||
if (&get_current_value($virtual_maps) eq "")
|
||||
{
|
||||
print ($text{'no_map'}."<br><br>");
|
||||
@@ -56,7 +47,7 @@ if (&get_current_value($virtual_maps) eq "")
|
||||
else
|
||||
{
|
||||
&generate_map_edit($virtual_maps, $text{'map_click'}." ".
|
||||
"<font size=\"-1\">".&hlink("$text{'help_map_format'}", "virtual")."</font>\n<br>\n");
|
||||
&hlink($text{'help_map_format'}, "virtual"));
|
||||
}
|
||||
|
||||
&ui_print_footer("", $text{'index_return'});
|
||||
|
||||
Reference in New Issue
Block a user