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

Revision 2437, 6.2 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Adicao de contatos com resultados da busca do ldap e exclusao de contatos da lista.

Line 
1(function()
2{
3                var Xtools      = null;
4                var conn        = null;
5       
6                function addContact()
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                        TrophyIM.addContact( jidFrom, jidTo, name, group );
14                       
15                        _winBuild('add_user_info','remove');
16                }
17               
18                function search()
19                {
20                        var _input      = document.getElementById('search_user_jabber');
21                        var _span       = document.getElementById('span_searching_im');
22                        var _div        = document.getElementById('list_users_ldap_im');
23
24                        _span.style.display = "block";
25                       
26                        if( _input.value.substring((_input.value.length-1),_input.value.length) === "*" )
27                                _input.value = _input.value.substring(0, ( _input.value.length - 1 ));
28
29                        if( _input.value.substring(0 ,1) === "*" )
30                                _input.value = _input.value.substring( 1, _input.value.length );
31                       
32                        conn.go('p.cc.getListContacts',
33                                        function(data)
34                                        {       
35                                                var _paramsVar =
36                                                {
37                                                        'lang_addContact'       : 'Adicionar Contatos',
38                                                        'lang_empty'            : 'None result was found.',
39                                                        'lang_many_results' : 'Many results. Please, try to refine your search.'
40                                                };     
41                                               
42                                                _div.innerHTML = Xtools.parse( data, 'listLdapContacts.xsl', _paramsVar );
43
44                                                var _newUser = _div.firstChild;
45                                               
46                                                while ( _newUser )
47                                                {
48                                                        if( _newUser.getAttribute('photo') === '1' )
49                                                        {
50                                                                var jid         = _newUser.getAttribute('jid');
51                                                                var ou          = _newUser.getAttribute('ou');
52
53                                                                var _img_path  = path_jabberit + 'inc/webservice.php?' + Date.parse( new Date );
54                                                                        _img_path += '&phpPhoto=' + jid + '&phpOu=' + ou;
55
56                                                                _newUser.style.backgroundImage = 'url(' + _img_path + ')';
57                                                        }
58                                                       
59                                                        loadIM.configEvents(_newUser, 'onclick', showContact);
60                                                       
61                                                        _newUser = _newUser.nextSibling;
62                                                }
63
64                                                _input.focus();
65                                                _input.value            = "";
66                                                _span.style.display = "none";
67                                               
68                                        },'name=' + _input.value );
69                }
70               
71                function showContact(Element)
72                {
73                        var element             = ( Element.target ) ? Element.target : Element.srcElement;
74                        var infoUser    = null;         
75                        var img                 = document.createElement('img');
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                                        'ou'                            : element.getAttribute('ou'),
88                                        'selectBoxOptions'      : "grupo1; grupo2; grupo3",
89                                        'uid'                           : element.getAttribute('value').substring( element.getAttribute('value').indexOf(';') + 1 )
90                                };
91                        }
92                        else if( element.parentNode.getAttribute('value') )
93                        {
94                                var infoUser =
95                                {
96                                        'email'                         : element.parentNode.getAttribute('value').substring( 0, element.parentNode.getAttribute('value').indexOf(';')),
97                                        'jid'                           : element.parentNode.getAttribute('jid'),
98                                        'lang_group'            : "Grupo",
99                                        'lang_name_contact'     : "Contato",                                   
100                                        'group'                         : element.parentNode.getAttribute('ou'),
101                                        'name'                          : element.parentNode.getAttribute('name').substring( 0, element.parentNode.getAttribute('name').indexOf(' ')),
102                                        'ou'                            : element.parentNode.getAttribute('ou'),
103                                        'selectBoxOptions'      : "grupo1; grupo2; grupo3",
104                                        'uid'                           : element.parentNode.getAttribute('value').substring( element.parentNode.getAttribute('value').indexOf(';') + 1)
105                                };
106                        }
107                       
108                        var winAddUser =
109                        {
110                                        id_window        : "add_user_info",
111                                        width            : 370,
112                                        height           : 190,
113                                        top                      : 85,
114                                        left             : 220,
115                                        draggable        : true,
116                                        visible          : "display",
117                                        resizable        : true,
118                                        zindex           : loadIM.getZIndex(),
119                                        title            : 'Expresso Messenger - Add Contact',
120                                        closeAction  : "remove",
121                                        content          : Xtools.parse( Xtools.xml('adduser'), 'addUser.xsl', infoUser )
122                        };
123
124                        _winBuild( winAddUser );
125                       
126                       
127                        var _pButtons =
128                        {
129                                'lang1'                 : 'Adicionar',
130                                'lang2'                 : 'Fechar',
131                                'onclickClose'  : '_winBuild("' + winAddUser.id_window + '","remove");',
132                                'onclickSubmit' : 'loadIM.addContact(this);'
133                        };
134
135                        // Add Buttons
136                        document.getElementById('buttons_adduser').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
137                       
138                        // Select Editable
139                        loadIM.setSelectEditable(document.getElementById('user_group_jabberIM'));
140                       
141                        if( element.style.backgroundImage )
142                        {
143                                var _img = element.cloneNode( false );
144                                _img.style.width        = '60px';
145                                _img.style.height       = '80px';
146                                _img.style.display      = 'block';
147                                _img.style.backgroundRepeat = 'no-repeat';
148                                                       
149                        }
150                        else
151                        {
152                                var _img = document.createElement("img");
153                                _img.style.width        = '60px';
154                                _img.style.height       = '80px';
155                                _img.style.display      = 'block';
156                                _img.src                        = path_jabberit + "templates/default/images/photo.png";
157                        }
158                       
159                        with ( document.getElementById('photo_user_ldap_jabber') )
160                        {
161                                if( hasChildNodes( ) )
162                                        while( hasChildNodes( ) )
163                                        {
164                                                removeNode( firstChild );
165                                        }
166                               
167                                appendChild( _img );
168                        }
169                       
170                }
171               
172                function showForm()
173                {
174                        var _paramsWindAddUser =
175                        {
176                                        'lang_group'            : 'Grupo',
177                                        'lang_load'                     : 'Carregando',
178                                        'lang_name_contact'     : 'Nome do Contato',
179                                        'lang_result'           : 'Resultado da Busca',
180                                        'path'                          : path_jabberit
181                        };
182
183                        var windAddUser =
184                        {
185                                        id_window        : "add_user_im",
186                                        width            : 440,
187                                        height           : 350,
188                                        top                      : 80,
189                                        left             : 200,
190                                        draggable        : true,
191                                        visible          : "display",
192                                        resizable        : true,
193                                        zindex           : loadIM.getZIndex(),
194                                        title            : 'Expresso Messenger - Search users',
195                                        closeAction  : "remove",
196                                        content          : Xtools.parse( Xtools.xml('userinfo'), 'addUser.xsl', _paramsWindAddUser )
197                        };
198                       
199                        _winBuild( windAddUser );
200                       
201                }
202       
203                function loadAddUser()
204                {
205                        if( arguments.length > 0 )
206                        {
207                                Xtools  = arguments[0];
208                                conn    = arguments[1];                         
209                        }       
210                }
211
212                loadAddUser.prototype.add               = addContact;
213                loadAddUser.prototype.search    = search;
214                loadAddUser.prototype.show              = showForm;
215                               
216                window.addUserIM        = loadAddUser;
217})();
Note: See TracBrowser for help on using the repository browser.