Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / httemplate / elements / select-taxproduct.html
1 % if (!$init) {
2 %   $init = 1;
3 <STYLE TYPE="text/css">
4 .ui-autocomplete-loading {
5   background-color: silver;
6 }
7 ul.ui-autocomplete li.ui-menu-item {
8   font-size: 0.8em;
9   padding: 2px;
10 }
11 ul.ui-autocomplete li.ui-state-focus {
12   font-weight: normal;
13   color: #7e0079;
14   background-color: inherit;
15   border: 1px solid #7e0079;
16 }
17 </STYLE>
18 <SCRIPT TYPE="text/javascript">
19 $().ready(function() {
20   $('input.taxproduct_desc').autocomplete({
21     source: '<% $fsurl %>misc/taxproduct.cgi',
22     minLength: 3,
23     autoFocus: true,
24     response: function( event, ui ) {
25       // if there's only one choice (user entered an exact taxproduct) then
26       // select it
27       if ( ui.content.length == 1 ) {
28         var input_taxproductnum = $(this).siblings('.taxproductnum')
29         var item = ui.content[0];
30         $(this).val(item.label);
31         input_taxproductnum.val(item.value);
32       }
33     },
34     focus: function( event, ui ) {
35       return false;
36     },
37     select: function( event, ui ) {
38       // find the hidden input for the taxproductnum
39       var input_taxproductnum = $(this).siblings('.taxproductnum')
40       if ( ui.item ) {
41         $(this).val(ui.item.label);
42         input_taxproductnum.val(ui.item.value);
43         return false; // don't store item.value in this input
44       } else {
45         input_taxproductnum.val('');
46       }
47     },
48     change: function( event, ui ) {
49       var input_taxproductnum = $(this).siblings('.taxproductnum')
50       if ( $(this).val() == '' ) {
51         input_taxproductnum.val('');
52       }
53     }
54   });
55 });
56 </SCRIPT>
57 % }
58 <% $opt{'prefix'} %>
59 <INPUT NAME    = "<% $name %>"
60        ID      = "<% $name %>"
61        TYPE    = "hidden"
62        VALUE   = "<% $value |h %>"
63        CLASS   = "taxproductnum"
64 >
65 <INPUT NAME    = "<% $name %>_description"
66        ID      = "<% $name %>_description"
67        TYPE    = "text"
68        VALUE   = "<% $description %>"
69        SIZE    = "50"
70        CLASS   = "taxproduct_desc" 
71 >
72 <BUTTON STYLE="padding: 0" onclick="<% $onclick %>">...</BUTTON>
73 <% $opt{'postfix'} %>
74 <%shared>
75 my $init = 0;
76 </%shared>
77 <%init>
78
79 my %opt = @_;
80 my $name = $opt{element_name} || $opt{field} || 'taxproductnum';
81 my $value = length($opt{curr_value}) ? $opt{curr_value} : $opt{value};
82 my $description = $opt{'taxproduct_description'};
83   
84 unless ( $description || ! $value ) {
85     my $part_pkg_taxproduct =
86       qsearchs( 'part_pkg_taxproduct', { 'taxproductnum'=> $value } );
87     $description = $part_pkg_taxproduct->taxproduct . ' ' .
88                    $part_pkg_taxproduct->description
89       if $part_pkg_taxproduct;
90 }
91
92 my $conf = FS::Conf->new;
93 my $vendor = lc($conf->config('tax_data_vendor'));
94 my $onclick = $opt{onclick} ||
95               "overlib( OLiframeContent('${p}/browse/part_pkg_taxproduct/$vendor.html?_type=select&id=${name}&taxproductnum='+document.getElementById('${name}').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;";
96
97 </%init>