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