add ability to disable package classes
authorivan <ivan>
Wed, 20 Dec 2006 09:49:08 +0000 (09:49 +0000)
committerivan <ivan>
Wed, 20 Dec 2006 09:49:08 +0000 (09:49 +0000)
FS/FS/Schema.pm
FS/FS/pkg_class.pm
httemplate/browse/pkg_class.html
httemplate/edit/pkg_class.html
httemplate/elements/select-part_referral.html
httemplate/elements/select-pkg_class.html
httemplate/elements/select-table.html
httemplate/elements/tr-select-pkg_class.html
httemplate/search/elements/search.html

index 691edd7..2f28994 100644 (file)
@@ -1388,10 +1388,11 @@ sub tables_hashref {
       'columns' => [
         'classnum',   'serial',  '', '', '', '', 
         'classname',  'varchar', '', $char_d, '', '', 
+        'disabled',     'char', 'NULL',   1, '', '', 
       ],
       'primary_key' => 'classnum',
       'unique' => [],
-      'index' => [],
+      'index' => [ ['disabled'] ],
     },
 
     'cdr' => {
index 0fa6e48..bab6e5e 100644 (file)
@@ -38,6 +38,8 @@ from FS::Record.  The following fields are currently supported:
 
 =item classname - Text name of this package class
 
+=item disabled - Disabled flag, empty or 'Y'
+
 =back
 
 =head1 METHODS
index 3ec5e55..68cf492 100644 (file)
@@ -12,9 +12,9 @@
 %
 <% include( 'elements/browse.html',
                  'title'       => 'Package classes',
-                 'menubar'     => [ 'Main menu' => $p, ],
                  'html_init'   => $html_init,
                  'name'        => 'package classes',
+                 'disableable' => 1,
                  'query'       => { 'table'     => 'pkg_class',
                                     'hashref'   => {},
                                     'extra_sql' => 'ORDER BY classnum',
index 181072f..6f2b072 100644 (file)
@@ -1,10 +1,16 @@
 <% include( 'elements/edit.html',
-                 'name'   => 'Package Class',
-                 'table'  => 'pkg_class',
-                 'labels' => { 
-                               'classnum'  => 'Class number',
-                               'classname' => 'Class name',
-                             },
-                 'viewall_dir' => 'browse',
+              'name'   => 'Package Class',
+              'table'  => 'pkg_class',
+              'fields' => [
+                            'classname',
+                            { field=>'disabled', type=>'checkbox', value=>'Y', },
+                          ],
+              'labels' => { 
+                            'classnum'  => 'Class number',
+                            'classname' => 'Class name',
+                            'disabled'  => 'Disable class',
+                          },
+              'viewall_dir' => 'browse',
            )
+          
 %>
index efcc477..670b70c 100644 (file)
@@ -12,7 +12,7 @@
                  'empty_label' => 'Select advertising source',
                  'hashref'     => { 'disabled' => '' },
                  'extra_sql'   => ' AND '.
-                                  FS::part_referral->all_part_referral(1),
+                                  FS::part_referral->acl_agentnum_sql(1),
                  %opt,
              )
 %>
index 0d8e6ac..8e873ed 100644 (file)
@@ -1,4 +1,3 @@
-%
 %  my( $classnum, %opt ) = @_;
 %
 %  $opt{'records'} = delete $opt{'pkg_class'}
@@ -6,13 +5,12 @@
 %
 %  #warn "***** select-pkg-class: \n". Dumper(%opt);
 %
-%
 <% include( '/elements/select-table.html',
                  'table'       => 'pkg_class',
                  'name_col'    => 'classname',
                  'value'       => $classnum,
                  'empty_label' => '(none)',
-                 #'hashref'     => { 'disabled' => '' },
+                 'hashref'     => { 'disabled' => '' },
                  %opt,
              )
 %>
index 83445f4..0c3c005 100644 (file)
@@ -1,65 +1,77 @@
-%
-%
-%  ##required
-%  # 'table'    => 'table_name',
-%  # 'name_col' => 'name_column',
-%  #
-%  ##strongly recommended (you want your forms to be "sticky" on errors, right?)
-%  # 'value'    => 'current_value',
-%  #
-%  ##opt
-%  # 'empty_label'  => '', #better specify it though, the default might change
-%  # 'hashref'      => {},
-%  # 'extra_sql'    => '',
-%  # 'records'      => \@records, #instead of hashref
-%  # 'pre_options'  => [ 'value' => 'option' ], #before normal options
-%  # 'element_name' => '', #HTML element name, defaults to the name of
-%  #                       # the primary key column
-%  # 'element_etc'  => '', #additional attributes (i.e. "DISABLED") for the
-%  #                       #<SELECT> element
-%
-%  my( %opt ) = @_;
-%
-%  #warn "***** select-table: \n". Dumper(%opt);
-%
-%  my $key = dbdef->table($opt{'table'})->primary_key; #? $opt{'primary_key'} ||
-%
-%  my $name_col = $opt{'name_col'};
-%
-%  my @records = ();
-%  if ( $opt{'records'} ) {
-%    @records = @{ $opt{'records'} };
-%  } else {
-%    @records = qsearch( {
-%      'table'     => $opt{'table'},
-%      'hashref'   => ( $opt{'hashref'} || {} ),
-%      'extra_sql' => ( $opt{'extra_sql'} || '' ),
-%    });
-%  }
-%
-%  my @pre_options = $opt{'pre_options'} ? @{ $opt{'pre_options'} } : ();
-%
-%
-
-
 <SELECT NAME="<% $opt{'element_name'} || $key %>" <% $opt{'element_etc'} %>>
+
 % while ( @pre_options ) { 
 
     <OPTION VALUE="<% shift(@pre_options) %>"><% shift(@pre_options) %>
-% } 
 
+% } 
 
   <OPTION VALUE=""><% $opt{'empty_label'} || 'all' %>
-% foreach my $record ( sort { $a->$name_col() cmp $b->$name_col() }
-%                               @records
-%                        )
-%     {
-%  
 
+% foreach my $record ( sort { $a->$name_col() cmp $b->$name_col() } @records ) {
 
     <OPTION VALUE="<% $record->$key() %>"<% $opt{'value'} == $record->$key() ? ' SELECTED' : '' %>><% $record->$name_col() %>
-% } 
 
+% } 
 
 </SELECT>
+<%init>
+
+##required
+# 'table'    => 'table_name',
+# 'name_col' => 'name_column',
+#
+##strongly recommended (you want your forms to be "sticky" on errors, right?)
+# 'value'    => 'current_value',
+#
+##opt
+# 'empty_label'  => '', #better specify it though, the default might change
+# 'hashref'      => {},
+# 'extra_sql'    => '',
+# 'records'      => \@records, #instead of hashref
+# 'pre_options'  => [ 'value' => 'option' ], #before normal options
+# 'element_name' => '', #HTML element name, defaults to the name of
+#                       # the primary key column
+# 'element_etc'  => '', #additional attributes (i.e. "DISABLED") for the
+#                       #<SELECT> element
+# 'debug'        => 0, #set true to enable
+
+my( %opt ) = @_;
+
+warn "elements/select-table.html: \n". Dumper(%opt)
+  if exists $opt{debug} && $opt{debug};
+
+my $key = dbdef->table($opt{table})->primary_key; #? $opt{primary_key} ||
+
+my $name_col = $opt{name_col};
+
+$opt{hashref} ||= {};
+
+my @records = ();
+if ( $opt{records} ) {
+  @records = @{ $opt{records} };
+} else {
+  @records = qsearch( {
+    'table'     => $opt{table},
+    'hashref'   => $opt{hashref},
+    'extra_sql' => ( $opt{extra_sql} || '' ),
+  });
+}
+
+unless (    ! $opt{value}
+         or ! exists( $opt{hashref}->{disabled} ) #??
+         or grep { $opt{value} == $_->$key() } @records
+       ) {
+  delete $opt{hashref}->{disabled};
+  $opt{hashref}->{$key} = $opt{value};
+  my $record = qsearchs( {
+    'table'     => $opt{table},
+    'hashref'   => $opt{hashref},
+    'extra_sql' => ( $opt{extra_sql} || '' ),
+  });
+  push @records, $record if $record;
+}
+
+my @pre_options = $opt{pre_options} ? @{ $opt{pre_options} } : ();
 
+</%init>
index 7f37e81..5421424 100644 (file)
@@ -1,16 +1,14 @@
-%
 %  my( $classnum, %opt ) = @_;
 %
-%  $opt{'pkg_class'} ||= [ qsearch( 'pkg_class', {} ) ]; # { disabled=>'' } )
+%  $opt{'pkg_class'} ||= [ qsearch( 'pkg_class', { disabled=>'' } ) ];
 %
 %  #warn "***** tr-select-pkg-class: \n". Dumper(%opt);
 %
 % if ( scalar(@{ $opt{'pkg_class'} }) == 0 ) { 
 
-
   <INPUT TYPE="hidden" NAME="classnum" VALUE="">
-% } else { 
 
+% } else { 
 
   <TR>
     <TD ALIGN="right"><% $opt{'label'} || 'Package class' %></TD>
@@ -18,5 +16,5 @@
       <% include( '/elements/select-pkg_class.html', $classnum, %opt ) %>
     </TD>
   </TR>
-% } 
 
+% } 
index 689cbe3..c6d0bb6 100644 (file)
 %  # # listref of URL base and column name (or method)
 %  # # or a coderef that returns the same
 %  # 'redirect' =>
