v4 style
[freeside.git] / httemplate / elements / search-svc_broadband.html
1 <%doc>
2
3 Example:
4
5   include( '/elements/search-svc_broadband.html,
6              'field'       => 'svcnum',
7              #slightly deprecated old synonym for field#'field_name'=>'svcnum',
8              'find_button' => 1, #add a "find" button to the field
9              'curr_value'  => 54, #current value
10              'value        => 32, #deprecated synonym for curr_value
11   );
12
13 </%doc>
14 <INPUT TYPE="hidden" NAME="<% $field %>" ID="<% $field %>" VALUE="<% $value %>">
15
16 <!-- some false laziness w/ misc/batch-cust_pay.html, though not as bad as i'd thought at first... -->
17
18 <INPUT TYPE = "text"
19        NAME = "<% $field %>_search"
20        ID   = "<% $field %>_search"
21        SIZE = "32"
22        VALUE="<% $svc_broadband ? $svc_broadband->label : '(svcnum, ip or mac)' %>"
23        onFocus="clearhint_<% $field %>_search(this);"
24        onClick="clearhint_<% $field %>_search(this);"
25        onChange="smart_<% $field %>_search(this);"
26 >
27
28 % if ( $opt{'find_button'} ) {
29     <INPUT TYPE    = "button"
30            VALUE   = 'Find',
31            NAME    = "<% $field %>_findbutton"
32            onClick = "smart_<% $field %>_search(this.form.<% $field %>_search);"
33     >
34 % }
35
36 <SELECT NAME="<% $field %>_select" ID="<% $field %>_select" STYLE="color:#ff0000; display:none" onChange="select_<% $field %>(this);">
37 </SELECT>
38
39 <% include('/elements/xmlhttp.html',
40               'url'  => $p. 'misc/xmlhttp-svc_broadband-search.cgi',
41               'subs' => [ 'smart_search' ],
42            )
43 %>
44
45 <SCRIPT TYPE="text/javascript">
46
47   function clearhint_<% $field %>_search (what) {
48
49     what.style.color = '#000000';
50
51     if ( what.value == '(svcnum, ip or mac)' )
52       what.value = '';
53
54     if ( what.value.indexOf('Service not found: ') == 0 )
55       what.value = what.value.substr(20);
56
57   }
58
59   var <% $field %>_search_active = false;
60
61   function smart_<% $field %>_search(what) {
62
63     if ( <% $field %>_search_active )
64       return;
65
66     var service = what.value;
67
68     if ( service == 'searching...' || service == ''
69          || service.indexOf('Service not found: ') == 0 )
70       return;
71
72     if ( what.getAttribute('magic') == 'nosearch' ) {
73       what.setAttribute('magic', '');
74       return;
75     }
76
77     //what.value = 'searching...'
78     what.disabled = true;
79     what.style.color= '#000000';
80     what.style.backgroundColor = '#dddddd';
81
82     var service_select = document.getElementById('<% $field %>_select');
83
84     //alert("search for customer " + customer);
85
86     function <% $field %>_search_update(services) {
87
88       //alert('customers returned: ' + customers);
89
90       var serviceArray = eval('(' + services + ')');
91
92       what.disabled = false;
93       what.style.backgroundColor = '#ffffff';
94
95       if ( serviceArray.length == 0 ) {
96
97         what.form.<% $field %>.value = '';
98
99         what.value = 'Service not found: ' + what.value;
100         what.style.color = '#ff0000';
101
102         what.style.display = '';
103         service_select.style.display = 'none';
104
105       } else if ( serviceArray.length == 1 ) {
106
107         //alert('one customer found: ' + customerArray[0]);
108
109         what.form.<% $field %>.value = serviceArray[0][0];
110         what.value = serviceArray[0][1];
111
112         what.style.display = '';
113         service_select.style.display = 'none';
114
115       } else {
116
117         //alert('multiple customers found, have to create select dropdown');
118
119         //blank the current list
120         for ( var i = service_select.length; i >= 0; i-- )
121           service_select.options[i] = null;
122
123         opt(service_select, '', 'Multiple services match "' + service + '" - select one', '#ff0000');
124
125         //add the multiple services
126         for ( var s = 0; s < serviceArray.length; s++ )
127           opt(service_select, serviceArray[s][0], serviceArray[s][1], '#000000');
128
129         opt(service_select, 'cancel', '(Edit search string)', '#000000');
130
131         what.style.display = 'none';
132         service_select.style.display = '';
133
134       }
135
136       <% $field %>_search_active = false;
137
138     }
139
140     <% $field %>_search_active = true;
141
142     smart_search( service, <% $field %>_search_update );
143
144
145   }
146
147   function select_<% $field %> (what) {
148
149     var svcnum = what.options[what.selectedIndex].value;
150     var service = what.options[what.selectedIndex].text;
151
152     var service_obj = document.getElementById('<% $field %>_search');
153
154     if ( svcnum == '' ) {
155       //what.style.color = '#ff0000';
156
157     } else if ( svcnum == 'cancel' ) {
158
159       service_obj.style.color = '#000000';
160
161       what.style.display = 'none';
162       service_obj.style.display = '';
163       service_obj.focus();
164
165     } else {
166     
167       what.form.<% $field %>.value = svcnum;
168
169       service_obj.value = service;
170       service_obj.style.color = '#000000';
171
172       what.style.display = 'none';
173       service_obj.style.display = '';
174
175     }
176
177   }
178
179   function opt(what,value,text,color) {
180     var optionName = new Option(text, value, false, false);
181     optionName.style.color = color;
182     var length = what.length;
183     what.options[length] = optionName;
184   }
185
186 </SCRIPT>
187 <%init>
188
189 my( %opt ) = @_;
190
191 my $field = $opt{'field'} || $opt{'field_name'} || 'svcnum';
192
193 my $value = $opt{'curr_value'} || $opt{'value'};
194
195 my $svc_broadband = '';
196 if ( $value ) {
197   $svc_broadband = qsearchs({
198     'table'     => 'svc_broadband',
199     'hashref'   => { 'svcnum' => $value },
200     #have to join to cust_main for an agentnum 'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql,
201   });
202 }
203
204 </%init>