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

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