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

Revision 978, 8.5 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #542 - Em algumas versões do java ocorrem problemas no carregamento do applet.

  • 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                _config( _win_add.wc.childNodes[2].childNodes[0],
39                        'onclick',
40                        function()
41                        {
42                                var _name = document.getElementById('im_name');
43                                var _group = document.getElementById('im_group');
44                                var jidUser = document.getElementById('im_jidUser').value;
45                                var     _jid = document.getElementById('im_jid').value;
46                                var _status = document.getElementById('im_status_add');
47
48                                _status.innerHTML = '';
49                                _name.previousSibling.style.color = "#000";
50
51                                if ( _jid )
52                                {
53                                        _name.value = _name.value.replace(/^( )*|( )*$/g, '');
54                                        _group.value = _group.value.replace(/^( )*|( )*$/g, '');
55
56                                        if ( !(_name.value) || !(_group.value) )
57                                        {
58                                                if ( !(_name.value) )
59                                                        alert( jabberitGetLang('ATTENTION') + "!!\n" + jabberitGetLang("Enter a NAME") + ".");
60
61                                                if ( !(_group.value) )
62                                                        alert( jabberitGetLang('ATTENTION') + "!!\n" + jabberitGetLang("Enter a GROUP") + ".");                                                 
63                                        }
64                                        else
65                                        {
66                                                var _uid;
67                                               
68                                                if ( (_uid = document.getElementById('im_uid')) )
69                                                        _uid = _uid.value;
70                                                else
71                                                        _uid = _jid.substr(0, (_jid.indexOf('@') - 1));
72
73                                                _conn.go('$this.contacts_im.verifyAddNewContact',
74                                                                 function(data)
75                                                                 {
76                                                                        data = eval(data);
77
78                                                                        if( !data )
79                                                                        {
80                                                                                alert("*********** " + jabberitGetLang("Attention") + "!! ***********\n" +
81                                                                                          jabberitGetLang("This user is part of a small group!") +
82                                                                                          "\n" + jabberitGetLang("Contact was not added!"));
83                                                                                _name.value = '';
84                                                                                _group.value = '';
85                                                                        }
86                                                                        else
87                                                                        {       
88                                                                                var result;
89                                                                                _name.parentNode.style.display = 'none';
90                                                                                _name.parentNode.nextSibling.style.display = 'none';
91                                                                                _status.innerHTML = '<br/>' + jabberitGetLang('Add contact wait') + '....<br/>';
92                               
93                                                                                try
94                                                                                {
95                                                                                        if( elementIframe = document.getElementById('iframe_applet_jabberit') )
96                                                                                        {
97                                                                                                if( !_is_ie )
98                                                                                                        result = elementIframe.contentDocument.applets[0].addContact( jidUser, _name.value, _group.value );
99                                                                                                else
100                                                                                                        result = elementIframe.contentWindow.document.applets[0].addContact( jidUser, _name.value, _group.value );
101                                                                                        }
102                                                                                        else // If Pop-Up
103                                                                                        {
104                                                                                                result = _myWindow.document.applets[0].addContact( jidUser, _name.value, _group.value );
105                                                                                        }
106                                                                                        _status.innerHTML = '<br/>' + jabberitGetLang('Add contact!') +  '<br/>';
107                                                                                }
108                                                                                catch(e)
109                                                                                {
110                                                                                        _status.innerHTML = '<br/>' + jabberitGetLang('The module is not loaded') + '! ' +
111                                                                                                                                jabberitGetLang('Contact was not added!') + '<br/>';
112                                                                                }
113
114                                                                                setTimeout('cleanStatusAddContactIM();',2500);
115                                                                                _name.value = '';
116                                                                                _group.value = '';
117                                                                        }
118                                                                 }, "uid="+_uid);
119                                        }
120                                }
121                        }
122                );
123
124                _config(_win_add.wc.childNodes[2].childNodes[1],
125                        'onclick',
126                        function()
127                        {
128                                _win_add.button(_win_add.bc);
129                        }
130                );
131        }
132
133        function _config(pObj, pEvent, pHandler)
134        {
135                if ( typeof pObj == 'object' )
136                {
137                        if ( pEvent.substring(0, 2) == 'on' )
138                                pEvent = pEvent.substring(2, pEvent.length);
139
140                        if ( pObj.addEventListener )
141                                pObj.addEventListener(pEvent, pHandler, false);
142                        else if ( pObj.attachEvent )
143                                pObj.attachEvent('on' + pEvent, pHandler);
144                }
145        }
146
147        function _highlight(e)
148        {
149                var el = ( e.target ) ? e.target : e.srcElement;
150                var color = "#fff";
151                if ( e.type.indexOf('mouseover') != -1 )
152                        color = "#dedede";
153                el.style.backgroundColor = color;
154        }
155
156        function _search()
157        {
158                var _loading = document.getElementById('__span_load_im');               
159                var _target      = document.getElementById('im_ldap_user');
160       
161                _loading.style.display = "block";
162       
163                _conn.go('$this.contacts_im.list_contacts',             
164                                function( data )
165                                {
166                                        if( data )
167                                        {
168                                                var _params = {
169                                                                                'many_results' : jabberitGetLang('More than 50 results. Please, try to refine your search.'),
170                                                                                'empty' : jabberitGetLang('None result was found.')
171                                                                          };
172                                       
173                                                _target.innerHTML = _xtools.parse( data, 'list_ldap_contacts.xsl', _params);
174                                               
175                                                // Add Contact
176                                                function _show(m)
177                                                {
178                                                        m = ( m.target ) ? m.target : m.srcElement;
179                       
180                                                        if ( m.getAttribute('value'))
181                                                        {
182                                                                var jidUser = m.getAttribute('jid');
183                                                                m = m.getAttribute('value');
184                                                        }
185                                                        else
186                                                        {
187                                                                var jidUser = m.parentNode.getAttribute('jid');
188                                                                m = m.parentNode.getAttribute('value');
189                                                        }
190                               
191                                                        if ( !m )
192                                                                return false;
193                       
194                                                        document.getElementById('__span_load_im_group').style.display = 'block';
195                                                        document.getElementById('im_jidUser').value = jidUser;
196                                                        document.getElementById('im_jid').value = m.substr(0, m.indexOf(';'));
197                                                        document.getElementById('im_uid').value = m.substr((m.indexOf(';')+1));
198
199
200                                                        var _name = document.getElementById('im_name');
201                                                        var groups = "";
202                                                        var data;
203                       
204                                                        var first_name = document.getElementById(m).innerHTML;
205                                                                first_name = first_name.substr(0, first_name.indexOf(' '));
206                                                               
207                                                                _name.value = first_name;                                                       
208                                                                _name.previousSibling.style.color = "#000";
209                                                                _name.parentNode.style.display = 'block';
210                                                                _name.parentNode.nextSibling.style.display = 'block';
211                                                                _name.parentNode.nextSibling.nextSibling.innerHTML = '';
212                                                       
213                                                        try
214                                                        {
215                                                                // If Layer;
216                                                                if( elementIframe = document.getElementById('iframe_applet_jabberit') )
217                                                                {
218                                                                        if( !_is_ie )
219                                                                                groups = elementIframe.contentDocument.applets[0].getGroupsToExpresso();
220                                                                        else
221                                                                                groups = elementIframe.contentWindow.document.applets[0].getGroupsToExpresso();
222                                                                }
223                                                                else // If Pop-Up
224                                                                {
225                                                                        groups = _myWindow.document.applets[0].getGroupsToExpresso();
226                                                                }
227                                               
228                                                                if( typeof(groups) == 'object')
229                                                                {
230                                                                        data = groups + ";";
231                                                                        data = data.substring(0,(data.length-2));
232                                                                }
233                                                                else                   
234                                                                        data = groups.substring(0,(groups.length-1));
235                                                               
236                                                                if( data )
237                                                                {
238                                                                        document.getElementById('im_group').setAttribute('selectBoxOptions', data);
239                                                                       
240                                                                        if( document.getElementById('selectBox0') == null )
241                                                                                editS.create(document.getElementById('im_group'));
242                                                                }
243                               
244                                                                document.getElementById('__span_load_im_group').style.display = 'none';
245                                                                document.getElementById('im_group').value = '';
246                                                                document.getElementById('im_group').focus();
247                                                        }
248                                                        catch(e)
249                                                        {
250                                                                alert("*********** " + jabberitGetLang("Attention") + "!! ***********\n" +
251                                                                          jabberitGetLang("The module is not loaded") + "!\n" );
252                       
253                                                                document.getElementById('__span_load_im_group').style.display = 'none';                                 
254                                                        }
255                                                }
256                                        }
257                                       
258                                        var _member = _target.firstChild;
259                       
260                                        while ( _member )
261                                        {
262                                                if( _member.getAttribute('photo') === '1' )
263                                                {
264                                                        var jid = _member.getAttribute('jid');
265                                                        var ou = _member.getAttribute('ou');
266
267                                                        var _img_path = path_jabberit + 'inc/webservice.php?' + Date.parse( new Date );
268                                                                _img_path += '&phpPhoto=' + jid + '&phpOu=' + ou;
269                                                       
270                                                        _member.style.backgroundImage = 'url(' + _img_path + ')';
271                                                }
272                                                _config(_member, 'onclick', _show);
273                                               
274                                                _member = _member.nextSibling;
275                                        }
276
277                                        _loading.style.display = "none";                                               
278                                },
279                                'name='+ arguments[0]
280                            );
281        }
282
283        function LDAP()
284        {
285                _conn           = arguments[0];
286                _xtools         = arguments[1];
287                _window         = arguments[2];
288                _is_ie          = arguments[3];
289        }
290
291        LDAP.prototype.search = _search;
292        LDAP.prototype.add = _add_user;
293        window.JITLdap = LDAP;
294}
295)();
296
297function cleanStatusAddContactIM()
298{
299        document.getElementById('im_status_add').innerHTML = '';
300}
Note: See TracBrowser for help on using the repository browser.