From 64aec88c35418b8c630811cdf5afb19b2a1c4299 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 25 Aug 2016 15:06:45 -0700 Subject: [PATCH] usability: customer tags with checkboxes instead of a select-multiple --- httemplate/edit/cust_main.cgi | 2 -- httemplate/edit/cust_main/basics.html | 1 + httemplate/edit/process/cust_main.cgi | 7 ++++++- httemplate/elements/checkboxes-table.html | 18 +++++++++--------- httemplate/elements/select-cust_tag.html | 13 +++++++------ httemplate/elements/tr-select-cust_tag.html | 4 ++-- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index b314d2d6e..3ba1e859b 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -303,8 +303,6 @@ if ( $cgi->param('error') ) { $ss = ''; $stateid = ''; - $cgi->param('tagnum', FS::part_tag->default_tags); - if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) { my $qualnum = $1; my $qual = qsearchs('qual', { 'qualnum' => $qualnum } ) diff --git a/httemplate/edit/cust_main/basics.html b/httemplate/edit/cust_main/basics.html index c3768ac42..a30d7f88c 100644 --- a/httemplate/edit/cust_main/basics.html +++ b/httemplate/edit/cust_main/basics.html @@ -123,6 +123,7 @@ %# tags <& /elements/tr-select-cust_tag.html, 'custnum' => $custnum, + 'default' => { map { $_=>1 } FS::part_tag->default_tags }, 'cgi' => $cgi, &> diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi index 74f8f2382..2cb1648f7 100755 --- a/httemplate/edit/process/cust_main.cgi +++ b/httemplate/edit/process/cust_main.cgi @@ -109,7 +109,12 @@ if ( $cgi->param('no_credit_limit') ) { $new->setfield('credit_limit', ''); } -$new->tagnum( [ $cgi->param('tagnum') ] ); +#$new->tagnum( [ $cgi->param('tagnum') ] ); +my $params = $cgi->Vars; +$new->tagnum( [ + map { /^tagnum(\d+)/ && $1 } + grep { /^tagnum(\d+)/ && $cgi->param($_) } keys %$params +] ); $error ||= $new->set_national_id_from_cgi( $cgi ); diff --git a/httemplate/elements/checkboxes-table.html b/httemplate/elements/checkboxes-table.html index 671cd1f9b..d3bbab430 100644 --- a/httemplate/elements/checkboxes-table.html +++ b/httemplate/elements/checkboxes-table.html @@ -69,6 +69,7 @@ % 'select' => $opt{'target_table'}. '.*', % 'addl_from' => "LEFT JOIN $opt{'link_table'} USING ( $target_pkey )", % 'extra_sql' => $extra_sql, +% 'order_by' => $opt{'order_by'}, % }) % ) { % @@ -83,7 +84,11 @@ % % } elsif ( !$sourcenum ) { # newly created object, has no links yet % -% $checked = $opt{'default'} ? 'CHECKED' : '' +% if ( ref($opt{'default'}) ) { +% $checked = $opt{'default'}->{$targetnum} ? 'CHECKED' : ''; +% } else { +% $checked = $opt{'default'} ? 'CHECKED' : '' +% } % % } else { % @@ -98,17 +103,12 @@ % % - - VALUE="ON"> +% my $color_col = $opt{'color_col'}; + VALUE="ON">
% if ( $opt{'target_link'} ) { - - -% -% % } % -<% $targetnum %>: % if ( $opt{'name_callback'} ) { @@ -118,7 +118,7 @@ % - <% $target_obj->$name_col() %><% $opt{'target_link'} ? '' : '' %> + <% $target_obj->$name_col() %>
<% $opt{'target_link'} ? '' : '' %> % } % if ( $opt{'disable-able'} ) { diff --git a/httemplate/elements/select-cust_tag.html b/httemplate/elements/select-cust_tag.html index 61d4dca3b..02f849850 100644 --- a/httemplate/elements/select-cust_tag.html +++ b/httemplate/elements/select-cust_tag.html @@ -1,11 +1,12 @@ -<% include( '/elements/select-table.html', - 'table' => 'part_tag', +<% include( '/elements/checkboxes-table.html', + 'target_table' => 'part_tag', + 'link_table' => 'cust_tag', 'name_col' => 'tagname', #tagname - tagdesc?? - 'multiple' => 1, - #'value' => $agentnum || '', - #'agent_virt' => 1, - 'hashref' => { 'disabled' => '' }, + 'color_col' => 'tagcolor', + 'disable-able' => 1, 'order_by' => ' ORDER BY tagname', + 'source_table' => 'cust_main', + 'sourcenum' => $opt{'custnum'}, %opt, ) %> diff --git a/httemplate/elements/tr-select-cust_tag.html b/httemplate/elements/tr-select-cust_tag.html index b133dcc15..711408e27 100644 --- a/httemplate/elements/tr-select-cust_tag.html +++ b/httemplate/elements/tr-select-cust_tag.html @@ -4,8 +4,6 @@ <% $opt{'label'} || 'Tags' %> <% include( '/elements/select-cust_tag.html', - 'curr_value' => \@curr_tagnum, - 'part_tag' => \@part_tag, %opt, ) %> @@ -38,6 +36,8 @@ if ( $cgi && $cgi->param('tagnum') ) { my $extra_sql = "WHERE disabled IS NULL OR disabled = '' "; $extra_sql .= ' OR tagnum IN ('. join(',', @curr_tagnum). ')' if @curr_tagnum; +#now kind of inefficient (we only want to know if there are any), but since +# its an edit control its not significant my @part_tag = qsearch({ 'table' => 'part_tag', 'hashref' => {}, -- 2.11.0