summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2006-12-20 09:49:08 +0000
committerivan <ivan>2006-12-20 09:49:08 +0000
commit7002af78bc3e683ff8ce18b39de6d7de484422bf (patch)
tree03f45fbc10293e939d414c861216d5dc2ff298d4
parent7b5280c065aaa4887ce4e36fb4be7a80a74a8392 (diff)
add ability to disable package classes
-rw-r--r--FS/FS/Schema.pm3
-rw-r--r--FS/FS/pkg_class.pm2
-rw-r--r--httemplate/browse/pkg_class.html2
-rw-r--r--httemplate/edit/pkg_class.html20
-rw-r--r--httemplate/elements/select-part_referral.html2
-rw-r--r--httemplate/elements/select-pkg_class.html4
-rw-r--r--httemplate/elements/select-table.html114
-rw-r--r--httemplate/elements/tr-select-pkg_class.html8
-rw-r--r--httemplate/search/elements/search.html88
9 files changed, 165 insertions, 78 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 691edd7..2f28994 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -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' => {
diff --git a/FS/FS/pkg_class.pm b/FS/FS/pkg_class.pm
index 0fa6e48..bab6e5e 100644
--- a/FS/FS/pkg_class.pm
+++ b/FS/FS/pkg_class.pm
@@ -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
diff --git a/httemplate/browse/pkg_class.html b/httemplate/browse/pkg_class.html
index 3ec5e55..68cf492 100644
--- a/httemplate/browse/pkg_class.html
+++ b/httemplate/browse/pkg_class.html
@@ -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',
diff --git a/httemplate/edit/pkg_class.html b/httemplate/edit/pkg_class.html
index 181072f..6f2b072 100644
--- a/httemplate/edit/pkg_class.html
+++ b/httemplate/edit/pkg_class.html
@@ -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',
)
+
%>
diff --git a/httemplate/elements/select-part_referral.html b/httemplate/elements/select-part_referral.html
index efcc477..670b70c 100644
--- a/httemplate/elements/select-part_referral.html
+++ b/httemplate/elements/select-part_referral.html
@@ -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,
)
%>
diff --git a/httemplate/elements/select-pkg_class.html b/httemplate/elements/select-pkg_class.html
index 0d8e6ac..8e873ed 100644
--- a/httemplate/elements/select-pkg_class.html
+++ b/httemplate/elements/select-pkg_class.html
@@ -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,
)
%>
diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html
index 83445f4..0c3c005 100644
--- a/httemplate/elements/select-table.html
+++ b/httemplate/elements/select-table.html
@@ -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>
diff --git a/httemplate/elements/tr-select-pkg_class.html b/httemplate/elements/tr-select-pkg_class.html
index 7f37e81..5421424 100644
--- a/httemplate/elements/tr-select-pkg_class.html
+++ b/httemplate/elements/tr-select-pkg_class.html
@@ -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>
-% }
+% }
diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html
index 689cbe3..c6d0bb6 100644
--- a/httemplate/search/elements/search.html
+++ b/httemplate/search/elements/search.html
@@ -78,6 +78,11 @@
% # # 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;
%
@@ -104,11 +109,17 @@
%
% } 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+)$/ ) {
@@ -131,11 +142,72 @@
%
% }
%
+% #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(
@@ -306,12 +378,9 @@
% 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 )
@@ -357,6 +426,7 @@
% $cgi->param('maxrecords', $maxrecords);
% }
+ <% $posttotal %>
<% defined($opt{'html_posttotal'})
? ( ref($opt{'html_posttotal'})