source: trunk/instant_messenger/js/im_preferences.js @ 76

Revision 76, 15.5 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1// Instant Messenger
2// im_preferences.js
3
4        function IM_Preferences()
5        {
6                this.save_vcard = "";   
7                this.jid = false;
8                this.im_timer_xa = "";
9        }
10
11   /*
12        * Add
13        */
14       
15        IM_Preferences.prototype.Add_userLoad = function()
16        {
17                Templates.add_user();
18                this.SearchOrganizationsLdap();
19                var select_contact = document.getElementById('ImSelAddContact');
20                select_contact.innerHTML = "";
21        }
22       
23        IM_Preferences.prototype.SearchOrganizationsLdap = function()
24        {
25                var handler_organizations = function(data)
26                {
27                        var data = func.interface(data);
28                        var select_org = document.getElementById('ImSelOrg');
29                        if(select_org.options.length > 0)
30                                select_org.options.splice(0,select_org.options.length);
31                        var options = new Option("--Selecione -- ", -1, false, true);
32                        select_org[select_org.length] = options;
33                       
34                        for(var i in data){
35                                var options = new Option(data[i], data[i], false, true);
36                                select_org[select_org.length] = options;
37                        }
38                        select_org[0].selected = true;
39                }
40                XMLTools.request('$this.ldap_im.list_organizations_ldap','GET',handler_organizations);
41        }
42       
43        IM_Preferences.prototype.SearchContacts = function()
44        {
45                var select_org = document.getElementById('ImSelOrg');
46                var organization = "";
47                var span_load = document.getElementById('_span_load_im');
48                        span_load.style.display = "block";
49               
50                for(var i=0; i < select_org.options.length; i++){
51                        if(select_org.options[i].selected == true){
52                                organization = select_org.options[i].value;
53                        }
54                }
55                var handler_contacts = function(XMLdata)
56                {
57                        var data = func.interface(XMLdata);
58                        var select_contact = document.getElementById('ImSelAddContact');
59                        var text0 = document.getElementById('text0');
60                        var text1 = document.getElementById('text1');
61                        var content = "";
62                        select_contact.innerHTML = "";
63                        text0.value = "";
64                        text1.value = "";
65                        if(data)
66                        {
67                                for(var i in data)
68                                {
69                                        var options =  new Option(data[i].cn + " ( "+ data[i].mail + " )", data[i].mail + ";" + data[i].uid, false, false);
70                                        select_contact[select_contact.length] = options;
71                                }
72                        }
73                        span_load.style.display = "none";               
74                }
75                XMLTools.request('$this.contacts_im.list_contacts','POST',handler_contacts, 'ou='+organization);
76        }
77
78        IM_Preferences.prototype.preenche = function()
79        {
80                var select = document.getElementById('ImSelAddContact');
81                if(select.options.length > 0){
82                        for(var i=0; i < select.options.length; i++){
83                                if(select.options[i].selected == true){
84                                        var email = select.options[i].value.substr(0,select.options[i].value.indexOf(';'));
85                                        var uid = select.options[i].value.substr((select.options[i].value.indexOf(';')+1),select.options[i].value.length);
86                                        document.getElementById('text0').value = email;
87                                        document.getElementById('text1').value = select.options[i].value.substr(0,select.options[i].value.indexOf('@'));       
88                                        document.getElementById('text2').focus();
89                                        document.getElementById('text3').value = uid;                   
90                                }
91                        }
92                }
93        }
94       
95        IM_Preferences.prototype.Add_user = function(pFunc)
96        {
97                var text0 = document.getElementById('text0');
98                var text1 = document.getElementById('text1');
99                var text2 = document.getElementById('text2');
100                var text3 = ( document.getElementById('text3') != null ) ? document.getElementById('text3') : false;
101
102                var _this = this;
103                var jid   = text0.value;
104                var subscription = "";
105
106                if(func.trim(text0.value) != "" && func.trim(text1.value) != "" && func.trim(text2.value) != "")
107                {
108                        var handler_add_contact = function(data)
109                        {
110                                IM.vcards = false;
111                                IM.Vcard();
112                               
113                                text0.value = "";
114                                text1.value = "";
115                                text2.value = "";       
116                                if(pFunc != 'divAddUser_im')
117                                {
118                                        if(document.getElementById('im_cell_' + jid))
119                                        {
120                                                var div_jid = document.getElementById('im_cell_' + jid);
121                                                div_jid.parentNode.removeChild(div_jid);
122                               
123                                                for(var i in IM.UsersNot)
124                                                        if( IM.UsersNot[i] === jid )
125                                                                IM.UsersNot.splice(i,1);
126       
127                                                im_win.windowClose(pFunc);
128                                                Subscription.subscribed(jid);
129                                                IM.setStatus(statusFlag);
130                                                setTimeout('Subscription.subscribe("'+jid+'")',2000);
131                                        }
132                                }
133                               
134                                if( IM.UsersNot.length == 0 )
135                                        im_win.windowClose('divFormAuthUser_im');
136                        }
137                        var name = text1.value;
138                        var group = text2.value;
139                        if(text3){
140                                var email = text3.value + "@" + text0.value.substr((text0.value.indexOf('@')+1),text0.value.length);
141                        }else{
142                                var email = text0.value;
143                        }
144                        XMLTools.request('$this.Ujabber.addContacts','POST',handler_add_contact,"email="+email+"&name="+name+"&group="+group);
145                }else{
146                        alert("Informe todos os campos!");
147                }
148        }
149       
150        IM_Preferences.prototype.AcceptRequestUser = function(pJid)
151        {
152                Templates.AcceptRequestUser();
153                document.getElementById('text0').value = pJid;
154                document.getElementById('text1').value = pJid.substr(0,pJid.indexOf('@'));
155                document.getElementById('text1').focus();
156                document.getElementById('text1').select();
157                document.getElementById('span0').innerHTML = pJid.substr(0,pJid.indexOf('@'));
158        }
159
160   /*
161        * Remove
162        */
163
164        IM_Preferences.prototype.RemoveContact = function(pJid)
165        {
166                var _this = this;
167                if(!pJid)
168                {
169                        var sel_box = document.getElementById('sel_contact');
170                        for(var i=0; i < sel_box.options.length; i++)
171                        {
172                                if(sel_box[i].selected && sel_box.options[i].value != 0)
173                                        pJid = sel_box.options[i].value;
174                        }
175                }
176                if( pJid )
177                {
178                        if( confirm('Deseja remover o contato : ' + pJid) )
179                        {
180                                IM.vcards = false;
181                                IM.Vcard();
182                                var div_child = document.getElementById(pJid);
183                                div_child.parentNode.removeChild(div_child);
184                                _this.ComboRemoveUser(_this.LoadJids());               
185                                var handler_remove_contact = function(data)
186                                {
187                                };
188                                XMLTools.request('$this.Ujabber.removeContact','POST',handler_remove_contact,"jid="+pJid);
189                        }
190                }else
191                        alert('Opção inválida !!');
192        }
193       
194        IM_Preferences.prototype.Remove_userLoad = function()
195        {
196                Templates.remove_user();
197                var div_allg = document.getElementById('all_groups');
198                var _this = this;
199                _this.ComboRemoveUser(_this.LoadJids());               
200        }
201
202        IM_Preferences.prototype.ComboRemoveUser = function(pJids)
203        {
204                var sel_box = document.getElementById('sel_contact');
205               
206                if( document.getElementById('sel_contact') != null )
207                {
208                        if( sel_box.options.length > 0 )
209                        {
210                                for(var i=0; i < sel_box.options.length; i++)
211                                {
212                                        sel_box.options[i] = null;
213                                        i--;
214                                }
215                        }
216       
217                        var opt = new Option('--- Selecione ---',0,false,true);
218                        sel_box[sel_box.length] = opt;         
219                        for(var i in pJids)
220                        {
221                                var opt = new Option(pJids[i], pJids[i], false, true);
222                                sel_box[sel_box.length] = opt;
223                        }
224                        sel_box[0].selected = true;
225                }
226        }
227
228        IM_Preferences.prototype.DenyRequestUser = function(pJid)
229        {
230                if(confirm('Deseja excluir ' + pJid + '?'))
231                {
232                        var div_jid = document.getElementById('im_cell_' + pJid);
233                        div_jid.parentNode.removeChild(div_jid);
234                       
235                        for(var i in IM.UsersNot)
236                                if(IM.UsersNot[i] === pJid)
237                                        IM.UsersNot.splice(i,1);
238
239                        if( IM.UsersNot.length == 0 )
240                                im_win.windowClose('divFormAuthUser_im');
241
242                        var handler_denyrequest = function(data)
243                        {
244                        };
245                        XMLTools.request('$this.Ujabber.unsubscribe','POST',handler_denyrequest,'jid='+pJid);
246                }
247        }
248
249        /*
250         * LoadJids
251         */
252
253        IM_Preferences.prototype.LoadJids = function()
254        {
255                var div_allg = document.getElementById('all_groups');
256                var elements = div_allg.firstChild;
257                var jids = [];
258                while ( elements )
259                {                       
260                        var childs = elements.firstChild;
261                        while( childs )
262                        {
263                                if(childs.tagName == "DIV")
264                                        jids[jids.length] = childs.id;
265                                childs = childs.nextSibling;
266                        }
267                        elements = elements.nextSibling;
268                }
269                jids.sort();
270               
271                return jids;   
272        }
273       
274   /*
275    * Update
276    */
277   
278   IM_Preferences.prototype.Update_ = function(pJid,pType)
279   {
280                var div_child = document.getElementById(pJid);
281                var group = div_child.parentNode.id;
282                var name  = div_child.firstChild;
283                        name = name.nextSibling.nodeValue;
284
285                if(pType)
286                {
287                        var action = prompt('Digite um novo apelido para : ' + pJid, " ");
288                        name = (action == "Apelido") ? "" : action ;
289                }else{
290                        var action = prompt('Digite um novo grupo para : ' + pJid , " ");
291                        group = action ;
292                }
293               
294                if( action != "" && action != null)
295                {
296                        var handler_update_contact = function(XMLdata)
297                        {
298                        };
299                        XMLTools.request('$this.Ujabber.updateContact','POST',handler_update_contact,"jid="+pJid+"&name="+name+"&group="+group);
300                }
301   }
302
303        IM_Preferences.prototype.Update_Group = function(pJid)
304        {
305                this.Update_(pJid,false);               
306        }
307               
308        IM_Preferences.prototype.Update_NickName = function(pJid)
309        {
310                this.Update_(pJid,true);   
311        }
312   
313   /*
314        * Vcard
315        */
316
317        IM_Preferences.prototype.vCardInit = function()
318        {
319                var _this = this;
320                var nickname = "";
321                var message  = "";
322                var vcards   = "";
323
324                var handler_getId = function(_XMLdata)
325                {
326                        var jid = _XMLdata.getElementsByTagName("retorno").item(0);
327                        jid = jid.firstChild.nodeValue;
328                        _this.jid = jid;
329                       
330                        if((vcards = _this.vCardLoad(jid)))
331                        {
332                                nickname = vcards.substr(vcards.indexOf('NICKNAME'),vcards.length);
333                                nickname = nickname.substr(0,nickname.indexOf('|'));
334                                nickname = nickname.substr(nickname.indexOf(':') + 1 , nickname.length);
335
336                                message = vcards.substr(vcards.indexOf('DESC'),vcards.length);
337                                message = message.substr(0,message.indexOf('|'));
338                                message = message.substr(message.indexOf(':') + 1 , message.length);
339                        }
340                       
341                        nickname = (func.trim(nickname) != "" ) ? nickname : _this.jid ;
342                        message  = (func.trim(message) != "" ) ? message : "Sua Mensagem";
343                        IM.custom_message = message;
344                       
345                        var span_nick = document.getElementById('span_nickname');
346                                span_nick.innerHTML = ( nickname ) ? "<b>" + decodeURI(nickname.substring(0,15)) + "</b>" : "<b>" + IM.get_lang('Nickname') + "</b>";
347                }
348                XMLTools.request('$this.Ujabber.getJid','GET',handler_getId);
349        }
350
351        IM_Preferences.prototype.vCardLoad = function(Jid)
352        {
353                var div_jid  = document.getElementById("vcard_" + Jid);
354                var strg = div_jid.innerHTML;
355                var elements = div_jid.firstChild;
356                var exp , tag  = '';
357               
358                while ( elements )
359                {                       
360                        if(elements.tagName != undefined && elements.tagName.substr(0,1) != "/" )
361                        {               
362                                tag = elements.tagName;
363                                exp = eval('/<'+tag+'>/gi');
364                                strg = strg.replace(exp, tag + " : " );
365                                exp = eval('/<\\/'+tag+'>/gi');
366                                strg = strg.replace(exp, " | ");
367                        }
368                        elements = elements.nextSibling;
369                }                       
370
371                return strg;
372        }
373               
374        IM_Preferences.prototype.vCard = function()
375        {
376                if(!this.jid){
377                        alert('Carregando !!');
378                }else{
379                        var div_jid  = document.getElementById("vcard_" + this.jid);
380                        var strg = div_jid.innerHTML;
381                        Templates.information_user(strg);
382                }       
383        }
384
385        IM_Preferences.prototype.vCardLoad_Contact = function(pJid)
386        {
387                if(!this.jid){
388                        alert('Carregando !!');
389                }else{
390                        if(document.getElementById('vcard_' + pJid) != null)
391                        {
392                                var vcards = document.getElementById('vcard_' + pJid);
393                                Templates.information_Contact(vcards.innerHTML);
394                        }else
395                                alert('Vcard não carregado!');
396                }
397        }
398       
399        IM_Preferences.prototype.vCardAdd = function()
400        {
401                var Nvcard = new Array('FN','NICKNAME','ORGNAME','ORGUNIT','ROLE','BDAY','DESC');
402                var vcard = "";
403                var value = "";
404                for(var i in Nvcard)
405                {
406                        if( Nvcard[i] === 'NICKNAME' )
407                        {       
408                                var nn = ( func.trim(document.getElementById(Nvcard[i]).value) != "") ? document.getElementById(Nvcard[i]).value : this.jid;
409                                document.getElementById('span_nickname').innerHTML = "<b>" + nn.substring(0,15) + "</b>";
410                        }
411
412                        value = document.getElementById(Nvcard[i]).value;
413                        value = (func.trim(value) != "") ? value : "";
414                        vcard += value + "_vkrd_";
415                }
416               
417                vcard = vcard.substr(0,vcard.length - 6 );             
418               
419                var handler_vcard_add = function(XMLdata)
420                {
421                };
422                XMLTools.request('$this.Ujabber.newVcard','POST',handler_vcard_add,"vcard="+escape(vcard));     
423                alert('Informações Cadastradas / Adicionadas !!!');     
424        }
425       
426   /*
427        * IM_Preferences
428        */
429       
430        IM_Preferences.prototype.yourPreferences = function()
431        {
432                Templates.yourPreferences();
433        }
434
435        IM_Preferences.prototype.SetYourPreferences = function()
436        {
437                var preferences = "";
438                preferences  = ( func.byId('ch_offline').checked ) ? 'ch_offline:true;' : 'ch_offline:false;';
439                if( func.byId('in_time').value )
440                {
441                        var numbers = /^\d+$/;
442                        if(numbers.test(func.byId('in_time').value) && func.byId('in_time').value != "0")
443                                var minutes = func.byId('in_time').value;
444                        else
445                        {
446                                alert('Informe valores válidos !');
447                                func.byId('in_time').focus();
448                                return false;
449                        }
450                }
451
452                this.im_timer_xa = func.byId('in_time').value;
453                preferences += ( func.trim(func.byId('in_time').value )) ? 'in_time:' + func.byId('in_time').value + ";" : 'in_time:0;';
454                preferences += ( func.byId('rd_nm').checked ) ? 'rd_nm:true;' : 'rd_nm:false;';
455                preferences += ( func.byId('rd_ch').checked ) ? 'rd_ch:true' : 'rd_ch:false';
456                IM.userPrefe = preferences;
457               
458                var handler_preferences = function(XMLdata)
459                {
460                        var data = XMLdata.getElementsByTagName('retorno').item(0);
461                        data = eval(data.firstChild.nodeValue);
462                        if(data)
463                        {
464                                IM.Contacts_Offline();
465                                alert('Preferências salvas !');
466                        }
467                };
468                XMLTools.request('$this.db_im.set_preferences','POST',handler_preferences,'preferences='+preferences);
469        }
470       
471        IM_Preferences.prototype.GetYourPreferences = function()
472        {
473                var _this = this;
474                if(!IM.userPrefe)
475                {
476                        var handler_getPreferences = function(XMLdata)
477                        {
478                                var data = XMLdata.getElementsByTagName('retorno').item(0);
479                                data = data.firstChild.nodeValue;
480                                IM.userPrefe = data;
481                                _this.TimerXa(_this.LoadPreferences('in_time'));
482                        }
483                        XMLTools.request('$this.db_im.get_preferences','GET',handler_getPreferences);
484                }
485        }
486       
487        IM_Preferences.prototype.LoadPreferences = function(pElement)
488        {
489                var preferences_im = IM.userPrefe;
490               
491                while( preferences_im !== "")
492                {
493                        var values = "";
494                        var value = "";
495                        if(value = preferences_im.substr(0,preferences_im.indexOf(';')))
496                        {
497                                values = value + '\n';
498                                preferences_im = preferences_im.replace(value,'');     
499                        }
500                        if(preferences_im.substr(0,1) == ";"){
501                                preferences_im = preferences_im.substr(1,preferences_im.length);
502                        }else{
503                                values = preferences_im + '\n';
504                                preferences_im = '';
505                        }
506                       
507                        var ele = values.substr(0,values.indexOf(':'));
508                        var val = values.substr((values.indexOf(':')+1),values.length);
509
510                        if(ele == pElement)
511                                return val;
512
513                        if((document.getElementById(ele)!= null) && (document.getElementById(ele).type == 'text'))
514                                document.getElementById(ele).value = val;
515                        else
516                                if(document.getElementById(ele) != null)
517                                        document.getElementById(ele).checked = eval(val);
518                }
519        }
520
521   /*
522    * Estado de Ausente Automático
523    */
524       
525        IM_Preferences.prototype.TimerXa = function(pTimer)
526        {
527                this.im_timer_xa = pTimer;
528                _awayTimer = setTimeout("IM.setAway()", parseInt(pTimer) * 60000 );
529        }
530
531   /*
532        *  Detalhes do Contato para Autorização
533        */
534       
535        IM_Preferences.prototype.Info_Contact = function(pJid)
536        {
537                var element = "_span_not_" + pJid;
538                var uid = pJid.substr(0,pJid.indexOf('@'));
539                var handler_ldap =  function(data)
540                {
541                        var data = func.interface(data);
542                        var XMLinfoLdap = "";
543                        if(data)
544                        {
545                                XMLinfoLdap = '<info_user>';
546                                for(var i in data)                     
547                                        XMLinfoLdap += '<item lang_name="'+IM.get_lang('Name')+'" name="'+ data[i].cn +'" lang_email="'+IM.get_lang('E-mail')+'" email="'+ data[i].mail +'" />';
548                                XMLinfoLdap += '</info_user>';
549                        }
550                        im_menu_action.menu(element, parse_XmlXsl(XMLinfoLdap,'info_contact_ldap.xsl'));
551                        if(document.getElementById('im_span_avatar') != null)
552                        {
553                                var span = document.getElementById('im_span_avatar');
554                                var     img = func.newEl('img');
555                                func.confEl(img, 'id', pJid + '_avatar');
556                                func.confEl(img, 'src', img_photo.src);
557                                func.confEl(img, 'style', 'height:65px;width:60px;align:right;');
558                                span.appendChild(img);
559                                // Foto Ldap;
560                                im_win.get_photo_ldap(pJid);
561                        }
562                }
563                XMLTools.request('$this.ldap_im.info_user','POST',handler_ldap,'uid='+uid);
564        }
565       
566        // Build Object
567        var IM_Preferences = new IM_Preferences();
Note: See TracBrowser for help on using the repository browser.