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