1 | // Instant Messenger |
---|
2 | // im_functions.js |
---|
3 | |
---|
4 | function IM() |
---|
5 | { |
---|
6 | this.array_lang_im = []; |
---|
7 | this.user_not_aut = []; |
---|
8 | this.vcard_contacts = []; |
---|
9 | this.vcard_user = []; |
---|
10 | this.load_photo = false; |
---|
11 | } |
---|
12 | |
---|
13 | /* |
---|
14 | * Load Contatos |
---|
15 | */ |
---|
16 | |
---|
17 | IM.prototype.load_im = function() |
---|
18 | { |
---|
19 | var force = ( arguments.length ) ? true : false; |
---|
20 | var _this = this; |
---|
21 | Sincro.count = 0; |
---|
22 | |
---|
23 | var handler_contacts = function(data) |
---|
24 | { |
---|
25 | if ( data[1] ) |
---|
26 | { |
---|
27 | _this.vcard_contacts.splice(0,_this.vcard_contacts.length); |
---|
28 | _this.vcard_user.splice(0,_this.vcard_user.length); |
---|
29 | _this.user_not_aut.splice(0,_this.user_not_aut.length); |
---|
30 | _this.mount_list(data); |
---|
31 | |
---|
32 | } |
---|
33 | _this.conf_VcardUser(data[0]); |
---|
34 | } |
---|
35 | |
---|
36 | if ( force || this.getWinContactsState() ) |
---|
37 | cIM.cExecute("$this.Ujabber.list_user",handler_contacts); |
---|
38 | } |
---|
39 | |
---|
40 | /* |
---|
41 | * Update Contatos |
---|
42 | */ |
---|
43 | |
---|
44 | IM.prototype.UpdateContacts = function() |
---|
45 | { |
---|
46 | var _this = this; |
---|
47 | _this.load_im(); |
---|
48 | } |
---|
49 | |
---|
50 | IM.prototype.showContacts = function() |
---|
51 | { |
---|
52 | if ( this.getWinContactsState() ) |
---|
53 | im_win.windowClose('contacts_im'); |
---|
54 | else |
---|
55 | { |
---|
56 | im_win.windowMaximizeRestore('contacts_im'); |
---|
57 | this.load_im(); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | IM.prototype.getWinContactsState = function() |
---|
62 | { |
---|
63 | try |
---|
64 | { |
---|
65 | var win_state = false; |
---|
66 | win_state = ( windowItems['contacts'].state == WINDOW_STATE_REGULAR ) ? true : false; |
---|
67 | win_state = ( win_state ) ? win_state : ( windowItems['contacts'].state == WINDOW_STATE_MAXIMIZED ) ? true : false; |
---|
68 | return win_state; |
---|
69 | } |
---|
70 | catch(e) |
---|
71 | { |
---|
72 | return false; |
---|
73 | } |
---|
74 | } |
---|
75 | /* |
---|
76 | * Monta Lista de Contatos |
---|
77 | */ |
---|
78 | |
---|
79 | IM.prototype.mount_list = function(pList) |
---|
80 | { |
---|
81 | var _this = this; |
---|
82 | var div = document.getElementById("div_contacts"); |
---|
83 | div.innerHTML = ""; |
---|
84 | var groups = "<b>"+_this.get_lang("list of contacts")+" - 0 </b><br>"; |
---|
85 | |
---|
86 | if(pList.length > 0){ |
---|
87 | var name_group = ""; |
---|
88 | groups = "<img id='img_all_groups' src=" + img_group_open.src + " onclick=javascript:IM.visible_group('all_groups')>" + |
---|
89 | "<b>"+_this.get_lang("list of contacts")+" - " + ( pList.length - 1 ) + "</b><br>"+ |
---|
90 | "<div id='all_groups'>"; |
---|
91 | for(var i=1; i < pList.length; i++){ |
---|
92 | if( i == 1 ){ |
---|
93 | if(pList[i].group != "" && pList[i].name != ""){ |
---|
94 | name_group = pList[i].group; |
---|
95 | groups += '<img id="img_' + pList[i].group.rm_space() + '" src="' + img_group_open.src + '" onclick="javascript:IM.visible_group(\'' + pList[i].group.rm_space() + '\')" style="margin-left:16px;">'; |
---|
96 | groups += "<b>" + pList[i].group + "</b><br>"; |
---|
97 | groups += "<div id='" + pList[i].group.rm_space() + "'>"; |
---|
98 | if(pList[i].subscription == "both"){ |
---|
99 | groups += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+pList[i].online + '\', \'' + pList[i].jid + '\');" style="cursor:pointer;padding-left:32px;"><img src="' + ((pList[i].online) == parseInt(1) ? img_online.src : img_offline.src) + '">' + pList[i].name + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>'; |
---|
100 | }else{ |
---|
101 | groups += _this.FromToNone(pList[i].jid,pList[i].subscription,pList[i].group,pList[i].name); |
---|
102 | } |
---|
103 | }else |
---|
104 | _this.user_not_aut[_this.user_not_aut.length] = pList[i].jid + ";" + i; |
---|
105 | }else{ |
---|
106 | if(pList[i].group != "" && pList[i].name != ""){ |
---|
107 | if(pList[i].group == name_group){ |
---|
108 | if(pList[i].subscription == "both"){ |
---|
109 | groups += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+pList[i].online + '\', \'' + pList[i].jid + '\');" style="cursor:pointer;padding-left:32px;"><img src="' + ((pList[i].online) == parseInt(1) ? img_online.src : img_offline.src) + '">' + pList[i].name + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>'; |
---|
110 | }else{ |
---|
111 | groups += _this.FromToNone(pList[i].jid,pList[i].subscription,pList[i].group,pList[i].name); |
---|
112 | } |
---|
113 | name_group = pList[i].group; |
---|
114 | }else{ |
---|
115 | groups += "</div>"; |
---|
116 | groups += '<img id="img_' + pList[i].group.rm_space() + '" src="' + img_group_open.src + '" onclick="javascript:IM.visible_group(\'' + pList[i].group.rm_space() + '\')" style="margin-left:16px;">'; |
---|
117 | groups += "<b>" + pList[i].group + "</b><br>"; |
---|
118 | groups += "<div id='" + pList[i].group.rm_space() + "'>"; |
---|
119 | if(pList[i].subscription == "both"){ |
---|
120 | groups += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+pList[i].online + '\', \'' + pList[i].jid + '\');" style="cursor:pointer;padding-left:32px;"><img src="' + ((pList[i].online) == parseInt(1) ? img_online.src : img_offline.src) + '">' + pList[i].name + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>'; |
---|
121 | }else{ |
---|
122 | groups += _this.FromToNone(pList[i].jid,pList[i].subscription,pList[i].group,pList[i].name); |
---|
123 | } |
---|
124 | name_group = pList[i].group; |
---|
125 | } |
---|
126 | }else{ |
---|
127 | _this.user_not_aut[_this.user_not_aut.length] = pList[i].jid + ";" + i; |
---|
128 | } |
---|
129 | } |
---|
130 | } |
---|
131 | groups += "</div><div id='out_list'></div></div>"; |
---|
132 | } |
---|
133 | |
---|
134 | // Vcard Contato; |
---|
135 | if(pList.length > 0) |
---|
136 | _this.vcard_contacts = pList; |
---|
137 | |
---|
138 | // Imprime valor de groups; |
---|
139 | div.innerHTML = groups; |
---|
140 | |
---|
141 | // Usuários sem grupo e nome; |
---|
142 | if(_this.user_not_aut.length > 0) |
---|
143 | _this.Group_Name(document.getElementById('out_list')); |
---|
144 | } |
---|
145 | |
---|
146 | /* |
---|
147 | * Define se From - To - None |
---|
148 | */ |
---|
149 | |
---|
150 | IM.prototype.FromToNone = function(pJid,pSubscription,pGroup,pName) |
---|
151 | { |
---|
152 | var n_groups = ""; |
---|
153 | var _this = this; |
---|
154 | if(pSubscription == "from") |
---|
155 | n_groups += "<div id='" + pJid + "' nucontact="+ i +" style='cursor:pointer;padding-left:32px;' onclick=javascript:IM.Authorization(\'"+pJid+"\',\'"+pSubscription+"\')><img src="+img_not_authorized.src+" title='Aguardando/Enviar Autorização'>"+pName+"</div>"; |
---|
156 | else if(pSubscription == "to") |
---|
157 | n_groups += "<div id='" + pJid + "' nucontact="+ i +" style='cursor:pointer;padding-left:32px;' onclick=javascript:IM.Authorization(\'"+pJid+"\',\'"+pSubscription+"\')><img src="+img_not_authorized.src+" title='Enviar Autorização'>"+pName+"</div>"; |
---|
158 | else if(pSubscription == "none"){ |
---|
159 | n_groups += "<div id='" + pJid + "' nucontact="+ i +" style='cursor:pointer;padding-left:32px;' onclick=javascript:IM.Authorization(\'"+pJid+"\',\'"+pSubscription+"\')><img src="+img_not_authorized.src+" title='Pedir Autorização'>"+pName+"</div>"; |
---|
160 | } |
---|
161 | return n_groups; |
---|
162 | } |
---|
163 | |
---|
164 | /* |
---|
165 | * Usuário sem grupo e nome |
---|
166 | */ |
---|
167 | |
---|
168 | IM.prototype.Group_Name = function(el) |
---|
169 | { |
---|
170 | var _this = this; |
---|
171 | var group_nt = ""; |
---|
172 | |
---|
173 | group_nt += '<img id="img_not_aut" src="' + img_group_open.src + '" onclick="javascript:IM.visible_group(\'not_aut\')" style="margin-left:16px;">'; |
---|
174 | group_nt += "<b>" + _this.get_lang("Sem Cadastro") + "</b><br>"; |
---|
175 | group_nt += "<div id='not_aut'>"; |
---|
176 | for(var i=0; i < _this.user_not_aut.length; i++){ |
---|
177 | var pos = _this.user_not_aut[i].indexOf("@"); |
---|
178 | var ind = _this.user_not_aut[i].substr((_this.user_not_aut[i].indexOf(";")+1),1); |
---|
179 | group_nt += '<div id="'+_this.user_not_aut[i]+'" onclick=Preferences.updateLoad("'+ind+'") style="cursor:pointer;padding-left:32px;">'+ |
---|
180 | '<img src="'+img_not_authorized.src+'">'+_this.user_not_aut[i].substr(0,pos)+'</div>'; |
---|
181 | } |
---|
182 | group_nt += "</div>"; |
---|
183 | el.innerHTML = group_nt; |
---|
184 | setTimeout("Templates.Users_Not_Auth()",2500); |
---|
185 | } |
---|
186 | |
---|
187 | /* |
---|
188 | * Requisitar autorização; |
---|
189 | */ |
---|
190 | |
---|
191 | IM.prototype.Authorization = function(pJid,pSubscription) |
---|
192 | { |
---|
193 | if(confirm("Enviar pedido?")){ |
---|
194 | var handler_accept_request = function(data){ |
---|
195 | if(!data) |
---|
196 | alert("Pedido já foi enviado!"); |
---|
197 | } |
---|
198 | cIM.cExecute("$this.Ujabber.AcceptRequest",handler_accept_request,"jid="+pJid+"&subscription="+pSubscription); |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | /* |
---|
203 | * Grupos dos Contatos; |
---|
204 | */ |
---|
205 | |
---|
206 | IM.prototype.visible_group = function(el) |
---|
207 | { |
---|
208 | var _this = this; |
---|
209 | el = el.rm_space(); |
---|
210 | var div = document.getElementById(el); |
---|
211 | div.style.display = "none"; |
---|
212 | var img = document.getElementById("img_" + el); |
---|
213 | img.onclick = function(){_this.unvisible_group(el)}; |
---|
214 | img.src = img_group_close.src; |
---|
215 | |
---|
216 | } |
---|
217 | |
---|
218 | IM.prototype.unvisible_group = function(el) |
---|
219 | { |
---|
220 | var _this = this; |
---|
221 | el = el.rm_space(); |
---|
222 | var div = document.getElementById(el); |
---|
223 | div.style.display = ""; |
---|
224 | var img = document.getElementById("img_" + el); |
---|
225 | img.onclick = function(){_this.visible_group(el)}; |
---|
226 | img.src = img_group_open.src; |
---|
227 | |
---|
228 | } |
---|
229 | |
---|
230 | /* |
---|
231 | * Conf. Vcard |
---|
232 | */ |
---|
233 | |
---|
234 | IM.prototype.conf_VcardUser = function(data) |
---|
235 | { |
---|
236 | var _this = this; |
---|
237 | |
---|
238 | // Vcard pessoal; |
---|
239 | |
---|
240 | if ( !_this.load_photo ){ |
---|
241 | |
---|
242 | _this.vcard_user['VCARD_FN'] = data.VCARD_FN; |
---|
243 | _this.vcard_user['VCARD_NICKNAME'] = data.VCARD_NICKNAME; |
---|
244 | _this.vcard_user['VCARD_ORGNAME'] = data.VCARD_ORGNAME; |
---|
245 | _this.vcard_user['VCARD_ORGUNIT'] = data.VCARD_ORGUNIT; |
---|
246 | _this.vcard_user['VCARD_ROLE'] = data.VCARD_ROLE; |
---|
247 | _this.vcard_user['VCARD_BDAY'] = data.VCARD_BDAY; |
---|
248 | _this.vcard_user['VCARD_DESC'] = data.VCARD_DESC; |
---|
249 | _this.vcard_user['VCARD_JID'] = data.VCARD_JID; |
---|
250 | |
---|
251 | im_win.get_photo_ldap(_this.vcard_user['VCARD_JID']); |
---|
252 | _this.load_photo = true; |
---|
253 | } |
---|
254 | |
---|
255 | // NickName; |
---|
256 | if(_this.vcard_user['VCARD_NICKNAME'] != "") |
---|
257 | document.getElementById('span_nickname').innerHTML = "<b> " + _this.vcard_user['VCARD_NICKNAME'].substring(0,30) + "</b>"; |
---|
258 | else |
---|
259 | document.getElementById('span_nickname').innerHTML = "<b> " + IM.get_lang('your nickname') + "</b>"; |
---|
260 | |
---|
261 | // Custom Message; |
---|
262 | if(_this.vcard_user['VCARD_DESC'] != "") |
---|
263 | document.getElementById('span_message').innerHTML = "<b> " + _this.vcard_user['VCARD_DESC'].substring(0,30) + "</b>"; |
---|
264 | else |
---|
265 | document.getElementById('span_message').innerHTML = "<b> " + IM.get_lang('your message') + "</b>"; |
---|
266 | |
---|
267 | } |
---|
268 | |
---|
269 | /* |
---|
270 | * Menu |
---|
271 | */ |
---|
272 | |
---|
273 | IM.prototype.visible_box = function() |
---|
274 | { |
---|
275 | var _this = this; |
---|
276 | document.getElementById('list_users').style.display = ""; |
---|
277 | var img = document.getElementById('box_menu'); |
---|
278 | img.onclick = function(){_this.unvisible_box()}; |
---|
279 | img.src = img_open_box.src; |
---|
280 | } |
---|
281 | |
---|
282 | IM.prototype.unvisible_box = function() |
---|
283 | { |
---|
284 | var _this = this; |
---|
285 | document.getElementById('list_users').style.display = "none"; |
---|
286 | var img = document.getElementById('box_menu'); |
---|
287 | img.onclick = function(){_this.visible_box()}; |
---|
288 | img.src = img_close_box.src; |
---|
289 | } |
---|
290 | |
---|
291 | /* |
---|
292 | * Traduções |
---|
293 | */ |
---|
294 | |
---|
295 | // Translate words and phrases using user language from eGroupware. |
---|
296 | IM.prototype.get_lang = function(_key,_arg1,_arg2,_arg3,_arg4) |
---|
297 | { |
---|
298 | var _this = this; |
---|
299 | if(!_this.array_lang_im[0]){ |
---|
300 | return _key+"*"; |
---|
301 | } |
---|
302 | _value = ""; |
---|
303 | for(i = 0; i < _this.array_lang_im[0].length;i++){ |
---|
304 | if(_this.array_lang_im[0][i] == _key.toLowerCase()) { |
---|
305 | _value = _this.array_lang_im[1][i]; |
---|
306 | break; |
---|
307 | } |
---|
308 | } |
---|
309 | |
---|
310 | if(!_value) |
---|
311 | return _key+"*"; |
---|
312 | |
---|
313 | if(_arg1 || _arg2 ||_arg3 || _arg4) { |
---|
314 | for(j = 1; j <= 4; j++){ |
---|
315 | if(eval("_arg"+j)) { |
---|
316 | var regExp = new RegExp("%"+j+""); |
---|
317 | _value = _value.replace(regExp,eval("_arg"+j)); |
---|
318 | } |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | return _value; |
---|
323 | } |
---|
324 | |
---|
325 | /* |
---|
326 | * Pega Mensagens |
---|
327 | */ |
---|
328 | |
---|
329 | IM.prototype.getMessage = function() |
---|
330 | { |
---|
331 | _this = this; |
---|
332 | var handler_message = function(data) |
---|
333 | { |
---|
334 | if(data.length > 0) |
---|
335 | { |
---|
336 | var aux = ""; |
---|
337 | var hora = new Date(); |
---|
338 | for(var i=0; i < data.length; i++) |
---|
339 | { |
---|
340 | mensagens = document.getElementById(data[i].from.substr(0, data[i].from.indexOf('/')) + '_chatMessages'); |
---|
341 | var nickname = data[i].from.substr(0, data[i].from.indexOf('/')); |
---|
342 | for(var j=1 ; j < _this.vcard_contacts.length ; j++) |
---|
343 | { |
---|
344 | if(data[i].from.substr(0, data[i].from.indexOf('/')) == _this.vcard_contacts[j].VCARD_JID) |
---|
345 | if(_this.vcard_contacts[j].VCARD_NICKNAME != "") |
---|
346 | nickname = _this.vcard_contacts[j].VCARD_NICKNAME; |
---|
347 | } |
---|
348 | |
---|
349 | minuto = ( hora.getMinutes() > 9 ) ? hora.getMinutes() : '0' + hora.getMinutes(); |
---|
350 | _hora = '[' + hora.getHours() + ':' + minuto + '] '; |
---|
351 | data[i].body = decodeURI(data[i].body).replace(/\\\'/g, '\''); |
---|
352 | |
---|
353 | if ( mensagens ) |
---|
354 | { |
---|
355 | mensagens.innerHTML += '<strong>' + _hora + nickname + ' fala:</strong><br/> ' + _this.emotions_icons(data[i].body) + '<br/>'; |
---|
356 | if ( windowItems[data[i].from.substr(0, data[i].from.indexOf('/'))].state != WINDOW_STATE_REGULAR && windowItems[data[i].from.substr(0, data[i].from.indexOf('/'))].state != WINDOW_STATE_MAXIMIZED ) |
---|
357 | im_win.showWindowItem(data[i].from.substr(0, data[i].from.indexOf('/'))); |
---|
358 | } |
---|
359 | else |
---|
360 | { |
---|
361 | im_win.open_chat(data[i].from.substr(0, data[i].from.indexOf('/'))); |
---|
362 | mensagens = document.getElementById(data[i].from.substr(0, data[i].from.indexOf('/')) + '_chatMessages'); |
---|
363 | mensagens.innerHTML += '<strong>' + _hora + nickname + ' fala:</strong><br/> ' + _this.emotions_icons(data[i].body) + '<br/>'; |
---|
364 | } |
---|
365 | } |
---|
366 | mensagens.scrollTop = mensagens.scrollHeight; |
---|
367 | im_win.newMessageNotification(); |
---|
368 | } |
---|
369 | } |
---|
370 | cIM.cExecute("$this.Ujabber.getMessages", handler_message); |
---|
371 | } |
---|
372 | |
---|
373 | /* |
---|
374 | * Envia Mensagens |
---|
375 | */ |
---|
376 | |
---|
377 | IM.prototype.sendMessage = function (pJID) |
---|
378 | { |
---|
379 | var _this = this; |
---|
380 | var name_document = document.getElementById(pJID + '_edita'); |
---|
381 | var envio = name_document.contentWindow.document.getElementsByTagName('body').item(0); |
---|
382 | |
---|
383 | envio.innerHTML = func.trim(envio.innerHTML.replace(/^( |<br>| )*|( |<br>| )*$/g, '')); |
---|
384 | |
---|
385 | if ( envio.innerHTML != "" ) |
---|
386 | { |
---|
387 | var message_text = "<div style='"; |
---|
388 | message_text += (envio.style.fontFamily != "") ? "font-family:"+envio.style.fontFamily+";" : ""; |
---|
389 | message_text += (envio.style.fontSize != "") ? "font-size:"+envio.style.fontSize+";" : "" ; |
---|
390 | message_text += (envio.style.fontWeight != "") ? "font-weight:"+envio.style.fontWeight+";": ""; |
---|
391 | message_text += (envio.style.fontStyle != "" ) ? "font-style:"+envio.style.fontStyle+";" : ""; |
---|
392 | message_text += (envio.style.color != "") ? "color:"+envio.style.color+";" : "color:black"; |
---|
393 | message_text += "'>"; |
---|
394 | message_text += envio.innerHTML + "</div>"; |
---|
395 | |
---|
396 | envio.innerHTML = ''; |
---|
397 | |
---|
398 | var message_element = document.getElementById(pJID + '_chatMessages'); |
---|
399 | message_element.innerHTML += '<strong>' + ((_this.vcard_user['VCARD_NICKNAME'] != "") ? _this.vcard_user['VCARD_NICKNAME'] : _this.vcard_user['VCARD_JID'] ); |
---|
400 | message_element.innerHTML += ' ' + _this.get_lang('speak') + ':</strong><br/>'; |
---|
401 | message_element.innerHTML += _this.emotions_icons(message_text.replace(/^( |<br>| )*|( |<br>| )*$/g, '')) + '<br/>'; |
---|
402 | |
---|
403 | message_element.scrollTop = message_element.scrollHeight; |
---|
404 | |
---|
405 | var handler_sendMessage = function(data) |
---|
406 | { |
---|
407 | if(!data) |
---|
408 | alert(data); |
---|
409 | } |
---|
410 | cIM.cExecute("$this.Ujabber.SendMessage",handler_sendMessage,"to="+pJID+"&body="+url_encode(encodeURI(message_text))); |
---|
411 | } |
---|
412 | } |
---|
413 | |
---|
414 | /* |
---|
415 | * Smiles |
---|
416 | */ |
---|
417 | |
---|
418 | IM.prototype.emotions_icons = function(pMessage) |
---|
419 | { |
---|
420 | for ( i = 1; i < cod_emotions.length; i++ ) |
---|
421 | { |
---|
422 | var image = eval('smile_' + i + '.src.substr(smile_' + i + '.src.indexOf(im_path))') |
---|
423 | pMessage = pMessage.replace(cod_emotions[i], '<img src="' + image + '">'); |
---|
424 | } |
---|
425 | return pMessage; |
---|
426 | } |
---|
427 | |
---|
428 | IM.prototype.atalho = function() |
---|
429 | { |
---|
430 | if ( local = func.byId('user_info') ) |
---|
431 | { |
---|
432 | var aux = new Array(); |
---|
433 | var _mix = func.newEl('a', 'a', 'img', 'img', 'dl'); |
---|
434 | |
---|
435 | var fast_menu_link = _mix[0]; |
---|
436 | var contacts_link = _mix[1]; |
---|
437 | var fast_menu_image = _mix[2]; |
---|
438 | var contacts_image = _mix[3]; |
---|
439 | var im_fast_menu = _mix[4]; |
---|
440 | |
---|
441 | fast_menu_link.onclick = function(){IM.showFastMenu();}; |
---|
442 | contacts_link.onclick = function(){IM.showContacts();}; |
---|
443 | |
---|
444 | aux['fast_menu_image'] = new Array(); |
---|
445 | aux['fast_menu_image']['element'] = fast_menu_image; |
---|
446 | aux['fast_menu_image']['style'] = 'width:9px;height:9px'; |
---|
447 | aux['fast_menu_image']['src'] = im_path + 'templates/default/images/menuarwopen.gif'; |
---|
448 | |
---|
449 | aux['im_fast_menu'] = new Array(); |
---|
450 | aux['im_fast_menu']['element'] = im_fast_menu; |
---|
451 | aux['im_fast_menu']['id'] = 'fast_menu_im'; |
---|
452 | aux['im_fast_menu']['class'] = 'menu_im'; |
---|
453 | |
---|
454 | aux['contacts_image'] = new Array(); |
---|
455 | aux['contacts_image']['element'] = contacts_image; |
---|
456 | aux['contacts_image']['id'] = 'chat_bubble'; |
---|
457 | aux['contacts_image']['src'] = im_path + 'templates/default/images/navbar.png'; |
---|
458 | aux['contacts_image']['style'] = 'width:15px;height:15px'; |
---|
459 | func.confEl(aux); |
---|
460 | |
---|
461 | func.insEl(fast_menu_image, fast_menu_link); |
---|
462 | func.insEl(contacts_image, contacts_link); |
---|
463 | func.insElB(fast_menu_link, contacts_link, im_fast_menu, document.createTextNode(' '), local.firstChild); |
---|
464 | } |
---|
465 | else |
---|
466 | setTimeout('IM.atalho()', 5000); |
---|
467 | } |
---|
468 | |
---|
469 | IM.prototype.showFastMenu = function() |
---|
470 | { |
---|
471 | if ( !messages_timeout ) |
---|
472 | { |
---|
473 | var option = func.newEl('dt'); |
---|
474 | var option_link = func.newEl('a'); |
---|
475 | var option_image = func.newEl('img'); |
---|
476 | |
---|
477 | option_link.onclick = function(){IM.login();}; |
---|
478 | |
---|
479 | func.confEl(option_image, 'src', img_online.src); |
---|
480 | func.confEl(option_image, 'style', 'width:16px;height:16px;'); |
---|
481 | |
---|
482 | func.insEl(option_image, IM.get_lang('login'), option_link); |
---|
483 | func.insEl(option_link, option); |
---|
484 | |
---|
485 | im_menu_action.menu('fast_menu_im', option); |
---|
486 | } |
---|
487 | else |
---|
488 | { |
---|
489 | var _dt = func.newEl('dt', 'dt', 'dt', 'dt', 'dt'); |
---|
490 | var _a = func.newEl('a', 'a', 'a', 'a', 'a'); |
---|
491 | |
---|
492 | for ( var i in _dt ) |
---|
493 | { |
---|
494 | if ( typeof _dt[i] == 'function' ) |
---|
495 | continue; |
---|
496 | eval('var option' + (parseInt(i)+1) + ' = _dt[' + i + '];'); |
---|
497 | eval('var option' + (parseInt(i)+1) + '_link = _a[' + i + '];'); |
---|
498 | } |
---|
499 | |
---|
500 | var _img = func.newEl('img', 'img', 'img', 'img'); |
---|
501 | |
---|
502 | for ( var i in _img ) |
---|
503 | { |
---|
504 | if ( typeof _dt[i] == 'function' ) |
---|
505 | continue; |
---|
506 | eval('var option' + (parseInt(i)+1) + '_image = _img[' + i + '];'); |
---|
507 | } |
---|
508 | |
---|
509 | option1_link.onclick = function(){IM.setStatus('online');}; |
---|
510 | option2_link.onclick = function(){IM.setStatus('idle');}; |
---|
511 | option3_link.onclick = function(){IM.setStatus('busy');}; |
---|
512 | option4_link.onclick = function(){IM.logout();}; |
---|
513 | option5_link.onclick = function(){IM.setStatus('custom')}; |
---|
514 | |
---|
515 | func.confEl(option1_image, 'src', img_online.src); |
---|
516 | func.confEl(option1_image, 'style', 'width:16px;height:16px;'); |
---|
517 | func.confEl(option2_image, 'src', img_idle.src); |
---|
518 | func.confEl(option2_image, 'style', 'width:16px;height:16px;'); |
---|
519 | func.confEl(option3_image, 'src', img_busy.src); |
---|
520 | func.confEl(option3_image, 'style', 'width:16px;height:16px;'); |
---|
521 | func.confEl(option4_image, 'src', img_offline.src); |
---|
522 | func.confEl(option4_image, 'style', 'width:16px;height:16px;'); |
---|
523 | |
---|
524 | func.insEl(option1_image, IM.get_lang('online'), option1_link); |
---|
525 | func.insEl(option1_link, option1); |
---|
526 | func.insEl(option2_image, IM.get_lang('????'), option2_link); |
---|
527 | func.insEl(option2_link, option2); |
---|
528 | func.insEl(option3_image, IM.get_lang('busy'), option3_link); |
---|
529 | func.insEl(option3_link, option3); |
---|
530 | func.insEl(option4_image, IM.get_lang('offline'), option4_link); |
---|
531 | func.insEl(option4_link, option4); |
---|
532 | func.insEl(IM.get_lang('Custom message...'), option5_link); |
---|
533 | func.insEl(option5_link, option5); |
---|
534 | |
---|
535 | im_menu_action.menu('fast_menu_im', option1, option2, option3, option4, option5); |
---|
536 | } |
---|
537 | } |
---|
538 | |
---|
539 | IM.prototype.setStatus = function(pStatus) |
---|
540 | { |
---|
541 | im_menu_action.menu('fast_menu_im', null); |
---|
542 | } |
---|
543 | |
---|
544 | IM.prototype.getStatus = function() |
---|
545 | { |
---|
546 | } |
---|
547 | |
---|
548 | IM.prototype.login = function() |
---|
549 | { |
---|
550 | try |
---|
551 | { |
---|
552 | im_menu_action.menu('fast_menu_im', null); |
---|
553 | Sincro.get_list(); |
---|
554 | Sincro.get_Message(); |
---|
555 | var contacts_image = func.byId('chat_bubble'); |
---|
556 | contacts_image.parentNode.onclick = function(){IM.showContacts()}; |
---|
557 | func.confEl(contacts_image, 'src', im_path + 'templates/default/images/navbar.png'); |
---|
558 | } |
---|
559 | catch (e) |
---|
560 | { |
---|
561 | } |
---|
562 | } |
---|
563 | |
---|
564 | IM.prototype.logout = function() |
---|
565 | { |
---|
566 | im_menu_action.menu('fast_menu_im', null); |
---|
567 | clearTimeout(messages_timeout); |
---|
568 | clearTimeout(contacts_timeout); |
---|
569 | messages_timeout = false; |
---|
570 | contacts_timeout = false; |
---|
571 | var contacts_image = func.byId('chat_bubble'); |
---|
572 | contacts_image.parentNode.onclick = function(){IM.showFastMenu()}; |
---|
573 | func.confEl(contacts_image, 'src', img_chat_bubble.src); |
---|
574 | } |
---|
575 | |
---|
576 | IM.prototype.menu_preferences = function(pElement) |
---|
577 | { |
---|
578 | if ( document.getElementById(pElement).innerHTML == "" ) |
---|
579 | { |
---|
580 | var form_pref = "<dl>"; |
---|
581 | form_pref += "<dt><a href='javascript:void(0)' onclick='javascript:Preferences.Add_userLoad()'>"; |
---|
582 | form_pref += "<img src="+img_menu.src+"> "+IM.get_lang('Add Contact')+"</a></dt>"; |
---|
583 | form_pref += "<dt><a href='javascript:void(0)' onclick='javascript:Preferences.Remove_userLoad()'>"; |
---|
584 | form_pref += "<img src="+img_menu.src+"> "+IM.get_lang('Remove Contact')+"</a></dt>"; |
---|
585 | form_pref += "<dt><a href='javascript:void(0)' onclick='javascript:Preferences.vCardLoad()'>"; |
---|
586 | form_pref += "<img src="+img_menu.src+"> "+IM.get_lang('Information')+"</a></dt>"; |
---|
587 | form_pref += "</dl>"; |
---|
588 | im_menu_action.menu(pElement, form_pref); |
---|
589 | } |
---|
590 | } |
---|
591 | |
---|
592 | IM.prototype.menu_button_right = function(pElement) |
---|
593 | { |
---|
594 | var form_menu_button_right = '<dl>'+ |
---|
595 | '<dt><a href="javascript:void(0);" onclick="javascript:Preferences.Update_NickName(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Nick') + '</a>'+ |
---|
596 | '<dt><a href="javascript:void(0);" onclick="javascript:Preferences.SendFile(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Send File') + '</a>'+ |
---|
597 | '<dt><a href="javascript:void(0);" onclick="javascript:Preferences.Update_Group(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Group') + '</a>'+ |
---|
598 | '<dt><a href="javascript:void(0);" onclick="javascript:Preferences.Remove_Contact(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Delete') + '</a>'+ |
---|
599 | '<dt><a href="javascript:void(0);" onclick="javascript:Preferences.vCardLoad_Contact(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('See Info') + '</a>'+ |
---|
600 | '</dl>'; |
---|
601 | im_menu_action.menu("_span_" + pElement, form_menu_button_right); |
---|
602 | } |
---|
603 | |
---|
604 | /* |
---|
605 | * url_encode |
---|
606 | */ |
---|
607 | |
---|
608 | function url_encode(str) |
---|
609 | { |
---|
610 | var hex_chars = "0123456789ABCDEF"; |
---|
611 | var noEncode = /^([a-zA-Z0-9\_\-\.])$/; |
---|
612 | var n, strCode, hex1, hex2, strEncode = ""; |
---|
613 | |
---|
614 | for( n = 0; n < str.length; n++ ) |
---|
615 | { |
---|
616 | if ( noEncode.test(str.charAt(n)) ) |
---|
617 | { |
---|
618 | strEncode += str.charAt(n); |
---|
619 | } |
---|
620 | else |
---|
621 | { |
---|
622 | strCode = str.charCodeAt(n); |
---|
623 | hex1 = hex_chars.charAt(Math.floor(strCode / 16)); |
---|
624 | hex2 = hex_chars.charAt(strCode % 16); |
---|
625 | strEncode += "%" + (hex1 + hex2); |
---|
626 | } |
---|
627 | } |
---|
628 | return strEncode; |
---|
629 | } |
---|
630 | |
---|
631 | /* |
---|
632 | * Ação do botão onclick da lista de contatos; |
---|
633 | */ |
---|
634 | |
---|
635 | IM.prototype.action_button = function(pEv,pStatus,pJid) |
---|
636 | { |
---|
637 | var _this = this; |
---|
638 | if(pEv.button > 1){ |
---|
639 | _this.menu_button_right(pJid); |
---|
640 | document.oncontextmenu = new Function("return false"); |
---|
641 | }else{ |
---|
642 | if(pStatus == parseInt(1)) |
---|
643 | _this.open_chat(pJid); |
---|
644 | } |
---|
645 | } |
---|
646 | |
---|
647 | /* |
---|
648 | * Abre Conversa |
---|
649 | */ |
---|
650 | |
---|
651 | IM.prototype.open_chat = function(pJID) |
---|
652 | { |
---|
653 | func.byId(pJID).firstChild.src = img_chat_bubble.src; |
---|
654 | im_win.open_chat(pJID); |
---|
655 | } |
---|
656 | |
---|
657 | |
---|
658 | String.prototype.rm_space = function() |
---|
659 | { |
---|
660 | return this.replace(/( *)/g,""); |
---|
661 | } |
---|
662 | |
---|
663 | IM.prototype.LTrim = function(value) |
---|
664 | { |
---|
665 | var w_space = String.fromCharCode(32); |
---|
666 | var strTemp = ""; |
---|
667 | var iTemp = 0; |
---|
668 | |
---|
669 | if(v_length < 1) return ""; |
---|
670 | |
---|
671 | var v_length = value ? value.length : 0; |
---|
672 | |
---|
673 | while ( iTemp < v_length ) |
---|
674 | { |
---|
675 | if ( value && value.charAt(iTemp) != w_space ) |
---|
676 | { |
---|
677 | strTemp = value.substring(iTemp,v_length); |
---|
678 | break; |
---|
679 | } |
---|
680 | iTemp++; |
---|
681 | } |
---|
682 | return strTemp; |
---|
683 | } |
---|
684 | |
---|
685 | function teste(pJID) |
---|
686 | { |
---|
687 | document.getElementById(pJID + '_edita').onkeydown = function (e){ |
---|
688 | if (is_ie) |
---|
689 | { |
---|
690 | if ((window.event.keyCode) == 13) |
---|
691 | send(pJID); |
---|
692 | } |
---|
693 | else |
---|
694 | { |
---|
695 | if ((e.keyCode) == 13) |
---|
696 | { |
---|
697 | send(pJID); |
---|
698 | return false; |
---|
699 | } |
---|
700 | } |
---|
701 | } |
---|
702 | } |
---|
703 | |
---|
704 | // Build Object |
---|
705 | var IM = new IM(); |
---|