diff options
author | ivan <ivan> | 2006-12-20 09:49:08 +0000 |
---|---|---|
committer | ivan <ivan> | 2006-12-20 09:49:08 +0000 |
commit | 7002af78bc3e683ff8ce18b39de6d7de484422bf (patch) | |
tree | 03f45fbc10293e939d414c861216d5dc2ff298d4 /httemplate | |
parent | 7b5280c065aaa4887ce4e36fb4be7a80a74a8392 (diff) |
add ability to disable package classes
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/browse/pkg_class.html | 2 | ||||
-rw-r--r-- | httemplate/edit/pkg_class.html | 20 | ||||
-rw-r--r-- | httemplate/elements/select-part_referral.html | 2 | ||||
-rw-r--r-- | httemplate/elements/select-pkg_class.html | 4 | ||||
-rw-r--r-- | httemplate/elements/select-table.html | 114 | ||||
-rw-r--r-- | httemplate/elements/tr-select-pkg_class.html | 8 | ||||
-rw-r--r-- | httemplate/search/elements/search.html | 88 |
7 files changed, 161 insertions, 77 deletions
diff --git a/httemplate/browse/pkg_class.html b/httemplate/browse/pkg_class.html index 3ec5e559b..68cf49275 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 181072f71..6f2b072f1 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 efcc477af..670b70c7c 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 0d8e6ac84..8e873ed66 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 83445f41a..0c3c00563 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 7f37e816e..542142466 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 689cbe389..c6d0bb68b 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'}) |