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

Revision 32, 13.0 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
42                var select_org = document.getElementById('ImSelOrg');
43                var select_contact = document.getElementById('ImSelAddContact');
44                var organization = "";
45                var span_load = document.getElementById('_span_load_im');
46                        span_load.style.visibility = "visible";
47                               
48                for(var i=0; i < select_org.options.length; i++){
49                        if(select_org.options[i].selected == true){
50                                organization = select_org.options[i].value;
51                        }
52                }
53                var handler_contacts = function(data){
54                        var select_contact = document.getElementById('ImSelAddContact');
55                        var text0 = document.getElementById('text0');
56                        var text1 = document.getElementById('text1');
57                        var content = "";
58                        select_contact.innerHTML = "";
59                        text0.value = "";
60                        text1.value = "";
61                       
62                        if( data.length > 0 ){
63                                for(var i in data){
64                                        if(data[i].cn != ""){
65                                                var options =  new Option(data[i].cn + " ( "+ data[i].mail + " )", data[i].mail, false, false);
66                                                select_contact[select_contact.length] = options;
67                                        }
68                                }
69                        }
70
71                        span_load.style.visibility = "hidden";         
72                }
73                cIM.cExecute("$this.contacts_im.list_contacts", handler_contacts,"ou="+organization);
74       
75        }
76
77        Preferences.prototype.preenche = function()
78        {
79                var select = document.getElementById('ImSelAddContact');
80                if(select.options.length > 0){
81                        for(var i=0; i < select.options.length; i++){
82                                if(select.options[i].selected == true){
83                                        document.getElementById('text0').value = select.options[i].value;
84                                        document.getElementById('text1').value = select.options[i].value.substr(0,select.options[i].value.indexOf('@'));       
85                                        document.getElementById('text2').focus();                       
86                                }
87                        }
88                }
89        }
90       
91        Preferences.prototype.Add_user = function(pFunc)
92        {
93                var text0 = document.getElementById('text0');
94                var text1 = document.getElementById('text1');
95                var text2 = document.getElementById('text2');
96                var _this = this;
97                var jid   = text0.value;
98                var subscription = "";
99
100                if(func.trim(text0.value) != "" && func.trim(text1.value) != "" && func.trim(text2.value) != ""){
101                        var handler_add_contact = function(data){
102                                if(data){
103                                        text0.value = "";
104                                        text1.value = "";
105                                        text2.value = "";       
106                                        if(pFunc != 'divAddUser_im')
107                                                im_win.windowClose(pFunc);
108                                        IM.UpdateContacts();
109                                        _this.Refresh_Screen(jid);
110                                }
111                        }
112                        var name = url_encode(encodeURI(text1.value));
113                        var group = url_encode(encodeURI(text2.value));
114                        if(pFunc == 'divAddUser_im')
115                                subscription = "none";
116                        else
117                                subscription = "to";
118                        cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+name+"&group="+group+"&subscription="+subscription);
119                }else{
120                        alert("Informe todos os campos!");
121                }
122        }
123
124   /*
125        * Remove
126        */
127       
128        Preferences.prototype.Remove_userLoad = function()
129        {
130                Templates.remove_user();
131                var sel_contact = document.getElementById('sel_contact');
132                if(sel_contact.options.length > 0)
133                        sel_contact.options.splice(0,sel_contact.options.length);
134                var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true);
135                sel_contact.options[sel_contact.length] = opt;
136
137                for(var i=1; i < IM.array_users.length; i++){
138                        if(decodeURI(IM.array_users[i].name) != ""){
139                                opt = new Option(decodeURI(IM.array_users[i].name),IM.array_users[i].jid, false, false);
140                                sel_contact.options[sel_contact.length] = opt;
141                        }else{
142                                name = IM.array_users[i].jid.substr(0,IM.array_users[i].jid.indexOf('@'));
143                                opt = new Option(name,IM.array_users[i].jid, false, false);
144                                sel_contact.options[sel_contact.length] = opt;
145                        }
146                }
147        }
148       
149        Preferences.prototype.Remove_user = function()
150        {
151                var _this = this;
152                var sel_contact = document.getElementById('sel_contact');
153                for(var i=0; i < sel_contact.options.length; i++){
154                        if(sel_contact[i].selected && sel_contact.options[i].value != 0){
155                                if(confirm("Excluir o contato " + sel_contact.options[i].innerHTML + "?")){
156                                        var in_el = sel_contact.options[i].innerHTML;
157                                        for(var j=1 ; j < IM.array_users.length; j++){
158                                                var name = IM.array_users[j].jid.substr(0,IM.array_users[j].jid.indexOf('@'));
159                                                if(decodeURI(IM.array_users[j].name) == in_el || name == in_el){
160                                                        var handler_remove_contact = function(data){
161                                                                if(!data){
162                                                                        alert(data);
163                                                                        return false;
164                                                                }
165                                                            setTimeout("IM.UpdateContacts()",1000);
166                                                        }
167                                                        cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+sel_contact.options[i].value);
168                                                        IM.array_users.splice(j,1);
169                                                        _this.ComboRemove();                                                   
170                                                        j--;
171                                                }
172                                        }
173                                }
174                        }
175                }
176        }
177       
178        Preferences.prototype.ComboRemove = function()
179        {
180                var sel_contact = document.getElementById('sel_contact');
181                if(sel_contact.length > 0 ){
182                        for(var i=0; i < sel_contact.options.length; i++){
183                                sel_contact.options[i] = null;
184                                i--;
185                        }
186                }
187
188                var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true);
189                sel_contact.options[sel_contact.length] = opt;
190                for(var i=1; i < IM.array_users.length; i++){
191                        opt = new Option(decodeURI(IM.array_users[i].name),IM.array_users[i].jid, false, false);
192                        sel_contact.options[sel_contact.length] = opt;
193                }
194        }       
195
196        Preferences.prototype.Remove_Contact = function(pJid)
197        {
198                var _this = this;
199                for(var i=0; i < IM.array_users.length; i++){
200                        if(IM.array_users[i].jid == pJid){
201                                if(confirm("Excluir o contato " + decodeURI(IM.array_users[i].name) + "?")){
202                                        var handler_remove_contact = function(data){
203                                                if(!data){
204                                                        alert(data);
205                                                        return;
206                                                }else{
207                                                    _this.Refresh_Screen(pJid);                                                     
208                                                    IM.UpdateContacts();
209                                                }
210                                        }
211                                        cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+pJid);
212                                }       
213                                return;
214                        }       
215                }
216        }
217
218   /*
219    * Update
220    */
221   
222   Preferences.prototype.updateLoad = function(pJid)
223   {
224                Jid = pJid;
225                Templates.update_user();       
226                document.getElementById('text0').value = Jid;
227                document.getElementById('span0').innerHTML = Jid.substr(0,Jid.indexOf('@'));
228   }
229   
230   Preferences.prototype.Update_ = function(pJid,pType)
231   {
232                var name  = "";
233                var group = "";
234                var jid   = pJid;
235               
236                for(var i=1; i < IM.array_users.length; i++){
237                        if(IM.array_users[i].jid == pJid){
238                                name  = decodeURI(IM.array_users[i].name);
239                                group = decodeURI(IM.array_users[i].group);
240                        }
241                }
242               
243                if((name != "") && (group != "")){
244                        if(pType){
245                                var act = prompt("Digite um apelido para :" + pJid , name);
246                                name = url_encode(encodeURI(act));
247                                group = url_encode(encodeURI(group));
248                        }else{
249                                var act = prompt("Digite um novo grupo para : " + name, group);
250                                group = url_encode(encodeURI(act));
251                                name = url_encode(encodeURI(name));
252                        }                               
253                        if((act != null) && (act != "")){
254                                var handler_update_contacts = function(data){
255                                        if(data)
256                                                IM.UpdateContacts();
257                                        else
258                                                alert("erro");
259                                }                               
260                                cIM.cExecute("$this.Ujabber.UpdateUser",handler_update_contacts,"jid="+jid+"&name="+name+"&group="+group);
261                        }
262                }
263        }
264
265        Preferences.prototype.Update_Group = function(pJid)
266        {
267                this.Update_(pJid,false);               
268        }
269               
270        Preferences.prototype.Update_NickName = function(pJid)
271        {
272                this.Update_(pJid,true);   
273        }
274   
275   /*
276        * Vcard
277        */
278               
279        Preferences.prototype.vCardLoad = function()
280        {
281                Templates.information_user();
282                document.getElementById('FN').value = IM.vcard_user['VCARD_FN'];
283                document.getElementById('NICKNAME').value = IM.vcard_user['VCARD_NICKNAME'];
284                document.getElementById('ORGNAME').value = IM.vcard_user['VCARD_ORGNAME'];
285                document.getElementById('ORGUNIT').value = IM.vcard_user['VCARD_ORGUNIT'];
286                document.getElementById('ROLE').value = IM.vcard_user['VCARD_ROLE'];
287                document.getElementById('BDAY').value = IM.vcard_user['VCARD_BDAY'];
288                document.getElementById('DESC').value = IM.vcard_user['VCARD_DESC'];
289        }
290       
291        Preferences.prototype.vCardAdd = function()
292        {
293                var _this = this;
294                IM.vcard_user['VCARD_FN'] = document.getElementById('FN').value;
295                _this.save_vcard = url_encode(encodeURI(document.getElementById('FN').value)) + ";";
296                IM.vcard_user['VCARD_NICKNAME'] = document.getElementById('NICKNAME').value;
297                _this.save_vcard += url_encode(encodeURI(document.getElementById('NICKNAME').value)) + ";";
298                var nickname = document.getElementById('span_nickname').innerHTML;
299                document.getElementById('span_nickname').innerHTML = (IM.vcard_user['VCARD_NICKNAME']) ? "<b>&nbsp;" + IM.vcard_user['VCARD_NICKNAME'].substring(0,30) + "</b>" : nickname;
300                IM.vcard_user['VCARD_ORGNAME'] = document.getElementById('ORGNAME').value;
301                _this.save_vcard += url_encode(encodeURI(document.getElementById('ORGNAME').value)) + ";";
302                IM.vcard_user['VCARD_ORGUNIT'] = document.getElementById('ORGUNIT').value;
303                _this.save_vcard += url_encode(encodeURI(document.getElementById('ORGUNIT').value)) + ";";
304                IM.vcard_user['VCARD_ROLE'] = document.getElementById('ROLE').value;
305                _this.save_vcard += url_encode(encodeURI(document.getElementById('ROLE').value)) + ";";
306                IM.vcard_user['VCARD_BDAY'] = document.getElementById('BDAY').value;
307                _this.save_vcard += url_encode(encodeURI(document.getElementById('BDAY').value)) + ";";         
308                IM.vcard_user['VCARD_DESC'] = document.getElementById('DESC').value;
309                _this.save_vcard += url_encode(encodeURI(document.getElementById('DESC').value));               
310                var message_desc = document.getElementById('span_message').innerHTML;
311                document.getElementById('span_message').innerHTML = (IM.vcard_user['VCARD_DESC']) ? "<b>&nbsp;" + IM.vcard_user['VCARD_DESC'].substring(0,30) + "</b>" : message_desc ;
312
313                var handler_vcardAdd = function(data){
314                        if(!data)
315                                alert(data);
316                        else
317                                alert("Informações Cadastradas / Atualizadas !");
318                }
319                cIM.cExecute("$this.Ujabber.newVcard",handler_vcardAdd,"vcard="+_this.save_vcard);
320        }
321       
322        Preferences.prototype.vCardLoad_Contact = function(pJid)
323        {
324                Templates.information_Contact();
325                for(var i=0; i < IM.array_users.length; i++){
326                        if(IM.array_users[i].jid == pJid){
327                                document.getElementById('_lbl_FN').innerHTML = decodeURI(IM.array_users[i].VCARD_FN);
328                                document.getElementById('_lbl_Nickname').innerHTML = decodeURI(IM.array_users[i].VCARD_NICKNAME);
329                                document.getElementById('_lbl_Orgunit').innerHTML = decodeURI(IM.array_users[i].VCARD_ORGUNIT);
330                                document.getElementById('_lbl_Role').innerHTML = decodeURI(IM.array_users[i].VCARD_ROLE);
331                                document.getElementById('_lbl_Birthday').innerHTML = decodeURI(IM.array_users[i].VCARD_BDAY);                                                                                                                           
332                                return;
333                        }       
334                }
335        }
336
337   /*
338        *  Detalhes do Contato para Autorização
339        */
340       
341        Preferences.prototype.Info_Contact = function(pJid)
342        {
343                var element = "_span_not_" + pJid;
344                var pElement = "teste";
345                var uid = pJid.substr(0,pJid.indexOf('@'));
346               
347
348                var handler_ldap =  function(data){
349       
350                        var form_details = '<table cellpadding="0" cellspacing="0" style="background-color:#cbdae4;width:80%;border:1px solid #809aa9">' +
351                                                           '<tr><td style="vertical-align:top;width:80%">' +
352                                                           '<div style="padding-bottom">' +
353                                                           '<span><label>'+IM.get_lang('Name')+'</label></br>'+ data[0].cn + '</span></br></br>' +
354                                                           '<span><label>'+IM.get_lang('E-mail')+'</label></br>'+ data[0].mail + '</span></br>' +                                                           
355                                                           '</div></td>' +
356                                                           '<td style="vertical-align:top"><img id="' + pJid + '_avatar" src="' + img_photo.src + '" style="height:65px;width:60px;align:right">' +     
357                                                           '</td></tr>'+
358                                                           '</table>'; 
359       
360                        im_menu_action.menu(element, form_details);
361       
362                        // Foto Ldap;
363                        im_win.get_photo_ldap(pJid);
364                }
365                cIM.cExecute("$this.ldap_im.info_user",handler_ldap,"uid="+uid);
366       
367       
368        }
369       
370   /*
371    * Envio de arquivo
372    */
373   
374    Preferences.prototype.SendFile = function(pJid)
375    {
376                if(im_send_file == 'true'){
377                        Templates.Send_file(pJid);
378                }else{
379                        alert('Função Indisponível!');
380                }
381    }
382   
383    Preferences.prototype.SizeFile = function()
384    {
385        var h_SizeFile = function(data){
386                alert(data);   
387        }
388                cIM.cExecute("$this.upload.size_file",h_SizeFile);
389    }
390       
391   /*
392        * Preferências do Usuário
393        */
394
395        Preferences.prototype.yourPreferences = function()
396        {
397
398                //Templates.yourPreferences();
399       
400        }
401       
402   /*
403    * Tela de permissão para novos contatos
404    */ 
405
406        Preferences.prototype.Refresh_Screen = function(pJid)
407        {
408                var el_tbl = document.getElementById("_cell_" + pJid);
409                if(el_tbl != null)     
410                   el_tbl.parentNode.removeChild(el_tbl);
411        }
412   
413// Build Object
414        var Preferences = new Preferences();   
Note: See TracBrowser for help on using the repository browser.