source: branches/2.2/jabberit_messenger/js/ldap.js @ 3266

Revision 3266, 8.0 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #1316 - Correcoes e melhorias na busca dos contatos para o Modulo IM.

  • Property svn:executable set to *
Line 
1(function()
2{
3        var _conn;
4        var Xtools;
5        var _myWindow;
6        var _is_ie;
7
8        function addUser()
9        {
10                var _name = document.getElementById('im_name');
11                var _group = document.getElementById('im_group');
12                var jidUser = document.getElementById('im_jidUser').value;
13                var     _jid = document.getElementById('im_jid').value;
14
15                if ( _jid )
16                {
17                        _name.value = _name.value.replace(/^( )*|( )*$/g, '');
18                        _group.value = _group.value.replace(/^( )*|( )*$/g, '');
19
20                        if ( !(_name.value) || !(_group.value) )
21                        {
22                                if ( !(_name.value) || !(_group.value) )
23                                {
24                                        alert( jabberitGetLang('ATTENTION') + "!!\n" +
25                                                   jabberitGetLang("Enter a NAME") + " / " +
26                                                   jabberitGetLang("Enter a GROUP") + ".");
27                                }
28                        }
29                        else
30                        {
31                                var _uid;
32                               
33                                if ( (_uid = document.getElementById('im_uid')) )
34                                        _uid = _uid.value;
35                                else
36                                        _uid = _jid.substr(0, (_jid.indexOf('@') - 1));
37
38                                _conn.go('$this.contacts_im.verifyAddNewContact',
39                                                 function(data)
40                                                 {
41                                                        data = eval(data);
42
43                                                        if( !data )
44                                                        {
45                                                                alert("*********** " + jabberitGetLang("Attention") + "!! ***********\n" +
46                                                                          jabberitGetLang("This user is part of a small group!") +
47                                                                          "\n" + jabberitGetLang("Contact was not added!"));
48                                                        }
49                                                        else
50                                                        {       
51                                                                var result;
52               
53                                                                try
54                                                                {
55                                                                        if( elementIframe = document.getElementById('iframe_applet_jabberit') )
56                                                                        {
57                                                                                if( !_is_ie )
58                                                                                        result = elementIframe.contentDocument.applets[0].addContact( jidUser, _name.value, _group.value );
59                                                                                else
60                                                                                        result = elementIframe.contentWindow.document.applets[0].addContact( jidUser, _name.value, _group.value );
61                                                                        }
62                                                                        else // If Pop-Up
63                                                                        {
64                                                                                result = _myWindow.document.applets[0].addContact( jidUser, _name.value, _group.value );
65                                                                        }
66                                                                }
67                                                                catch(e)
68                                                                {
69                                                                        alert("*********** " + jabberitGetLang("Attention") + "!! ***********\n" +
70                                                                                   jabberitGetLang('The module is not loaded') + "! " +
71                                                                                   "\n" + jabberitGetLang('Contact was not added!')) ;
72                                                                }
73                                                        }
74                                                       
75                                                        winBuild("add_user_info","remove");
76                                                       
77                                                 },"uid="+_uid);
78                                }
79                        }
80        }
81
82        function _config(pObj, pEvent, pHandler)
83        {
84                if ( typeof pObj == 'object' )
85                {
86                        if ( pEvent.substring(0, 2) == 'on' )
87                                pEvent = pEvent.substring(2, pEvent.length);
88
89                        if ( pObj.addEventListener )
90                                pObj.addEventListener(pEvent, pHandler, false);
91                        else if ( pObj.attachEvent )
92                                pObj.attachEvent('on' + pEvent, pHandler);
93                }
94        }
95
96        function _load()
97        {
98                if( arguments.length > 0 )
99                        _myWindow = arguments[0];
100
101                var _params =   {
102                                'lang1':jabberitGetLang('Name of Contacts'),
103                                'lang2':jabberitGetLang('Search'),
104                                'lang3':jabberitGetLang('Search result'),
105                                'lang4':jabberitGetLang('Nickname'),
106                                'lang5':jabberitGetLang('group')
107                };
108
109                var _win_addUser = {
110                                id_window        : "add_user_im",
111                                width            : 440,
112                                height           : 350,
113                                top                      : 80,
114                                left             : 200,
115                                draggable        : true,
116                                visible          : "display",
117                                resizable        : true,
118                                zindex           : _ZINDEX++,
119                                title            : 'Expresso Messenger - ' + jabberitGetLang('Search users'),
120                                closeAction  : "remove",
121                                content          : Xtools.parse(Xtools.xml('userinfo'), 'add_user.xsl', _params)
122                };
123               
124                winBuild( _win_addUser );
125        }
126
127        function _search()
128        {
129                var _loading = document.getElementById('__span_load_im');               
130                var _target      = document.getElementById('im_ldap_user');
131       
132                _loading.style.display = "block";
133       
134                _conn.go('$this.contacts_im.list_contacts',             
135                                function( data )
136                                {
137                                        if( data )
138                                        {
139                                                var _pList = {
140                                                                                'lang_addContact'       : "Adicionar Contatos" ,
141                                                                                'lang_empty'            : "Nenhum resultado encontrado !",
142                                                                                'lang_error'            : "Tente Novamente!",
143                                                                                'lang_many_results' : "Muitos Resultados ! Por favor tente refinar sua busca !"
144                                                                         };     
145                                               
146                                                _target.innerHTML = Xtools.parse( data, 'list_ldap_contacts.xsl', _pList);
147                                               
148                                                // Show Contact
149                                                function _show(Obj)
150                                                {
151                                                        var data;
152                                                        var _element = ( Obj.target ) ? Obj.target : Obj.srcElement;
153                                                        var groups;
154                       
155                                                        if ( !_element || _element.id == "" )
156                                                                return false;
157
158                                                       
159                                                        var _params     =       {
160                                                                        'lang1':jabberitGetLang('Name of Contacts'),
161                                                                        'lang2':jabberitGetLang('Search'),
162                                                                        'lang3':jabberitGetLang('Resultado da Busca'),
163                                                                        'lang4':jabberitGetLang('nickname'),
164                                                                        'lang5':jabberitGetLang('group')
165                                                        };
166
167                                                        var _win_addUser = {
168                                                                        id_window        : "add_user_info",
169                                                                        width            : 400,
170                                                                        height           : 190,
171                                                                        top                      : 85,
172                                                                        left             : 220,
173                                                                        draggable        : true,
174                                                                        visible          : "display",
175                                                                        resizable        : true,
176                                                                        zindex           : _ZINDEX++,
177                                                                        title            : 'Expresso Messenger - ' + jabberitGetLang('Add Contact'),
178                                                                        closeAction  : "remove",
179                                                                        content          : Xtools.parse(Xtools.xml('adduser'), 'add_user.xsl', _params)
180                                                        };
181
182                                                        winBuild( _win_addUser );
183
184                                                        try
185                                                        {
186                                                                var elementIframe = document.getElementById('iframe_applet_jabberit');
187                                                               
188                                                                // If Layer;
189                                                                if( elementIframe != null )
190                                                                {
191                                                                        if( !_is_ie )
192                                                                                groups = elementIframe.contentDocument.applets[0].getGroupsToExpresso();
193                                                                        else
194                                                                                groups = elementIframe.contentWindow.document.applets[0].getGroupsToExpresso();
195                                                                }
196                                                                else // If Pop-Up
197                                                                {
198                                                                        groups = _myWindow.document.applets[0].getGroupsToExpresso();
199                                                                }
200                                               
201                                                                if( typeof(groups) == 'object')
202                                                                {
203                                                                        data = groups + ";";
204                                                                        data = data.substring(0,(data.length-2));
205                                                                }
206                                                                else                   
207                                                                        data = groups.substring(0,(groups.length-1));
208                                                               
209                                                                setTimeout(function(){showUser(data, _element);}, 250);
210                                                        }
211                                                        catch(e)
212                                                        {
213                                                                alert("*********** " + jabberitGetLang("Attention") + "!! ***********\n" +
214                                                                          jabberitGetLang("The module is not loaded") + "!\n" );
215                                                        }
216                                                }
217                                        }
218                                       
219                                        var _member = _target.firstChild;
220                       
221                                        while ( _member )
222                                        {
223                                                if( _member.getAttribute('photo') === '1' )
224                                                {
225                                                        var jid = _member.getAttribute('jid');
226                                                        var ou = _member.getAttribute('ou');
227
228                                                        var _img_path = path_jabberit + 'inc/webservice.php?' + Date.parse( new Date );
229                                                                _img_path += '&phpPhoto=' + jid + '&phpOu=' + ou;
230
231                                                        _member.style.backgroundImage = 'url(' + _img_path + ')';
232                                                }
233                                                _config(_member, 'onclick', _show);
234                                               
235                                                _member = _member.nextSibling;
236                                        }
237
238                                        _loading.style.display = "none";                                               
239                                },
240                                'name='+ arguments[0]
241                            );
242        }
243
244        function showUser(pData, pElement)
245        {
246                var jidUser = "";
247               
248                if ( pElement.getAttribute('value'))
249                {
250                        jidUser = pElement.getAttribute('jid');
251                        pElement = m.getAttribute('value');
252                }
253                else
254                {
255                        jidUser = pElement.parentNode.getAttribute('jid');
256                        pElement = pElement.parentNode.getAttribute('value');
257                }
258
259                document.getElementById('im_jidUser').value = jidUser;
260                document.getElementById('im_jid').value         = pElement.substr(0, pElement.indexOf(';'));
261                document.getElementById('im_uid').value         = pElement.substr((pElement.indexOf(';')+1));
262
263                var fname = document.getElementById(pElement).innerHTML;
264                fname = fname.substr(0, fname.indexOf(' '));
265                document.getElementById('im_name').value = fname;
266
267                if( pData)
268                {
269                        document.getElementById('im_group').setAttribute('selectboxoptions', pData);
270
271                        if( document.getElementById('selectBox0') == null )
272                                editS.create(document.getElementById('im_group'));
273                }
274               
275                var _pButtons = {
276                                                        'lang1' : jabberitGetLang('add'),
277                                                        'lang2' : jabberitGetLang('close'),
278                                                        'onclickClose' : 'winBuild("add_user_info","remove")',
279                                                        'onclickSubmit' : 'loadscript.addUser()'
280                                                };
281               
282                document.getElementById('buttons_adduser').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
283        }
284       
285        function LDAP()
286        {
287                _conn           = arguments[0];
288                Xtools          = arguments[1];
289                _is_ie          = arguments[2];
290        }
291
292        LDAP.prototype.addUser  = addUser;
293        LDAP.prototype.load             = _load;
294        LDAP.prototype.search   = _search;
295        window.JITLdap = LDAP;
296}
297)();
Note: See TracBrowser for help on using the repository browser.