summaryrefslogtreecommitdiff
path: root/httemplate/elements/select-taxproduct.html
blob: d08ac22d1a9e03645b62f71e77f26db8c261b262 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
% if (!$init) {
%   $init = 1;
<STYLE TYPE="text/css">
.ui-autocomplete-loading {
  background-color: silver;
}
ul.ui-autocomplete li.ui-menu-item {
  font-size: 0.8em;
  padding: 2px;
}
ul.ui-autocomplete li.ui-state-focus {
  font-weight: normal;
  color: #7e0079;
  background-color: inherit;
  border: 1px solid #7e0079;
}
</STYLE>
<SCRIPT TYPE="text/javascript">
$().ready(function() {
  $('input.taxproduct_desc').autocomplete({
    source: '<% $fsurl %>misc/taxproduct.cgi',
    minLength: 3,
    autoFocus: true,
    response: function( event, ui ) {
      // if there's only one choice (user entered an exact taxproduct) then
      // select it
      if ( ui.content.length == 1 ) {
        var input_taxproductnum = $(this).siblings('.taxproductnum')
        var item = ui.content[0];
        $(this).val(item.label);
        input_taxproductnum.val(item.value);
      }
    },
    focus: function( event, ui ) {
      return false;
    },
    select: function( event, ui ) {
      // find the hidden input for the taxproductnum
      var input_taxproductnum = $(this).siblings('.taxproductnum')
      if ( ui.item ) {
        $(this).val(ui.item.label);
        input_taxproductnum.val(ui.item.value);
        return false; // don't store item.value in this input
      } else {
        input_taxproductnum.val('');
      }
    },
    change: function( event, ui ) {
      var input_taxproductnum = $(this).siblings('.taxproductnum')
      if ( $(this).val() == '' ) {
        input_taxproductnum.val('');
      }
    }
  });
});
</SCRIPT>
% }
<% $opt{'prefix'} %>
<INPUT NAME    = "<% $name %>"
       ID      = "<% $name %>"
       TYPE    = "hidden"
       VALUE   = "<% $value |h %>"
       CLASS   = "taxproductnum"
>
<INPUT NAME    = "<% $name %>_description"
       ID      = "<% $name %>_description"
       TYPE    = "text"
       VALUE   = "<% $description %>"
       SIZE    = "50"
       CLASS   = "taxproduct_desc" 
>
<BUTTON STYLE="padding: 0" onclick="<% $onclick %>">...</BUTTON>
<% $opt{'postfix'} %>
<%shared>
my $init = 0;
</%shared>
<%init>

my %opt = @_;
my $name = $opt{element_name} || $opt{field} || 'taxproductnum';
my $value = length($opt{curr_value}) ? $opt{curr_value} : $opt{value};
my $description = $opt{'taxproduct_description'};
  
unless ( $description || ! $value ) {
    my $part_pkg_taxproduct =
      qsearchs( 'part_pkg_taxproduct', { 'taxproductnum'=> $value } );
    $description = $part_pkg_taxproduct->taxproduct . ' ' .
                   $part_pkg_taxproduct->description
      if $part_pkg_taxproduct;
}

my $conf = FS::Conf->new;
my $vendor = lc($conf->config('tax_data_vendor'));
my $onclick = $opt{onclick} ||
              "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;";

</%init>