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

Revision 946, 8.6 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #505 - Arquivos modificados para a administração de hosts virtuais no servidor Jabber.

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