summaryrefslogtreecommitdiff
path: root/httemplate/elements/search-svc_broadband.html
blob: d83516172c8b5dd1ee1a9b869a49e8fe65c4fe81 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<%doc>

Example:

  include( '/elements/search-svc_broadband.html,
             'field'       => 'svcnum',
             #slightly deprecated old synonym for field#'field_name'=>'svcnum',
             'find_button' => 1, #add a "find" button to the field
             'curr_value'  => 54, #current value
             'value        => 32, #deprecated synonym for curr_value
  );

</%doc>
<INPUT TYPE="hidden" NAME="<% $field %>" ID="<% $field %>" VALUE="<% $value %>">

<!-- some false laziness w/ misc/batch-cust_pay.html, though not as bad as i'd thought at first... -->

<INPUT TYPE = "text"
       NAME = "<% $field %>_search"
       ID   = "<% $field %>_search"
       SIZE = "32"
       VALUE="<% $svc_broadband ? $svc_broadband->label : '(svcnum, ip or mac)' %>"
       onFocus="clearhint_<% $field %>_search(this);"
       onClick="clearhint_<% $field %>_search(this);"
       onChange="smart_<% $field %>_search(this);"
>

% if ( $opt{'find_button'} ) {
    <INPUT TYPE    = "button"
           VALUE   = 'Find',
           NAME    = "<% $field %>_findbutton"
           onClick = "smart_<% $field %>_search(this.form.<% $field %>_search);"
    >
% }

<SELECT NAME="<% $field %>_select" ID="<% $field %>_select" STYLE="color:#ff0000; display:none" onChange="select_<% $field %>(this);">
</SELECT>

<% include('/elements/xmlhttp.html',
              'url'  => $p. 'misc/xmlhttp-svc_broadband-search.cgi',
              'subs' => [ 'smart_search' ],
           )
%>

<SCRIPT TYPE="text/javascript">

  function clearhint_<% $field %>_search (what) {

    what.style.color = '#000000';

    if ( what.value == '(svcnum, ip or mac)' )
      what.value = '';

    if ( what.value.indexOf('Service not found: ') == 0 )
      what.value = what.value.substr(20);

  }

  var <% $field %>_search_active = false;

  function smart_<% $field %>_search(what) {

    if ( <% $field %>_search_active )
      return;

    var service = what.value;

    if ( service == 'searching...' || service == ''
         || service.indexOf('Service not found: ') == 0 )
      return;

    if ( what.getAttribute('magic') == 'nosearch' ) {
      what.setAttribute('magic', '');
      return;
    }

    //what.value = 'searching...'
    what.disabled = true;
    what.style.color= '#000000';
    what.style.backgroundColor = '#dddddd';

    var service_select = document.getElementById('<% $field %>_select');

    //alert("search for customer " + customer);

    function <% $field %>_search_update(services) {

      //alert('customers returned: ' + customers);

      var serviceArray = eval('(' + services + ')');

      what.disabled = false;
      what.style.backgroundColor = '#ffffff';

      if ( serviceArray.length == 0 ) {

        what.form.<% $field %>.value = '';

        what.value = 'Service not found: ' + what.value;
        what.style.color = '#ff0000';

        what.style.display = '';
        service_select.style.display = 'none';

      } else if ( serviceArray.length == 1 ) {

        //alert('one customer found: ' + customerArray[0]);

        what.form.<% $field %>.value = serviceArray[0][0];
        what.value = serviceArray[0][1];

        what.style.display = '';
        service_select.style.display = 'none';

      } else {

        //alert('multiple customers found, have to create select dropdown');

        //blank the current list
        for ( var i = service_select.length; i >= 0; i-- )
          service_select.options[i] = null;

        opt(service_select, '', 'Multiple services match "' + service + '" - select one', '#ff0000');

        //add the multiple services
        for ( var s = 0; s < serviceArray.length; s++ )
          opt(service_select, serviceArray[s][0], serviceArray[s][1], '#000000');

        opt(service_select, 'cancel', '(Edit search string)', '#000000');

        what.style.display = 'none';
        service_select.style.display = '';

      }

      <% $field %>_search_active = false;

    }

    <% $field %>_search_active = true;

    smart_search( service, <% $field %>_search_update );


  }

  function select_<% $field %> (what) {

    var svcnum = what.options[what.selectedIndex].value;
    var service = what.options[what.selectedIndex].text;

    var service_obj = document.getElementById('<% $field %>_search');

    if ( svcnum == '' ) {
      //what.style.color = '#ff0000';

    } else if ( svcnum == 'cancel' ) {

      service_obj.style.color = '#000000';

      what.style.display = 'none';
      service_obj.style.display = '';
      service_obj.focus();

    } else {
    
      what.form.<% $field %>.value = svcnum;

      service_obj.value = service;
      service_obj.style.color = '#000000';

      what.style.display = 'none';
      service_obj.style.display = '';

    }

  }

  function opt(what,value,text,color) {
    var optionName = new Option(text, value, false, false);
    optionName.style.color = color;
    var length = what.length;
    what.options[length] = optionName;
  }

</SCRIPT>
<%init>

my( %opt ) = @_;

my $field = $opt{'field'} || $opt{'field_name'} || 'svcnum';

my $value = $opt{'curr_value'} || $opt{'value'};

my $svc_broadband = '';
if ( $value ) {
  $svc_broadband = qsearchs({
    'table'     => 'svc_broadband',
    'hashref'   => { 'svcnum' => $value },
    #have to join to cust_main for an agentnum 'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql,
  });
}

</%init>