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

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