From 66b66c807d63205ae6a799d2f04de328cb4587b1 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 31 Aug 2008 16:25:04 +0000 Subject: [PATCH] ui-lib conversion of map editing pages --- postfix/edit_manual.cgi | 10 ++- postfix/lang/en | 2 +- postfix/postfix-lib.pl | 153 +++++++++++++++++++++------------------- postfix/virtual.cgi | 27 +++---- 4 files changed, 96 insertions(+), 96 deletions(-) diff --git a/postfix/edit_manual.cgi b/postfix/edit_manual.cgi index 1d8830617..210d3bcab 100755 --- a/postfix/edit_manual.cgi +++ b/postfix/edit_manual.cgi @@ -20,16 +20,14 @@ if (@files > 1) { } # Show the file contents -&open_readfile(FILE, $file); -while() { - $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', "$file"),"
\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'}); diff --git a/postfix/lang/en b/postfix/lang/en index a0d826ea9..56e13eb20 100644 --- a/postfix/lang/en +++ b/postfix/lang/en @@ -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. diff --git a/postfix/postfix-lib.pl b/postfix/postfix-lib.pl index 7e098248a..84b2d534d 100644 --- a/postfix/postfix-lib.pl +++ b/postfix/postfix-lib.pl @@ -303,14 +303,11 @@ sub option_radios_freefield my $check_free_field = 1; my $help = -r &help_file($module_name, "opt_".$name) ? - &hlink("$text{$key}", "opt_".$name) : - "$text{$key}"; - printf "$help \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 "\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("$text{$key}", "opt_".$name) : - "$text{$key}"; - printf "$help \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 "\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 "
\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],"

\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 = ( "{'number'}&map_name=$_[0]\">$map->{'name'}", - $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 "

\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 "
\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), + "". + $text{'new_mapping'}."", + ); + 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'} }, + "{'number'}&". + "map_name=$_[0]\">".&html_escape($map->{'name'}). + "", + &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 "\n"; +local ($name, $mapname) = @_; +return &popup_window_button("map_chooser.cgi?mapname=$mapname", 1024, 600, 1, + [ [ "ifield", $name, "map" ] ]); } # get_maps_types_files(value) diff --git a/postfix/virtual.cgi b/postfix/virtual.cgi index 1664d6c18..428dcab1d 100755 --- a/postfix/virtual.cgi +++ b/postfix/virtual.cgi @@ -24,31 +24,22 @@ $access{'virtual'} || &error($text{'virtual_ecannot'}); # alias general options - -print "
\n"; -print "\n"; -print "\n"; -print "
$text{'virtual_title'}
\n"; +print &ui_form_start("save_opts_virtual.cgi"); +print &ui_table_start($text{'virtual_title'}, "width=100%", 2); $none = $text{'opts_none'}; - -print "\n"; -&option_mapfield($virtual_maps, 60, $none); -print "\n"; +&option_mapfield($virtual_maps, 40, $none); if ($postfix_version >= 2) { - print "\n"; - &option_radios_freefield("virtual_alias_domains", 60, + &option_radios_freefield("virtual_alias_domains", 40, $text{'virtual_same'}); - print "\n"; } -print "

\n"; -print "

\n"; +print &ui_table_end(); +print &ui_form_end([ [ undef, $text{'opts_save'} ] ]); + +# Current map contents print &ui_hr(); -print "
\n"; - - if (&get_current_value($virtual_maps) eq "") { print ($text{'no_map'}."

"); @@ -56,7 +47,7 @@ if (&get_current_value($virtual_maps) eq "") else { &generate_map_edit($virtual_maps, $text{'map_click'}." ". - "".&hlink("$text{'help_map_format'}", "virtual")."\n
\n"); + &hlink($text{'help_map_format'}, "virtual")); } &ui_print_footer("", $text{'index_return'});