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

Revision 21, 11.3 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                var select_org = document.getElementById('ImSelOrg');
42                var organization = "";
43                for(var i=0; i < select_org.options.length; i++){
44                        if(select_org.options[i].selected == true){
45                                organization = select_org.options[i].value;
46                        }
47                }
48                var handler_contacts = function(data){
49                        var select_contact = document.getElementById('ImSelAddContact');
50                        var text0 = document.getElementById('text0');
51                        var text1 = document.getElementById('text1');
52                        var content = "";
53                        select_contact.innerHTML = "";
54                        text0.value = "";
55                        text1.value = "";
56                        if(data){
57                                for(var i in data){
58                                        var options =  new Option(data[i].cn + " ( "+ data[i].mail + " )", data[i].mail, false, false);
59                                        select_contact[select_contact.length] = options;
60                                }
61                        }
62                }
63                cIM.cExecute("$this.contacts_im.list_contacts", handler_contacts,"ou="+organization);
64        }
65
66        Preferences.prototype.preenche = function()
67        {
68                var select = document.getElementById('ImSelAddContact');
69                if(select.options.length > 0){
70                        for(var i=0; i < select.options.length; i++){
71                                if(select.options[i].selected == true){
72                                        document.getElementById('text0').value = select.options[i].value;
73                                        document.getElementById('text1').value = select.options[i].value.substr(0,select.options[i].value.indexOf('@'));       
74                                        document.getElementById('text2').focus();                       
75                                }
76                        }
77                }
78        }
79       
80        Preferences.prototype.Add_user = function(pFunc)
81        {
82                var text0 = document.getElementById('text0');
83                var text1 = document.getElementById('text1');
84                var text2 = document.getElementById('text2');
85                var _this = this;
86               
87                if(pFunc != "divUpdateUser_im"){
88                        var jid = text0.value.substr(0,text0.value.indexOf('@'));
89                        for(var i=0; i < IM.user_not_aut.length; i++){
90                                if(IM.user_not_aut[i].substr(0,IM.user_not_aut[i].indexOf('@')) == jid){
91                                        return;
92                                }                                       
93                        }
94                }
95                       
96                if(IM.LTrim(text0.value) != "" && IM.LTrim(text1.value) != "" && IM.LTrim(text2.value) != ""){
97                        var handler_add_contact = function(data){
98                                if(data){
99                                        text0.value = "";
100                                        text1.value = "";
101                                        text2.value = "";       
102                                        if(pFunc != 'divAddUser_im')
103                                                im_win.windowClose(pFunc);
104                                        IM.UpdateContacts();
105                                       
106                                }
107                        }
108                        if(pFunc == 'divAddUser_im')
109                                cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+text1.value+"&group="+text2.value+"&subscription=none");
110                        else
111                                cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+text1.value+"&group="+text2.value+"&subscription=to");
112                }else{
113                        alert("Informe todos os campos!");
114                }
115        }
116
117   /*
118        * Remove
119        */
120       
121        Preferences.prototype.Remove_userLoad = function()
122        {
123                Templates.remove_user();
124                var sel_contact = document.getElementById('sel_contact');
125                if(sel_contact.options.length > 0)
126                        sel_contact.options.splice(0,sel_contact.options.length);
127                var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true);
128                sel_contact.options[sel_contact.length] = opt;
129
130                for(var i=1; i < IM.vcard_contacts.length; i++){
131                        if(IM.vcard_contacts[i].name != ""){
132                                opt = new Option(IM.vcard_contacts[i].name,IM.vcard_contacts[i].jid, false, false);
133                                sel_contact.options[sel_contact.length] = opt;
134                        }else{
135                                name = IM.vcard_contacts[i].jid.substr(0,IM.vcard_contacts[i].jid.indexOf('@'));
136                                opt = new Option(name,IM.vcard_contacts[i].jid, false, false);
137                                sel_contact.options[sel_contact.length] = opt;
138                        }
139                }
140        }
141       
142        Preferences.prototype.Remove_user = function()
143        {
144                var _this = this;
145                var sel_contact = document.getElementById('sel_contact');
146                for(var i=0; i < sel_contact.options.length; i++){
147                        if(sel_contact[i].selected && sel_contact.options[i].value != 0){
148                                if(confirm("Excluir o contato " + sel_contact.options[i].innerHTML + "?")){
149                                        var in_el = sel_contact.options[i].innerHTML;
150                                        for(var j=1 ; j < IM.vcard_contacts.length; j++){
151                                                var name = IM.vcard_contacts[j].jid.substr(0,IM.vcard_contacts[j].jid.indexOf('@'));
152                                                if(IM.vcard_contacts[j].name == in_el || name == in_el){
153                                                        var handler_remove_contact = function(data){
154                                                                if(!data){
155                                                                        alert(data);
156                                                                        return false;
157                                                                }
158                                                            setTimeout("IM.UpdateContacts()",1000);
159                                                        }
160                                                        cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+sel_contact.options[i].value);
161                                                        IM.vcard_contacts.splice(j,1);
162                                                        _this.ComboRemove();                                                   
163                                                        j--;
164                                                }
165                                        }
166                                }
167                        }
168                }
169        }
170       
171        Preferences.prototype.ComboRemove = function()
172        {
173                var sel_contact = document.getElementById('sel_contact');
174                if(sel_contact.length > 0 ){
175                        for(var i=0; i < sel_contact.options.length; i++){
176                                sel_contact.options[i] = null;
177                                i--;
178                        }
179                }
180
181                var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true);
182                sel_contact.options[sel_contact.length] = opt;
183                for(var i=0; i < IM.vcard_contacts.length; i++){
184                        opt = new Option(IM.vcard_contacts[i].name,IM.vcard_contacts[i].jid, false, false);
185                        sel_contact.options[sel_contact.length] = opt;
186                }
187        }       
188
189        Preferences.prototype.Remove_Contact = function(pJid)
190        {
191                for(var i=0; i < IM.vcard_contacts.length; i++){
192                        if(IM.vcard_contacts[i].jid == pJid){
193                                if(confirm("Excluir o contato " + IM.vcard_contacts[i].name + "?")){
194                                        var handler_remove_contact = function(data){
195                                                if(!data){
196                                                        alert(data);
197                                                        return;
198                                                }else{
199                                                    setTimeout("IM.UpdateContacts()",1000);
200                                                }
201                                        }
202                                        cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+pJid);
203                                }       
204                                return;
205                        }       
206                }
207        }
208
209   /*
210    * Update
211    */
212   
213   Preferences.prototype.updateLoad = function(i)
214   {
215                Jid = IM.vcard_contacts[i].jid;
216                Templates.update_user();       
217                document.getElementById('text0').value = Jid;
218                document.getElementById('span0').innerHTML = Jid.substr(0,Jid.indexOf('@'));
219   }
220   
221   Preferences.prototype.Update_ = function(pJid,pType)
222   {
223                var name  = "";
224                var group = "";
225                var jid   = pJid;
226               
227                for(var i=1; i < IM.vcard_contacts.length; i++){
228                        if(IM.vcard_contacts[i].jid == pJid){
229                                name  = IM.vcard_contacts[i].name;
230                                group = IM.vcard_contacts[i].group;
231                        }
232                }
233               
234                if((name != "") && (group != "")){
235                        if(pType){
236                                var act = prompt("Digite um apelido para :" + pJid , name);
237                                name = act;
238                        }else{
239                                var act = prompt("Digite um novo grupo para : " + name, group);
240                                group = act;
241                        }                               
242                        if((act != null) && (act != "")){
243                                var handler_update_contacts = function(data){
244                                        if(data)
245                                                IM.UpdateContacts();
246                                        else
247                                                alert("erro");
248                                }                               
249                                cIM.cExecute("$this.Ujabber.UpdateUser",handler_update_contacts,"jid="+jid+"&name="+name+"&group="+group);
250                        }
251                }
252        }
253
254        Preferences.prototype.Update_Group = function(pJid)
255        {
256                this.Update_(pJid,false);               
257        }
258               
259        Preferences.prototype.Update_NickName = function(pJid)
260        {
261                this.Update_(pJid,true);   
262        }
263   
264   /*
265        * Vcard
266        */
267               
268        Preferences.prototype.vCardLoad = function()
269        {
270                Templates.information_user();
271                document.getElementById('FN').value = IM.vcard_user['VCARD_FN'];
272                document.getElementById('NICKNAME').value = IM.vcard_user['VCARD_NICKNAME'];
273                document.getElementById('ORGNAME').value = IM.vcard_user['VCARD_ORGNAME'];
274                document.getElementById('ORGUNIT').value = IM.vcard_user['VCARD_ORGUNIT'];
275                document.getElementById('ROLE').value = IM.vcard_user['VCARD_ROLE'];
276                document.getElementById('BDAY').value = IM.vcard_user['VCARD_BDAY'];
277                document.getElementById('DESC').value = IM.vcard_user['VCARD_DESC'];
278        }
279       
280        Preferences.prototype.vCardAdd = function()
281        {
282                var _this = this;
283                IM.vcard_user['VCARD_FN'] = document.getElementById('FN').value;
284                _this.save_vcard = url_encode(encodeURI(document.getElementById('FN').value)) + ";";
285                IM.vcard_user['VCARD_NICKNAME'] = document.getElementById('NICKNAME').value;
286                _this.save_vcard += url_encode(encodeURI(document.getElementById('NICKNAME').value)) + ";";
287                var nickname = document.getElementById('span_nickname').innerHTML;
288                document.getElementById('span_nickname').innerHTML = (IM.vcard_user['VCARD_NICKNAME']) ? "<b>&nbsp;" + IM.vcard_user['VCARD_NICKNAME'].substring(0,30) + "</b>" : nickname;
289                IM.vcard_user['VCARD_ORGNAME'] = document.getElementById('ORGNAME').value;
290                _this.save_vcard += url_encode(encodeURI(document.getElementById('ORGNAME').value)) + ";";
291                IM.vcard_user['VCARD_ORGUNIT'] = document.getElementById('ORGUNIT').value;
292                _this.save_vcard += url_encode(encodeURI(document.getElementById('ORGUNIT').value)) + ";";
293                IM.vcard_user['VCARD_ROLE'] = document.getElementById('ROLE').value;
294                _this.save_vcard += url_encode(encodeURI(document.getElementById('ROLE').value)) + ";";
295                IM.vcard_user['VCARD_BDAY'] = document.getElementById('BDAY').value;
296                _this.save_vcard += url_encode(encodeURI(document.getElementById('BDAY').value)) + ";";         
297                IM.vcard_user['VCARD_DESC'] = document.getElementById('DESC').value;
298                _this.save_vcard += url_encode(encodeURI(document.getElementById('DESC').value));               
299                var message_desc = document.getElementById('span_message').innerHTML;
300                document.getElementById('span_message').innerHTML = (IM.vcard_user['VCARD_DESC']) ? "<b>&nbsp;" + IM.vcard_user['VCARD_DESC'].substring(0,30) + "</b>" : message_desc ;
301
302                var handler_vcardAdd = function(data){
303                        if(!data)
304                                alert(data);
305                        else
306                                alert("Informações Cadastradas / Atualizadas !");
307                }
308                cIM.cExecute("$this.Ujabber.newVcard",handler_vcardAdd,"vcard="+_this.save_vcard);
309        }
310       
311        Preferences.prototype.vCardLoad_Contact = function(pJid)
312        {
313                Templates.information_Contact();
314                for(var i=0; i < IM.vcard_contacts.length; i++){
315                        if(IM.vcard_contacts[i].jid == pJid){
316                                document.getElementById('_lbl_FN').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_FN);
317                                document.getElementById('_lbl_Nickname').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_NICKNAME);
318                                document.getElementById('_lbl_Orgunit').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_ORGUNIT);
319                                document.getElementById('_lbl_Role').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_ROLE);
320                                document.getElementById('_lbl_Birthday').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_BDAY);                                                                                                                               
321                                return;
322                        }       
323                }
324        }
325       
326   /*
327    * Envio de arquivo
328    */
329   
330    Preferences.prototype.SendFile = function(pJid)
331    {
332                if(im_send_file == 'true'){
333                        Templates.Send_file(pJid);
334                }else{
335                        alert('Funçao Indisponível!');
336                }
337    }
338   
339    Preferences.prototype.SizeFile = function()
340    {
341        var h_SizeFile = function(data){
342                alert(data);   
343        }
344                cIM.cExecute("$this.upload.size_file",h_SizeFile);
345    }
346   
347// Build Object
348        var Preferences = new Preferences();   
Note: See TracBrowser for help on using the repository browser.