From c2833f823676e017f2f693364d56d86c49592028 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 13 Apr 2008 20:35:10 +0000 Subject: [PATCH] select-table and select-part_pkg updates so we can use select-part_pkg as an edit/elements/edit.html m2 type --- httemplate/elements/select-cust-part_pkg.html | 25 +++------------ httemplate/elements/select-part_pkg.html | 34 +++++++++++++++++++++ httemplate/elements/select-table.html | 1 + httemplate/elements/tr-select-part_pkg.html | 44 ++++++++++++++++----------- 4 files changed, 66 insertions(+), 38 deletions(-) create mode 100644 httemplate/elements/select-part_pkg.html diff --git a/httemplate/elements/select-cust-part_pkg.html b/httemplate/elements/select-cust-part_pkg.html index 8b446b95d..57da5cd84 100644 --- a/httemplate/elements/select-cust-part_pkg.html +++ b/httemplate/elements/select-cust-part_pkg.html @@ -18,14 +18,9 @@ Example: -<% include( '/elements/select-table.html', - 'table' => 'part_pkg', - 'name_col' => 'pkg', - 'empty_label' => 'Select package', - 'label_callback' => sub { $_[0]->pkgpart. ': '. - $_[0]->pkg. ' - '. - $_[0]->comment; - }, +<% include( '/elements/select-part_pkg.html', + 'empty_label' => 'Select package', #? need here in case removed + #from select-part_pkg ?? %opt, ) %> @@ -36,21 +31,9 @@ my( %opt ) = @_; my $cust_main = $opt{'cust_main'} or die "cust_main not specified"; -$opt{'records'} = delete $opt{'part_pkg'} - if $opt{'part_pkg'}; - -my $extra_sql = $opt{'extra_sql'}. +$opt{'extra_sql'} .= ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '. ' WHERE typenum = '. $cust_main->agent->typenum. ' AND type_pkgs.pkgpart = part_pkg.pkgpart )'; -$opt{'records'} ||= [ qsearch({ - 'table' => 'part_pkg', - 'hashref' => { 'disabled' => '', }, - 'extra_sql' => "$extra_sql ORDER BY pkg", - #'extra_sql' => $extra_sql, - #'order_by' => 'ORDER BY pkg', - }) - ]; - diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html new file mode 100644 index 000000000..a1d5f40f2 --- /dev/null +++ b/httemplate/elements/select-part_pkg.html @@ -0,0 +1,34 @@ +<%doc> + +Example: + + include( '/elements/select-part_pkg.html', + + #strongly recommended (you want your forms to be "sticky" on errors, right?) + 'curr_value' => 'current_value', + + #opt + 'part_pkg' => \@records, + + #select-table.html options + ) + + + +<% include( '/elements/select-table.html', + 'table' => 'part_pkg', + 'name_col' => 'pkg', + 'empty_label' => 'Select package', #should this be the default? + 'label_callback' => sub { shift->pkg_comment }, + 'hashref' => { 'disabled' => '' }, + %opt, + ) +%> +<%init> + +my( %opt ) = @_; + +$opt{'records'} = delete $opt{'part_pkg'} + if $opt{'part_pkg'}; + + diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html index 5d6c4a82c..7339f362c 100644 --- a/httemplate/elements/select-table.html +++ b/httemplate/elements/select-table.html @@ -100,6 +100,7 @@ if ( $opt{'records'} ) { 'table' => $opt{'table'}, 'hashref' => ( $opt{'hashref'} || {} ), 'extra_sql' => ( $opt{'extra_sql'} || '' ), + 'order_by' => ( $opt{'order_by'} || "ORDER BY $name_col" ), }); } diff --git a/httemplate/elements/tr-select-part_pkg.html b/httemplate/elements/tr-select-part_pkg.html index b6d4d4d9e..db9afd2df 100644 --- a/httemplate/elements/tr-select-part_pkg.html +++ b/httemplate/elements/tr-select-part_pkg.html @@ -1,29 +1,39 @@ -% if ( scalar(@{ $opt{'part_pkg'} }) == 0 ) { +% if ( $opt{'part_pkg'} && scalar(@{ $opt{'part_pkg'} }) == 0 ) { +% unless ( $opt{'js_only'} ) { - + +% } +% % } else { +% +% unless ( $opt{'js_only'} ) { - - <% $opt{'label'} || 'Package definition' %> - - <% include( '/elements/select-table.html', - 'table' => 'part_pkg', - 'name_col' => 'pkg', - 'multiple' => 1, - #N/A 'empty_label' => '(none)', - %opt, - ) - %> - - + <% include('tr-td-label.html', %opt) %> + > -% } +% } +% + <% include( '/elements/select-part_pkg.html', %opt ) %> +% +% unless ( $opt{'js_only'} ) { + + + +% } +% +% } <%init> my( %opt ) = @_; -$opt{'part_pkg'} ||= [ qsearch( 'part_pkg', {} ) ]; # { disabled=>'' } ) +my $cell_style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : ''; + +$opt{'label'} ||= 'Package definition'; + +#taken care of (better) in select-part_pkg now (is there anything using this +# that needs to override the disabed=>'' ??) +#$opt{'part_pkg'} ||= [ qsearch( 'part_pkg', {} ) ]; # { disabled=>'' } ) -- 2.11.0