source: sandbox/jabberit_messenger/trophy_expresso/js/AddUser.js @ 2421

Revision 2421, 5.2 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Adicionado a funcionalidade de procurar contatos no ldap, com templates XSL.

Line 
1(function()
2{
3                var Xtools      = null;
4                var conn        = null;
5       
6                function addContacts()
7                {
8                        var jidFrom             = loadIM.getUserCurrent().jid;
9                        var jidTo               = document.getElementById('user_jid_jabberIM').value;
10                        var name                = document.getElementById('user_name_jabberIM').value;
11                        var group               = document.getElementById('user_group_jabberIM').value;
12                       
13                        alert( jidFrom + "\n" + jidTo + "\n" + name + "\n" + group );
14                       
15                        //TrophyIM.addContacts( jidFrom, jidTo, name, group );
16                       
17                }
18               
19                function search()
20                {
21                        var _input      = document.getElementById('search_user_jabber');
22                        var _span       = document.getElementById('span_searching_im');
23                        var _div        = document.getElementById('list_users_ldap_im');
24
25                        _span.style.display = "block";
26                       
27                        if( _input.value.substring((_input.value.length-1),_input.value.length) === "*" )
28                                _input.value = _input.value.substring(0, ( _input.value.length - 1 ));
29
30                        if( _input.value.substring(0 ,1) === "*" )
31                                _input.value = _input.value.substring( 1, _input.value.length );
32                       
33                        conn.go('p.cc.getListContacts',
34                                        function(data)
35                                        {       
36                                                var _paramsVar =
37                                                {
38                                                        'lang_addContact'       : 'Adicionar Contatos',
39                                                        'lang_empty'            : 'None result was found.',
40                                                        'lang_many_results' : 'Many results. Please, try to refine your search.'
41                                                };     
42                                               
43                                                _div.innerHTML = Xtools.parse( data, 'listLdapContacts.xsl', _paramsVar );
44
45                                                var _newUser = _div.firstChild;
46                                               
47                                                while ( _newUser )
48                                                {
49                                                        if( _newUser.getAttribute('photo') === '1' )
50                                                        {
51                                                                var jid         = _newUser.getAttribute('jid');
52                                                                var ou          = _newUser.getAttribute('ou');
53
54                                                                var _img_path  = path_jabberit + 'inc/webservice.php?' + Date.parse( new Date );
55                                                                        _img_path += '&phpPhoto=' + jid + '&phpOu=' + ou;
56
57                                                                _newUser.style.backgroundImage = 'url(' + _img_path + ')';
58                                                        }
59                                                       
60                                                        loadIM.configEvents(_newUser, 'onclick', showContact);
61                                                       
62                                                        _newUser = _newUser.nextSibling;
63                                                }
64
65                                                _input.focus();
66                                                _input.value            = "";
67                                                _span.style.display = "none";
68                                               
69                                        },'name=' + _input.value );
70                }
71               
72                function showContact(Element)
73                {
74                        var element             = ( Element.target ) ? Element.target : Element.srcElement;
75                        var infoUser    = null;         
76                       
77                        if( element.getAttribute('value') )
78                        {
79                                var infoUser =
80                                {
81                                        'email'                         : element.getAttribute('value').substring( 0, element.getAttribute('value').indexOf(';')),
82                                        'jid'                           : element.getAttribute('jid'),
83                                        'lang_group'            : "Grupo",
84                                        'lang_name_contact'     : "Contato",                                   
85                                        'group'                         : element.getAttribute('ou'),
86                                        'name'                          : element.getAttribute('name').substring( 0, element.getAttribute('name').indexOf(' ')),
87                                        'uid'                           : element.getAttribute('value').substring( element.getAttribute('value').indexOf(';') + 1 )
88                                };
89                        }
90                        else if( element.parentNode.getAttribute('value') )
91                        {
92                                var infoUser =
93                                {
94                                        'email'                         : element.parentNode.getAttribute('value').substring( 0, element.parentNode.getAttribute('value').indexOf(';')),
95                                        'jid'                           : element.parentNode.getAttribute('jid'),
96                                        'lang_group'            : "Grupo",
97                                        'lang_name_contact'     : "Contato",                                   
98                                        'group'                         : element.parentNode.getAttribute('ou'),
99                                        'name'                          : element.parentNode.getAttribute('name').substring( 0, element.parentNode.getAttribute('name').indexOf(' ')),                                 
100                                        'uid'                           : element.parentNode.getAttribute('value').substring( element.parentNode.getAttribute('value').indexOf(';') + 1)
101                                };
102                        }
103                       
104                        var winAddUser =
105                        {
106                                        id_window        : "add_user_info",
107                                        width            : 355,
108                                        height           : 190,
109                                        top                      : 85,
110                                        left             : 220,
111                                        draggable        : true,
112                                        visible          : "display",
113                                        resizable        : true,
114                                        zindex           : loadIM.getZIndex(),
115                                        title            : 'Expresso Messenger - Add Contact',
116                                        closeAction  : "remove",
117                                        content          : Xtools.parse( Xtools.xml('adduser'), 'addUser.xsl', infoUser )
118                        };
119
120                        _winBuild( winAddUser );
121                       
122                       
123                        var _pButtons =
124                        {
125                                'lang1'                 : 'Adicionar',
126                                'lang2'                 : 'Fechar',
127                                'onclickClose'  : '_winBuild("' + winAddUser.id_window + '","remove");',
128                                'onclickSubmit' : 'loadIM.addContacts(this);'
129                        };
130
131                        document.getElementById('buttons_adduser').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
132                }
133               
134                function showForm()
135                {
136                        var _paramsWindAddUser =
137                        {
138                                        'lang_group'            : 'Grupo',
139                                        'lang_load'                     : 'Carregando',
140                                        'lang_name_contact'     : 'Nome do Contato',
141                                        'lang_result'           : 'Resultado da Busca',
142                                        'path'                          : path_jabberit
143                        };
144
145                        var windAddUser =
146                        {
147                                        id_window        : "add_user_im",
148                                        width            : 440,
149                                        height           : 350,
150                                        top                      : 80,
151                                        left             : 200,
152                                        draggable        : true,
153                                        visible          : "display",
154                                        resizable        : true,
155                                        zindex           : loadIM.getZIndex(),
156                                        title            : 'Expresso Messenger - Search users',
157                                        closeAction  : "remove",
158                                        content          : Xtools.parse( Xtools.xml('userinfo'), 'addUser.xsl', _paramsWindAddUser )
159                        };
160                       
161                        _winBuild( windAddUser );
162                }
163       
164                function loadAddUser()
165                {
166                        if( arguments.length > 0 )
167                        {
168                                Xtools  = arguments[0];
169                                conn    = arguments[1];                         
170                        }       
171                }
172
173                loadAddUser.prototype.add               = addContacts;
174                loadAddUser.prototype.search    = search;
175                loadAddUser.prototype.show              = showForm;
176                               
177                window.addUserIM        = loadAddUser;
178})();
Note: See TracBrowser for help on using the repository browser.