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

Revision 459, 6.0 KB checked in by niltonneto, 16 years ago (diff)

Alterações feitas por Alexandre Correia.
Vide alterações 0.79 (Trac).
Email: alexandrecorreia@…

  • Property svn:executable set to *
Line 
1(function()
2{
3        var _conn;
4        var _xtools;
5        var _window;
6
7        function _add_user()
8        {
9                var _win_add = _window.load('add_user_im');
10                        _win_add.title('.:: Adicionar Novos Contatos ::.');
11                        _win_add.size(440);
12                        _win_add.position(200,80);
13                        _win_add.wc.style.padding = "3px";
14               
15                var _params = {
16                        'lang1':jabberitGetLang('Name of Contacts'),
17                        'lang2':jabberitGetLang('Search'),
18                        'lang3':jabberitGetLang('member of organization'),
19                        'lang4':jabberitGetLang('nickname'),
20                        'lang5':jabberitGetLang('group'),
21                        'lang6':jabberitGetLang('add'),
22                        'lang7':jabberitGetLang('close')
23                };
24
25                _win_add.bz.style.display = "none";
26                _win_add.bx.style.display = "none";
27
28                _win_add.content(_xtools.parse(_xtools.xml('adduser'), 'add_user.xsl', _params));
29
30                _config(_win_add.wc.childNodes[2].childNodes[0],
31                        'onclick',
32                        function()
33                        {
34                                var _name = document.getElementById('im_name');
35                                var _group = document.getElementById('im_group');
36                                var     _jid = document.getElementById('im_jid').value;
37                                var _status = document.getElementById('im_status_add');
38
39                                _status.innerHTML = '';
40                                _name.previousSibling.style.color = "#000";
41
42                                if ( !_jid )
43                                {
44                                        _status.innerHTML = 'Selecione uma organização no campo da esquerda e em<br/>'
45                                                                                + ' seguida, no campo da direita, um membro da organização<br/>'
46                                                                                + ' para adicionar como contato';
47                                }
48                                else
49                                {
50                                        _name.value = _name.value.replace(/^( )*|( )*$/g, '');
51                                        _group.value = _group.value.replace(/^( )*|( )*$/g, '');
52
53                                        if ( !(_name.value) || !(_group.value) )
54                                        {
55                                                _status.innerHTML = '<br/>O campo destacado em vermelho é obrigatório!<br/>';
56
57                                                if ( !(_name.value) )
58                                                {
59                                                        _name.previousSibling.style.color = "#f00";
60                                                        _status.innerHTML += '<br/>** Informe um "NOME" para o contato.';
61                                                }
62
63                                                if ( !(_group.value) )
64                                                {
65                                                        _status.innerHTML += '<br/>** Informe um "GRUPO" para o contato.';
66                                                }
67                                        }
68                                        else
69                                        {
70                                                var _uid;
71
72                                                if ( (_uid = document.getElementById('im_uid')) )
73                                                        _uid = _uid.value;
74                                                else
75                                                        _uid = _jid.substr(0, (_jid.indexOf('@') - 1));
76
77                                               
78                                                _name.parentNode.style.display = 'none';
79                                                _name.parentNode.nextSibling.style.display = 'none';
80                                                _status.innerHTML = '<br/>Adicionando contato, aguarde....<br/>';
81
82                                                _conn.go(
83                                                        '$this.ujabber.AddNewContact',
84                                                        function()
85                                                        {
86                                                                _status.innerHTML = '<br/>Contato adicionado !<br/>';
87                                                                setTimeout('cleanStatusAddContactIM();',2500);
88                                                        },
89                                                        'uid='+_uid+'&name='+_name.value+'&group='+_group.value
90                                                );
91
92                                                _name.value = '';
93                                                _group.value = '';
94                                               
95                                        }
96                                }
97                        }
98                );
99
100                _config(_win_add.wc.childNodes[2].childNodes[1],
101                        'onclick',
102                        function()
103                        {
104                                _win_add.button(_win_add.bc);
105                        }
106                );
107        }
108
109        function _config(pObj, pEvent, pHandler)
110        {
111                if ( typeof pObj == 'object' )
112                {
113                        if ( pEvent.substring(0, 2) == 'on' )
114                                pEvent = pEvent.substring(2, pEvent.length);
115
116                        if ( pObj.addEventListener )
117                                pObj.addEventListener(pEvent, pHandler, false);
118                        else if ( pObj.attachEvent )
119                                pObj.attachEvent('on' + pEvent, pHandler);
120                }
121        }
122
123        function _highlight(e)
124        {
125                var el = ( e.target ) ? e.target : e.srcElement;
126                var color = "#fff";
127                if ( e.type.indexOf('mouseover') != -1 )
128                        color = "#dedede";
129                el.style.backgroundColor = color;
130        }
131
132        function _search()
133        {
134                var _loading = document.getElementById('__span_load_im');
135                var _target = document.getElementById('im_ldap_user');
136               
137                _loading.style.display = "block";       
138
139                _conn.go(
140                                '$this.contacts_im.list_contacts',             
141                                function(_data)
142                                {
143                                        var _params = {
144                                                'many_results' : jabberitGetLang('More than 50 results. Please, try to refine your search.'),
145                                                'empty' : jabberitGetLang('None result was found.')
146                                         };
147                               
148                                        _target.innerHTML = _xtools.parse(_data,'list_ldap_contacts.xsl', _params);
149                                       
150                                        function _show(m)
151                                        {
152                                                m = ( m.target ) ? m.target : m.srcElement;
153                                                if ( m.getAttribute('value'))
154                                                        m = m.getAttribute('value');
155                                                else
156                                                        m = m.parentNode.getAttribute('value');
157                                               
158                                                if ( !m )
159                                                        return false;
160
161                                                document.getElementById('__span_load_im_group').style.display = 'block';
162                                                document.getElementById('im_jid').value = m.substr(0, m.indexOf(';'));
163                                                document.getElementById('im_uid').value = m.substr((m.indexOf(';')+1));
164
165                                                var _name = document.getElementById('im_name');
166                                                        _name.value = document.getElementById(m).innerHTML;                                                     
167                                                        _name.previousSibling.style.color = "#000";
168
169                                                        _name.parentNode.style.display = 'block';
170                                                        _name.parentNode.nextSibling.style.display = 'block';
171                                                        _name.parentNode.nextSibling.nextSibling.innerHTML = '';
172                                               
173                                                _conn.go('$this.ujabber.getGroupsJabber',
174                                                                function(data)
175                                                                {
176                                                                        if( data = data.replace(/(^\s*)|(\s*$)/g,''))
177                                                                        {
178                                                                                var _group = document.getElementById('im_group');
179                                                                                var _groupOptions = '';
180
181                                                                                _group.setAttribute('selectBoxOptions', data);
182                                                                                if( document.getElementById('selectBox0') == null)
183                                                                                        editS.create(document.getElementById('im_group'));
184                                                                        }
185                                                                        document.getElementById('__span_load_im_group').style.display = 'none';
186                                                                });
187
188                                                document.getElementById('im_group').value = '';
189                                                document.getElementById('im_group').focus();
190                                        }
191
192                                        var _member = _target.firstChild;
193                                       
194                                        while ( _member )
195                                        {
196                                                if( _member.getAttribute('photo') === '1' )
197                                                {
198                                                        var uid = _member.getAttribute('value');
199                                                        uid = uid.substr(uid.indexOf(';') + 1);
200                                                        _member.style.backgroundImage = 'url(' + path_jabberit + 'inc/getphoto.php?uid=' + uid + ')';
201                                                }
202                                                _config(_member, 'onclick', _show);
203                                               
204                                                _member = _member.nextSibling;
205                                        }
206                                        _loading.style.display = "none";
207                                },
208                                'name='+ arguments[0]
209                            );
210        }
211
212        function LDAP()
213        {
214                _conn = arguments[0];
215                _xtools = arguments[1];
216                _window = arguments[2];
217        }
218
219        LDAP.prototype.search = _search;
220        LDAP.prototype.add = _add_user;
221        window.JITLdap = LDAP;
222}
223)();
224
225function cleanStatusAddContactIM()
226{
227        document.getElementById('im_status_add').innerHTML = '';
228}
Note: See TracBrowser for help on using the repository browser.