source: trunk/jmessenger/js/AddUser.js @ 2971

Revision 2971, 7.7 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #1116 - Melhorar a visualizacao/avisos de novos contatos e pedidos de autorizacao no modulo.

  • Property svn:executable set to *
Line 
1(function()
2{
3                var Xtools      = null;
4                var conn        = null;
5       
6                function addContact()
7                {
8                        if( arguments.length > 0 )
9                        {
10                                var jidFrom             = loadscript.getUserCurrent().jid;
11                                var jidTo               = arguments[0];
12                                var group               = "";
13                                var name                = jidTo.substring(0, jidTo.indexOf('@'));
14
15                                // Name
16                                if(( name = prompt("Informe um nome para " + name + "!", name )))
17                                        if(( name = name.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" )
18                                                name = "";
19
20                                if( name == null || name == "")
21                                        name = "";
22                               
23                                // Group
24                                if((group = prompt("Informe um grupo ou deixe em branco")))
25                                        if(( group = group.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" )
26                                                group = "";
27
28                                if( group == null || group == "")
29                                        group = "";
30                               
31                                // Remove Element
32                                if( getElement('itenContact_' + jidTo ) )
33                                {
34                                        loadscript.removeElement( getElement('itenContact_' + jidTo ) );
35                                        loadscript.removeElement( getElement('span_show_itenContact_' + jidTo ) );
36                                }
37
38                                TrophyIM.rosterObj.removeContact( jidTo );
39                        }
40                        else
41                        {       
42                                var jidFrom             = loadscript.getUserCurrent().jid;
43                                var jidTo               = document.getElementById('user_jid_jabberIM').value;
44                                var name                = document.getElementById('user_name_jabberIM').value;
45                                var group               = document.getElementById('user_group_jabberIM').value;
46                               
47                                _winBuild('add_user_info','remove');                           
48                        }
49                       
50                        if( jidFrom != jidTo )
51                        {
52                                TrophyIM.addContact( jidTo, name, group );
53                        }
54                }
55               
56                function getElement( elementId )
57                {
58                        return document.getElementById( elementId );
59                }
60
61                function search()
62                {
63                        var _input      = document.getElementById('search_user_jabber');
64                        var _span       = document.getElementById('span_searching_im');
65                        var _div        = document.getElementById('list_users_ldap_im');
66
67                        _span.style.display = "block";
68                       
69                        if( _input.value.substring((_input.value.length-1),_input.value.length) === "*" )
70                                _input.value = _input.value.substring(0, ( _input.value.length - 1 ));
71
72                        if( _input.value.substring(0 ,1) === "*" )
73                                _input.value = _input.value.substring( 1, _input.value.length );
74                       
75                        conn.go('p.cc.getListContacts',
76                                        function(data)
77                                        {       
78                                                var _paramsVar =
79                                                {
80                                                        'lang_addContact'       : 'Adicionar Contatos',
81                                                        'lang_empty'            : 'None result was found.',
82                                                        'lang_many_results' : 'Many results. Please, try to refine your search.'
83                                                };     
84                                               
85                                                _div.innerHTML = Xtools.parse( data, 'listLdapContacts.xsl', _paramsVar );
86
87                                                var _newUser = _div.firstChild;
88                                               
89                                                while ( _newUser )
90                                                {
91                                                        if( _newUser.getAttribute('photo') === '1' )
92                                                        {
93                                                                var jid         = _newUser.getAttribute('jid');
94                                                                var ou          = _newUser.getAttribute('ou');
95                                                               
96                                                                var _img_path  = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date );
97                                                                        _img_path += '&photo_session=' + jid + '&ou=' + ou;
98                                                               
99                                                                _newUser.style.backgroundImage = 'url(' + _img_path + ')';
100                                                        }
101                                                       
102                                                        loadscript.configEvents(_newUser, 'onclick', showContact);
103                                                       
104                                                        _newUser = _newUser.nextSibling;
105                                                }
106
107                                                _input.focus();
108                                                _input.value            = "";
109                                                _span.style.display = "none";
110                                               
111                                        },'name=' + _input.value );
112                }
113               
114                function showContact(Element)
115                {
116                        var element             = ( Element.target ) ? Element.target : Element.srcElement;
117                        var infoUser    = null;         
118                        var img                 = document.createElement('img');
119                        var _groups             = "Sem Grupos";
120
121                        if( TrophyIM.rosterObj)
122                        {
123                                _groups = "";
124                               
125                                for (var group in TrophyIM.rosterObj.groups)
126                                {
127                                        _groups += group + ";";
128                                }       
129                               
130                                _groups = _groups.substring(0, ( _groups.length - 1) );
131                        }
132                       
133                        if( element.getAttribute('value') )
134                        {
135                                var infoUser =
136                                {
137                                        'email'                         : element.getAttribute('value').substring( 0, element.getAttribute('value').indexOf(';')),
138                                        'jid'                           : element.getAttribute('jid'),
139                                        'lang_group'            : "Grupo",
140                                        'lang_name_contact'     : "Contato",                                   
141                                        'group'                         : element.getAttribute('ou'),
142                                        'name'                          : element.getAttribute('name').substring( 0, element.getAttribute('name').indexOf(' ')),
143                                        'ou'                            : element.getAttribute('ou'),
144                                        'selectBoxOptions'      : _groups,
145                                        'uid'                           : element.getAttribute('value').substring( element.getAttribute('value').indexOf(';') + 1 )
146                                };
147                        }
148                        else if( element.parentNode.getAttribute('value') )
149                        {
150                                var infoUser =
151                                {
152                                        'email'                         : element.parentNode.getAttribute('value').substring( 0, element.parentNode.getAttribute('value').indexOf(';')),
153                                        'jid'                           : element.parentNode.getAttribute('jid'),
154                                        'lang_group'            : "Grupo",
155                                        'lang_name_contact'     : "Contato",                                   
156                                        'group'                         : element.parentNode.getAttribute('ou'),
157                                        'name'                          : element.parentNode.getAttribute('name').substring( 0, element.parentNode.getAttribute('name').indexOf(' ')),
158                                        'ou'                            : element.parentNode.getAttribute('ou'),
159                                        'selectBoxOptions'      : _groups,
160                                        'uid'                           : element.parentNode.getAttribute('value').substring( element.parentNode.getAttribute('value').indexOf(';') + 1)
161                                };
162                        }
163                       
164                        var winAddUser =
165                        {
166                                        id_window        : "add_user_info",
167                                        width            : 370,
168                                        height           : 200,
169                                        top                      : 85,
170                                        left             : 220,
171                                        draggable        : true,
172                                        visible          : "display",
173                                        resizable        : true,
174                                        zindex           : loadscript.getZIndex(),
175                                        title            : 'Expresso Messenger - Add Contact',
176                                        closeAction  : "remove",
177                                        content          : Xtools.parse( Xtools.xml('adduser'), 'addUser.xsl', infoUser )
178                        };
179
180                        _winBuild( winAddUser );
181                       
182                       
183                        var _pButtons =
184                        {
185                                'lang1'                 : 'Adicionar',
186                                'lang2'                 : 'Fechar',
187                                'onclickClose'  : '_winBuild("' + winAddUser.id_window + '","remove");',
188                                'onclickSubmit' : 'loadscript.addContact(this);'
189                        };
190
191                        // Add Buttons
192                        document.getElementById('buttons_adduser').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
193                       
194                        // Select Editable
195                        loadscript.setSelectEditable(document.getElementById('user_group_jabberIM'));
196                       
197                        // Load Photo;
198                        var _img = null;
199                       
200                        if( element.style.backgroundImage )
201                                _img = element.cloneNode( false );
202                                                       
203                        if( element.parentNode.style.backgroundImage )
204                                _img = element.parentNode.cloneNode( false );
205                       
206                        if( _img != null )
207                        {
208                                _img.style.width        = '60px';
209                                _img.style.height       = '80px';
210                                _img.style.display      = 'block';
211                                _img.style.backgroundRepeat = 'no-repeat';
212                               
213                        }
214                        else
215                        {
216                                _img = document.createElement("img");
217                                _img.style.width        = '60px';
218                                _img.style.height       = '80px';
219                                _img.style.display      = 'block';
220                                _img.src                        = path_jabberit + "templates/default/images/photo.png";
221                        }
222                       
223                       
224                        with ( document.getElementById('photo_user_ldap_jabber') )
225                        {
226                                if( hasChildNodes( ) )
227                                        while( hasChildNodes( ) )
228                                        {
229                                                removeNode( firstChild );
230                                        }
231                               
232                                appendChild( _img );
233                        }
234                }
235               
236                function showForm()
237                {
238                       
239                        var _paramsWindAddUser =
240                        {
241                                        'lang_group'            : 'Grupo',
242                                        'lang_load'                     : 'Carregando',
243                                        'lang_name_contact'     : 'Nome do Contato',
244                                        'lang_result'           : 'Resultado da Busca',
245                                        'path'                          : path_jabberit
246                        };
247
248                        var windAddUser =
249                        {
250                                        id_window        : "add_user_im",
251                                        width            : 440,
252                                        height           : 350,
253                                        top                      : 80,
254                                        left             : 200,
255                                        draggable        : true,
256                                        visible          : "display",
257                                        resizable        : true,
258                                        zindex           : loadscript.getZIndex(),
259                                        title            : 'Expresso Messenger - Search users',
260                                        closeAction  : "remove",
261                                        content          : Xtools.parse( Xtools.xml('userinfo'), 'addUser.xsl', _paramsWindAddUser )
262                        };
263                       
264                        _winBuild( windAddUser );
265                       
266                }
267       
268                function loadAddUser()
269                {
270                        if( arguments.length > 0 )
271                        {
272                                Xtools  = arguments[0];
273                                conn    = arguments[1];                         
274                        }       
275                }
276
277                loadAddUser.prototype.add               = addContact;
278                loadAddUser.prototype.search    = search;
279                loadAddUser.prototype.show              = showForm;
280                               
281                window.addUserIM        = loadAddUser;
282})();
Note: See TracBrowser for help on using the repository browser.