1 | (function() |
---|
2 | { |
---|
3 | var _conn; |
---|
4 | var _xtools; |
---|
5 | var _window; |
---|
6 | var _myWindow; |
---|
7 | var _is_ie; |
---|
8 | |
---|
9 | function _add_user() |
---|
10 | { |
---|
11 | if( arguments.length > 0 ) |
---|
12 | { |
---|
13 | _myWindow = arguments[0]; |
---|
14 | } |
---|
15 | |
---|
16 | var _win_add = _window.load('add_user_im'); |
---|
17 | _win_add.title('.:: Adicionar Novos Contatos ::.'); |
---|
18 | _win_add.size(440); |
---|
19 | _win_add.position(200,80); |
---|
20 | _win_add.wc.style.padding = "3px"; |
---|
21 | |
---|
22 | var _params = { |
---|
23 | 'lang1':jabberitGetLang('Name of Contacts'), |
---|
24 | 'lang2':jabberitGetLang('Search'), |
---|
25 | 'lang3':jabberitGetLang('member of organization'), |
---|
26 | 'lang4':jabberitGetLang('nickname'), |
---|
27 | 'lang5':jabberitGetLang('group'), |
---|
28 | 'lang6':jabberitGetLang('add'), |
---|
29 | 'lang7':jabberitGetLang('close'), |
---|
30 | 'lang8':jabberitGetLang('Others Expressos') |
---|
31 | }; |
---|
32 | |
---|
33 | _win_add.bz.style.display = "none"; |
---|
34 | _win_add.bx.style.display = "none"; |
---|
35 | |
---|
36 | _win_add.content( _xtools.parse(_xtools.xml('adduser'), 'add_user.xsl', _params)); |
---|
37 | |
---|
38 | _conn.go('$this.contacts_im.getParticipantsExternal', |
---|
39 | function(data) |
---|
40 | { |
---|
41 | var data = eval(data); |
---|
42 | var elementDiv = document.getElementById('external_Participants_Jabberit'); |
---|
43 | |
---|
44 | if( data ) |
---|
45 | elementDiv.style.display = 'block'; |
---|
46 | }); |
---|
47 | |
---|
48 | _config( _win_add.wc.childNodes[2].childNodes[0], |
---|
49 | 'onclick', |
---|
50 | function() |
---|
51 | { |
---|
52 | var _name = document.getElementById('im_name'); |
---|
53 | var _group = document.getElementById('im_group'); |
---|
54 | var jidUser = document.getElementById('im_jidUser').value; |
---|
55 | var _jid = document.getElementById('im_jid').value; |
---|
56 | var _status = document.getElementById('im_status_add'); |
---|
57 | |
---|
58 | _status.innerHTML = ''; |
---|
59 | _name.previousSibling.style.color = "#000"; |
---|
60 | |
---|
61 | if ( _jid ) |
---|
62 | { |
---|
63 | _name.value = _name.value.replace(/^( )*|( )*$/g, ''); |
---|
64 | _group.value = _group.value.replace(/^( )*|( )*$/g, ''); |
---|
65 | |
---|
66 | if ( !(_name.value) || !(_group.value) ) |
---|
67 | { |
---|
68 | if ( !(_name.value) ) |
---|
69 | alert( jabberitGetLang('ATTENTION') + "!!\nInforme um \"NOME\"."); |
---|
70 | |
---|
71 | if ( !(_group.value) ) |
---|
72 | alert( jabberitGetLang('ATTENTION') + "!!\nInforme um \"GRUPO\"."); |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | var _uid; |
---|
77 | |
---|
78 | if ( (_uid = document.getElementById('im_uid')) ) |
---|
79 | _uid = _uid.value; |
---|
80 | else |
---|
81 | _uid = _jid.substr(0, (_jid.indexOf('@') - 1)); |
---|
82 | |
---|
83 | |
---|
84 | _conn.go('$this.contacts_im.verifyAddNewContact', |
---|
85 | function(data) |
---|
86 | { |
---|
87 | data = eval(data); |
---|
88 | |
---|
89 | if( !data ) |
---|
90 | { |
---|
91 | alert("*********** " + jabberitGetLang("Attention") + "!! ***********\n" + |
---|
92 | jabberitGetLang("This user is part of a small group!") + |
---|
93 | "\n" + jabberitGetLang("Contact was not added!")); |
---|
94 | _name.value = ''; |
---|
95 | _group.value = ''; |
---|
96 | |
---|
97 | } |
---|
98 | else |
---|
99 | { |
---|
100 | |
---|
101 | var result; |
---|
102 | _name.parentNode.style.display = 'none'; |
---|
103 | _name.parentNode.nextSibling.style.display = 'none'; |
---|
104 | _status.innerHTML = '<br/>Adicionando contato, aguarde....<br/>'; |
---|
105 | |
---|
106 | try |
---|
107 | { |
---|
108 | |
---|
109 | if( elementIframe = document.getElementById('iframe_applet_jabberit') ) |
---|
110 | { |
---|
111 | if( !_is_ie ) |
---|
112 | result = elementIframe.contentDocument.applets[0].addContact( jidUser, _name.value, _group.value ); |
---|
113 | else |
---|
114 | result = elementIframe.contentWindow.document.applets[0].addContact( jidUser, _name.value, _group.value ); |
---|
115 | } |
---|
116 | else // If Pop-Up |
---|
117 | { |
---|
118 | result = _myWindow.document.applets[0].addContact( jidUser, _name.value, _group.value ); |
---|
119 | } |
---|
120 | _status.innerHTML = '<br/>' + jabberitGetLang('Add contact!') + '<br/>'; |
---|
121 | } |
---|
122 | catch(e) |
---|
123 | { |
---|
124 | _status.innerHTML = '<br/>' + jabberitGetLang('The module is not loaded') + '! ' + |
---|
125 | jabberitGetLang('Contact was not added!') + '<br/>'; |
---|
126 | |
---|
127 | } |
---|
128 | setTimeout('cleanStatusAddContactIM();',2500); |
---|
129 | |
---|
130 | _name.value = ''; |
---|
131 | _group.value = ''; |
---|
132 | } |
---|
133 | }, "uid="+_uid); |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | ); |
---|
138 | |
---|
139 | _config(_win_add.wc.childNodes[2].childNodes[1], |
---|
140 | 'onclick', |
---|
141 | function() |
---|
142 | { |
---|
143 | _win_add.button(_win_add.bc); |
---|
144 | } |
---|
145 | ); |
---|
146 | } |
---|
147 | |
---|
148 | function _config(pObj, pEvent, pHandler) |
---|
149 | { |
---|
150 | if ( typeof pObj == 'object' ) |
---|
151 | { |
---|
152 | if ( pEvent.substring(0, 2) == 'on' ) |
---|
153 | pEvent = pEvent.substring(2, pEvent.length); |
---|
154 | |
---|
155 | if ( pObj.addEventListener ) |
---|
156 | pObj.addEventListener(pEvent, pHandler, false); |
---|
157 | else if ( pObj.attachEvent ) |
---|
158 | pObj.attachEvent('on' + pEvent, pHandler); |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | function _highlight(e) |
---|
163 | { |
---|
164 | var el = ( e.target ) ? e.target : e.srcElement; |
---|
165 | var color = "#fff"; |
---|
166 | if ( e.type.indexOf('mouseover') != -1 ) |
---|
167 | color = "#dedede"; |
---|
168 | el.style.backgroundColor = color; |
---|
169 | } |
---|
170 | |
---|
171 | function _search() |
---|
172 | { |
---|
173 | var _loading = document.getElementById('__span_load_im'); |
---|
174 | var _target = document.getElementById('im_ldap_user'); |
---|
175 | var _particiExt = document.getElementById('external_Participants_Jabberit').firstChild; |
---|
176 | |
---|
177 | function getUsersLdap(_data) |
---|
178 | { |
---|
179 | var _params = { |
---|
180 | 'many_results' : jabberitGetLang('More than 50 results. Please, try to refine your search.'), |
---|
181 | 'empty' : jabberitGetLang('None result was found.') |
---|
182 | }; |
---|
183 | |
---|
184 | _target.innerHTML = _xtools.parse(_data,'list_ldap_contacts.xsl', _params); |
---|
185 | |
---|
186 | function _show(m) |
---|
187 | { |
---|
188 | m = ( m.target ) ? m.target : m.srcElement; |
---|
189 | |
---|
190 | if ( m.getAttribute('value')) |
---|
191 | { |
---|
192 | var jidUser = m.getAttribute('jid'); |
---|
193 | m = m.getAttribute('value'); |
---|
194 | } |
---|
195 | else |
---|
196 | { |
---|
197 | var jidUser = m.parentNode.getAttribute('jid'); |
---|
198 | m = m.parentNode.getAttribute('value'); |
---|
199 | } |
---|
200 | |
---|
201 | if ( !m ) |
---|
202 | return false; |
---|
203 | |
---|
204 | document.getElementById('__span_load_im_group').style.display = 'block'; |
---|
205 | document.getElementById('im_jidUser').value = jidUser; |
---|
206 | document.getElementById('im_jid').value = m.substr(0, m.indexOf(';')); |
---|
207 | document.getElementById('im_uid').value = m.substr((m.indexOf(';')+1)); |
---|
208 | |
---|
209 | var _name = document.getElementById('im_name'); |
---|
210 | var groups = ""; |
---|
211 | var data; |
---|
212 | |
---|
213 | var first_name = document.getElementById(m).innerHTML; |
---|
214 | first_name = first_name.substr(0, first_name.indexOf(' ')); |
---|
215 | |
---|
216 | _name.value = first_name; |
---|
217 | _name.previousSibling.style.color = "#000"; |
---|
218 | _name.parentNode.style.display = 'block'; |
---|
219 | _name.parentNode.nextSibling.style.display = 'block'; |
---|
220 | _name.parentNode.nextSibling.nextSibling.innerHTML = ''; |
---|
221 | |
---|
222 | try |
---|
223 | { |
---|
224 | // If Layer; |
---|
225 | if( elementIframe = document.getElementById('iframe_applet_jabberit') ) |
---|
226 | { |
---|
227 | if( !_is_ie ) |
---|
228 | groups = elementIframe.contentDocument.applets[0].getGroupsToExpresso(); |
---|
229 | else |
---|
230 | groups = elementIframe.contentWindow.document.applets[0].getGroupsToExpresso(); |
---|
231 | } |
---|
232 | else // If Pop-Up |
---|
233 | { |
---|
234 | groups = _myWindow.document.applets[0].getGroupsToExpresso(); |
---|
235 | } |
---|
236 | |
---|
237 | if( typeof(groups) == 'object') |
---|
238 | { |
---|
239 | data = groups + ";"; |
---|
240 | data = data.substring(0,(data.length-2)); |
---|
241 | } |
---|
242 | else |
---|
243 | data = groups.substring(0,(groups.length-1)); |
---|
244 | |
---|
245 | if( data ) |
---|
246 | { |
---|
247 | document.getElementById('im_group').setAttribute('selectBoxOptions', data); |
---|
248 | |
---|
249 | if( document.getElementById('selectBox0') == null ) |
---|
250 | editS.create(document.getElementById('im_group')); |
---|
251 | } |
---|
252 | |
---|
253 | document.getElementById('__span_load_im_group').style.display = 'none'; |
---|
254 | document.getElementById('im_group').value = ''; |
---|
255 | document.getElementById('im_group').focus(); |
---|
256 | } |
---|
257 | catch(e) |
---|
258 | { |
---|
259 | alert("*********** " + jabberitGetLang("Attention") + "!! ***********\n" + |
---|
260 | jabberitGetLang("The module is not loaded") + "!\n" ); |
---|
261 | |
---|
262 | document.getElementById('__span_load_im_group').style.display = 'none'; |
---|
263 | } |
---|
264 | } |
---|
265 | |
---|
266 | var _member = _target.firstChild; |
---|
267 | |
---|
268 | while ( _member ) |
---|
269 | { |
---|
270 | if( _member.getAttribute('photo') === '1' ) |
---|
271 | { |
---|
272 | var uid = _member.getAttribute('value'); |
---|
273 | uid = uid.substr(uid.indexOf(';') + 1); |
---|
274 | _member.style.backgroundImage = 'url(' + path_jabberit + 'inc/getphoto.php?uid=' + uid + ')'; |
---|
275 | } |
---|
276 | _config(_member, 'onclick', _show); |
---|
277 | |
---|
278 | _member = _member.nextSibling; |
---|
279 | } |
---|
280 | } |
---|
281 | |
---|
282 | _loading.style.display = "block"; |
---|
283 | |
---|
284 | if(!_particiExt.checked) |
---|
285 | { |
---|
286 | _conn.go( |
---|
287 | '$this.contacts_im.list_contacts', |
---|
288 | function(_data) |
---|
289 | { |
---|
290 | getUsersLdap(_data); |
---|
291 | _loading.style.display = "none"; |
---|
292 | }, |
---|
293 | 'name='+ arguments[0] |
---|
294 | ); |
---|
295 | } |
---|
296 | else |
---|
297 | { |
---|
298 | |
---|
299 | function checkMail(pMail) |
---|
300 | { |
---|
301 | var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); |
---|
302 | if(er.test(pMail)) |
---|
303 | return true; |
---|
304 | else |
---|
305 | return false; |
---|
306 | } |
---|
307 | |
---|
308 | if( checkMail(arguments[0]) ) |
---|
309 | { |
---|
310 | _conn.go( |
---|
311 | '$this.ldap_im.list_participants_externals', |
---|
312 | function(data) |
---|
313 | { |
---|
314 | getUsersLdap(data); |
---|
315 | _loading.style.display = "none"; |
---|
316 | }, |
---|
317 | 'mail=' + arguments[0] |
---|
318 | ); |
---|
319 | } |
---|
320 | else |
---|
321 | { |
---|
322 | alert(jabberitGetLang('Inform a valid e-mail!')); |
---|
323 | _loading.style.display = "none"; |
---|
324 | } |
---|
325 | } |
---|
326 | |
---|
327 | } |
---|
328 | |
---|
329 | function LDAP() |
---|
330 | { |
---|
331 | _conn = arguments[0]; |
---|
332 | _xtools = arguments[1]; |
---|
333 | _window = arguments[2]; |
---|
334 | _is_ie = arguments[3]; |
---|
335 | } |
---|
336 | |
---|
337 | LDAP.prototype.search = _search; |
---|
338 | LDAP.prototype.add = _add_user; |
---|
339 | window.JITLdap = LDAP; |
---|
340 | } |
---|
341 | )(); |
---|
342 | |
---|
343 | function cleanStatusAddContactIM() |
---|
344 | { |
---|
345 | document.getElementById('im_status_add').innerHTML = ''; |
---|
346 | } |
---|