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

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