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/elements | |
parent | 7b5280c065aaa4887ce4e36fb4be7a80a74a8392 (diff) |
add ability to disable package classes
Diffstat (limited to 'httemplate/elements')
-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 |
4 files changed, 68 insertions, 60 deletions
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> -% } +% } |