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

Revision 41, 15.8 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 Preferences()
5        {
6                this.save_vcard = "";   
7        }
8
9   /*
10        * Add
11        */
12       
13        Preferences.prototype.Add_userLoad = function()
14        {
15                Templates.add_user();
16                this.SearchOrganizationsLdap();
17                var select_contact = document.getElementById('ImSelAddContact');
18                select_contact.innerHTML = "";
19        }
20       
21        Preferences.prototype.SearchOrganizationsLdap = function()
22        {
23                var handler_organizations = function(data){
24                        var select_org = document.getElementById('ImSelOrg');
25                        if(select_org.options.length > 0)
26                                select_org.options.splice(0,select_org.options.length);
27                        var options = new Option("--Selecione -- ", -1, false, true);
28                        select_org[select_org.length] = options;
29                       
30                        for(var i in data){
31                                var options = new Option(data[i], data[i], false, true);
32                                select_org[select_org.length] = options;
33                        }
34                        select_org[0].selected = true;
35                }
36                cIM.cExecute("$this.ldap_im.list_organizations_ldap", handler_organizations);
37        }
38       
39        Preferences.prototype.SearchContacts = function()
40        {
41                var select_org = document.getElementById('ImSelOrg');
42                var select_contact = document.getElementById('ImSelAddContact');
43                var organization = "";
44                var span_load = document.getElementById('_span_load_im');
45                        span_load.style.visibility = "visible";
46                               
47                for(var i=0; i < select_org.options.length; i++){
48                        if(select_org.options[i].selected == true){
49                                organization = select_org.options[i].value;
50                        }
51                }
52                var handler_contacts = function(data){
53                        var select_contact = document.getElementById('ImSelAddContact');
54                        var text0 = document.getElementById('text0');
55                        var text1 = document.getElementById('text1');
56                        var content = "";
57                        select_contact.innerHTML = "";
58                        text0.value = "";
59                        text1.value = "";
60                       
61                        if( data.length > 0 ){
62                                for(var i in data){
63                                        if(data[i].cn != ""){
64                                                var options =  new Option(data[i].cn + " ( "+ data[i].mail + " )", data[i].mail + ";" + data[i].uid, false, false);
65                                                select_contact[select_contact.length] = options;
66                                        }
67                                }
68                        }
69
70                        span_load.style.visibility = "hidden";         
71                }
72                cIM.cExecute("$this.contacts_im.list_contacts", handler_contacts,"ou="+organization);
73       
74        }
75
76        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 = email.substr(0,email.indexOf('@'));   
86                                        document.getElementById('text2').focus();                       
87                                        document.getElementById('text3').value = uid;
88                                }
89                        }
90                }
91        }
92       
93        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                        var handler_add_contact = function(data){
106                                if(data){
107                                        text0.value = "";
108                                        text1.value = "";
109                                        text2.value = "";       
110                                        if(pFunc != 'divAddUser_im')
111                                                im_win.windowClose(pFunc);
112                                        IM.UpdateContacts();
113                                        _this.Refresh_Screen(jid);
114                                }
115                        }
116                        var name = url_encode(encodeURI(text1.value));
117                        var group = url_encode(encodeURI(text2.value));
118                        if(pFunc == 'divAddUser_im')
119                                subscription = "none";
120                        else
121                                subscription = "to";
122                        if(text3){
123                                var email = text3.value + "@" + text0.value.substr((text0.value.indexOf('@')+1),text0.value.length);
124                        }else{
125                                var email = text0.value;
126                        }
127                        cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+email+"&name="+name+"&group="+group+"&subscription="+subscription);
128                }else{
129                        alert("Informe todos os campos!");
130                }
131        }
132
133   /*
134        * Remove
135        */
136       
137        Preferences.prototype.Remove_userLoad = function()
138        {
139                Templates.remove_user();
140                var sel_contact = document.getElementById('sel_contact');
141                if(sel_contact.options.length > 0)
142                        sel_contact.options.splice(0,sel_contact.options.length);
143                var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true);
144                sel_contact.options[sel_contact.length] = opt;
145
146                for(var i=1; i < IM.array_users.length; i++){
147                        if(decodeURI(IM.array_users[i].name) != ""){
148                                opt = new Option(decodeURI(IM.array_users[i].name),IM.array_users[i].jid, false, false);
149                                sel_contact.options[sel_contact.length] = opt;
150                        }else{
151                                name = IM.array_users[i].jid.substr(0,IM.array_users[i].jid.indexOf('@'));
152                                opt = new Option(name,IM.array_users[i].jid, false, false);
153                                sel_contact.options[sel_contact.length] = opt;
154                        }
155                }
156        }
157       
158        Preferences.prototype.Remove_user = function()
159        {
160                var _this = this;
161                var sel_contact = document.getElementById('sel_contact');
162                for(var i=0; i < sel_contact.options.length; i++){
163                        if(sel_contact[i].selected && sel_contact.options[i].value != 0){
164                                if(confirm("Excluir o contato " + sel_contact.options[i].innerHTML + "?")){
165                                        var in_el = sel_contact.options[i].innerHTML;
166                                        for(var j=1 ; j < IM.array_users.length; j++){
167                                                var name = IM.array_users[j].jid.substr(0,IM.array_users[j].jid.indexOf('@'));
168                                                if(decodeURI(IM.array_users[j].name) == in_el || name == in_el){
169                                                        var handler_remove_contact = function(data){
170                                                                if(!data){
171                                                                        alert(data);
172                                                                        return false;
173                                                                }
174                                                            setTimeout("IM.UpdateContacts()",1000);
175                                                        }
176                                                        cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+sel_contact.options[i].value);
177                                                        IM.array_users.splice(j,1);
178                                                        _this.ComboRemove();                                                   
179                                                        j--;
180                                                }
181                                        }
182                                }
183                        }
184                }
185        }
186       
187        Preferences.prototype.ComboRemove = function()
188        {
189                var sel_contact = document.getElementById('sel_contact');
190                if(sel_contact.length > 0 ){
191                        for(var i=0; i < sel_contact.options.length; i++){
192                                sel_contact.options[i] = null;
193                                i--;
194                        }
195                }
196
197                var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true);
198                sel_contact.options[sel_contact.length] = opt;
199                for(var i=1; i < IM.array_users.length; i++){
200                        opt = new Option(decodeURI(IM.array_users[i].name),IM.array_users[i].jid, false, false);
201                        sel_contact.options[sel_contact.length] = opt;
202                }
203        }       
204
205        Preferences.prototype.Remove_Contact = function(pJid)
206        {
207                var _this = this;
208                for(var i=0; i < IM.array_users.length; i++){
209                        if(IM.array_users[i].jid == pJid){
210                                if(confirm("Excluir o contato " + decodeURI(IM.array_users[i].name) + "?")){
211                                        var handler_remove_contact = function(data){
212                                                if(!data){
213                                                        alert(data);
214                                                        return;
215                                                }else{
216                                                    _this.Refresh_Screen(pJid);                                                     
217                                                    IM.UpdateContacts();
218                                                }
219                                        }
220                                        cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+pJid);
221                                }       
222                                return;
223                        }       
224                }
225        }
226
227   /*
228    * Update
229    */
230   
231   Preferences.prototype.updateLoad = function(pJid)
232   {
233                Jid = pJid;
234                Templates.update_user();       
235                document.getElementById('text0').value = Jid;
236                document.getElementById('span0').innerHTML = Jid.substr(0,Jid.indexOf('@'));
237   }
238   
239   Preferences.prototype.Update_ = function(pJid,pType)
240   {
241                var name  = "";
242                var group = "";
243                var jid   = pJid;
244               
245                for(var i=1; i < IM.array_users.length; i++){
246                        if(IM.array_users[i].jid == pJid){
247                                name  = decodeURI(IM.array_users[i].name);
248                                group = decodeURI(IM.array_users[i].group);
249                        }
250                }
251               
252                if((name != "") && (group != "")){
253                        if(pType){
254                                var act = prompt("Digite um apelido para :" + pJid , name);
255                                name = url_encode(encodeURI(act));
256                                group = url_encode(encodeURI(group));
257                        }else{
258                                var act = prompt("Digite um novo grupo para : " + name, group);
259                                group = url_encode(encodeURI(act));
260                                name = url_encode(encodeURI(name));
261                        }                               
262                        if((act != null) && (act != "")){
263                                var handler_update_contacts = function(data){
264                                        if(data)
265                                                IM.UpdateContacts();
266                                        else
267                                                alert("erro");
268                                }                               
269                                cIM.cExecute("$this.Ujabber.UpdateUser",handler_update_contacts,"jid="+jid+"&name="+name+"&group="+group);
270                        }
271                }
272        }
273
274        Preferences.prototype.Update_Group = function(pJid)
275        {
276                this.Update_(pJid,false);               
277        }
278               
279        Preferences.prototype.Update_NickName = function(pJid)
280        {
281                this.Update_(pJid,true);   
282        }
283   
284   /*
285        * Vcard
286        */
287               
288        Preferences.prototype.vCardLoad = function()
289        {
290                Templates.information_user();
291                document.getElementById('FN').value = IM.vcard_user['VCARD_FN'];
292                document.getElementById('NICKNAME').value = IM.vcard_user['VCARD_NICKNAME'];
293                document.getElementById('ORGNAME').value = IM.vcard_user['VCARD_ORGNAME'];
294                document.getElementById('ORGUNIT').value = IM.vcard_user['VCARD_ORGUNIT'];
295                document.getElementById('ROLE').value = IM.vcard_user['VCARD_ROLE'];
296                document.getElementById('BDAY').value = IM.vcard_user['VCARD_BDAY'];
297                document.getElementById('DESC').value = IM.vcard_user['VCARD_DESC'];
298        }
299       
300        Preferences.prototype.vCardAdd = function()
301        {
302                var _this = this;
303                IM.vcard_user['VCARD_FN'] = document.getElementById('FN').value;
304                _this.save_vcard = url_encode(encodeURI(document.getElementById('FN').value)) + ";";
305                IM.vcard_user['VCARD_NICKNAME'] = document.getElementById('NICKNAME').value;
306                _this.save_vcard += url_encode(encodeURI(document.getElementById('NICKNAME').value)) + ";";
307                var nickname = document.getElementById('span_nickname').innerHTML;
308                document.getElementById('span_nickname').innerHTML = (IM.vcard_user['VCARD_NICKNAME']) ? "<b>&nbsp;" + IM.vcard_user['VCARD_NICKNAME'].substring(0,30) + "</b>" : nickname;
309                IM.vcard_user['VCARD_ORGNAME'] = document.getElementById('ORGNAME').value;
310                _this.save_vcard += url_encode(encodeURI(document.getElementById('ORGNAME').value)) + ";";
311                IM.vcard_user['VCARD_ORGUNIT'] = document.getElementById('ORGUNIT').value;
312                _this.save_vcard += url_encode(encodeURI(document.getElementById('ORGUNIT').value)) + ";";
313                IM.vcard_user['VCARD_ROLE'] = document.getElementById('ROLE').value;
314                _this.save_vcard += url_encode(encodeURI(document.getElementById('ROLE').value)) + ";";
315                IM.vcard_user['VCARD_BDAY'] = document.getElementById('BDAY').value;
316                _this.save_vcard += url_encode(encodeURI(document.getElementById('BDAY').value)) + ";";         
317                IM.vcard_user['VCARD_DESC'] = document.getElementById('DESC').value;
318                _this.save_vcard += url_encode(encodeURI(document.getElementById('DESC').value));               
319                var message_desc = document.getElementById('span_message').innerHTML;
320                document.getElementById('span_message').innerHTML = (IM.vcard_user['VCARD_DESC']) ? "<b>&nbsp;" + IM.vcard_user['VCARD_DESC'].substring(0,30) + "</b>" : message_desc ;
321
322                var handler_vcardAdd = function(data){
323                        if(!data)
324                                alert(data);
325                        else
326                                alert("Informações Cadastradas / Atualizadas !");
327                }
328                cIM.cExecute("$this.Ujabber.newVcard",handler_vcardAdd,"vcard="+_this.save_vcard);
329        }
330       
331        Preferences.prototype.vCardLoad_Contact = function(pJid)
332        {
333                Templates.information_Contact();
334                for(var i=0; i < IM.array_users.length; i++){
335                        if(IM.array_users[i].jid == pJid){
336                                document.getElementById('_lbl_FN').innerHTML = decodeURI(IM.array_users[i].VCARD_FN);
337                                document.getElementById('_lbl_Nickname').innerHTML = decodeURI(IM.array_users[i].VCARD_NICKNAME);
338                                document.getElementById('_lbl_Orgunit').innerHTML = decodeURI(IM.array_users[i].VCARD_ORGUNIT);
339                                document.getElementById('_lbl_Role').innerHTML = decodeURI(IM.array_users[i].VCARD_ROLE);
340                                document.getElementById('_lbl_Birthday').innerHTML = decodeURI(IM.array_users[i].VCARD_BDAY);                                                                                                                           
341                                return;
342                        }       
343                }
344        }
345
346   /*
347        *  Detalhes do Contato para Autorização
348        */
349       
350        Preferences.prototype.Info_Contact = function(pJid)
351        {
352                var element = "_span_not_" + pJid;
353                var pElement = "teste";
354                var uid = pJid.substr(0,pJid.indexOf('@'));
355
356                var handler_ldap =  function(data){
357
358                        if(data){
359                                var form_details = '<table cellpadding="0" cellspacing="0" style="background-color:#cbdae4;width:80%;border:1px solid #809aa9">' +
360                                                                   '<tr><td style="vertical-align:top;width:80%">' +
361                                                                   '<div style="padding-bottom">' +
362                                                                   '<span><label>'+IM.get_lang('Name')+'</label></br>'+ data[0].cn + '</span></br></br>' +
363                                                                   '<span><label>'+IM.get_lang('E-mail')+'</label></br>'+ data[0].mail + '</span></br>' +                                                           
364                                                                   '</div></td>' +
365                                                                   '<td style="vertical-align:top"><img id="' + pJid + '_avatar" src="' + img_photo.src + '" style="height:65px;width:60px;align:right">' +     
366                                                                   '</td></tr>'+
367                                                                   '</table>'; 
368               
369                                im_menu_action.menu(element, form_details);
370               
371                                // Foto Ldap;
372                                im_win.get_photo_ldap(pJid);
373                        }
374                }
375                cIM.cExecute("$this.ldap_im.info_user",handler_ldap,"uid="+uid);
376       
377       
378        }
379       
380   /*
381    * Envio de arquivo
382    */
383   
384    Preferences.prototype.SendFile = function(pJid)
385    {
386                if(im_send_file == 'true'){
387                        Templates.Send_file(pJid);
388                }else{
389                        alert('Função Indisponível!');
390                }
391    }
392   
393    Preferences.prototype.SizeFile = function()
394    {
395        var h_SizeFile = function(data){
396                alert(data);   
397        }
398                cIM.cExecute("$this.upload.size_file",h_SizeFile);
399    }
400       
401   /*
402        * Preferências do Usuário
403        */
404
405        Preferences.prototype.yourPreferences = function()
406        {
407                Templates.yourPreferences();
408                if( IM.array_prefe['sizeof'] > 0 ){
409                        document.getElementById('ch_time').checked = eval(IM.array_prefe['ch_time']);
410                        document.getElementById('ch_offline').checked = eval(IM.array_prefe['ch_offline']);
411                        document.getElementById('ch_contacts').checked = eval(IM.array_prefe['ch_contacts']);
412                        document.getElementById('rd_nm').checked = eval(IM.array_prefe['rd_nm']);
413                        document.getElementById('rd_al').checked = eval(IM.array_prefe['rd_al']);
414                        document.getElementById('rd_ch').checked = eval(IM.array_prefe['rd_ch']);                                                                                               
415                }else{
416                        this.GetPreferences();
417                }
418               
419        }
420       
421        Preferences.prototype.SetPreferences = function()
422        {
423                var EcheckBox = new Array();
424                        EcheckBox[0] = 'ch_time';
425                        EcheckBox[1] = 'ch_offline';
426                        EcheckBox[2] = 'ch_contacts';
427                var Eradio = new Array()
428                        Eradio[0] =     'rd_nm';
429                        Eradio[1] = 'rd_al';
430                        Eradio[2] =     'rd_ch';                               
431                var preferences = '';
432                var _this = this;
433               
434                for(var i in EcheckBox){
435                        if(document.getElementById(EcheckBox[i]).checked){
436                                preferences += EcheckBox[i] + ':' + true + ';';
437                                IM.array_prefe[EcheckBox[i]] = true;
438                        }else{
439                                preferences += EcheckBox[i] + ':' + false + ';';
440                                IM.array_prefe[EcheckBox[i]] = false;                           
441                        }
442                        IM.array_prefe['sizeof'] = i;
443                }
444               
445                for(var i in Eradio){
446                        if(document.getElementById(Eradio[i]).checked){
447                                preferences += Eradio[i] + ':' + true + ';';
448                                IM.array_prefe[Eradio[i]] = true;                               
449                        }else{
450                                preferences += Eradio[i] + ':' + false + ';';
451                                IM.array_prefe[Eradio[i]] = false;                             
452                        }
453                        IM.array_prefe['sizeof'] = IM.array_prefe['sizeof'] = i + 1;
454                }
455               
456                var handler_set_preferences = function(data)
457                {
458                        if(data)
459                                alert('Preferências cadastradas com sucesso!');
460                        IM.ContactsOffline();                           
461                }
462                cIM.cExecute("$this.db_im.set_preferences",handler_set_preferences,"preferences="+preferences);
463
464        }
465       
466        Preferences.prototype.GetPreferences = function()
467        {
468                var handler_get_preferences = function(data){
469                        var opt =  data.split(";");
470                        for(var i in opt){
471                                if(opt[i] != ""){
472                                        var el = opt[i].split(":");
473                                        if(document.getElementById(el[0]) != null){
474                                                var id_el = document.getElementById(el[0]);
475                                                        id_el.checked = eval(el[1]);
476                                        }
477                                        IM.array_prefe[el[0]] = eval(el[1]);
478                                        IM.array_prefe['sizeof'] = i;
479                                }
480                        }
481                }
482                cIM.cExecute("$this.db_im.get_preferences",handler_get_preferences);
483
484        }
485       
486   /*
487    * Tela de permissão para novos contatos
488    */ 
489
490        Preferences.prototype.Refresh_Screen = function(pJid)
491        {
492                var el_tbl = document.getElementById("_cell_" + pJid);
493                if(el_tbl != null)     
494                   el_tbl.parentNode.removeChild(el_tbl);
495        }
496   
497// Build Object
498        var Preferences = new Preferences();   
Note: See TracBrowser for help on using the repository browser.