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

Revision 57, 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','POST',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 name  = div_child.innerHTML.substr((div_child.innerHTML.indexOf('>') + 1 ),div_child.innerHTML.length);
280                var group = div_child.parentNode.id;
281               
282                if(pType)
283                {
284                        var action = prompt('Digite um novo apelido para : ' + pJid );
285                        name = action;
286                }else{
287                        var action = prompt('Digite um novo grupo para : ' + pJid );
288                        group = action;
289                }
290               
291                if( action != "" && action != null)
292                {
293                        var handler_update_contact = function(XMLdata)
294                        {
295                        };
296                        XMLTools.request('$this.Ujabber.updateContact','POST',handler_update_contact,"jid="+pJid+"&name="+name+"&group="+group);
297                }
298               
299   }
300
301        IM_Preferences.prototype.Update_Group = function(pJid)
302        {
303                this.Update_(pJid,false);               
304        }
305               
306        IM_Preferences.prototype.Update_NickName = function(pJid)
307        {
308                this.Update_(pJid,true);   
309        }
310   
311   /*
312        * Vcard
313        */
314
315        IM_Preferences.prototype.vCardInit = function()
316        {
317                var _this = this;
318                var handler_getId = function(_XMLdata)
319                {
320                        var jid = _XMLdata.getElementsByTagName("retorno").item(0);
321                        jid = jid.firstChild.nodeValue;
322                        _this.jid = jid;
323
324                        var vcards = _this.vCardLoad(jid);
325                       
326                        var nickname = vcards.substr(vcards.indexOf('NICKNAME'),vcards.length);
327                                nickname = nickname.substr(0,nickname.indexOf('|'));
328                                nickname = nickname.substr(nickname.indexOf(':') + 1 , nickname.length);
329
330                        var message = vcards.substr(vcards.indexOf('DESC'),vcards.length);
331                                message = message.substr(0,message.indexOf('|'));
332                                message = message.substr(message.indexOf(':') + 1 , message.length);
333
334                        var span_nick = document.getElementById('span_nickname');
335                                span_nick.innerHTML = ( nickname ) ? "<b>&nbsp;" + decodeURI(nickname.substring(0,15)) + "</b>" : "<b>&nbsp;" + IM.get_lang('Nickname') + "</b>";
336                        var span_mess = document.getElementById('span_message');
337                                span_mess.innerHTML = ( message ) ? "<b>&nbsp;" + decodeURI(message.substring(0,20)) + "</b>" : "<b>&nbsp;" + IM.get_lang('Status') + "</b>";
338                }
339                XMLTools.request('$this.Ujabber.getJid','GET',handler_getId);
340        }
341
342        IM_Preferences.prototype.vCardLoad = function(Jid)
343        {
344                var div_jid  = document.getElementById("vcard_" + Jid);
345                var strg = div_jid.innerHTML;
346                var elements = div_jid.firstChild;
347                var exp , tag  = '';
348               
349                while ( elements )
350                {                       
351                        if(elements.tagName != undefined && elements.tagName.substr(0,1) != "/" )
352                        {               
353                                tag = elements.tagName;
354                                exp = eval('/<'+tag+'>/gi');
355                                strg = strg.replace(exp, tag + " : " );
356                                exp = eval('/<\\/'+tag+'>/gi');
357                                strg = strg.replace(exp, " | ");
358                        }
359                        elements = elements.nextSibling;
360                }                       
361
362                return strg;
363        }
364               
365        IM_Preferences.prototype.vCard = function()
366        {
367                if(!this.jid){
368                        alert('Carregando !!');
369                }else{
370                        var div_jid  = document.getElementById("vcard_" + this.jid);
371                        var strg = div_jid.innerHTML;
372                        Templates.information_user(strg);
373                }       
374        }
375
376        IM_Preferences.prototype.vCardLoad_Contact = function(pJid)
377        {
378                if(!this.jid){
379                        alert('Carregando !!');
380                }else{
381                        var vcards = document.getElementById('vcard_' + pJid).innerHTML;
382                        Templates.information_Contact(vcards);
383                }
384        }
385       
386        IM_Preferences.prototype.vCardAdd = function()
387        {
388                var el_vcard = new Array('FN','NICKNAME','ROLE','ORGNAME','ORGUNIT','BDAY','DESC');
389                var vcard        = "";
390                var value        = "";
391                var div_jid  = document.getElementById("vcard_" + this.jid);
392                var elements = div_jid.firstChild;
393
394                for(var i in el_vcard)
395                {
396                        value = ( document.getElementById(el_vcard[i]).value ) ? document.getElementById(el_vcard[i]).value : "";
397                        if( elements.tagName == el_vcard[i] && value != "")
398                        {
399                                if( el_vcard[i] === 'NICKNAME' )       
400                                        document.getElementById('span_nickname').innerHTML = "<b>&nbsp;" + value.substring(0,15) + "</b>";
401                                if( el_vcard[i] === 'DESC' )
402                                        document.getElementById('span_message').innerHTML = "<b>&nbsp;" + value.substring(0,20) + "...</b>";
403                                elements.innerHTML = value;
404                        }
405                        elements = elements.nextSibling;                               
406                        vcard += value + "_vkrd_";                     
407                }
408               
409                vcard = vcard.substr(0,vcard.length - 6 );
410               
411                var handler_vcard_add = function(XMLdata)
412                {
413                };
414                XMLTools.request('$this.Ujabber.newVcard','POST',handler_vcard_add,"vcard="+escape(vcard));     
415                alert('Informações Cadastradas / Adicionads !!!');     
416        }
417       
418   /*
419        * IM_Preferences
420        */
421       
422        IM_Preferences.prototype.yourPreferences = function()
423        {
424                Templates.yourPreferences();
425        }
426
427        IM_Preferences.prototype.SetYourPreferences = function()
428        {
429                var preferences = "";
430                preferences  = ( func.byId('ch_offline').checked ) ? 'ch_offline:true;' : 'ch_offline:false;';
431                if( func.byId('in_time').value )
432                {
433                        var numbers = /^\d+$/;
434                        if(numbers.test(func.byId('in_time').value))
435                                var minutes = func.byId('in_time').value;
436                        else
437                        {
438                                alert('Informe valores numéricos');
439                                func.byId('in_time').focus();
440                                return false;
441                        }
442                }
443                IM.im_time_  = func.byId('in_time').value;
444                preferences += ( func.trim(func.byId('in_time').value )) ? 'in_time:' + func.byId('in_time').value + ";" : 'in_time:0;';
445                preferences += ( func.byId('rd_nm').checked ) ? 'rd_nm:true;' : 'rd_nm:false;';
446                preferences += ( func.byId('rd_ch').checked ) ? 'rd_ch:true' : 'rd_ch:false';
447                IM.userPrefe = preferences;
448               
449                var handler_preferences = function(XMLdata)
450                {
451                        var data = XMLdata.getElementsByTagName('retorno').item(0);
452                        data = eval(data.firstChild.nodeValue);
453                        if(data)
454                        {
455                                IM.Contacts_Offline();
456                                alert('Preferências salvas !');
457                        }
458                };
459                XMLTools.request('$this.db_im.set_preferences','POST',handler_preferences,'preferences='+preferences);
460        }
461       
462        IM_Preferences.prototype.GetYourPreferences = function()
463        {
464                if(!IM.userPrefe)
465                {
466                        var handler_getPreferences = function(XMLdata)
467                        {
468                                var data = XMLdata.getElementsByTagName('retorno').item(0);
469                                data = data.firstChild.nodeValue;
470                                IM.userPrefe = data;
471                                IM.im_time_ = this.LoadPreferences('ch_offline');
472                        }
473                        XMLTools.request('$this.db_im.get_preferences','POST',handler_getPreferences);
474                }
475        }
476       
477        IM_Preferences.prototype.LoadPreferences = function(pElement)
478        {
479                var preferences_im = IM.userPrefe;
480
481                while( preferences_im !== "")
482                {
483                        var values = "";
484                        var value = "";
485                        if(value = preferences_im.substr(0,preferences_im.indexOf(';')))
486                        {
487                                values = value + '\n';
488                                preferences_im = preferences_im.replace(value,'');     
489                        }
490                        if(preferences_im.substr(0,1) == ";"){
491                                preferences_im = preferences_im.substr(1,preferences_im.length);
492                        }else{
493                                values = preferences_im + '\n';
494                                preferences_im = '';
495                        }
496                       
497                        var ele = values.substr(0,values.indexOf(':'));
498                        var val = values.substr((values.indexOf(':')+1),values.length);
499
500                        if(ele == pElement)
501                                return val;
502
503                        if((document.getElementById(ele)!= null) && (document.getElementById(ele).type == 'text'))
504                                document.getElementById(ele).value = val;
505                        else
506                                if(document.getElementById(ele) != null)
507                                        document.getElementById(ele).checked = eval(val);
508                }
509        }
510
511   /*
512        *  Detalhes do Contato para Autorização
513        */
514       
515        IM_Preferences.prototype.Info_Contact = function(pJid)
516        {
517                var element = "_span_not_" + pJid;
518                var uid = pJid.substr(0,pJid.indexOf('@'));
519                var handler_ldap =  function(data)
520                {
521                        var data = func.interface(data);
522                        var XMLinfoLdap = "";
523                        if(data)
524                        {
525                                XMLinfoLdap = '<info_user>';
526                                for(var i in data)                     
527                                        XMLinfoLdap += '<item lang_name="'+IM.get_lang('Name')+'" name="'+ data[i].cn +'" lang_email="'+IM.get_lang('E-mail')+'" email="'+ data[i].mail +'" />';
528                                XMLinfoLdap += '</info_user>';
529                        }
530                        im_menu_action.menu(element, parse_XmlXsl(XMLinfoLdap,'info_contact_ldap.xsl'));
531                        if(document.getElementById('im_span_avatar') != null)
532                        {
533                                var span = document.getElementById('im_span_avatar');
534                                var     img = func.newEl('img');
535                                func.confEl(img, 'id', pJid + '_avatar');
536                                func.confEl(img, 'src', img_photo.src);
537                                func.confEl(img, 'style', 'height:65px;width:60px;align:right;');
538                                span.appendChild(img);
539                                // Foto Ldap;
540                                im_win.get_photo_ldap(pJid);
541                        }
542                }
543                XMLTools.request('$this.ldap_im.info_user','POST',handler_ldap,'uid='+uid);
544        }
545       
546   /*
547    * Envio de arquivo
548    */
549   
550    IM_Preferences.prototype.SendFile = function(pJid)
551    {
552                if(im_send_file == 'true'){
553                        Templates.Send_file(pJid);
554                }else{
555                        alert('Funçao Indisponível!');
556                }
557    }
558   
559    IM_Preferences.prototype.SizeFile = function()
560    {
561        var h_SizeFile = function(data)
562        {
563                alert(data);   
564        }
565                cIM.cExecute("$this.upload.size_file",h_SizeFile);
566    }
567   
568        // Build Object
569       
570        var IM_Preferences = new IM_Preferences();
Note: See TracBrowser for help on using the repository browser.