1 | /***************************************************************************\ |
---|
2 | * eGroupWare - Contacts Center * |
---|
3 | * http://www.egroupware.org * |
---|
4 | * Written by: * |
---|
5 | * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * |
---|
6 | * sponsored by Thyamad - http://www.thyamad.com * |
---|
7 | * ------------------------------------------------------------------------- * |
---|
8 | * This program is free software; you can redistribute it and/or modify it * |
---|
9 | * under the terms of the GNU General Public License as published by the * |
---|
10 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
11 | * option) any later version. * |
---|
12 | \***************************************************************************/ |
---|
13 | |
---|
14 | /* |
---|
15 | * ContactCenter API - Add Group |
---|
16 | * |
---|
17 | * USAGE INSTRUCTIONS |
---|
18 | */ |
---|
19 | |
---|
20 | function cAddGroup () |
---|
21 | { |
---|
22 | // Private |
---|
23 | this._card; |
---|
24 | this._button = new Array(); |
---|
25 | |
---|
26 | // Public |
---|
27 | this.window; |
---|
28 | this.afterSave; |
---|
29 | this.load; |
---|
30 | |
---|
31 | // Constructor |
---|
32 | var wHeight = 0; |
---|
33 | |
---|
34 | // Elements |
---|
35 | this.title = Element('title'); |
---|
36 | this.contact_in_list = Element('contact_in_list'); |
---|
37 | this.group_id = Element('group_id'); |
---|
38 | |
---|
39 | this.old_contacts_in_list = new Array(); |
---|
40 | |
---|
41 | ccAGWinHeight = 'ccAGWinHeightMO'; |
---|
42 | |
---|
43 | if (is_ie) |
---|
44 | ccAGWinHeight = 'ccAGWinHeightIE'; |
---|
45 | |
---|
46 | wHeight = Element(ccAGWinHeight).value; |
---|
47 | |
---|
48 | |
---|
49 | this.window = new dJSWin({ |
---|
50 | id: 'ccAddGroup DOM', |
---|
51 | content_id: 'ccAddGroupContent', |
---|
52 | width: '700px', |
---|
53 | height: wHeight+'px', |
---|
54 | title_color: '#3978d6', |
---|
55 | bg_color: '#eee', |
---|
56 | title: Element('ccAGTitle').value, |
---|
57 | title_text_color: 'white', |
---|
58 | button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif', |
---|
59 | border: true }); |
---|
60 | |
---|
61 | this.window.draw(); |
---|
62 | |
---|
63 | } |
---|
64 | |
---|
65 | /*! |
---|
66 | @method associateAsButton |
---|
67 | @abstract Associates the button functions with the spacified DOM Element |
---|
68 | @author Raphael Derosso Pereira |
---|
69 | |
---|
70 | @param div DOMElement The HTML DOM element that will "host" the |
---|
71 | plugin button. |
---|
72 | |
---|
73 | @param func function The function that returns the data to be used |
---|
74 | to pre-populate the quickAdd fields. The return format MUST be |
---|
75 | an Array like: |
---|
76 | |
---|
77 | var return_data = new Array(); |
---|
78 | return_data[0] = <value>; // Value for the first field |
---|
79 | return_data[1] = <value>; // Value for the second field |
---|
80 | ... |
---|
81 | |
---|
82 | */ |
---|
83 | cAddGroup.prototype.associateAsButton = function (div) |
---|
84 | { |
---|
85 | var _this = this; |
---|
86 | div.onclick = function() { |
---|
87 | |
---|
88 | if (_this.load) { |
---|
89 | switch (typeof(_this.load)) { |
---|
90 | |
---|
91 | case 'function': |
---|
92 | _this.load(); |
---|
93 | break; |
---|
94 | |
---|
95 | case 'string': |
---|
96 | eval(_this.load); |
---|
97 | break; |
---|
98 | } |
---|
99 | } |
---|
100 | }; |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | /*! |
---|
105 | |
---|
106 | @method send |
---|
107 | @abstract Sends data to server |
---|
108 | @author Raphael Derosso Pereira |
---|
109 | |
---|
110 | */ |
---|
111 | cAddGroup.prototype.send = function () |
---|
112 | { |
---|
113 | var _this = this; |
---|
114 | |
---|
115 | var handler = function (responseText) |
---|
116 | { |
---|
117 | Element('cc_debug').innerHTML = responseText; |
---|
118 | var data = unserialize(responseText); |
---|
119 | |
---|
120 | if (!data || typeof(data) != 'object') |
---|
121 | { |
---|
122 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
123 | return; |
---|
124 | } |
---|
125 | |
---|
126 | //showMessage(data['msg']); |
---|
127 | |
---|
128 | if (data['status'] != 'ok' && data['status'] != 'warning') |
---|
129 | { |
---|
130 | showMessage(Element('cc_msg_err_duplicate_group').value); |
---|
131 | return; |
---|
132 | } |
---|
133 | |
---|
134 | if(data['status'] == 'warning') |
---|
135 | showMessage(data['msg']); |
---|
136 | |
---|
137 | _this.clear(); |
---|
138 | _this.window.close(); |
---|
139 | |
---|
140 | if (_this.afterSave) |
---|
141 | { |
---|
142 | switch (typeof(_this.afterSave)) |
---|
143 | { |
---|
144 | case 'function': |
---|
145 | _this.afterSave(); |
---|
146 | break; |
---|
147 | |
---|
148 | case 'string': |
---|
149 | eval(_this.afterSave); |
---|
150 | break; |
---|
151 | } |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | var sdata = new Array(); |
---|
156 | var empty = true; |
---|
157 | |
---|
158 | sdata[0] = this.title.value; |
---|
159 | var contacts = new Array(); |
---|
160 | var old_contacts = new Array(); |
---|
161 | |
---|
162 | for (j =0; j < this.contact_in_list.length; j++) |
---|
163 | contacts[j] = this.contact_in_list.options[j].value; |
---|
164 | for (i = 0; i < this.old_contacts_in_list.length; i++) |
---|
165 | old_contacts[i] = this.old_contacts_in_list[i]; |
---|
166 | |
---|
167 | if(!this.title.value) { |
---|
168 | alert(Element('cc_msg_fill_field_name').value); |
---|
169 | this.title.focus(); |
---|
170 | return false; |
---|
171 | } |
---|
172 | |
---|
173 | if(! contacts.length) { |
---|
174 | alert(Element('cc_msg_add_contact_to_group').value); |
---|
175 | return false; |
---|
176 | } |
---|
177 | |
---|
178 | sdata[1] = contacts; |
---|
179 | sdata[2] = this.group_id.value == 'undefined' ? sdata[2] = 0 : sdata[2] = this.group_id.value; |
---|
180 | sdata[3] = old_contacts; |
---|
181 | var sdata = 'add='+escape(serialize(sdata)); |
---|
182 | Connector.newRequest('cAddGroup.Send', CC_url+'add_group', 'POST', handler, sdata); |
---|
183 | } |
---|
184 | |
---|
185 | /*! |
---|
186 | |
---|
187 | @method clear |
---|
188 | @abstract Clear all Plugin Fields |
---|
189 | @author Raphael Derosso Pereira |
---|
190 | |
---|
191 | */ |
---|
192 | cAddGroup.prototype.clear = function (reload) |
---|
193 | { |
---|
194 | for (j =0; j < this.contact_in_list.options.length; j++) { |
---|
195 | this.contact_in_list.options[j].selected = false; |
---|
196 | this.contact_in_list.options[j--] = null; |
---|
197 | } |
---|
198 | |
---|
199 | if(reload) { |
---|
200 | if(Element("contact_list")) |
---|
201 | for (j =0; j < Element("contact_list").options.length; j++) { |
---|
202 | Element("contact_list").options[j].selected = false; |
---|
203 | Element("contact_list").options[j--] = null; |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | this.title.value = ''; |
---|
208 | ccAGSearchTerm.value = ''; |
---|
209 | } |
---|
210 | |
---|
211 | cAddGroup.prototype.openEditWindow = function() |
---|
212 | { |
---|
213 | var list_old_contacts = Element('contact_in_list'); |
---|
214 | for (var i = 0; i < list_old_contacts.length; i++) |
---|
215 | { |
---|
216 | this.old_contacts_in_list[i] = list_old_contacts.options[i].value; |
---|
217 | } |
---|
218 | this.window.open(); |
---|
219 | }; |
---|
220 | |
---|
221 | /* Função para remover contato da lista */ |
---|
222 | |
---|
223 | cAddGroup.prototype.remUser = function(){ |
---|
224 | |
---|
225 | select_in = this.contact_in_list; |
---|
226 | |
---|
227 | for(var i = 0;i < select_in.options.length; i++) |
---|
228 | if(select_in.options[i].selected) |
---|
229 | select_in.options[i--] = null; |
---|
230 | } |
---|
231 | |
---|
232 | /* Função para adicionar contato na lista */ |
---|
233 | cAddGroup.prototype.addUser = function(){ |
---|
234 | |
---|
235 | var select = Element("contact_list"); |
---|
236 | var select_in = this.contact_in_list; |
---|
237 | |
---|
238 | for (i = 0 ; i < select.length ; i++) { |
---|
239 | |
---|
240 | if (select.options[i].selected) { |
---|
241 | isSelected = false; |
---|
242 | |
---|
243 | for(var j = 0;j < select_in.options.length; j++) { |
---|
244 | if((select_in.options[j].value == select.options[i].value) && (select_in.options[j].textContent == select.options[i].textContent)){ |
---|
245 | isSelected = true; |
---|
246 | //break; |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | if(!isSelected){ |
---|
251 | |
---|
252 | option = document.createElement('option'); |
---|
253 | option.value =select.options[i].value; |
---|
254 | option.text = select.options[i].text; |
---|
255 | option.selected = true; |
---|
256 | select_in.options[select_in.options.length] = option; |
---|
257 | |
---|
258 | } |
---|
259 | |
---|
260 | } |
---|
261 | } |
---|
262 | |
---|
263 | for (j =0; j < select.options.length; j++) |
---|
264 | select .options[j].selected = false; |
---|
265 | } |
---|
266 | |
---|
267 | cAddGroup.prototype.setSelectedSourceLevel = function(sourceLevel) |
---|
268 | { |
---|
269 | var ccAGSourceSelect = Element('ccAGSourceSelect'); |
---|
270 | var selectedLevel = ''; |
---|
271 | for (i = 0; i < ccAGSourceSelect.length; i++) |
---|
272 | { |
---|
273 | if (ccAGSourceSelect[i].selected == true) |
---|
274 | { |
---|
275 | selectedLevel = ccAGSourceSelect[i].value; |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | if (selectedLevel != sourceLevel) |
---|
280 | { |
---|
281 | for (i = 0; i < ccAGSourceSelect.length; i++) |
---|
282 | { |
---|
283 | if (ccAGSourceSelect[i].value == sourceLevel) |
---|
284 | { |
---|
285 | ccAGSourceSelect[i].selected = true; |
---|
286 | } |
---|
287 | } |
---|
288 | } |
---|
289 | this.setCatalog(); |
---|
290 | } |
---|
291 | |
---|
292 | cAddGroup.prototype.loadPersonalContacts = function(){ |
---|
293 | handler = function(data) |
---|
294 | { |
---|
295 | if (data) |
---|
296 | { |
---|
297 | data = unserialize(data); |
---|
298 | if (data.result == 'ok') |
---|
299 | { |
---|
300 | var options_contact_list = Element('span_contact_list'); |
---|
301 | var select_contact_list = '<select id="contact_list" multiple name="contact_list[]" style="width:280px" size="10">'; |
---|
302 | select_contact_list += data['contact_list'] + "</select>"; |
---|
303 | options_contact_list.innerHTML = select_contact_list; |
---|
304 | } |
---|
305 | return; |
---|
306 | } |
---|
307 | |
---|
308 | alert(get_lang('Erro ao carregar contatos pessoais.')); |
---|
309 | |
---|
310 | |
---|
311 | } |
---|
312 | |
---|
313 | Connector.newRequest('cAddGroup.loadPersonalContacts', CC_url+'get_group', 'GET', handler); |
---|
314 | |
---|
315 | } |
---|
316 | |
---|
317 | cAddGroup.prototype.clearSourceList = function(){ |
---|
318 | var contact_list = Element("contact_list"); |
---|
319 | var options = contact_list.options; |
---|
320 | for (j =0; j < options.length; j++) { |
---|
321 | contact_list.options[j].selected = false; |
---|
322 | contact_list.options[j--] = null; |
---|
323 | } |
---|
324 | } |
---|
325 | |
---|
326 | // usar ui_data.get_cards_data('all', 1); |
---|
327 | cAddGroup.prototype.search = function(){ |
---|
328 | |
---|
329 | var type = Element('cc_type_contact').value; |
---|
330 | |
---|
331 | var data = new Array(); |
---|
332 | data['fields'] = new Array(); |
---|
333 | |
---|
334 | // never search groups |
---|
335 | data['fields']['id'] = 'contact.id_contact'; |
---|
336 | data['fields']['search'] = 'contact.names_ordered'; |
---|
337 | |
---|
338 | var ccAGSearchTerm = Element('ccAGSearchTerm'); |
---|
339 | |
---|
340 | data['search_for'] = ccAGSearchTerm.value; |
---|
341 | data['ccAddGroup'] = true; |
---|
342 | |
---|
343 | var invalidChars = /[\%\?]/; |
---|
344 | if(invalidChars.test(data['search_for']) || invalidChars.test(data['search_for_area'])){ |
---|
345 | showMessage(Element('cc_msg_err_invalid_serch').value); |
---|
346 | return; |
---|
347 | } |
---|
348 | |
---|
349 | var search_for = data['search_for'].split(' '); |
---|
350 | //var greaterThan4 = false; |
---|
351 | //var use_length = v_min; |
---|
352 | |
---|
353 | //for (i = 0; i < search_for.length; i++) |
---|
354 | //{ |
---|
355 | // if (search_for[i].length >= use_length) |
---|
356 | // { |
---|
357 | // greaterThan4 = true; |
---|
358 | // } |
---|
359 | //} |
---|
360 | |
---|
361 | // if (!greaterThan4){ |
---|
362 | // alert("Favor fazer a consulta com pelo menos " + v_min + " caracteres!"); |
---|
363 | // return; |
---|
364 | // } |
---|
365 | |
---|
366 | var handler = function(data) |
---|
367 | { |
---|
368 | data = unserialize(data); |
---|
369 | |
---|
370 | if( !data || data[0] == 0){ |
---|
371 | |
---|
372 | var contact_list = Element('contact_list'); |
---|
373 | for (var i = contact_list.options.length - 1; i >= 0; i--){ |
---|
374 | contact_list.options[i] = null; |
---|
375 | } |
---|
376 | contact_list.selectedIndex = -1; |
---|
377 | return false; |
---|
378 | } |
---|
379 | |
---|
380 | ccAddGroup.clearSourceList(); |
---|
381 | ccAGSearchTerm.value = ''; |
---|
382 | if (typeof(data) != 'object') |
---|
383 | { |
---|
384 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
385 | return false; |
---|
386 | } |
---|
387 | |
---|
388 | if (data[3].length > 300) |
---|
389 | { |
---|
390 | alert("Mais de 300 resultados foram retornados! \n Favor refinar sua busca."); |
---|
391 | |
---|
392 | return false; |
---|
393 | } |
---|
394 | |
---|
395 | var contact_list = Element('contact_list'); |
---|
396 | for (var i=0; i < data[3].length; i++) |
---|
397 | { |
---|
398 | |
---|
399 | var item = data[3][i]; |
---|
400 | if (data[8] == 'bo_shared_people_manager' || data[8] == 'bo_people_catalog'){ |
---|
401 | var id = data[3][i][13]; |
---|
402 | } |
---|
403 | else |
---|
404 | { |
---|
405 | var id = 'ldap:'+data[11]+':'+item[6]; |
---|
406 | } |
---|
407 | var option = document.createElement('OPTION'); |
---|
408 | option.value = id; |
---|
409 | option.text = item[1]+' ('+item[4]+')'; |
---|
410 | contact_list.options[contact_list.options.length] = option; |
---|
411 | } |
---|
412 | |
---|
413 | } |
---|
414 | |
---|
415 | Connector.newRequest('ccAGSearch', CC_url+'search&data='+serialize(data), 'GET', handler); |
---|
416 | |
---|
417 | } |
---|
418 | |
---|
419 | cAddGroup.prototype.setCatalog = function(){ |
---|
420 | var select = Element('ccAGSourceSelect'); |
---|
421 | var catalogLevel = '0.0'; |
---|
422 | for (i = 0 ; i < select.length ; i++) { |
---|
423 | if (select.options[i].selected) |
---|
424 | { |
---|
425 | catalogLevel = select.options[i].value; |
---|
426 | break; |
---|
427 | } |
---|
428 | |
---|
429 | } |
---|
430 | ccTree.select(catalogLevel); |
---|
431 | |
---|
432 | if (catalogLevel == '0.0') |
---|
433 | { |
---|
434 | ccAddGroup.loadPersonalContacts(); |
---|
435 | } |
---|
436 | else |
---|
437 | { |
---|
438 | ccAddGroup.clearSourceList(); |
---|
439 | if (catalogLevel == '0.2') |
---|
440 | ccAddGroup.search(); |
---|
441 | } |
---|
442 | |
---|
443 | //eval(refresh); |
---|
444 | |
---|
445 | } |
---|
446 | |
---|
447 | /* Build the Object */ |
---|
448 | var ccAddGroup ; |
---|
449 | var cAddGroup_pre_load = document.body.onload; |
---|
450 | /* Se for IE, modifica a largura da coluna dos botoes.*/ |
---|
451 | if(document.all) |
---|
452 | document.getElementById('buttons').width = 140; |
---|
453 | |
---|
454 | if (is_ie) |
---|
455 | { |
---|
456 | document.body.onload = function (e) |
---|
457 | { |
---|
458 | cAddGroup_pre_load(); |
---|
459 | ccAddGroup = new cAddGroup(); |
---|
460 | |
---|
461 | }; |
---|
462 | } |
---|
463 | else |
---|
464 | { |
---|
465 | ccAddGroup = new cAddGroup(); |
---|
466 | } |
---|