From f96adaf19c0097ef8c9d6f29a5541b75381cc05d Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 12 Mar 2002 15:33:22 +0000 Subject: [PATCH] abstract stupid HTML layer trick out to HTML::Widgets::SelectLayers --- README.1.4.0pre12 | 2 + htetc/global.asa | 3 + htetc/handler.pl | 3 + httemplate/docs/install.html | 1 + httemplate/docs/upgrade8.html | 2 +- httemplate/edit/part_pkg.cgi | 256 ++++++++++++++++-------------------------- httemplate/edit/part_svc.cgi | 225 ++++++++++++------------------------- 7 files changed, 177 insertions(+), 315 deletions(-) diff --git a/README.1.4.0pre12 b/README.1.4.0pre12 index 0b453a4e4..824b7fd86 100644 --- a/README.1.4.0pre12 +++ b/README.1.4.0pre12 @@ -7,6 +7,8 @@ httemplate/docs/upgrade8.html instead ---- +install HTML-Widgets-SelectLayers from CPAN or http://www.420.am/selectlayers + install the FS perl modules and httemplate as per install.html or upgrade8.html ALTER TABLE cust_bill_event ADD status varchar(80); diff --git a/htetc/global.asa b/htetc/global.asa index 339f01dae..083f2253d 100644 --- a/htetc/global.asa +++ b/htetc/global.asa @@ -9,6 +9,7 @@ use HTML::Entities; use IO::Handle; use IO::File; use String::Approx qw(amatch); +use HTML::Widgets::SelectLayers; use FS::UID qw(cgisuidsetup dbh getotaker datasrc); use FS::Record qw(qsearch qsearchs fields dbdef); use FS::Conf; @@ -45,6 +46,8 @@ use FS::svc_domain; use FS::svc_forward; use FS::svc_www; use FS::type_pkgs; +use FS::part_export; +#use FS::part_export_option; sub Script_OnStart { $Response->AddHeader('Pragma' => 'no-cache'); diff --git a/htetc/handler.pl b/htetc/handler.pl index 680d11ec8..5f244921e 100644 --- a/htetc/handler.pl +++ b/htetc/handler.pl @@ -66,6 +66,7 @@ sub handler use IO::Handle; use IO::File; use String::Approx qw(amatch); + use HTML::Widgets::SelectLayers; use FS::UID qw(cgisuidsetup dbh getotaker datasrc); use FS::Record qw(qsearch qsearchs fields dbdef); use FS::Conf; @@ -102,6 +103,8 @@ sub handler use FS::svc_forward; use FS::svc_www; use FS::type_pkgs; + use FS::part_export; + #use FS::part_export_option; *CGI::redirect = sub { my( $self, $location ) = @_; diff --git a/httemplate/docs/install.html b/httemplate/docs/install.html index d7c014f4d..1a4942bc9 100644 --- a/httemplate/docs/install.html +++ b/httemplate/docs/install.html @@ -50,6 +50,7 @@ Before installing, you need:
  • Apache::ASP or HTML::Mason
  • Tie-IxHash
  • Time-Duration +
  • HTML-Widgets-SelectLayers Install the Freeside distribution: diff --git a/httemplate/docs/upgrade8.html b/httemplate/docs/upgrade8.html index 4b0c493f0..2640be419 100644 --- a/httemplate/docs/upgrade8.html +++ b/httemplate/docs/upgrade8.html @@ -7,7 +7,7 @@
  • If migrating from less than 1.3.1, see these instructions first.
  • Backup your database and current Freeside installation. (with PostgreSQL) (with MySQL)
  • mod_perl is now required. -
  • Install Time-Duration, and Tie-IxHash +
  • Install Time-Duration, Tie-IxHash and HTML-Widgets-SelectLayers.
  • Install Apache::ASP or HTML::Mason.
  • Install rsync diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index 8e7a6c5cf..d3213dd46 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -42,24 +42,12 @@ unless ( $part_pkg->plan ) { #backwards-compat $action ||= $part_pkg->pkgpart ? 'Edit' : 'Add'; my $hashref = $part_pkg->hashref; -%> - - - -<% print header("$action Package Definition", menubar( 'Main Menu' => popurl(2), 'View all packages' => popurl(2). 'browse/part_pkg.cgi', -), ' onLoad="visualize()"'); +)); +#), ' onLoad="visualize()"'); print qq!Error: !, $cgi->param('error'), "" @@ -164,8 +152,12 @@ unless ( 0 ) { #print ""; } +foreach my $f ( qw( clone pkgnum ) ) { + print qq!'; +} +print ''; + # prolly should be in database -use Tie::IxHash; tie my %plans, 'Tie::IxHash', 'flat' => { 'name' => 'Flat rate', @@ -314,159 +306,99 @@ tie my %plans, 'Tie::IxHash', ; -%> - - -
    -Price plan - - - -<% my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); } +my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); } split("\n", $part_pkg->plandata ); - #foreach my $layer ( 'konq_kludge', keys %plans ) { - foreach my $layer ( 'konq_kludge', keys %plans ) { - my $visibility = "hidden"; -%> - - -
    - - - - - - - -<% foreach my $f ( @fixups ) { %> - -<% } %> -<% -if ( $cgi->param('clone') ) { - print qq!!; -} -if ( $cgi->param('pkgnum') ) { - print qq!!; -} -%> +tie my %options, 'Tie::IxHash', map { $_=>$plans{$_}->{'name'} } keys %plans; + +my $widget = new HTML::Widgets::SelectLayers( + 'selected_layer' => $part_pkg->plan, + 'options' => \%options, + 'form_name' => 'dummy', + 'form_action' => 'process/part_pkg.cgi', + 'form_text' => [ qw(pkg comment freq clone pkgnum pkgpart), @fixups ], + 'form_checkbox' => [ qw(setuptax recurtax disabled) ], + 'fixup_callback' => sub { + #my $ = @_; + my $html = ''; + for my $p ( keys %plans ) { + $html .= "if ( what.plan.value == \"$p\" ) { + what.setup.value = $plans{$p}->{setup} ; + what.recur.value = $plans{$p}->{recur} ; + }\n"; + } + $html; + }, + 'layer_callback' => sub { + my $layer = shift; + my $html = qq!!. + ntable("#cccccc",2); + my $href = $plans{$layer}->{'fields'}; + foreach my $field ( exists($plans{$layer}->{'fieldorder'}) + ? @{$plans{$layer}->{'fieldorder'}} + : keys %{ $href } + ) { + + $html .= ''. $href->{$field}{'name'}. ''; + + if ( ! exists($href->{$field}{'type'}) ) { + $html .= qq!!; + } elsif ( $href->{$field}{'type'} eq 'select_multiple' ) { + $html .= qq!'; + } - -<%= ntable("#cccccc",2) %> + $html .= ''; + } + $html .= ''; + + $html .= ''. + '

    '; + + $html .= ''; + + $html .= '

    don\'t edit this unless you know what you\'re doing '. + ''. + ntable("#cccccc",2). + ''. + 'Setup expression
    '. + ''. + '

    '. + 'Recurring espression
    '. + ''. + '
    '. + ''. + ''; + + $html; -<% my $href = $plans{$layer}->{'fields'}; - foreach my $field ( exists($plans{$layer}->{'fieldorder'}) - ? @{$plans{$layer}->{'fieldorder'}} - : keys %{ $href } - ) { -%> - <%= $href->{$field}{'name'} %> - - <% if ( ! exists($href->{$field}{'type'}) ) { %> - - <% } elsif ( $href->{$field}{'type'} eq 'select_multiple' ) { %> - - <% } %> - -<% } %> - - - -

    + }, +); -<% -print qq!!; %> -

    don't edit this unless you know what you're doing <%= ntable("#cccccc",2) %> -Setup expression

    -Recurring espression
    - - - -
    - - - -<% } %> - - +
    +Price plan <%= $widget->html %> diff --git a/httemplate/edit/part_svc.cgi b/httemplate/edit/part_svc.cgi index 57ab3985e..3292a9b9b 100755 --- a/httemplate/edit/part_svc.cgi +++ b/httemplate/edit/part_svc.cgi @@ -15,25 +15,16 @@ } my $action = $part_svc->svcpart ? 'Edit' : 'Add'; my $hashref = $part_svc->hashref; - my $p_svcdb = $part_svc->svcdb || 'svc_acct'; +# my $p_svcdb = $part_svc->svcdb || 'svc_acct'; -%> - + #" onLoad=\"visualize()\"" +%> <%= header("$action Service Definition", menubar( 'Main Menu' => $p, 'View all service definitions' => "${p}browse/part_svc.cgi" ), - " onLoad=\"visualize()\"" ) %> @@ -47,6 +38,7 @@ function visualize(what) {

    Service
    Disable new orders {disabled} eq 'Y' ? ' CHECKED' : '' %>>
    +
    Services are items you offer to your customers.
    • svc_acct - Shell accounts, POP mailboxes, SLIP/PPP and ISDN accounts @@ -64,37 +56,6 @@ values. For example, a SLIP/PPP account may have a default (or perhaps fixed) blank slipip as well as a fixed shell something like /bin/true or /usr/bin/passwd.

      - -<% my @dbs = $hashref->{svcdb} - ? ( $hashref->{svcdb} ) - : qw( svc_acct svc_domain svc_acct_sm svc_forward svc_www ); %> -Table <% #these might belong somewhere else for other user interfaces @@ -152,121 +113,81 @@ my %defs = ( }, ); -# svc_acct svc_domain svc_acct_sm svc_charge svc_wo -foreach my $svcdb ( qw( - konq_kludge svc_acct svc_domain svc_acct_sm svc_forward svc_www -) ) { - -# my(@fields) = $svcdb eq 'konq_kludge' -# ? () -# : grep { $_ ne 'svcnum' } fields($svcdb); - #yucky kludge - my(@fields) = defined( $FS::Record::dbdef->table($svcdb) ) - ? grep { $_ ne 'svcnum' } fields($svcdb) - : (); - #my($rowspan)=scalar(@rows); - - #my($ptmp)="$svcdb"; -# $visibility = $svcdb eq $part_svc->svcdb ? "SHOW" : "HIDDEN"; -# $visibility = $svcdb eq $p_svcdb ? "visible" : "hidden"; - my $visibility = "hidden"; -%> - -
      - - - - -<% - #print "$svcdb
      " unless $svcdb eq 'konq_kludge'; - print table(). "FieldModifier" unless $svcdb eq 'konq_kludge'; - - foreach my $field (@fields) { - my $part_svc_column = $part_svc->part_svc_column($field); - my $value = $cgi->param('error') - ? $cgi->param("${svcdb}__${field}") - : $part_svc_column->columnvalue; - my $flag = $cgi->param('error') - ? $cgi->param("${svcdb}__${field}_flag") - : $part_svc_column->columnflag; - #print "$ptmp$field"; - print "$field"; - my $def = $defs{$svcdb}{$field}; - my $desc = ref($def) ? $def->{desc} : $def; - - print "- $desc" if $desc; - print ""; - print qq!Off"; - print qq!Default "; - print qq!Fixed "; - print '
      '; - if ( ref($def) ) { - if ( $def->{type} eq 'select' ) { - print qq!!. + table(). "FieldModifier"; + #yucky kludge + my @fields = defined( $FS::Record::dbdef->table($layer) ) + ? grep { $_ ne 'svcnum' } fields($layer) + : (); + foreach my $field (@fields) { + my $part_svc_column = $part_svc->part_svc_column($field); + my $value = $cgi->param('error') + ? $cgi->param("${layer}__${field}") + : $part_svc_column->columnvalue; + my $flag = $cgi->param('error') + ? $cgi->param("${layer}__${field}_flag") + : $part_svc_column->columnflag; + my $def = $defs{$layer}{$field}; + my $desc = ref($def) ? $def->{desc} : $def; + + $html .= "$field"; + $html .= "- $desc" if $desc; + $html .= ""; + $html .= + qq!Off". + qq!Default ". + qq!Fixed ". + '
      '; + if ( ref($def) ) { + if ( $def->{type} eq 'select' ) { + $html .= qq!'; + } else { + $html .= 'unknown type'. $def->{type}; + } + } else { + $html .= + qq!!; } - print ''; - } else { - print 'unknown type'. $def->{type}; + $html .= "\n"; } - } else { - print qq!!; - } - print "\n"; - #$ptmp=''; - } - print "" unless $svcdb eq 'konq_kludge'; + $html .= ""; -print qq!\n
      ! unless $svcdb eq 'konq_kludge'; + $html .= '
      '; - print ""; - print < - if (document.getElementById) { - document.write(""); - } else { - document.write(""); - } - -END -} -#print ""; -%> + $html; - + }, + ); +%> +Table <%= $widget->html %> -- 2.11.0