source: trunk/jabberit_messenger/js/ldap.js @ 815

Revision 815, 8.2 KB checked in by niltonneto, 15 years ago (diff)

Ticket #494 - Problema ao carregar applet no IE, quando entra pelo próprio módulo.

  • Property svn:executable set to *
Line 
1(function()
2{
3        var _conn;
4        var _xtools;
5        var _window;
6        var _myWindow;
7        var _is_ie;
8
9        function _add_user()
10        {
11                if( arguments.length > 0 )
12                {
13                        _myWindow = arguments[0];
14                }
15               
16                var _win_add = _window.load('add_user_im');
17                        _win_add.title('.:: Adicionar Novos Contatos ::.');
18                        _win_add.size(440);
19                        _win_add.position(200,80);
20                        _win_add.wc.style.padding = "3px";
21               
22                var _params = {
23                        'lang1':jabberitGetLang('Name of Contacts'),
24                        'lang2':jabberitGetLang('Search'),
25                        'lang3':jabberitGetLang('member of organization'),
26                        'lang4':jabberitGetLang('nickname'),
27                        'lang5':jabberitGetLang('group'),
28                        'lang6':jabberitGetLang('add'),
29                        'lang7':jabberitGetLang('close'),
30                        'lang8':jabberitGetLang('Others Expressos')                     
31                };
32
33                _win_add.bz.style.display = "none";
34                _win_add.bx.style.display = "none";
35
36                _win_add.content( _xtools.parse(_xtools.xml('adduser'), 'add_user.xsl', _params));
37
38                _conn.go('$this.contacts_im.getParticipantsExternal',
39                                function(data)
40                                {
41                                        var data = eval(data);
42                                        var elementDiv =  document.getElementById('external_Participants_Jabberit');                                   
43                                       
44                                        if( data )
45                                                elementDiv.style.display = 'block';
46                                });
47
48                _config( _win_add.wc.childNodes[2].childNodes[0],
49                        'onclick',
50                        function()
51                        {
52                                var _name = document.getElementById('im_name');
53                                var _group = document.getElementById('im_group');
54                                var     _jid = document.getElementById('im_jid').value;
55                                var _status = document.getElementById('im_status_add');
56
57                                _status.innerHTML = '';
58                                _name.previousSibling.style.color = "#000";
59
60                                if ( _jid )
61                                {
62                                        _name.value = _name.value.replace(/^( )*|( )*$/g, '');
63                                        _group.value = _group.value.replace(/^( )*|( )*$/g, '');
64
65                                        if ( !(_name.value) || !(_group.value) )
66                                        {
67                                                if ( !(_name.value) )
68                                                        alert( jabberitGetLang('ATTENTION') + "!!\nInforme um \"NOME\".");
69
70                                                if ( !(_group.value) )
71                                                        alert( jabberitGetLang('ATTENTION') + "!!\nInforme um \"GRUPO\".");                                                     
72                                        }
73                                        else
74                                        {
75                                                var _uid;
76                                               
77                                                if ( (_uid = document.getElementById('im_uid')) )
78                                                        _uid = _uid.value;
79                                                else
80                                                        _uid = _jid.substr(0, (_jid.indexOf('@') - 1));
81
82                                               
83                                                _conn.go('$this.contacts_im.verifyAddNewContact',
84                                                                 function(data)
85                                                                 {
86                                                                        data = eval(data);
87                                                                       
88                                                                        if( !data )
89                                                                        {
90                                                                                alert("*********** " + jabberitGetLang("Attention") + "!! ***********\n" +
91                                                                                          jabberitGetLang("This user is part of a small group!") +
92                                                                                          "\n" + jabberitGetLang("Contact was not added!"));
93
94                                                                                _name.value = '';
95                                                                                _group.value = '';
96                                                                                         
97                                                                        }
98                                                                        else
99                                                                        {       
100                                                                               
101                                                                                var result;
102                                                                                _name.parentNode.style.display = 'none';
103                                                                                _name.parentNode.nextSibling.style.display = 'none';
104                                                                                _status.innerHTML = '<br/>Adicionando contato, aguarde....<br/>';
105                               
106                                                                                if( elementIframe = document.getElementById('iframe_applet_jabberit') )
107                                                                                {
108                                                                                        if( !_is_ie )
109                                                                                                result = elementIframe.contentDocument.applets[0].addContact( _uid, _name.value, _group.value );
110                                                                                        else
111                                                                                                result = elementIframe.contentWindow.document.applets[0].addContact( _uid, _name.value, _group.value );
112                                                                                }
113                                                                                else // If Pop-Up
114                                                                                {
115                                                                                        result = _myWindow.document.applets[0].addContact( _uid, _name.value, _group.value );
116                                                                                }
117
118                                                                                _status.innerHTML = '<br/>Contato adicionado !<br/>';
119                                                                                setTimeout('cleanStatusAddContactIM();',2500);
120                                                                               
121                                                                                _name.value = '';
122                                                                                _group.value = '';
123                                                                               
124                                                                        }
125                                                                 }, "uid="+_uid);
126                                        }
127                                }
128                        }
129                );
130
131                _config(_win_add.wc.childNodes[2].childNodes[1],
132                        'onclick',
133                        function()
134                        {
135                                _win_add.button(_win_add.bc);
136                        }
137                );
138        }
139
140        function _config(pObj, pEvent, pHandler)
141        {
142                if ( typeof pObj == 'object' )
143                {
144                        if ( pEvent.substring(0, 2) == 'on' )
145                                pEvent = pEvent.substring(2, pEvent.length);
146
147                        if ( pObj.addEventListener )
148                                pObj.addEventListener(pEvent, pHandler, false);
149                        else if ( pObj.attachEvent )
150                                pObj.attachEvent('on' + pEvent, pHandler);
151                }
152        }
153
154        function _highlight(e)
155        {
156                var el = ( e.target ) ? e.target : e.srcElement;
157                var color = "#fff";
158                if ( e.type.indexOf('mouseover') != -1 )
159                        color = "#dedede";
160                el.style.backgroundColor = color;
161        }
162
163        function _search()
164        {
165                var _loading = document.getElementById('__span_load_im');
166                var _target = document.getElementById('im_ldap_user');
167                var _particiExt = document.getElementById('external_Participants_Jabberit').firstChild;
168
169                function getUsersLdap(_data)
170                {
171                        var _params = {
172                                'many_results' : jabberitGetLang('More than 50 results. Please, try to refine your search.'),
173                                'empty' : jabberitGetLang('None result was found.')
174                         };
175               
176                        _target.innerHTML = _xtools.parse(_data,'list_ldap_contacts.xsl', _params);
177                       
178                        function _show(m)
179                        {
180                                m = ( m.target ) ? m.target : m.srcElement;
181                                if ( m.getAttribute('value'))
182                                        m = m.getAttribute('value');
183                                else
184                                        m = m.parentNode.getAttribute('value');
185                               
186                                if ( !m )
187                                        return false;
188
189                                document.getElementById('__span_load_im_group').style.display = 'block';
190                                document.getElementById('im_jid').value = m.substr(0, m.indexOf(';'));
191                                document.getElementById('im_uid').value = m.substr((m.indexOf(';')+1));
192                               
193                                var _name = document.getElementById('im_name');
194                                var groups = "";
195                                var data;
196
197                                var first_name = document.getElementById(m).innerHTML;
198                                        first_name = first_name.substr(0, first_name.indexOf(' '));
199                                       
200                                        _name.value = first_name;                                                       
201                                        _name.previousSibling.style.color = "#000";
202                                        _name.parentNode.style.display = 'block';
203                                        _name.parentNode.nextSibling.style.display = 'block';
204                                        _name.parentNode.nextSibling.nextSibling.innerHTML = '';
205                               
206                                // If Layer;
207                                if( elementIframe = document.getElementById('iframe_applet_jabberit') )
208                                {
209                                        if( !_is_ie )
210                                                groups = elementIframe.contentDocument.applets[0].getGroupsToExpresso();
211                                        else
212                                                groups = elementIframe.contentWindow.document.applets[0].getGroupsToExpresso();
213                                }
214                                else // If Pop-Up
215                                {
216                                        groups = _myWindow.document.applets[0].getGroupsToExpresso();
217                                }
218               
219                                if( typeof(groups) == 'object')
220                                {
221                                        data = groups + ";";
222                                        data = data.substring(0,(data.length-2));
223                                }
224                                else                   
225                                        data = groups.substring(0,(groups.length-1));
226                               
227                                if( data )
228                                {
229                                        document.getElementById('im_group').setAttribute('selectBoxOptions', data);
230                                       
231                                        if( document.getElementById('selectBox0') == null )
232                                                editS.create(document.getElementById('im_group'));
233                                }
234
235                                document.getElementById('__span_load_im_group').style.display = 'none';
236                                document.getElementById('im_group').value = '';
237                                document.getElementById('im_group').focus();
238                        }
239
240                        var _member = _target.firstChild;
241                       
242                        while ( _member )
243                        {
244                                if( _member.getAttribute('photo') === '1' )
245                                {
246                                        var uid = _member.getAttribute('value');
247                                        uid = uid.substr(uid.indexOf(';') + 1);
248                                        _member.style.backgroundImage = 'url(' + path_jabberit + 'inc/getphoto.php?uid=' + uid + ')';
249                                }
250                                _config(_member, 'onclick', _show);
251                               
252                                _member = _member.nextSibling;
253                        }
254                }
255
256                _loading.style.display = "block";       
257               
258                if(!_particiExt.checked)
259                {
260                        _conn.go(
261                                        '$this.contacts_im.list_contacts',             
262                                        function(_data)
263                                        {
264                                                getUsersLdap(_data);
265                                                _loading.style.display = "none";                                               
266                                        },
267                                        'name='+ arguments[0]
268                                    );
269                }
270                else
271                {
272
273                        function checkMail(pMail)
274                        {
275                                var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
276                                if(er.test(pMail))
277                                        return true;
278                                else
279                                        return false;
280                        }
281                       
282                        if( checkMail(arguments[0]) )                   
283                        {                       
284                                _conn.go(
285                                        '$this.ldap_im.list_participants_externals',           
286                                        function(data)
287                                        {
288                                                getUsersLdap(data);
289                                                _loading.style.display = "none";
290                                        },
291                                        'mail=' + arguments[0]
292                                        );
293                        }
294                        else
295                        {
296                                alert(jabberitGetLang('Inform a valid e-mail!'));
297                                _loading.style.display = "none";       
298                        }
299                }
300                               
301        }
302
303        function LDAP()
304        {
305                _conn           = arguments[0];
306                _xtools         = arguments[1];
307                _window         = arguments[2];
308                _is_ie          = arguments[3];
309        }
310
311        LDAP.prototype.search = _search;
312        LDAP.prototype.add = _add_user;
313        window.JITLdap = LDAP;
314}
315)();
316
317function cleanStatusAddContactIM()
318{
319        document.getElementById('im_status_add').innerHTML = '';
320}
Note: See TracBrowser for help on using the repository browser.