1 | function emQuickCatalogSearch () |
---|
2 | { |
---|
3 | this.arrayWin = new Array(); |
---|
4 | this.el; |
---|
5 | this.cc_contacts = new Array(); |
---|
6 | this.cc_groups = new Array(); |
---|
7 | } |
---|
8 | |
---|
9 | emQuickCatalogSearch.prototype.showList = function(data, begin, end){ |
---|
10 | connector.loadScript("ccQuickAdd"); |
---|
11 | |
---|
12 | if(preferences.use_shortcuts == '0'){ |
---|
13 | connector.loadScript("shortcut"); |
---|
14 | } |
---|
15 | |
---|
16 | id = '1'; |
---|
17 | _this = this; |
---|
18 | var el_A = document.createElement("DIV"); |
---|
19 | el_A.style.visibility = "hidden"; |
---|
20 | el_A.style.position = "absolute"; |
---|
21 | el_A.style.left = "0px"; |
---|
22 | el_A.style.top = "0px"; |
---|
23 | el_A.style.width = "0px"; |
---|
24 | el_A.style.height = "0px"; |
---|
25 | el_A.id = 'window_QuickCatalogSearch_A'; |
---|
26 | document.body.appendChild(el_A); |
---|
27 | el_A.innerHTML = ""; |
---|
28 | |
---|
29 | var el = document.createElement("DIV"); |
---|
30 | el.style.visibility = "hidden"; |
---|
31 | el.style.position = "absolute"; |
---|
32 | el.style.left = "0px"; |
---|
33 | el.style.top = "40px"; |
---|
34 | el.style.width = "695px"; |
---|
35 | el.style.height = "186px"; |
---|
36 | el.style.overflow = "auto"; |
---|
37 | el.id = 'window_QuickCatalogSearch'; |
---|
38 | el_A.appendChild(el); |
---|
39 | el.innerHTML = ""; |
---|
40 | |
---|
41 | |
---|
42 | func_add_contact = function () { |
---|
43 | var select_QuickCatalogSearch = document.getElementById("select_QuickCatalogSearch"); |
---|
44 | var contact_selected = select_QuickCatalogSearch.options[select_QuickCatalogSearch.selectedIndex].text; |
---|
45 | |
---|
46 | contact_selected = contact_selected.split('('); |
---|
47 | |
---|
48 | var first_and_last_name = contact_selected[0].split(" "); |
---|
49 | |
---|
50 | var data = []; |
---|
51 | data[0] = first_and_last_name[0]; |
---|
52 | data[1] = first_and_last_name[0]; |
---|
53 | data[2] = ""; |
---|
54 | |
---|
55 | for (i=1; i < first_and_last_name.length; i++) |
---|
56 | data[2] += first_and_last_name[i] + " "; |
---|
57 | |
---|
58 | data[2] = data[2].replace(/\s*$/g,''); |
---|
59 | data[3] = contact_selected[1].substring(0, contact_selected[1].indexOf(")") ); |
---|
60 | |
---|
61 | ccQuickAddOne.showList( data ); |
---|
62 | }; |
---|
63 | |
---|
64 | var title_innerHTML = get_lang('Select a name') + ':'; |
---|
65 | if (data.quickSearch_only_in_userSector) |
---|
66 | title_innerHTML += "<font color='BLACK' nowrap> ("+get_lang('Showing only the results found in your organization')+".)</font>" |
---|
67 | |
---|
68 | var title = document.createElement("SPAM"); |
---|
69 | title.id = 'window_QuickCatalogSearch_title'; |
---|
70 | title.innerHTML = " <b><font color='BLUE' nowrap>"+title_innerHTML+"</font></b><br> "; |
---|
71 | el_A.appendChild(title); |
---|
72 | var butt = document.createElement('BUTTON'); |
---|
73 | var buttext = document.createTextNode('OK'); |
---|
74 | butt.id = "QuickCatalogSearch_button_ok"; |
---|
75 | butt.appendChild(buttext); |
---|
76 | butt.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);}; |
---|
77 | el_A.appendChild(butt); |
---|
78 | |
---|
79 | var space = document.createElement('SPAN'); |
---|
80 | space.innerHTML = " "; |
---|
81 | el_A.appendChild(space); |
---|
82 | |
---|
83 | var butt = document.createElement('BUTTON'); |
---|
84 | butt.id = "QuickCatalogSearch_button_close"; |
---|
85 | var buttext = document.createTextNode(get_lang('Close')); |
---|
86 | butt.appendChild(buttext); |
---|
87 | butt.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);}; |
---|
88 | el_A.appendChild(butt); |
---|
89 | |
---|
90 | var space = document.createElement('SPAN'); |
---|
91 | space.innerHTML = " "; |
---|
92 | el_A.appendChild(space); |
---|
93 | |
---|
94 | var butt = document.createElement('BUTTON'); |
---|
95 | butt.id = "QuickCatalogSearch_button_add_contact"; |
---|
96 | var buttext = document.createTextNode(get_lang("Add Contact")); |
---|
97 | butt.appendChild(buttext); |
---|
98 | butt.onclick = func_add_contact; |
---|
99 | el_A.appendChild(butt); |
---|
100 | |
---|
101 | if (document.getElementById('select_QuickCatalogSearch') == null){ |
---|
102 | |
---|
103 | var cmb = document.createElement("SELECT"); |
---|
104 | cmb.id = "select_QuickCatalogSearch"; |
---|
105 | cmb.style.width = "2400px"; |
---|
106 | //cmb.size = "12"; |
---|
107 | cmb.ondblclick = function() {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);}; |
---|
108 | cmb.onkeypress = function (e) |
---|
109 | { |
---|
110 | if (is_ie) |
---|
111 | { |
---|
112 | if ((window.event.keyCode) == 13) |
---|
113 | { |
---|
114 | QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end); |
---|
115 | } |
---|
116 | else if ((window.event.keyCode) == 27) |
---|
117 | { |
---|
118 | QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID); |
---|
119 | } |
---|
120 | } |
---|
121 | else |
---|
122 | { |
---|
123 | if ((e.keyCode) == 13) |
---|
124 | { |
---|
125 | QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end); |
---|
126 | } |
---|
127 | else if ((e.keyCode) == 27) |
---|
128 | { |
---|
129 | QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID); |
---|
130 | } |
---|
131 | } |
---|
132 | }; |
---|
133 | el.appendChild(cmb); |
---|
134 | |
---|
135 | } |
---|
136 | else{ |
---|
137 | var title_innerHTML = get_lang('Select a name') + ':'; |
---|
138 | if (data.quickSearch_only_in_userSector) |
---|
139 | title_innerHTML += "<font color='BLACK' nowrap> ("+get_lang('Showing only the results found in your organization')+".)</font>" |
---|
140 | |
---|
141 | var title = Element('window_QuickCatalogSearch_title'); |
---|
142 | title.innerHTML = " <b><font color='BLUE' nowrap>"+title_innerHTML+"</font></b><br> "; |
---|
143 | |
---|
144 | var cmb = document.getElementById('select_QuickCatalogSearch'); |
---|
145 | cmb.ondblclick = function() {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);}; |
---|
146 | cmb.onkeypress = function (e) |
---|
147 | { |
---|
148 | if (is_ie) |
---|
149 | { |
---|
150 | if ((window.event.keyCode) == 13) |
---|
151 | { |
---|
152 | QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end); |
---|
153 | } |
---|
154 | else if ((window.event.keyCode) == 27) |
---|
155 | { |
---|
156 | QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID); |
---|
157 | } |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | if ((e.keyCode) == 13) |
---|
162 | { |
---|
163 | QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end); |
---|
164 | } |
---|
165 | else if ((e.keyCode) == 27) |
---|
166 | { |
---|
167 | QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID); |
---|
168 | } |
---|
169 | } |
---|
170 | }; |
---|
171 | |
---|
172 | for (i=0; i<cmb.length; i++) |
---|
173 | cmb.options[i--] = null; |
---|
174 | |
---|
175 | var butt_ok = document.getElementById("QuickCatalogSearch_button_ok"); |
---|
176 | var butt_close = document.getElementById("QuickCatalogSearch_button_close"); |
---|
177 | var butt_add_contact = document.getElementById("QuickCatalogSearch_button_add_contact"); |
---|
178 | butt_ok.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);}; |
---|
179 | butt_close.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);}; |
---|
180 | butt_add_contact.onclick = func_add_contact; |
---|
181 | } |
---|
182 | |
---|
183 | for (i=0; i<data.length; i++){ |
---|
184 | var Op = document.createElement("OPTION"); |
---|
185 | Op.text = data[i].cn + ' (' + data[i].mail + ')'; |
---|
186 | if (data[i].phone != '') |
---|
187 | Op.text += ' - ' + data[i].phone; |
---|
188 | if (data[i].ou != '') |
---|
189 | Op.text += ' - ' + data[i].ou; // adicionado "data[i].ou" para exibir setor (F9) |
---|
190 | Op.value = '"' + data[i].cn + '" ' + '<' + data[i].mail + '>'; |
---|
191 | cmb.options.add(Op); |
---|
192 | } |
---|
193 | cmb.options[0].selected = true; |
---|
194 | cmb.size = data.length+1; |
---|
195 | _this.showWindow(el_A); |
---|
196 | } |
---|
197 | |
---|
198 | emQuickCatalogSearch.prototype.showWindow = function (div) |
---|
199 | { |
---|
200 | if(! div) { |
---|
201 | alert(get_lang('The list has no participant.')); |
---|
202 | return; |
---|
203 | } |
---|
204 | |
---|
205 | if(! this.arrayWin[div.id]) { |
---|
206 | div.style.width = "700px"; |
---|
207 | div.style.height = "230px"; |
---|
208 | var title = get_lang('The results were found in the Global Catalog')+':'; |
---|
209 | var wHeight = div.offsetHeight + "px"; |
---|
210 | var wWidth = div.offsetWidth + "px"; |
---|
211 | div.style.width = div.offsetWidth - 5; |
---|
212 | |
---|
213 | win = new dJSWin({ |
---|
214 | id: 'QuickCatalogSearch_'+div.id, |
---|
215 | content_id: div.id, |
---|
216 | width: wWidth, |
---|
217 | height: wHeight, |
---|
218 | title_color: '#3978d6', |
---|
219 | bg_color: '#eee', |
---|
220 | title: title, |
---|
221 | title_text_color: 'white', |
---|
222 | button_x_img: '../phpgwapi/images/winclose.gif', |
---|
223 | border: true, |
---|
224 | onclose: 'QuickCatalogSearch.restoreShortcuts("'+ div.id +'")' }); |
---|
225 | |
---|
226 | this.arrayWin[div.id] = win; |
---|
227 | win.draw(); |
---|
228 | } |
---|
229 | else { |
---|
230 | win = this.arrayWin[div.id]; |
---|
231 | } |
---|
232 | document.getElementById("window_QuickCatalogSearch").style.visibility = "visible"; |
---|
233 | win.open(); |
---|
234 | document.getElementById('select_QuickCatalogSearch').focus(); |
---|
235 | |
---|
236 | if(is_ie && (preferences.use_shortcuts == '1')){ |
---|
237 | shortcut.remove('down'); |
---|
238 | shortcut.remove('up'); |
---|
239 | shortcut.remove('return'); |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | emQuickCatalogSearch.prototype.transfer_result = function (field, ID, begin, end){ |
---|
244 | cm = document.getElementById('select_QuickCatalogSearch'); |
---|
245 | option_selected = cm.options[cm.selectedIndex].value + ", "; |
---|
246 | emailList = document.getElementById(field + "_" + ID).value; |
---|
247 | |
---|
248 | new_emailList = emailList.substring(0, begin) + option_selected + emailList.substring((parseInt(end) + 2), emailList.length); |
---|
249 | document.getElementById(field + "_" + ID).value = new_emailList; |
---|
250 | document.getElementById(field + "_" + ID).focus(); |
---|
251 | |
---|
252 | this.arrayWin['window_QuickCatalogSearch_A'].close(); |
---|
253 | document.getElementById("window_QuickCatalogSearch").style.visibility = "hidden"; |
---|
254 | } |
---|
255 | |
---|
256 | emQuickCatalogSearch.prototype.close_QuickSearch_window = function (field, ID){ |
---|
257 | //document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none"; |
---|
258 | document.getElementById(field + "_" + ID).focus(); |
---|
259 | this.arrayWin['window_QuickCatalogSearch_A'].close(); |
---|
260 | document.getElementById("window_QuickCatalogSearch").style.visibility = "hidden"; |
---|
261 | if(typeof shortcut.all_shortcuts['down'] == 'undefined'){ |
---|
262 | if(is_ie && (preferences.use_shortcuts == '1')) |
---|
263 | { |
---|
264 | shortcut.add("down",function(){select_msg('null', 'down');},{'disable_in_input':false}); |
---|
265 | shortcut.add("up",function(){select_msg('null', 'up');},{'disable_in_input':false}); |
---|
266 | shortcut.add("return",function(){ |
---|
267 | if ( Element('border_id_0').className==='menu-sel' ) |
---|
268 | { |
---|
269 | all_messages = Element('tbody_box').childNodes; |
---|
270 | for (var i=0; i < all_messages.length; i++) |
---|
271 | { |
---|
272 | if ( exist_className(all_messages[i], 'selected_shortcut_msg') ) |
---|
273 | { |
---|
274 | Element("td_who_" + all_messages[i].id).onclick(); |
---|
275 | return; |
---|
276 | } |
---|
277 | } |
---|
278 | } |
---|
279 | },{'disable_in_input':true}); |
---|
280 | } |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | emQuickCatalogSearch.prototype.restoreShortcuts = function(id) { |
---|
285 | |
---|
286 | var search_win = document.getElementById(id); |
---|
287 | if(typeof shortcut.all_shortcuts['down'] == 'undefined'){ |
---|
288 | if (search_win.style.visibility == 'visible') |
---|
289 | { |
---|
290 | shortcut.add("down",function(){select_msg('null', 'down');},{'disable_in_input':false}); |
---|
291 | shortcut.add("up",function(){select_msg('null', 'up');},{'disable_in_input':false}); |
---|
292 | shortcut.add("return",function(){ |
---|
293 | if ( Element('border_id_0').className==='menu-sel' ) |
---|
294 | { |
---|
295 | all_messages = Element('tbody_box').childNodes; |
---|
296 | for (var i=0; i < all_messages.length; i++) |
---|
297 | { |
---|
298 | if ( exist_className(all_messages[i], 'selected_shortcut_msg') ) |
---|
299 | { |
---|
300 | Element("td_who_" + all_messages[i].id).onclick(); |
---|
301 | return; |
---|
302 | } |
---|
303 | } |
---|
304 | } |
---|
305 | },{'disable_in_input':true}); |
---|
306 | } |
---|
307 | } |
---|
308 | search_win.style.visibility = 'hidden'; |
---|
309 | |
---|
310 | } |
---|
311 | |
---|
312 | emQuickCatalogSearch.prototype.close_window = function(id) { |
---|
313 | this.arrayWin[id].close(); |
---|
314 | var group_values = Element('list_values'); |
---|
315 | var user_values = Element('user_values'); |
---|
316 | } |
---|
317 | emQuickCatalogSearch.prototype.showCatalogList = function (border_id){ |
---|
318 | var el = Element('catalog_list'); |
---|
319 | |
---|
320 | if(el) { |
---|
321 | Element('border_id').value = border_id; |
---|
322 | win = this.arrayWin[el.id]; |
---|
323 | win.open(); |
---|
324 | return; |
---|
325 | } |
---|
326 | var border_input = document.createElement("INPUT"); |
---|
327 | border_input.type = 'hidden'; |
---|
328 | border_input.id = 'border_id'; |
---|
329 | border_input.value = border_id; |
---|
330 | document.body.appendChild(border_input); |
---|
331 | el = document.createElement("DIV"); |
---|
332 | el.id = 'catalog_list'; |
---|
333 | document.body.appendChild(el); |
---|
334 | el.style.visibility = "hidden"; |
---|
335 | el.style.position = "absolute"; |
---|
336 | el.style.width = "700px"; |
---|
337 | el.style.height = is_ie ? "360px" : "375px"; |
---|
338 | el.style.left = "0px"; |
---|
339 | el.style.top = "0px"; |
---|
340 | el.innerHTML = "<table border='0' cellpading='0' cellspacing='0' width='100%'>"+ |
---|
341 | "<tr><td id='td1' style='cursor:pointer' align='center' onclick='QuickCatalogSearch.select_div(\"tab1\")'><a href='#' class='catalog' onclick='QuickCatalogSearch.select_div(\"tab1\");'>"+get_lang('Global Catalog')+"</a></td>"+ |
---|
342 | "<td id='td2' style='background:#cecece;cursor:pointer' onclick='QuickCatalogSearch.select_div(\"tab2\")' align='center'><a href='#' class='catalog' onclick='QuickCatalogSearch.select_div(\"tab2\");'>"+get_lang('Personal Catalog')+"</a></td></tr>"+ |
---|
343 | '</table>'+ |
---|
344 | '<div id="tab1" align="center"><br>'+ |
---|
345 | '<table border="0" cellpading="0" cellspacing="0">'+ |
---|
346 | '<tr><td>'+get_lang("Select an organization and click on button <b>Search</b>")+' :</td></tr>'+ |
---|
347 | '<tr><td><select style="display:none;width:150px" id="select_catalog" name="select_catalog" onchange="javascript:QuickCatalogSearch.update_organizations();"></select> '+ |
---|
348 | '<select id="select_organization" style="width:150px" name="select_organization"></select> '+ |
---|
349 | '<input type="text" id="search_for" name="search_for" value="" size="30" maxlength="30"/> <input type="button" onclick="QuickCatalogSearch.searchCatalogList(true)" class="button" value="'+get_lang('Search')+'"> <input style="display:visible" type="button" onclick="QuickCatalogSearch.searchCatalogList(false)" class="button" value="'+get_lang('List All')+'"></td></tr>'+ |
---|
350 | '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" id="type_l" type="radio" name="type" value="l"/>'+get_lang('Public Lists')+' <input type="radio" id="type_u" name="type" value="u" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" checked/>'+get_lang('Users')+' '+ |
---|
351 | '<span style="visibility:hidden;background:#cc4444" id=msg_search> <font face="Verdana" size="1" color="WHITE">'+get_lang('Search in Catalog')+'...</font> </span></td></tr>'+ |
---|
352 | '<tr><td>'+ |
---|
353 | '<span id="list_span"><select multiple style="display:none;width:580px" size="14" id="list_values"></select></span>'+ |
---|
354 | '<span id="user_span"><select multiple style="width:580px" size="14" id="user_values"></select></span>'+ |
---|
355 | '</td></tr>'+ |
---|
356 | '<tr><td nowrap><center>'+get_lang('Click here to add into the fields')+': <input type="button" class="button" value="'+get_lang('TO')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'to\')"> '+ |
---|
357 | '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc\')"> '+ |
---|
358 | '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco\')">'+ |
---|
359 | '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+ |
---|
360 | '</table>'+ |
---|
361 | '</div>'+ |
---|
362 | '<div style="display:none" id="tab2" align="center">'+ |
---|
363 | '<br><br><br>'+ |
---|
364 | '<table border="0" cellpading="0" cellspacing="0">'+ |
---|
365 | '<tr><td>'+get_lang("Select the type of contact that you want to view")+' :</td></tr>'+ |
---|
366 | '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" type="radio" name="type" value="p"/>' + get_lang('People') + ' <input type="radio" name="type" value="g" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)"/>' + get_lang('Groups') + ' '+ |
---|
367 | '<tr><td>'+ |
---|
368 | '<span id="personal_span"><select multiple style="width:580px" size="14" id="list_personal"></select></span>'+ |
---|
369 | '<span id="groups_span"><select multiple style="display:none;width:580px" size="14" id="list_groups"></select></span>'+ |
---|
370 | '</td></tr>'+ |
---|
371 | '<tr><td nowrap><center>'+get_lang('Click here to add into the fields')+': <input type="button" class="button" value="'+get_lang('TO')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'to1\')"> '+ |
---|
372 | '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc1\')"> '+ |
---|
373 | '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco1\')">'+ |
---|
374 | '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+ |
---|
375 | '</table>'+ |
---|
376 | '</div>'; |
---|
377 | |
---|
378 | var title = get_lang('Search in the Global Catalog'); |
---|
379 | var wHeight = el.offsetHeight - (is_ie ? 10 : 0) + "px"; |
---|
380 | var wWidth = el.offsetWidth + "px"; |
---|
381 | el.style.width = el.offsetWidth; |
---|
382 | |
---|
383 | Element('search_for').onkeypress = function (e) { |
---|
384 | if ((is_ie && (window.event.keyCode == 13)) || (!is_ie && e.keyCode == 13)) { |
---|
385 | QuickCatalogSearch.searchCatalogList(true); |
---|
386 | } |
---|
387 | }; |
---|
388 | |
---|
389 | win = new dJSWin({ |
---|
390 | id: 'win_'+el.id, |
---|
391 | content_id: el.id, |
---|
392 | width: wWidth, |
---|
393 | height: wHeight, |
---|
394 | title_color: '#3978d6', |
---|
395 | bg_color: '#eee', |
---|
396 | title: title, |
---|
397 | title_text_color: 'white', |
---|
398 | button_x_img: '../phpgwapi/images/winclose.gif', |
---|
399 | border: true }); |
---|
400 | |
---|
401 | this.arrayWin[el.id] = win; |
---|
402 | win.draw(); |
---|
403 | win.open(); |
---|
404 | |
---|
405 | var handler_catalogs = function(data){ |
---|
406 | var user_catalog = get_lang("Global Catalog"); |
---|
407 | if(data.length > 1) { |
---|
408 | Element('select_catalog').style.display = ''; |
---|
409 | for(i = 0; i < data.length; i++) { |
---|
410 | Element('select_catalog').options[i] = new Option(data[i],i); |
---|
411 | if(user_catalog.toUpperCase() == data[i].toUpperCase()) |
---|
412 | Element('select_catalog').options[i].selected = true; |
---|
413 | } |
---|
414 | } |
---|
415 | } |
---|
416 | cExecute ("$this.ldap_functions.get_catalogs", handler_catalogs); |
---|
417 | |
---|
418 | this.update_organizations(); |
---|
419 | var handler_cc_contacts= function(data){ |
---|
420 | if(data && data.length > 0){ |
---|
421 | var aux = data.split(","); |
---|
422 | for(var i=0; i< aux.length; i++){ |
---|
423 | QuickCatalogSearch.cc_contacts[QuickCatalogSearch.cc_contacts.length] = aux[i]; |
---|
424 | } |
---|
425 | } |
---|
426 | } |
---|
427 | cExecute("$this.db_functions.get_cc_contacts",handler_cc_contacts); |
---|
428 | |
---|
429 | var handler_cc_groups = function(data){ |
---|
430 | if(data && data.length > 0){ |
---|
431 | var aux = data.split(","); |
---|
432 | for(var i=0; i < data.length; i++){ |
---|
433 | QuickCatalogSearch.cc_groups[QuickCatalogSearch.cc_groups.length] = aux[i]; |
---|
434 | } |
---|
435 | } |
---|
436 | } |
---|
437 | cExecute("$this.db_functions.get_cc_groups",handler_cc_groups); |
---|
438 | |
---|
439 | } |
---|
440 | |
---|
441 | emQuickCatalogSearch.prototype.select_div = function(element){ |
---|
442 | if(element == 'tab1'){ |
---|
443 | Element('tab1').style.display = ''; |
---|
444 | Element('tab2').style.display = 'none'; |
---|
445 | Element('td1').style.background = '#eee'; |
---|
446 | Element('td2').style.background = '#cecece'; |
---|
447 | } |
---|
448 | if(element == 'tab2'){ |
---|
449 | Element('tab1').style.display = 'none'; |
---|
450 | Element('tab2').style.display = ''; |
---|
451 | Element('td1').style.background = '#cecece'; |
---|
452 | Element('td2').style.background = '#eee'; |
---|
453 | |
---|
454 | } |
---|
455 | } |
---|
456 | |
---|
457 | emQuickCatalogSearch.prototype.load_catalog = function(){ |
---|
458 | |
---|
459 | var _this = this; |
---|
460 | var content = new Array; |
---|
461 | var select = Element('list_personal').style.display == 'none'? Element('list_groups'): Element('list_personal'); |
---|
462 | |
---|
463 | if(Element('list_personal').style.display == 'none'){ |
---|
464 | content = _this.cc_groups; |
---|
465 | }else{ |
---|
466 | content = _this.cc_contacts; |
---|
467 | } |
---|
468 | if(select.options.length > 0){ |
---|
469 | for(var i=0; i < select.options.length; i++){ |
---|
470 | select.options[i] = null; |
---|
471 | i--; |
---|
472 | } |
---|
473 | } |
---|
474 | for(var i=0; i < content.length; i++){ |
---|
475 | if(content[i] != undefined){ |
---|
476 | var aux = content[i].split(";"); |
---|
477 | var opt = new Option(aux[0] + ' (' + aux[1] + ')','"' + aux[0] + '" ' + '<' + aux[1] + '>',false,false); |
---|
478 | select[select.length] = opt; |
---|
479 | } |
---|
480 | } |
---|
481 | content.splice(0,(content.lenght)); |
---|
482 | } |
---|
483 | |
---|
484 | emQuickCatalogSearch.prototype.update_organizations = function(){ |
---|
485 | while(Element('select_organization').options.length > 0) { |
---|
486 | Element('select_organization').remove(0); |
---|
487 | } |
---|
488 | var handler_org = function(data){ |
---|
489 | Element('select_organization').options[0] = new Option(get_lang('all'),'all'); |
---|
490 | if (data != null){ |
---|
491 | var user_organization = Element('user_organization').value; |
---|
492 | for(x = 0; x < data.length; x++) { |
---|
493 | Element('select_organization').options[x+1] = new Option(data[x].toUpperCase(),data[x]); |
---|
494 | if(user_organization.toUpperCase() == data[x].toUpperCase()) |
---|
495 | Element('select_organization').options[x+1].selected = true; |
---|
496 | } |
---|
497 | } |
---|
498 | } |
---|
499 | cExecute ("$this.ldap_functions.get_organizations&referral=false&catalog="+Element('select_catalog').value, handler_org); |
---|
500 | } |
---|
501 | |
---|
502 | emQuickCatalogSearch.prototype.changeOptions = function(type){ |
---|
503 | |
---|
504 | switch(type){ |
---|
505 | case 'u': |
---|
506 | Element('list_values').style.display = 'none'; |
---|
507 | Element('user_values').style.display = ''; |
---|
508 | break; |
---|
509 | |
---|
510 | case 'l': |
---|
511 | Element('user_values').style.display = 'none'; |
---|
512 | Element('list_values').style.display = ''; |
---|
513 | break; |
---|
514 | |
---|
515 | case 'p': |
---|
516 | Element('list_personal').style.display = ''; |
---|
517 | Element('list_groups').style.display = 'none' |
---|
518 | QuickCatalogSearch.load_catalog(); |
---|
519 | break; |
---|
520 | |
---|
521 | case 'g': |
---|
522 | Element('list_personal').style.display = 'none'; |
---|
523 | Element('list_groups').style.display = '' |
---|
524 | QuickCatalogSearch.load_catalog(); |
---|
525 | break; |
---|
526 | } |
---|
527 | |
---|
528 | } |
---|
529 | |
---|
530 | emQuickCatalogSearch.prototype.addContacts = function(field) { |
---|
531 | |
---|
532 | var border_id = Element('border_id').value; |
---|
533 | var select = Element('user_values').style.display == 'none' ? Element('list_values') : Element('user_values'); |
---|
534 | if(field == "to1" || field == "cc1" || field == "cco1"){ |
---|
535 | field = field.substr(0,field.length - 1); |
---|
536 | var select = Element('list_personal').style.display == 'none' ? Element('list_groups') : Element('list_personal'); |
---|
537 | } |
---|
538 | var fieldOpener = Element(field+"_"+border_id); |
---|
539 | var not_selected = true; |
---|
540 | |
---|
541 | for (i = 0 ; i < select.length ; i++) { |
---|
542 | if (select.options[i].selected && select.options[i].value != '-1') { |
---|
543 | if(fieldOpener.value.length > 0 && (fieldOpener.value.lastIndexOf(',') != (fieldOpener.value.length - 1))){ |
---|
544 | fieldOpener.value += ","; |
---|
545 | } |
---|
546 | fieldOpener.value += select.options[i].value + ","; |
---|
547 | not_selected = false; |
---|
548 | select.options[i].selected = false; |
---|
549 | } |
---|
550 | } |
---|
551 | |
---|
552 | if(not_selected) |
---|
553 | return false; |
---|
554 | |
---|
555 | if(field != 'to'){ |
---|
556 | a_link = Element("a_"+field+"_link_"+border_id); |
---|
557 | if(a_link) |
---|
558 | a_link.onclick(); |
---|
559 | } |
---|
560 | } |
---|
561 | |
---|
562 | emQuickCatalogSearch.prototype.searchCatalogList = function (itemSearch){ |
---|
563 | |
---|
564 | if(itemSearch && Element('search_for').value.length < preferences.search_characters_number){ |
---|
565 | alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number)); |
---|
566 | Element('search_for').focus(); |
---|
567 | return false; |
---|
568 | } |
---|
569 | var organization = Element('select_organization').value; |
---|
570 | var search = itemSearch ? Element('search_for').value : ''; |
---|
571 | var catalog = Element('select_catalog').value; |
---|
572 | var max_result = 400; |
---|
573 | |
---|
574 | var handler_searchResults = function(data){ |
---|
575 | Element('msg_search').style.visibility = 'hidden'; |
---|
576 | if(data.error){ |
---|
577 | alert(get_lang('More than %1 results. Please, try to refine your search.',max_result)); |
---|
578 | return false; |
---|
579 | }else if(data.users.length == 0 && data.groups.length == 0){ |
---|
580 | alert(get_lang('None result was found.')); |
---|
581 | } |
---|
582 | |
---|
583 | |
---|
584 | var group = Element('list_span'); |
---|
585 | var user = Element('user_span'); |
---|
586 | if(is_ie){ |
---|
587 | group.innerHTML = ''; |
---|
588 | user.innerHTML = ''; |
---|
589 | } |
---|
590 | else { |
---|
591 | group = Element('list_values'); |
---|
592 | user = Element('user_values'); |
---|
593 | for(var i = 0;i < group.options.length; i++) |
---|
594 | group.options[i--] = null; |
---|
595 | for(var i = 0;i < user.options.length; i++) |
---|
596 | user.options[i--] = null; |
---|
597 | } |
---|
598 | |
---|
599 | var arr = new Array(max_result); |
---|
600 | |
---|
601 | for(i = 0; data.groups && i < data.groups.length; i++) { |
---|
602 | // Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento. |
---|
603 | if(is_ie) |
---|
604 | arr[i] = '<option value="'+'"'+data.groups[i].name+'" <'+data.groups[i].email+'>">'+data.groups[i].name+' ('+data.groups[i].email+')'+'</option>'; |
---|
605 | else |
---|
606 | group.options[i] = new Option(data.groups[i].name+' ('+data.groups[i].email+')','"'+data.groups[i].name+'" <'+data.groups[i].email+'>'); |
---|
607 | } |
---|
608 | |
---|
609 | |
---|
610 | if(is_ie) |
---|
611 | group.innerHTML = '<select multiple style="display:none;width:580px" size="14" id="list_values">'+ arr.join() +'</select>'; |
---|
612 | |
---|
613 | arr = new Array(max_result); |
---|
614 | |
---|
615 | for(i = 0; data.users && i < data.users.length; i++) { |
---|
616 | /*******************************************************************************************/ |
---|
617 | /* O resultado pratico do bloco de codigo a seguir eh a exibicao dos valores em tela, |
---|
618 | ja que vai verificar se o departamento e o email estao vazios ou nulos e a partir dai o |
---|
619 | resultado apresentado em tela sera exibido de maneira mais apresentavel; |
---|
620 | */ |
---|
621 | //verifica se departamento eh null ou nao; |
---|
622 | var department = data.users[i].department ? " - " + data.users[i].department : ""; |
---|
623 | //verifica se email eh null ou nao; |
---|
624 | var email = data.users[i].email ? data.users[i].email : ""; |
---|
625 | |
---|
626 | // Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento. |
---|
627 | if(is_ie) |
---|
628 | arr[i] = '<option value="'+'"'+data.users[i].name+'" <'+email+'>">'+data.users[i].name+' ('+email+')'+department+'</option>'; |
---|
629 | else { |
---|
630 | user.options[i] = new Option(data.users[i].name+' ('+email+')'+department,'"'+data.users[i].name+'" <'+email+'>'); // incluido data.users[i].department para exibir setor na opcao "Pesquisar" do email; |
---|
631 | } |
---|
632 | } |
---|
633 | |
---|
634 | if(is_ie) |
---|
635 | user.innerHTML = '<select multiple style="width:580px" size="14" id="user_values">'+ arr.join() +'</select>'; |
---|
636 | |
---|
637 | // Display entries found. |
---|
638 | var type = (data.groups.length > 0 && data.users.length == 0) ? 'l' : 'u'; |
---|
639 | Element("type_"+type).checked = true; |
---|
640 | QuickCatalogSearch.changeOptions(type); |
---|
641 | } |
---|
642 | |
---|
643 | Element('msg_search').style.visibility = 'visible'; |
---|
644 | cExecute ("$this.ldap_functions.catalogsearch&max_result="+max_result+"&organization="+organization+"&search_for="+search+"&catalog="+catalog, handler_searchResults); |
---|
645 | } |
---|
646 | |
---|
647 | |
---|
648 | /* Build the Object */ |
---|
649 | //QuickCatalogSearch; |
---|
650 | QuickCatalogSearch = new emQuickCatalogSearch(); |
---|