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

Revision 526, 6.1 KB checked in by niltonneto, 16 years ago (diff)

Correções referentes à versão 0.7.9

  • 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                _config(_win_add.wc.childNodes[2].childNodes[1],
100                        'onclick',
101                        function()
102                        {
103                                _win_add.button(_win_add.bc);
104                        }
105                );
106        }
107
108        function _config(pObj, pEvent, pHandler)
109        {
110                if ( typeof pObj == 'object' )
111                {
112                        if ( pEvent.substring(0, 2) == 'on' )
113                                pEvent = pEvent.substring(2, pEvent.length);
114
115                        if ( pObj.addEventListener )
116                                pObj.addEventListener(pEvent, pHandler, false);
117                        else if ( pObj.attachEvent )
118                                pObj.attachEvent('on' + pEvent, pHandler);
119                }
120        }
121
122        function _highlight(e)
123        {
124                var el = ( e.target ) ? e.target : e.srcElement;
125                var color = "#fff";
126                if ( e.type.indexOf('mouseover') != -1 )
127                        color = "#dedede";
128                el.style.backgroundColor = color;
129        }
130
131        function _search()
132        {
133                var _loading = document.getElementById('__span_load_im');
134                var _target = document.getElementById('im_ldap_user');
135               
136                _loading.style.display = "block";       
137
138                _conn.go(
139                                '$this.contacts_im.list_contacts',             
140                                function(_data)
141                                {
142                                        var _params = {
143                                                'many_results' : jabberitGetLang('More than 50 results. Please, try to refine your search.'),
144                                                'empty' : jabberitGetLang('None result was found.')
145                                         };
146                               
147                                        _target.innerHTML = _xtools.parse(_data,'list_ldap_contacts.xsl', _params);
148                                       
149                                        function _show(m)
150                                        {
151                                                m = ( m.target ) ? m.target : m.srcElement;
152                                                if ( m.getAttribute('value'))
153                                                        m = m.getAttribute('value');
154                                                else
155                                                        m = m.parentNode.getAttribute('value');
156                                               
157                                                if ( !m )
158                                                        return false;
159
160                                                document.getElementById('__span_load_im_group').style.display = 'block';
161                                                document.getElementById('im_jid').value = m.substr(0, m.indexOf(';'));
162                                                document.getElementById('im_uid').value = m.substr((m.indexOf(';')+1));
163                                               
164                                                var _name = document.getElementById('im_name');
165
166                                                var first_name = document.getElementById(m).innerHTML;
167                                                        first_name = first_name.substr(0, first_name.indexOf(' '));
168                                                       
169                                                        _name.value = first_name;                                                       
170                                                        _name.previousSibling.style.color = "#000";
171                                                        _name.parentNode.style.display = 'block';
172                                                        _name.parentNode.nextSibling.style.display = 'block';
173                                                        _name.parentNode.nextSibling.nextSibling.innerHTML = '';
174                                               
175                                                _conn.go('$this.ujabber.getGroupsJabber',
176                                                                function(data)
177                                                                {
178                                                                        if( data = data.replace(/(^\s*)|(\s*$)/g,''))
179                                                                        {
180                                                                                var _group = document.getElementById('im_group');
181                                                                                var _groupOptions = '';
182
183                                                                                _group.setAttribute('selectBoxOptions', data);
184                                                                                if( document.getElementById('selectBox0') == null)
185                                                                                        editS.create(document.getElementById('im_group'));
186                                                                        }
187                                                                        document.getElementById('__span_load_im_group').style.display = 'none';
188                                                                });
189
190                                                document.getElementById('im_group').value = '';
191                                                document.getElementById('im_group').focus();
192                                        }
193
194                                        var _member = _target.firstChild;
195                                       
196                                        while ( _member )
197                                        {
198                                                if( _member.getAttribute('photo') === '1' )
199                                                {
200                                                        var uid = _member.getAttribute('value');
201                                                        uid = uid.substr(uid.indexOf(';') + 1);
202                                                        _member.style.backgroundImage = 'url(' + path_jabberit + 'inc/getphoto.php?uid=' + uid + ')';
203                                                }
204                                                _config(_member, 'onclick', _show);
205                                               
206                                                _member = _member.nextSibling;
207                                        }
208                                        _loading.style.display = "none";
209                                },
210                                'name='+ arguments[0]
211                            );
212        }
213
214        function LDAP()
215        {
216                _conn = arguments[0];
217                _xtools = arguments[1];
218                _window = arguments[2];
219        }
220
221        LDAP.prototype.search = _search;
222        LDAP.prototype.add = _add_user;
223        window.JITLdap = LDAP;
224}
225)();
226
227function cleanStatusAddContactIM()
228{
229        document.getElementById('im_status_add').innerHTML = '';
230}
Note: See TracBrowser for help on using the repository browser.