source: sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js @ 2471

Revision 2471, 15.1 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Correção da lista de contatos para a leitura de um contato em varios grupos.

  • Property svn:executable set to *
Line 
1(function()
2{
3        var fullName            = "";
4        var path                        = "";
5        var addUser                     = null;
6        var conn                        = null;
7        var selectEditable      = null;
8        var showhidden          = null;
9        var userCurrent         = null;
10        var Xtools                      = null;
11        var zIndex                      = 9001;
12       
13        // Images
14        var add_user = new Image();
15        add_user.src = path_jabberit + 'templates/default/images/adduser_azul.png';
16
17        var arrow_down = new Image();
18        arrow_down.src = path_jabberit + 'templates/default/images/arrow_down.gif';
19
20        var arrow_right = new Image();
21        arrow_right.src = path_jabberit + 'templates/default/images/arrow_right.gif';
22       
23        function actionButton()
24        {
25                if( arguments.length > 0 )
26                {
27                        var e           = arguments[0];
28                        var jid         = arguments[1];
29                        var index       = arguments[2];
30               
31                        if ( !e )
32                                var e = window.event;
33                       
34                        ( ( e.target ) ? e.target : e.srcElement ).oncontextmenu = function(e)
35                        {
36                                return false;
37                        };
38       
39                        if ( ( e.which && e.which > 1 ) || ( e.button && e.button > 1 ) )
40                                optionsItensContact(jid, index);
41                        else
42                                TrophyIM.rosterClick(jid);
43                }
44        }
45
46        function addContact()
47        {
48                if( arguments.length > 0 )
49                        addUser.add();
50                else
51                        addUser.show();
52        }
53       
54        function addIcon()
55        {
56                var StatusBar = getElement('divStatusBar');
57
58                /**
59                 * @quando estiver habilitada a opção fora de escritório nos filtros.
60                 */
61               
62                if( div_write_msg = getElement('em_div_write_msg') )
63                {               
64                        var StatusBarIM = getElement('JabberMessenger');
65                                StatusBarIM.style.paddingLeft = '33px';
66                       
67                        div_write_msg.parentNode.insertBefore( StatusBarIM, div_write_msg );
68                       
69                        return;                 
70                }
71               
72                if( StatusBar )
73                {
74                        StatusBar.style.paddingLeft = '33px';
75                       
76                        var _div = document.createElement('div');
77                                _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
78                       
79                                StatusBar.parentNode.insertBefore( _div, StatusBar);
80                       
81                        var divJabber = document.createElement('div');
82                                divJabber.setAttribute('id', 'JabberMessenger');
83                       
84                        var _fastMenu = top.document.createElement('div');
85                                _fastMenu.setAttribute('id', 'fast_menu_jabber_expresso');
86                                _fastMenu.style.background              = 'no-repeat';
87                                _fastMenu.style.backgroundImage = 'url(' + arrow_down.src + ')';
88                                _fastMenu.style.float                   = 'left';
89                                _fastMenu.style.height                  = '15px';
90                                _fastMenu.style.left                    = '7px';
91                                _fastMenu.style.margin                  = '8 0 0 10px';
92                                _fastMenu.style.padding                 = '0px';
93                                _fastMenu.style.position                = 'absolute';
94                                _fastMenu.style.width                   = '15px';
95                                _fastMenu.style.cursor                  = 'pointer';
96
97                        divJabber.insertBefore( _fastMenu, divJabber.firstChild );
98                       
99                        // Add event onclick element _fastMenu
100                        configEvents( _fastMenu, 'onclick', function(){ fastMenu(_fastMenu); });
101
102                        var _statusJabber = top.document.createElement('div');
103                                _statusJabber.setAttribute('id','status_jabber_expresso');
104                                _statusJabber.style.background          = 'no-repeat';
105                                _statusJabber.style.backgroundImage = 'url(' + add_user.src +')';
106                                _statusJabber.style.float                       = 'left';
107                                _statusJabber.style.height                      = '18px';
108                                _statusJabber.style.left                        = '19px';
109                                _statusJabber.style.margin                      = '0 0 0 10px';
110                                _statusJabber.style.padding                     = '0px';
111                                _statusJabber.style.position            = 'absolute';
112                                _statusJabber.style.width                       = '18px';
113                                _statusJabber.style.cursor                      = 'pointer';
114                                _statusJabber.style.zindex                      = '999999';
115                       
116                        divJabber.insertBefore( _statusJabber, divJabber.firstChild );
117                       
118                        StatusBar.insertBefore( divJabber, StatusBar.firstChild );
119
120                        // Add event onclick element _statusJabber
121                        configEvents( _statusJabber, 'onclick', function(){ TrophyIM.load();});
122                }
123        }
124
125        function configEvents(pObj, pEvent, pHandler)
126        {
127                if ( typeof pObj == 'object' )
128                {
129                        if ( pEvent.substring(0, 2) == 'on' )
130                                pEvent = pEvent.substring(2, pEvent.length);
131
132                        if ( pObj.addEventListener )
133                                pObj.addEventListener(pEvent, pHandler, false);
134                        else if ( pObj.attachEvent )
135                                pObj.attachEvent('on' + pEvent, pHandler);
136                }
137        }
138       
139        function fastMenu()
140        {
141                if( arguments.length > 0 )
142                {
143                        var element = arguments[0];
144                       
145                        if( showhidden == null )
146                                showhidden = new ShowHidden(300);
147
148                        var _options = [
149                                                ['Adicionar Contato', 'loadIM.addContact();' ],
150                                                ['Ajuda', 'alert("2")' ],
151                                                ['Preferências', 'alert("3")'],
152                                                   ];
153
154                        var _itens = "";
155                       
156                        for( var i in _options )
157                        {
158                                _itens += '<img src="'+arrow_right.src+'"/>';
159                                _itens += '<span style="cursor:pointer; margin:3px;" onclick='+_options[i][1]+'>';
160                                _itens += _options[i][0] + '</span><br/>';
161                        }
162                       
163                        var _optionsItens = document.createElement("div");
164                                _optionsItens.setAttribute("style", "margin: 20px 0px 0px -4px;");
165                                _optionsItens.className         = "x-menu";
166                                _optionsItens.style.zIndex      = '99999';
167                                _optionsItens.innerHTML         = _itens; 
168                                                                                 
169                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
170                               
171                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
172                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
173                        element.parentNode.appendChild( _optionsItens );
174                       
175                }
176        }
177       
178        function getElement( elementId )
179        {
180                return document.getElementById( elementId );
181        }
182       
183        function getUserCurrent()
184        {
185                return userCurrent;
186        }
187       
188        function getZindex()
189        {
190                return zIndex++;
191        }
192       
193        function groupsHidden()
194        {
195                if( arguments.length > 0 )
196                {
197                        var _element = arguments[0];
198                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif')no-repeat center left";
199                                _element.onclick = function(){ groupsVisible(_element);};
200                               
201                                // Hidden all
202                                var _elementNext = _element.nextSibling;
203                               
204                                while( _elementNext )
205                                {       
206                                        _elementNext.style.display = "none";
207                                        _elementNext = _elementNext.nextSibling;
208                                }
209                }
210        }
211       
212        function groupsVisible()
213        {
214                if( arguments.length > 0 )
215                {
216                        var _element = arguments[0];
217                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif')no-repeat center left";
218                                _element.onclick = function(){ groupsHidden(_element);};
219
220                                // Display all
221                                var _elementNext = _element.nextSibling;
222                               
223                                while( _elementNext )
224                                {       
225                                        _elementNext.style.display = "block";
226                                        _elementNext = _elementNext.nextSibling;
227                                }
228                }
229        }
230       
231        function keyPressSearch()
232        {
233                if( arguments.length > 0 )
234                {
235                        var ev          = arguments[0];
236                        var element     = arguments[1];
237       
238                        if ( ev.keyCode == 13 )
239                                if( element.value.length >= 3 )
240                                        searchUser( element.value );   
241                                else
242                                        alert('Your search argument must be longer than 3 characters.');
243                }
244        }
245
246       
247        function loginPage()
248        {
249                var winLoginPage =
250                {       
251                         id_window              : "window_login_page",
252                         width                  : 260,
253                         height                 : 150,
254                         top                    : 100,
255                         left                   : 400,
256                         draggable              : true,
257                         visible                : "display",
258                         resizable              : true,
259                         zindex                 : zIndex++,
260                         title                  : "Login - Expresso Messenger",
261                         closeAction    : "remove",
262                         content                : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl")       
263                };
264
265                _winBuild( winLoginPage );
266        }
267
268        function loadScripts(pFiles)
269        {
270                // Load JavaScript
271                var loadJavaScript = function(pJs)
272                {
273                        var newScript = document.createElement("script");
274                                newScript.setAttribute("type", "text/javascript");
275                                newScript.setAttribute("src", pJs );
276                               
277                        return newScript;
278                };
279               
280                // Load CSS
281                var loadStyleSheet = function(pCss)
282                {
283                        var newStyle = document.createElement("link");
284                                newStyle.setAttribute("rel", "stylesheet");
285                                newStyle.setAttribute("type", "text/css");
286                                newStyle.setAttribute("href", pCss);
287                               
288                        return newStyle;
289                };
290               
291                for(var i = 0; i < pFiles.length; i++)
292                {
293                        if( pFiles[i].indexOf(".js") > -1 )
294                                document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
295                               
296                        if( pFiles[i].indexOf(".css") > -1 )
297                                document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
298                }
299        }
300
301       
302        function optionsItensContact()
303        {
304                if( arguments.length > 0 )
305                {
306                        var jid         = arguments[0];
307                        var index       = arguments[1];
308                        var element = document.getElementById('itenContact_' + jid + '_' + index );
309                       
310                        if( showhidden == null )
311                                showhidden = new ShowHidden(300);
312
313                        var _options = [
314                                                ['Autorizar', 'TrophyIM.setAutorization(\''+jid+'\')'],
315                                                ['Remover', 'loadIM.removeContact(\''+jid+'\')'],
316                                                ['Renomear', 'Renomear : ' + jid],
317                                                ['Trocar grupo', 'Trocar grupo : ' + jid],
318                                                   ];
319
320                        var _itens = "";
321                       
322                        for( var i in _options )
323                        {
324                                _itens += '<img src="'+arrow_right.src+'"/>';
325                                _itens += '<span style="cursor:pointer; margin:3px; font-weight:normal;" onclick='+_options[i][1]+'>';
326                                _itens += _options[i][0] + '</span><br/>';
327                        }
328                       
329                        var _optionsItens = document.createElement("div");
330                                _optionsItens.setAttribute("style", "margin: -5px 0px 0px 20px;");
331                                _optionsItens.className         = "x-menu";
332                                _optionsItens.style.zIndex      = '99999';
333                                _optionsItens.innerHTML         = _itens; 
334                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };                                         
335                               
336                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
337                               
338                        element.onmouseout      = function(){ showhidden.hiddenObject(false); };
339                        element.onmouseover     = function(){ showhidden.hiddenObject(true); };
340                        element.appendChild( _optionsItens );
341                }
342               
343        }
344
345        function parse()
346        {
347                if( arguments.length == 2 )
348                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
349               
350                if( arguments.length === 3 )
351                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
352        }
353       
354        function removeContact(jid)
355        {
356                setTimeout(function()
357                {
358                        TrophyIM.removeContact(jid);
359                       
360                }, 500);
361        }
362       
363        function removeGroup()
364        {
365                var _parent = arguments[0];
366               
367                if( _parent.childNodes.length <= 2 )
368                        _parent.parentNode.removeChild(_parent);
369               
370        }
371       
372        function rosterDiv()
373        {
374                var paramListContact =
375                {
376                        'path_jabberit' : path_jabberit,
377                        'full_name'             : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "..."))
378                };
379               
380                var winRosterDiv =
381                {
382                         id_window              : "window_Roster_im",
383                         width                  : 250,
384                         height                 : 410,
385                         top                    : 50,
386                         left                   : 50,
387                         draggable              : true,
388                         visible                : "display",
389                         resizable              : true,
390                         zindex                 : zIndex++,
391                         title                  : "Contatos - Expresso Messenger",
392                         closeAction    : "hidden",
393                         content                : Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)       
394                };
395               
396                _winBuild( winRosterDiv );
397        }
398
399        function searchUser()
400        {
401                var _input      = document.getElementById('search_user_jabber');
402               
403                if( _input.value.length >= 3 )
404                        addUser.search();
405                else
406                        alert('Your search argument must be longer than 3 characters.');
407        }
408       
409        function setSelectEditable(element)
410        {
411                if( document.getElementById('selectBox0') == null )
412                        selectEditable.create(element);
413        }
414       
415        function setPresence()
416        {
417                if( arguments.length > 0 )
418                {
419                        var element = arguments[0];
420                       
421                        if( showhidden == null )
422                                showhidden = new ShowHidden(300);
423                       
424                        var _status = [
425                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
426                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
427                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
428                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
429                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
430                                          ];
431                       
432                        var _itens = "";
433                       
434                        for( var i in _status )
435                        {
436                                _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadIM.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
437                                _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
438                        }
439                       
440                        var _statusItens = document.createElement("div");
441                                _statusItens.setAttribute("style", "margin: 62px 0px 0px 76px;");
442                                _statusItens.className          = "x-menu";
443                                _statusItens.style.zIndex       = '99999';
444                                _statusItens.innerHTML          = _itens; 
445                                _statusItens.onclick            = function(){ showhidden.hiddenObject(false); };
446                                                                                 
447                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
448                               
449                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
450                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
451                        element.parentNode.appendChild(_statusItens);
452                }
453        }
454       
455        function setStatusJabber()
456        {
457                if( arguments.length > 0 )
458                {
459                        var _text       = arguments[0];
460                        var _img        = arguments[1];
461                       
462                        getElement('statusJabberImg').setAttribute("style", "background-image: url('"+path_jabberit+"templates/default/images/"+_img+".gif'); margin-left: 13px;width:15px; height:15px;");
463                        getElement('statusJabberText').innerHTML = _text;
464                        getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
465                }       
466        }
467       
468        function setUserCurrent( _jid , _password )
469        {
470                userCurrent =
471                {
472                        'jid'           : _jid,
473                        'password'      : _password
474                }
475        }
476
477        function loadIM()
478        {
479                if( arguments.length > 0 )
480                {
481                        var files = [
482                                                path_jabberit + 'js/connector.js',
483                                                path_jabberit + 'js/xtools.js',
484                                                path_jabberit + 'js/dragdrop.js',
485                                                path_jabberit + 'js/makeW.js',
486                                                path_jabberit + 'js/show_hidden.js',
487                                                path_jabberit + 'js/trophyim.js',
488                                                path_jabberit + 'js/AddUser.js',
489                                                path_jabberit + 'js/SelectEditable.js',
490                                                path_jabberit + 'templates/default/css/button.css',
491                                                path_jabberit + 'templates/default/css/common.css',
492                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
493                                                path_jabberit + 'templates/default/css/' + theme_jabberit
494                                    ];
495                        // FullName
496                        fullName = arguments[0];
497                       
498                        loadScripts(files);
499                       
500                        // User & Password Jabber;
501                        setUserCurrent( arguments[1], arguments[2]);
502                       
503                        setTimeout(function()
504                        {
505                                // Object Xtools       
506                                if( Xtools == null )
507                                        Xtools = new xtools(path_jabberit);
508                               
509                                // Object Conector
510                                if( conn == null )
511                                        conn = new AjaxConnector(path_jabberit);
512                               
513                                // Object Add User
514                                if( addUser == null )
515                                        addUser = new addUserIM(Xtools, conn);
516
517                               
518                                // Object SelectEditable
519                                if( selectEditable == null )
520                                        selectEditable = new SelectEditable();
521                                       
522                                // Add Jabber in StatusBar;
523                                addIcon();
524                               
525                        }, 1000);
526                }
527        }
528       
529        loadIM.prototype.actionButton           = actionButton;
530        loadIM.prototype.addContact                     = addContact;
531        loadIM.prototype.configEvents           = configEvents;
532        loadIM.prototype.getUserCurrent         = getUserCurrent;
533        loadIM.prototype.getZIndex                      = getZindex;
534        loadIM.prototype.groupsHidden           = groupsHidden;
535        loadIM.prototype.groupsVisible          = groupsVisible;
536        loadIM.prototype.keyPressSearch         = keyPressSearch;       
537        loadIM.prototype.loginPage                      = loginPage;
538        loadIM.prototype.parse                          = parse;
539        loadIM.prototype.searchUser                     = searchUser
540        loadIM.prototype.setPresence            = setPresence;
541        loadIM.prototype.setStatusJabber        = setStatusJabber;
542        loadIM.prototype.setSelectEditable      = setSelectEditable;
543        loadIM.prototype.removeContact          = removeContact;
544        loadIM.prototype.removeGroup            = removeGroup;
545        loadIM.prototype.rosterDiv                      = rosterDiv;
546       
547        window.loadIM = loadIM;
548       
549})();
Note: See TracBrowser for help on using the repository browser.