+%  #
+%  # #set to 1 (or column position for "disabled" status col) to enable
+%  # #"show disabled/hide disabled" links
+%  # #(can't be used with a literal query)
+%  # 'disableable' => 1,
 %
 %  my $DEBUG = 0;
 %
 %
 %  } else { #setup some pagination things if we're in html mode
 %
-%    unless (exists($opt{'count_query'}) && length($opt{'count_query'})) {
-%      ( $opt{'count_query'} = $opt{'query'} ) =~
+%    unless (exists($opt{count_query}) && length($opt{count_query})) {
+%      ( $opt{count_query} = $opt{query} ) =~
 %        s/^\s*SELECT\s*(.*?)\s+FROM\s/SELECT COUNT(*) FROM /i; #silly vim:/
 %    }
 %
+%    if ( $opt{disableable} && ! $cgi->param('showdisabled') ) {
+%      $opt{count_query} .=
+%        ( ( $opt{count_query} =~ /WHERE/i ) ? ' AND ' : ' WHERE ' ).
+%        "( disabled = '' OR disabled IS NULL )";
+%    }
+%
 %    my $conf = new FS::Conf;
 %    $confmax = $conf->config('maxsearchrecordsperpage');
 %    if ( $cgi->param('maxrecords') =~ /^(\d+)$/ ) {
 %
 %  }
 %
+%  #disableable handling
+%  my $posttotal = '';
+%  if ( $opt{disableable} ) {
+%
+%    my $name= $opt{'name_singular'} ? PL($opt{'name_singular'}) : $opt{'name'};
+%
+%    if ( $cgi->param('showdisabled') ) {
+%      $cgi->param('showdisabled', 0);
+%      $posttotal= '( <a href="'. $cgi->self_url. '">'.
+%                  "hide disabled $name</a> )";
+%      $cgi->param('showdisabled', 1);
+%    } else {
+%      $cgi->param('showdisabled', 1);
+%      $posttotal= '( <a href="'. $cgi->self_url. '">'.
+%                  "show disabled $name</a> )";
+%      $cgi->param('showdisabled', 0);
+%    }
+%
+%    if ( $cgi->param('showdisabled') ) {
+%
+%      my $offset = $opt{disableable};
+%
+%      splice @{ $opt{header} }, $offset, 0, 'Status';
+%
+%      splice @{ $opt{fields} }, $offset, 0,
+%        sub { shift->disabled ? 'DISABLED' : 'Active' };
+%
+%      if ( $opt{links} && scalar( @{ $opt{links} } ) ) {
+%        splice @{ $opt{links} }, $offset, 0, '';
+%      }
+%
+%      if ( $opt{align} && scalar( @{ $opt{align} } ) ) {
+%        splice @{ $opt{align} }, $offset, 0, 'center';
+%      }
+%
+%      unless ( $opt{color} && scalar( @{ $opt{color} } ) ) {
+%        #$opt{color} = [ map { '000000'; } @{$opt{header}} ];
+%        $opt{color} = [ map { ''; } @{$opt{header}} ];
+%      }
+%      splice @{ $opt{color} }, $offset, 0,
+%        sub { shift->disabled ? 'FF0000' : '00CC00'; };
+%
+%      if ( $opt{size} && scalar( @{ $opt{size} } ) ) {
+%        splice @{ $opt{size} }, $offset, 0, '';
+%      }
+%
+%      unless ( $opt{style} && scalar( @{ $opt{style} } ) ) {
+%        $opt{style} = [ map { ''; } @{$opt{header}} ];
+%      }
+%      splice @{ $opt{style} }, $offset, 0, 'b';
+%
+%    }
+%
+%  }
+%
 %  # run the query
 %
-%  my $header = $opt{'header'};
+%  my $header = $opt{header};
 %  my $rows;
-%  if ( ref($opt{'query'}) ) {
+%  if ( ref($opt{query}) ) {
+%
+%    if ( $opt{disableable} && ! $cgi->param('showdisabled') ) {
+%      #%search = ( 'disabled' => '' );
+%      $opt{'query'}->{'hashref'}->{'disabled'} = '';
+%      $opt{'query'}->{'extra_sql'} =~ s/^\s*WHERE/ AND/i;
+%    }
 %
 %    #eval "use FS::$opt{'query'};";
 %    $rows = [ qsearch(
 %      my @menubar = ();
 %      if ( $opt{'menubar'} ) {
 %        @menubar = @{ $opt{'menubar'} };
-%      } else {
-%        @menubar = ( 'Main menu' => $p );
+%      #} else {
+%      #  @menubar = ( 'Main menu' => $p );
 %      }
-%
-%
-%  
 
   <% include( '/elements/header.html', $opt{'title'},
                  include( '/elements/menubar.html', @menubar )
 %           $cgi->param('maxrecords', $maxrecords);
 %         }
 
+          <% $posttotal %>
 
           <% defined($opt{'html_posttotal'}) 
                 ? ( ref($opt{'html_posttotal'})