1 | var participantsClone = null; |
---|
2 | var chkOnlyVisibleAccountsClone = null; |
---|
3 | var searchTimer = null; |
---|
4 | var globalSearchEnter = true; |
---|
5 | |
---|
6 | function callAjax(action, mode, handler, parameters) |
---|
7 | { |
---|
8 | var url = '$this.' + action + '.' + mode; |
---|
9 | if (parameters) |
---|
10 | cExecute(url, handler, $H(parameters).toQueryString()); |
---|
11 | else |
---|
12 | cExecute(url, handler); |
---|
13 | } |
---|
14 | |
---|
15 | function getSectors() |
---|
16 | { |
---|
17 | function resultGetSectors(data) |
---|
18 | { |
---|
19 | setSelectValue($('sector'), data['sectors']); |
---|
20 | $('sector').onchange = getParticipants; |
---|
21 | resultGetParticipants(data['participants']); |
---|
22 | } |
---|
23 | |
---|
24 | var params = { |
---|
25 | organization: $F('organization'), |
---|
26 | onlyVisibleAccounts: $F('onlyVisibleAccounts'), |
---|
27 | entities: $F('entities'), |
---|
28 | id: $F('id'), |
---|
29 | usePreffix: $F('usePreffix') |
---|
30 | }; |
---|
31 | callAjax('bo_participants', 'getSectors', resultGetSectors, params); |
---|
32 | } |
---|
33 | |
---|
34 | function getParticipants() |
---|
35 | { |
---|
36 | var params = { |
---|
37 | context: $F('sector'), |
---|
38 | onlyVisibleAccounts: $F('onlyVisibleAccounts'), |
---|
39 | entities: $F('entities'), |
---|
40 | id: $F('id'), |
---|
41 | usePreffix: $F('usePreffix') |
---|
42 | }; |
---|
43 | callAjax('bo_participants', 'getEntities', resultGetParticipants, params); |
---|
44 | } |
---|
45 | |
---|
46 | function resultGetParticipants(data) |
---|
47 | { |
---|
48 | $('search').value = ''; |
---|
49 | setSelectValue($('participants'), data); |
---|
50 | participantsClone = data; |
---|
51 | if($('onlyVisibleAccounts')) |
---|
52 | chkOnlyVisibleAccountsClone = $('onlyVisibleAccounts').checked; |
---|
53 | } |
---|
54 | |
---|
55 | function searchParticipantsTimer(e) |
---|
56 | { |
---|
57 | if (checkShortcuts((e) ? e : window.event)) |
---|
58 | return true; |
---|
59 | |
---|
60 | if (searchTimer) |
---|
61 | clearTimeout(searchTimer); |
---|
62 | |
---|
63 | searchTimer = setTimeout(function(){searchParticipants($F('search'));}, 250); |
---|
64 | } |
---|
65 | |
---|
66 | function searchParticipants(searchString) |
---|
67 | { |
---|
68 | var reg = new RegExp("<option[^>]*>[^<]*" + searchString + "[^<]*<\/option>", "gi"); |
---|
69 | setSelectValue($('participants'), participantsClone.match(reg)); |
---|
70 | if($('onlyVisibleAccounts')) |
---|
71 | $('onlyVisibleAccounts').checked = chkOnlyVisibleAccountsClone; |
---|
72 | |
---|
73 | var participants = $('participants'); |
---|
74 | if (participants.options[0]) |
---|
75 | participants.selectedIndex = 0; |
---|
76 | } |
---|
77 | |
---|
78 | function checkShortcuts(e) |
---|
79 | { |
---|
80 | var whichCode = (e.which) ? e.which : e.keyCode; |
---|
81 | var handled = false; |
---|
82 | |
---|
83 | if (whichCode == 13) /* ENTER */ |
---|
84 | { |
---|
85 | $('addUserLink').onclick(); |
---|
86 | handled = true; |
---|
87 | } |
---|
88 | |
---|
89 | if (whichCode == 27) /* ESC */ |
---|
90 | { |
---|
91 | $('exitLink').onclick(); |
---|
92 | handled = true; |
---|
93 | } |
---|
94 | |
---|
95 | if (whichCode == 38) /* key up */ |
---|
96 | { |
---|
97 | var participants = $('participants'); |
---|
98 | if (participants.selectedIndex > 0) |
---|
99 | if (!participants[participants.selectedIndex - 1].disabled) |
---|
100 | participants.selectedIndex--; |
---|
101 | handled = true; |
---|
102 | } |
---|
103 | |
---|
104 | if (whichCode == 40) /* key down */ |
---|
105 | { |
---|
106 | var participants = $('participants'); |
---|
107 | if (participants.selectedIndex < participants.length - 1) |
---|
108 | if (!participants[participants.selectedIndex + 1].disabled) |
---|
109 | participants.selectedIndex++; |
---|
110 | handled = true; |
---|
111 | } |
---|
112 | |
---|
113 | return handled; |
---|
114 | } |
---|
115 | |
---|
116 | if (Event.observe) |
---|
117 | { |
---|
118 | Event.observe(window, 'load', function() { |
---|
119 | if (typeof Prototype == 'undefined') |
---|
120 | return; |
---|
121 | /* atribui as ações aos eventos */ |
---|
122 | var obj = $('organization'); |
---|
123 | if (obj) |
---|
124 | obj.onchange = getSectors; |
---|
125 | |
---|
126 | obj = $('sector'); |
---|
127 | if (obj) |
---|
128 | obj.onchange = getParticipants; |
---|
129 | |
---|
130 | obj = $('search'); |
---|
131 | if (obj) |
---|
132 | obj.onkeydown = searchParticipantsTimer; |
---|
133 | |
---|
134 | obj = $('participants'); |
---|
135 | if (obj){ |
---|
136 | participantsClone = obj.innerHTML; |
---|
137 | if($('onlyVisibleAccounts')) |
---|
138 | chkOnlyVisibleAccountsClone = $('onlyVisibleAccounts').checked; |
---|
139 | } |
---|
140 | |
---|
141 | obj = $('exitLink'); |
---|
142 | if (obj) |
---|
143 | obj.onclick = function(){window.close();}; |
---|
144 | |
---|
145 | obj = $('addUserLink'); |
---|
146 | if (obj) |
---|
147 | obj.onclick = addUser; |
---|
148 | |
---|
149 | obj = $('search'); |
---|
150 | if (obj) |
---|
151 | obj.focus(); |
---|
152 | |
---|
153 | obj = $('onlyVisibleAccounts'); |
---|
154 | if (obj) |
---|
155 | obj.onclick = checkOnlyVisibleAccounts; |
---|
156 | |
---|
157 | obj = $('useGlobalSearch'); |
---|
158 | if (obj) |
---|
159 | { |
---|
160 | obj.onclick = toggleFullSearch; |
---|
161 | toggleFullSearch(); |
---|
162 | } |
---|
163 | }); |
---|
164 | }; |
---|
165 | |
---|
166 | function checkOnlyVisibleAccounts() |
---|
167 | { |
---|
168 | if(!$('useGlobalSearch').checked) |
---|
169 | getParticipants(); |
---|
170 | else |
---|
171 | toggleFullSearch(); |
---|
172 | } |
---|
173 | |
---|
174 | function participantsFilterName(name) |
---|
175 | { |
---|
176 | if (!$('useGlobalSearch').checked) |
---|
177 | return name; |
---|
178 | |
---|
179 | return name.substr(0, name.lastIndexOf('(') - 1); |
---|
180 | } |
---|
181 | |
---|
182 | function addUser() |
---|
183 | { |
---|
184 | var participants = $('participants'); |
---|
185 | var target = window.opener.document.getElementById($F('target')); |
---|
186 | var previous = ''; |
---|
187 | var current = ''; |
---|
188 | |
---|
189 | if ((target.tagName == 'INPUT') || (target.tagName == 'TEXTAREA')) |
---|
190 | { |
---|
191 | previous = target.value; |
---|
192 | if ($F('id') == 'mail') |
---|
193 | { |
---|
194 | var participantsLength = participants.options.length; |
---|
195 | var current = null; |
---|
196 | for (var i = 0; i < participantsLength; i++) |
---|
197 | { |
---|
198 | current = participants.options[i]; |
---|
199 | if (current.selected) |
---|
200 | target.value += '"' + participantsFilterName(current.text) + '" ' + '<' + current.value + '>, '; |
---|
201 | } |
---|
202 | } |
---|
203 | else |
---|
204 | { |
---|
205 | if (participants.selectedIndex > -1) |
---|
206 | { |
---|
207 | target.value = participants.options[participants.selectedIndex].value.replace('u',''); |
---|
208 | window.opener.document.getElementById(target.id + '_desc').value = participantsFilterName(participants.options[participants.selectedIndex].text); |
---|
209 | } |
---|
210 | } |
---|
211 | current = target.value; |
---|
212 | } |
---|
213 | else |
---|
214 | { |
---|
215 | previous = target.innerHTML; |
---|
216 | var options = ''; |
---|
217 | var participantsLength = participants.options.length; |
---|
218 | var current = null; |
---|
219 | var insertElement; |
---|
220 | for (var i = 0; i < participantsLength; i++) |
---|
221 | { |
---|
222 | current = participants.options[i]; |
---|
223 | if (current.selected) |
---|
224 | { |
---|
225 | /* checa se o elemento que será inserido já existe na select box destino */ |
---|
226 | insertElement = true; |
---|
227 | for (var j = 0; j < target.options.length; j++) |
---|
228 | if (target.options[j].value == current.value) |
---|
229 | { |
---|
230 | insertElement = false; |
---|
231 | break; |
---|
232 | } |
---|
233 | if (insertElement) |
---|
234 | options += '<option value="' + current.value + '">' + participantsFilterName(current.text) + '</option>'; |
---|
235 | } |
---|
236 | } |
---|
237 | if (options.length > 0) |
---|
238 | { |
---|
239 | setSelectValue(target, target.innerHTML + options); |
---|
240 | /* refaz o link que se perde quando modifica-se o innerHTML da select box */ |
---|
241 | target = window.opener.document.getElementById($F('target')); |
---|
242 | } |
---|
243 | current = target.innerHTML; |
---|
244 | } |
---|
245 | |
---|
246 | /* se o código do desenvolvedor está esperando o evento onchange, dispara o evento */ |
---|
247 | if (target.onchange) |
---|
248 | if (current != previous) |
---|
249 | target.onchange(); |
---|
250 | } |
---|
251 | |
---|
252 | function setSelectValue(obj, value) |
---|
253 | { |
---|
254 | /* IE MAGIC */ |
---|
255 | if (obj.outerHTML) |
---|
256 | { |
---|
257 | obj.innerHTML = ''; |
---|
258 | obj.outerHTML = obj.outerHTML.match(/<select[^>]*>/gi) + value + '</select>'; |
---|
259 | } |
---|
260 | else |
---|
261 | obj.innerHTML = value; |
---|
262 | } |
---|
263 | |
---|
264 | function participantsRemoveUser(obj) |
---|
265 | { |
---|
266 | if (obj.tagName == 'INPUT') |
---|
267 | { |
---|
268 | obj.value = ''; |
---|
269 | obj = document.getElementById(obj.id + '_desc'); |
---|
270 | if (obj) |
---|
271 | obj.value = ''; |
---|
272 | } |
---|
273 | else |
---|
274 | { |
---|
275 | for(var i = 0;i < obj.options.length; i++) |
---|
276 | if(obj.options[i].selected) |
---|
277 | obj.options[i--] = null; |
---|
278 | } |
---|
279 | } |
---|
280 | |
---|
281 | function toggleFullSearch() |
---|
282 | { |
---|
283 | $('search').value = ''; |
---|
284 | |
---|
285 | if ($('useGlobalSearch').checked) |
---|
286 | { |
---|
287 | globalSearchEnter = true; |
---|
288 | if ($('organizationSectors')) |
---|
289 | $('organizationSectors').hide(); |
---|
290 | if ($('globalSearchTitle')) |
---|
291 | $('globalSearchTitle').show(); |
---|
292 | setSelectValue($('participants'), ''); |
---|
293 | $('search').onkeydown = globalSearchKeyAnalyzer; |
---|
294 | $('globalSearchWarnings').innerHTML = 'Para executar a busca, pressione ENTER.'; |
---|
295 | } |
---|
296 | else |
---|
297 | { |
---|
298 | $('globalSearchWarnings').innerHTML = ''; |
---|
299 | if ($('globalSearchTitle')) |
---|
300 | $('globalSearchTitle').hide(); |
---|
301 | if ($('organizationSectors')) |
---|
302 | $('organizationSectors').show(); |
---|
303 | searchParticipants(''); |
---|
304 | $('search').onkeydown = searchParticipantsTimer; |
---|
305 | } |
---|
306 | $('search').focus(); |
---|
307 | } |
---|
308 | |
---|
309 | function checkGlobalSearchShortcuts(e) |
---|
310 | { |
---|
311 | var whichCode = (e.which) ? e.which : e.keyCode; |
---|
312 | var handled = false; |
---|
313 | |
---|
314 | /* ENTER */ |
---|
315 | if ((whichCode == 13) && globalSearchEnter) |
---|
316 | { |
---|
317 | performGlobalSearch(); |
---|
318 | handled = true; |
---|
319 | globalSearchEnter = false; |
---|
320 | } |
---|
321 | |
---|
322 | if (handled == false) |
---|
323 | { |
---|
324 | handled = checkShortcuts(e); |
---|
325 | if (handled == true) |
---|
326 | globalSearchEnter = false; |
---|
327 | } |
---|
328 | |
---|
329 | if (handled == false) |
---|
330 | globalSearchEnter = true; |
---|
331 | |
---|
332 | return handled; |
---|
333 | } |
---|
334 | |
---|
335 | function globalSearchKeyAnalyzer(e) |
---|
336 | { |
---|
337 | if (checkGlobalSearchShortcuts((e) ? e : window.event)) |
---|
338 | return true; |
---|
339 | |
---|
340 | } |
---|
341 | |
---|
342 | function performGlobalSearch() |
---|
343 | { |
---|
344 | function resultPerformGlobalSearch(data) |
---|
345 | { |
---|
346 | setSelectValue($('participants'), data['participants']); |
---|
347 | if (data['warnings']) |
---|
348 | if (data['warnings'].length > 0) |
---|
349 | $('globalSearchWarnings').innerHTML = data['warnings'].join('<br/>'); |
---|
350 | } |
---|
351 | |
---|
352 | $('globalSearchWarnings').innerHTML = ''; |
---|
353 | var params = { |
---|
354 | onlyVisibleAccounts: $F('onlyVisibleAccounts'), |
---|
355 | searchTerm: $F('search'), |
---|
356 | entities: $F('entities'), |
---|
357 | id: $F('id'), |
---|
358 | usePreffix: $F('usePreffix') |
---|
359 | }; |
---|
360 | callAjax('bo_participants', 'globalSearch', resultPerformGlobalSearch, params); |
---|
361 | } |
---|
362 | |
---|
363 | function openParticipants(target, option) |
---|
364 | { |
---|
365 | newWidth = 500; |
---|
366 | newHeight = 315; |
---|
367 | newScreenX = screen.width - newWidth; |
---|
368 | newScreenY = 0; |
---|
369 | page = 'index.php?menuaction=workflow.ui_participants.form'; |
---|
370 | if (target) |
---|
371 | page += "&target_element=" + target; |
---|
372 | if (option) |
---|
373 | page += "&" + option; |
---|
374 | |
---|
375 | window.open(page,'','width='+newWidth+',height='+newHeight+',screenX='+newScreenX+',left='+newScreenX+',screenY='+newScreenY+',top='+newScreenY+',toolbar=no,scrollbars=no,resizable=no'); |
---|
376 | } |
---|