source: sandbox/jabberit_messenger/trophy_expresso/js/jscode/loadIM.js @ 2717

Revision 2717, 29.7 KB checked in by emmanuel.ferro, 14 years ago (diff)

Ticket #986 - Apenas um teste com a senha do Emmanuel Ferro do Serpro ( 06/05/2010 : 14:19 ).

  • Property svn:executable set to *
Line 
1(function()
2{
3       
4        var _autoStatus;
5        var _autoStatusTime = 60000; // 1 minuto       
6        var addUser                     = null;
7        var conn                        = null;
8        var fullName            = "";
9        var path                        = "";
10        var _preferencesIM      = "";
11        var selectEditable      = null;
12        var showhidden          = null;
13        var _statusMessage      = "";
14        var timeoutId           = null;
15        var userCurrent         = null;
16        var Xtools                      = null;
17        var zIndex                      = 9001;
18       
19        // Images
20        var add_user = new Image();
21        add_user.src = path_jabberit + 'templates/default/images/adduser_azul.png';
22
23        var arrow_down = new Image();
24        arrow_down.src = path_jabberit + 'templates/default/images/arrow_down.gif';
25
26        var arrow_right = new Image();
27        arrow_right.src = path_jabberit + 'templates/default/images/arrow_right.gif';
28       
29        function actionButton()
30        {
31                if( arguments.length > 0 )
32                {
33                        var e                   = arguments[0];
34                        var _element    = ( e.target ) ? e.target : e.srcElement;
35                        var jid         = arguments[1];
36                        var index       = arguments[2];
37                        var coord       = null;
38
39                        if ( !e )
40                                e = window.event;
41
42                        var _X = e.clientX + document.body.scrollLeft - document.body.clientLeft;
43                        var _Y = e.clientY + document.body.scrollTop  - document.body.clientTop;
44                               
45                        coord = { X : _X, Y : _Y };
46               
47
48                        var _onContextMenu = function()
49                        {
50                                return false;
51                        };
52                       
53                        window.document.oncontextmenu   = _onContextMenu;
54                       
55                        if( e.button )
56                        {
57                                if( e.button > 1 )
58                                        optionsItensContact( jid, index, coord );
59                                else
60                                        TrophyIM.rosterClick(jid);
61                        }       
62                        else if( e.which )
63                        {
64                                if( e.which > 1 )
65                                        optionsItensContact( jid, index, coord );
66                                else
67                                        if( e.target.id )
68                                                TrophyIM.rosterClick(jid);
69                        }
70                }
71        }
72
73        function addContact()
74        {
75                if( arguments.length > 0 )
76                        addUser.add();
77                else
78                        addUser.show();
79        }
80       
81        function addIcon()
82        {
83               
84                var div_write_msg       = ( getElement('em_div_write_msg') != null ) ? getElement('em_div_write_msg') : null ;
85                var StatusBar           = ( getElement('divStatusBar') != null ) ? getElement('divStatusBar') : null ;
86                var StatusBarIM         = ( getElement('JabberMessenger') != null ) ?  getElement('JabberMessenger') : null;
87               
88                /**************************************************************************
89                 *
90                 * Quando estiver habilitada a opção fora de escritório nos filtros.
91                 * 
92                 */
93
94                if( ( div_write_msg && StatusBarIM ) != null )
95                {               
96                        div_write_msg.parentNode.insertBefore(StatusBarIM, div_write_msg);
97                        StatusBarIM.style.paddingLeft = '33px';
98                        return;
99                }
100               
101                /**************************************************************************/
102               
103                if ( !StatusBarIM )
104                {
105                        StatusBarIM = document.createElement('div');
106                        StatusBarIM.setAttribute('id', 'JabberMessenger');
107                }
108               
109                if( StatusBar )
110                {
111                        StatusBar.style.paddingLeft = '33px';
112                       
113                        var _div = document.createElement('div');
114                                _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
115                       
116                                StatusBar.parentNode.insertBefore( _div, StatusBar);
117                       
118                        var _fastMenu = top.document.createElement('div');
119                                _fastMenu.setAttribute('id', 'fast_menu_jabber_expresso');
120                                _fastMenu.style.background              = 'no-repeat';
121                                _fastMenu.style.backgroundImage = 'url(' + arrow_down.src + ')';
122                                _fastMenu.style.float                   = 'left';
123                                _fastMenu.style.height                  = '15px';
124                                _fastMenu.style.left                    = '7px';
125                                _fastMenu.style.margin                  = '8 0 0 10px';
126                                _fastMenu.style.padding                 = '0px';
127                                _fastMenu.style.position                = 'absolute';
128                                _fastMenu.style.width                   = '15px';
129                                _fastMenu.style.cursor                  = 'pointer';
130
131                        StatusBarIM.insertBefore( _fastMenu, StatusBarIM.firstChild );
132                       
133                        // Add event onclick element _fastMenu
134                        configEvents( _fastMenu, 'onclick', function(){ fastMenu(_fastMenu); });
135
136                        var _statusJabber = top.document.createElement('div');
137                                _statusJabber.setAttribute('id','status_jabber_expresso');
138                                _statusJabber.style.background          = 'no-repeat';
139                                _statusJabber.style.backgroundImage = 'url(' + add_user.src +')';
140                                _statusJabber.style.float                       = 'left';
141                                _statusJabber.style.height                      = '18px';
142                                _statusJabber.style.left                        = '19px';
143                                _statusJabber.style.margin                      = '0 0 0 10px';
144                                _statusJabber.style.padding                     = '0px';
145                                _statusJabber.style.position            = 'absolute';
146                                _statusJabber.style.width                       = '18px';
147                                _statusJabber.style.cursor                      = 'pointer';
148                                _statusJabber.style.zindex                      = '999999';
149                       
150                        StatusBarIM.insertBefore( _statusJabber, StatusBarIM.firstChild );
151                       
152                        StatusBar.insertBefore( StatusBarIM, StatusBar.firstChild );
153
154                        // Add event onclick element _statusJabber
155                        configEvents( _statusJabber, 'onclick', function(){ TrophyIM.load();});
156                }
157        }
158
159        function autoStatus()
160        {
161                var _div_status = ( getElement('status_jabber_expresso') != null ) ?  getElement('status_jabber_expresso') : null;
162               
163                if ( _autoStatus )
164                        clearTimeout(_autoStatus);
165
166                if ( _div_status != null )
167                {
168                        var _status = _div_status.style.backgroundImage;
169                                _status = _status.substr(_status.lastIndexOf('/') + 1);
170                                _status = _status.substr(0, _status.indexOf('.'));
171                               
172                        if( _status == "xa" )
173                        {
174                                if( getStatusMessage() != "")
175                                        TrophyIM.setPresence("available", getStatusMessage());
176                                else
177                                        TrophyIM.setPresence("available");
178                               
179                                loadscript.setStatusJabber("Disponível","available");
180                        }
181                }
182               
183                var TimeStatus = _preferencesIM[2].split(':');
184
185                if( TimeStatus[1] )
186                        _autoStatus = setTimeout( function(){ autoStatusHandler();}, parseInt(TimeStatus[1]) * _autoStatusTime );
187                else
188                        _autoStatus = setTimeout( function(){ autoStatusHandler();}, parseInt(_autoStatusTime));
189        }
190       
191        function autoStatusHandler()
192        {
193                var _div_status = ( getElement('status_jabber_expresso') != null ) ?  getElement('status_jabber_expresso') : null;
194               
195                if ( _div_status != null )
196                {
197                        var _status = _div_status.style.backgroundImage;
198                                _status = _status.substr(_status.lastIndexOf('/') + 1);
199                                _status = _status.substr(0, _status.indexOf('.'));
200                       
201                        if( _status == "available" )
202                        {
203                                if(getStatusMessage() != "")
204                                        TrophyIM.setPresence("xa", getStatusMessage());
205                                else
206                                        TrophyIM.setPresence("xa");
207                               
208                                loadscript.setStatusJabber("Não Disponível","xa");
209                        }
210                }
211        }
212
213        function clrAllContacts()
214        {
215                getElement("JabberIMRoster").innerHTML = "";
216        }
217       
218        function configEvents(pObj, pEvent, pHandler)
219        {
220                if ( typeof pObj == 'object' )
221                {
222                        if ( pEvent.substring(0, 2) == 'on' )
223                                pEvent = pEvent.substring(2, pEvent.length);
224
225                        if ( pObj.addEventListener )
226                                pObj.addEventListener(pEvent, pHandler, false);
227                        else if ( pObj.attachEvent )
228                                pObj.attachEvent('on' + pEvent, pHandler);
229                }
230        }
231       
232        function fastMenu()
233        {
234                if( arguments.length > 0 )
235                {
236                        var element = arguments[0];
237
238                        if( showhidden == null )
239                                showhidden = new ShowHidden(300);
240
241                        var _options = [
242                                                ['Adicionar Contato', 'loadscript.addContact();' ],
243                                                ['Ajuda', 'alert("2")' ],
244                                                ['Preferências', 'loadscript.preferences();'],
245                                                   ];
246
247                        var _itens = "";
248                       
249                        for( var i in _options )
250                        {
251                                if( _options[i].constructor == Function )
252                                        continue;
253                               
254                                _itens += '<img src="'+arrow_right.src+'"/>';
255                                _itens += '<span style="cursor:pointer; margin:3px;" onclick='+_options[i][1]+'>';
256                                _itens += _options[i][0] + '</span><br/>';
257                        }
258                       
259                        var _optionsItens = document.createElement("div");
260                                _optionsItens.id        = "fastMenu_Jabber";                           
261                                _optionsItens.style.marginTop   = "19px";
262                                _optionsItens.style.marginLeft  = "-8px";
263                                _optionsItens.className         = "x-menu";
264                                _optionsItens.style.zIndex      = '999999';
265                                _optionsItens.innerHTML         = _itens;
266                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
267                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };
268                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
269                                                                                 
270                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
271                               
272                        element.parentNode.appendChild( _optionsItens );
273                }
274        }
275       
276        function getElement( elementId )
277        {
278                return document.getElementById( elementId );
279        }
280       
281        function getPhotoUser( jid )
282        {
283                var _divPhoto = getElement( jid + '__photo' );
284
285                if( _divPhoto.style.backgroundImage.indexOf('photo.png') > 0 )
286                {
287                        var _imgUser  = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date );
288                                _imgUser += '&photo_ldap=' + jid;
289
290                        _divPhoto.style.backgroundImage = 'url(' + _imgUser + ')';
291                }
292        }
293       
294        function getStatusMessage()
295        {
296                return _statusMessage;
297        }
298       
299        function getShowContactsOffline()
300        {
301                if( _preferencesIM[3] )
302                {
303                        var showOffline = _preferencesIM[3].split(":");
304                       
305                        if( showOffline[1] === "true")
306                                return true;
307                        else
308                                return false;
309                }
310               
311                return true;
312        }
313
314        function getUserCurrent()
315        {
316                return userCurrent;
317        }
318       
319        function getZindex()
320        {
321                return zIndex++;
322        }
323       
324        function groupsHidden()
325        {
326                if( arguments.length > 0 )
327                {
328                        var _element = arguments[0];
329                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif') no-repeat center left";
330                                _element.onclick = function(){ groupsVisible(_element);};
331                               
332                                // Hidden all
333                                var _elementNext = _element.nextSibling;
334                               
335                                while( _elementNext )
336                                {       
337                                        if( _elementNext.nodeType == 1 )
338                                                _elementNext.style.display = "none";
339                                       
340                                        _elementNext = _elementNext.nextSibling;
341                                }
342                }
343        }
344       
345        function groupsVisible()
346        {
347                if( arguments.length > 0 )
348                {
349                        var _element = arguments[0];
350                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif') no-repeat center left";
351                                _element.onclick = function(){ groupsHidden(_element);};
352
353                                // Display all
354                                var _elementNext = _element.nextSibling;
355                               
356                                while( _elementNext )
357                                {       
358                                        if( _elementNext.nodeType == 1 && _elementNext.nodeName.toLowerCase() == "div")
359                                        {
360                                                var is_off = _elementNext.style.backgroundImage.indexOf("unavailable");
361
362                                                if( is_off > 0 && !getShowContactsOffline())   
363                                                        _elementNext.style.display = "none";
364                                                else
365                                                        _elementNext.style.display = "block";
366                                        }
367
368                                        _elementNext = _elementNext.nextSibling;
369                                }
370                }
371        }
372       
373        function keyPressSearch()
374        {
375                if( arguments.length > 0 )
376                {
377                        var ev          = arguments[0];
378                        var element     = arguments[1];
379       
380                        if ( ev.keyCode == 13 )
381                                if( element.value.length >= 3 )
382                                        searchUser( element.value );   
383                                else
384                                        alert('Your search argument must be longer than 3 characters.');
385                }
386        }
387
388       
389        function loginPage()
390        {
391                var winLoginPage =
392                {       
393                         id_window              : "window_login_page",
394                         width                  : 260,
395                         height                 : 150,
396                         top                    : 100,
397                         left                   : 400,
398                         draggable              : true,
399                         visible                : "display",
400                         resizable              : true,
401                         zindex                 : zIndex++,
402                         title                  : "Expresso Messenger - Login",
403                         closeAction    : "remove",
404                         content                : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl")       
405                };
406
407                _winBuild( winLoginPage );
408        }
409
410        function loadScripts(pFiles)
411        {
412                // Load JavaScript
413                var loadJavaScript = function(pJs)
414                {
415                        var newScript = document.createElement("script");
416                                newScript.setAttribute("type", "text/javascript");
417                                newScript.setAttribute("src", pJs );
418                               
419                        return newScript;
420                };
421               
422                // Load CSS
423                var loadStyleSheet = function(pCss)
424                {
425                        var newStyle = document.createElement("link");
426                                newStyle.setAttribute("rel", "stylesheet");
427                                newStyle.setAttribute("type", "text/css");
428                                newStyle.setAttribute("href", pCss);
429                               
430                        return newStyle;
431                };
432               
433                for(var i = 0; i < pFiles.length; i++)
434                {
435                        if( pFiles[i].indexOf(".js") > -1 )
436                                document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
437                               
438                        if( pFiles[i].indexOf(".css") > -1 )
439                                document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
440                }
441        }
442       
443        function notificationNewMessage()
444        {
445                var oldTitle    = document.title;
446                var newTitle    = "## NOVA MENSAGEM ##";
447                var idWindow    = arguments[1];
448
449                if( timeoutId == null )
450                {
451                        timeoutId = setInterval(function()
452                        {
453                                document.title = ( document.title == newTitle ) ? oldTitle : newTitle;
454                        }, 1000);
455                       
456                        configEvents( window.document, 'onclick', function()
457                        {
458                                clearInterval(timeoutId);
459                                document.title  = oldTitle;
460                                timeoutId               = null;
461                        });
462                       
463                        configEvents( window.document, 'onkeypress', function()
464                        {
465                                clearInterval(timeoutId);
466                                document.title  = oldTitle;
467                                timeoutId               = null;
468                        });
469                }
470        }
471
472        function optionsItensContact()
473        {
474                if( arguments.length > 0 )
475                {
476                        var jid         = arguments[0];
477                        var index       = arguments[1];
478                        var coord       = arguments[2];
479                        var element = getElement('itenContact_' + jid + '_' + index );
480                        var action      = ( element.getAttribute("subscription") === "not-in-roster" ) ? "Adicionar" : "Autorizar";     
481                       
482                        if( showhidden == null )
483                                showhidden = new ShowHidden(300);
484
485                        var _options = [
486                                                [ action , 'loadscript.setAutorization(\''+jid+'\',\''+index+'\')'],
487                                                ['Remover' , 'loadscript.removeContact(\''+jid+'\',\''+index+'\')'],
488                                                ['Renomear' , 'loadscript.renameContact(\''+jid+'\',\''+index+'\')'],
489                                                ['Trocar grupo' , 'loadscript.renameGroup(\''+jid+'\',\''+index+'\')']
490                                                   ];
491
492                        var _itens = "";
493                       
494                        for( var i in _options )
495                        {
496                                if( typeof(_options[i]) == "object")
497                                {
498                                        _itens += '<img src="'+arrow_right.src+'"/>';
499                                        _itens += '<span style="cursor:pointer;margin:3px;font-weight:normal;" onclick='+_options[i][1]+'>';
500                                        _itens += _options[i][0] + '</span><br/>';
501                                }
502                        }
503                       
504                        var _optionsItens = document.createElement("div");
505                                _optionsItens.className         = "x-menu";
506                                _optionsItens.style.top         = coord.Y;
507                                _optionsItens.style.left        = ( coord.X - element.offsetLeft );
508                                _optionsItens.style.zIndex      = getZindex();
509                                _optionsItens.innerHTML         = _itens; 
510                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
511                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };       
512                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
513                               
514                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
515                               
516                        window.document.body.appendChild(_optionsItens);
517                       
518                       
519                        setTimeout(function()
520                        {
521                                window.document.oncontextmenu = function()
522                                {
523                                        return true;
524                                };
525                               
526                        },500);
527                }
528        }
529
530        function parse()
531        {
532                if( arguments.length == 2 )
533                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
534               
535                if( arguments.length === 3 )
536                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
537        }
538       
539        function preferences()
540        {
541                var paramPreferences =
542                {
543                        'path'  : path,
544                        'lang1' : 'Suas Preferências',
545                        'lang2' : 'Conexão',   
546                        'lang3' : 'Conectar Automaticamente o IM',
547                        'lang4' : 'Usuários OffLine',
548                        'lang5' : 'Exibir amigos Offline',
549                        'lang6' : 'Salvar',
550                        'lang7' : 'Cancelar',
551                        'lang8' : 'Janela de Contatos',
552                        'lang9' : 'Abrir janela como Pop-up',
553                        'lang10' : 'Ausente',
554                        'lang11' : 'Definir status de ausente depois de',
555                        'lang12' : 'minutos',   
556                        'lang13' : 'Mostrar Contatos', 
557                        'lang14' : 'Mostrar contatos desconectados',
558                        'langYes': 'Sim',
559                        'langNo' : 'Não'                                                                                           
560                };
561               
562               
563                var _win_preferences =
564                {
565                                id_window        : "jabberit_preferences",
566                                width            : 430,
567                                height           : 410,
568                                top                      : 150,
569                                left             : 100,
570                                draggable        : true,
571                                visible          : "display",
572                                resizable        : true,
573                                zindex           : zIndex++,
574                                title            : 'Expresso Messenger - Preferências',
575                                closeAction  : "remove",
576                                content          : Xtools.parse(Xtools.xml('preferences'), 'preferences.xsl', paramPreferences)
577                };
578
579                _winBuild(_win_preferences);
580               
581               
582                var _pButtons = {
583                                'lang1' : 'Salvar',
584                                'lang2' : 'Fechar',
585                                'onclickClose' : '_winBuild("jabberit_preferences","remove");',
586                                'onclickSubmit' : 'javascript:loadscript.setPreferences();'
587                };
588               
589                document.getElementById('buttons_preferences_jabberit').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
590               
591                // Element openWindowJabberit
592                var value1                      = _preferencesIM[0].split(':');
593                var element1            = document.getElementById(value1[0]);
594                var valueSelect1        = value1[1];
595               
596                for(var i = 0; i < element1.options.length; i++)
597                        if( element1.options[i].value == valueSelect1 )
598                                element1.options[i].selected = true;
599
600                // Element openWindowJabberitPopUp
601                var value2                      = _preferencesIM[1].split(':');
602                var element2            = document.getElementById(value2[0]);
603                var valueSelect2        = value2[1];
604                       
605                for(var i = 0; i < element2.options.length; i++)
606                        if( element2.options[i].value == valueSelect2 )
607                                element2.options[i].selected = true;
608
609                // Element flagAwayIM
610                var value3              = _preferencesIM[2].split(':');
611                var element3    = document.getElementById(value3[0]);
612                element3.value  = value3[1];
613               
614                // Element showContactsOfflineJabberit
615                var value4                      = _preferencesIM[3].split(':');
616                var element4            = document.getElementById(value4[0]);
617                var valueSelect4        = value4[1];
618                for(var i = 0; i < element4.options.length; i++)
619                        if( element4.options[i].value == valueSelect4 )
620                                element4.options[i].selected = true;
621        }
622       
623        function removeContact(jid, index)
624        {
625                setTimeout(function()
626                {
627                        TrophyIM.removeContact(jid, index);
628                       
629                },300);
630        }
631       
632        function removeElement( )
633        {
634                if( arguments.length > 0 )
635                {
636                        var _element = arguments[0]
637                        var _parent  = _element.parentNode;
638       
639                        _parent.removeChild( _element );
640                }
641        }
642       
643        function removeGroup()
644        {
645                var _parent = arguments[0];
646               
647                if( _parent.childNodes.length <= 2 )
648                        _parent.parentNode.removeChild(_parent);
649        }
650       
651        function renameContact()
652        {
653                if( arguments.length > 0 )
654                {
655                        var _jid        = arguments[0];
656                        var _index      = arguments[1];
657                       
658                        TrophyIM.renameContact( _jid, _index );
659                }
660        }
661       
662        function renameGroup()
663        {
664                if( arguments.length > 0 )
665                {
666                        var _jid        = arguments[0];
667                        var _index      = arguments[1];
668                       
669                        TrophyIM.renameGroup( _jid , _index );
670                }
671        }
672       
673        function rosterDiv()
674        {
675                var paramListContact =
676                {
677                        'idUser'                : Base64.decode(getUserCurrent().jid),
678                        'full_name'             : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "...")),
679                        'path_jabberit' : path_jabberit,
680                        'zIndex_'               : zIndex++
681                };
682               
683                var winRosterDiv =
684                {
685                         id_window              : "window_Roster_im",
686                         width                  : 250,
687                         height                 : 410,
688                         top                    : 50,
689                         left                   : 50,
690                         draggable              : true,
691                         visible                : "display",
692                         resizable              : true,
693                         zindex                 : zIndex++,
694                         title                  : "Expresso Messenger - Contatos",
695                         closeAction    : "hidden",
696                         content                : Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)       
697                };
698               
699                _winBuild( winRosterDiv );
700
701                // Photo User
702                getPhotoUser(Base64.decode(getUserCurrent().jid));
703        }
704
705        function searchUser()
706        {
707                var _input      = getElement('search_user_jabber');
708               
709                if( _input.value.length >= 3 )
710                        addUser.search();
711                else
712                        alert('Your search argument must be longer than 3 characters.');
713        }
714       
715        function setAutorization(jidTo, indexTo)
716        {
717        var divItenContact = null;
718       
719        if( ( divItenContact = getElement('itenContact_' + jidTo + '_' + indexTo )))
720        {       
721                var subscription = divItenContact.getAttribute('subscription');
722               
723                switch(subscription)
724                {
725                        case 'from':
726                               
727                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
728                                break;
729
730                        case 'none' :
731                       
732                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
733                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
734                               
735                                break;
736
737                        case 'not-in-roster':
738                                       
739                                setTimeout(function()
740                                        {
741                                        var _add = "";
742                               
743                                        if( ( _add = confirm("Deseja adicionar o usuario!")) )         
744                                        {
745                                                addUser.add( jidTo, indexTo );
746                                        }
747                                       
748                                        },100);
749                               
750                                        break;
751                                       
752                        case 'to' :
753                               
754                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
755                                       
756                        case 'subscribe' :
757                               
758                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
759                               
760                                        break;
761                }
762        }       
763        }
764       
765        function setMessageStatus()
766        {
767                if( arguments.length > 0 )
768                {
769                        var _element = arguments[0];
770                        var _parent      = _element.parentNode;                 
771
772                        if( _element.nodeName.toLowerCase() == "label")
773                        {
774                                var _input                              = document.createElement("input");
775                                        _input.size                     = "35";
776                                        _input.maxlength        = "35";
777                                        _input.style.border = "0";
778                                        _input.value            = _element.innerHTML;
779                                       
780                                // OnkeyUp
781                                configEvents( _input, "onkeyup", function(e)
782                                                {
783                                                        if( e.keyCode == 13 ) loadscript.setMessageStatus(_input, _element);
784                                                }
785                                );
786                               
787                                // Onblur       
788                            configEvents(_input, "onblur", function(){ loadscript.setMessageStatus(_input, _element)});         
789
790                           
791                                if( _parent != null )
792                                {       
793                                        // Remove label
794                                        if( _element != null )
795                                                _parent.removeChild( _element );
796                                               
797                                        // Add Input
798                                        if( _input != null )
799                                                _parent.appendChild( _input );
800                                }
801
802                                _input.focus();
803                                _input.select();
804                        }
805                        else
806                        {
807                                var _label              = arguments[1];
808                                _statusMessage  = _element.value.replace(/^\(+|\)+$/g,"");
809                               
810                                if( ( _statusMessage = _statusMessage.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "")
811                                        _label.innerHTML = "( " + _statusMessage + " )";
812                                else
813                                        _label.innerHTML = "( Digite aqui sua mensagem de Status )";
814                               
815                                if( _parent != null )
816                                {       
817                                        // Remove Input
818                                        if( _element != null )
819                                                _parent.removeChild( _element );
820                                               
821                                        // Add Label
822                                        if( _label != null )
823                                                _parent.appendChild( _label );
824                                }
825                               
826                                // Send Status Message
827                                TrophyIM.setPresence("status", _statusMessage );
828                        }       
829                }
830        }
831       
832        function setPreferences()
833        {
834                // Element openWindowJabberit
835                var elementOpenW        = document.getElementById('openWindowJabberit');
836                var value                       = '';
837                var flagReload          = false;
838               
839                for(var i = 0 ; i < elementOpenW.options.length; i++)
840                        if( elementOpenW.options[i].selected == true)
841                        {
842                                value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
843                                _preferencesIM[0] = 'openWindowJabberit:' + elementOpenW.options[i].value;
844                        }
845
846                // Element openWindowJabberitPopUp
847                var elementOpenPop = document.getElementById('openWindowJabberitPopUp');       
848
849                for(var i = 0; i < elementOpenPop.options.length; i++ )
850                        if( elementOpenPop.options[i].selected ==  true )
851                        {
852                                value += '&preferences2=openWindowJabberitPopUp:' + elementOpenPop.options[i].value;
853                               
854                                if( _preferencesIM[1] != 'openWindowJabberitPopUp:' + elementOpenPop.options[i].value)
855                                        flagReload = true;
856                                       
857                                _preferencesIM[1] = 'openWindowJabberitPopUp:' + elementOpenPop.options[i].value;
858                        }
859               
860                // Element flagAwayIM
861                var elementFlagIM = document.getElementById('flagAwayIM');
862               
863                if( elementFlagIM.value.length > 0 && parseInt(elementFlagIM.value) > 0 )
864                {
865                        _preferencesIM[2] = 'flagAwayIM:' + elementFlagIM.value;
866                        value += '&preferences3=flagAwayIM:' + elementFlagIM.value;
867                }
868                else
869                {
870                        alert('Informe um valor igual ou maior que 1!');
871                        return false;
872                }
873
874                // Element showContactsOfflineJabberit
875                var elementShowOffline  = document.getElementById('showContactsOfflineJabberit');
876               
877                for(var i = 0 ; i < elementShowOffline.options.length; i++)
878                        if( elementShowOffline.options[i].selected == true)
879                        {
880                                _preferencesIM[3] = 'showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
881                                value += '&preferences4=showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
882                        }
883
884                // Save Preferences
885                conn.go('p.pf.setPreferences',
886                                 function(data)
887                                 {
888                                        if(data == 'true')
889                                        {
890                                                if( flagReload )
891                                                {
892                                                        window.location.reload();
893                                                        myWindow.close();                                                       
894                                                }
895                                        }
896                                        else{ alert('Erro salvando suas preferências!'); }
897
898                                        _winBuild('jabberit_preferences', 'remove');
899                                 },
900                                 value);
901        }
902       
903        function setPresence()
904        {
905                if( arguments.length > 0 )
906                {
907                        var element = arguments[0];
908                       
909                        if( showhidden == null )
910                                showhidden = new ShowHidden(300);
911                       
912                        var _status = [
913                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
914                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
915                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
916                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
917                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
918                                               ['Desconectado', 'unavailable', '<img src="'+path_jabberit+'templates/default/images/unavailable.gif" />'],
919                                               ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />'],                                               
920                                          ];
921                       
922                        var _itens = "";
923                       
924                        for( var i in _status )
925                        {
926                                if( typeof( _status[i]) == "object" )
927                                {
928                                        _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadscript.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
929                                        _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
930                                }
931                        }
932                       
933                        var _statusItens = document.createElement("div");
934                                _statusItens.style.marginTop    = "65px";
935                                _statusItens.style.marginLeft   = "67px";
936                                _statusItens.className                  = "x-menu";
937                                _statusItens.style.zIndex               = '99999';
938                                _statusItens.innerHTML                  = _itens; 
939                                _statusItens.onclick                    = function(){ showhidden.hiddenObject(false); };
940                                                                                 
941                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
942                               
943                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
944                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
945                        element.parentNode.appendChild(_statusItens);
946                }
947        }
948
949        function setSelectEditable(element)
950        {
951                if( getElement('selectBox0') == null )
952                        selectEditable.create(element);
953        }
954
955        function setStatusJabber()
956        {
957                if( arguments.length > 0 )
958                {
959                        if( arguments[1] != 'status' )
960                        {
961                                var _text       = arguments[0];
962                                var _img        = arguments[1];
963                                                                                                                                       
964                                getElement('statusJabberText').innerHTML                = _text;
965                                getElement('statusJabberImg').style.background  = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')";
966                                getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
967                        }
968                }       
969        }
970
971        function teste_meu(_jid, _password )
972        {
973                userCurrent =
974                {
975                        'jid'           : _jid.substring(11, _jid.length),
976                        'password'      : _password.substring(11, _password.length)
977                }               
978        }
979       
980        function setUserCurrent()
981        {
982                conn.go('p.ff.data_0',
983                                        function(_User)
984                                        {
985                                                var _user = _User;
986                                               
987                                                conn.go('p.ff.data_1',
988                                                                function(_pass)
989                                                                {
990                                                                        teste_meu( _user, _pass );
991                                                                });
992                                        });     
993        }
994
995        function loadIM()
996        {
997                if( arguments.length > 0 )
998                {
999                        var files = [
1000                                                path_jabberit + 'js/connector.js',
1001                                                path_jabberit + 'js/xtools.js',
1002                                                path_jabberit + 'js/dragdrop.js',
1003                                                path_jabberit + 'js/makeW.js',
1004                                                path_jabberit + 'js/show_hidden.js',
1005                                                path_jabberit + 'js/trophyim.js',
1006                                                path_jabberit + 'js/AddUser.js',
1007                                                path_jabberit + 'js/SelectEditable.js',
1008                                                path_jabberit + 'templates/default/css/button.css',
1009                                                path_jabberit + 'templates/default/css/common.css',
1010                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
1011                                                path_jabberit + 'templates/default/css/' + theme_jabberit
1012                                    ];
1013                        // FullName
1014                        fullName = arguments[0];
1015                       
1016                        // Preferences
1017                        _preferencesIM = arguments[1].split(";");
1018                       
1019                        if( !_preferencesIM[3] ) _preferencesIM[3] = "showContactsOfflineJabberit:false";
1020                               
1021                        loadScripts(files);
1022                       
1023                        setTimeout(function()
1024                        {
1025                                // Object Xtools       
1026                                if( Xtools == null )
1027                                        Xtools = new xtools(path_jabberit);
1028                               
1029                                // Object Conector
1030                                if( conn == null )
1031                                        conn = new AjaxConnector(path_jabberit);
1032                               
1033                                // Object Add User
1034                                if( addUser == null )
1035                                        addUser = new addUserIM(Xtools, conn);
1036
1037                               
1038                                // Object SelectEditable
1039                                if( selectEditable == null )
1040                                        selectEditable = new SelectEditable();
1041                                       
1042                                // Add Jabber in StatusBar;
1043                                addIcon();
1044                               
1045                                window.document.oncontextmenu = function()
1046                                {
1047                                        return true;
1048                                };
1049                               
1050                               
1051                                // Auto Connect
1052                                setTimeout(function()
1053                                {
1054                                        if( _preferencesIM[0] === 'openWindowJabberit:true' )
1055                                                TrophyIM.load();
1056                                },1500);
1057                               
1058                                // Auto Status
1059                                autoStatus();
1060                                configEvents( document, 'onmousemove', autoStatus );
1061                                configEvents( document, 'onkeypress', autoStatus );
1062
1063                        }, 2000);
1064                }
1065        }
1066       
1067        loadIM.prototype.adIcon                         = addIcon;
1068        loadIM.prototype.actionButton           = actionButton;
1069        loadIM.prototype.addContact                     = addContact;
1070        loadIM.prototype.clrAllContacts         = clrAllContacts;
1071        loadIM.prototype.configEvents           = configEvents;
1072        loadIM.prototype.getPhotoUser           = getPhotoUser;
1073        loadIM.prototype.getStatusMessage       = getStatusMessage;
1074        loadIM.prototype.getShowContactsOffline = getShowContactsOffline;
1075        loadIM.prototype.getUserCurrent         = getUserCurrent;
1076        loadIM.prototype.getZIndex                      = getZindex;
1077        loadIM.prototype.groupsHidden           = groupsHidden;
1078        loadIM.prototype.groupsVisible          = groupsVisible;
1079        loadIM.prototype.keyPressSearch         = keyPressSearch;       
1080        loadIM.prototype.loginPage                      = loginPage;
1081        loadIM.prototype.notification           = notificationNewMessage;
1082        loadIM.prototype.parse                          = parse;
1083        loadIM.prototype.preferences            = preferences;
1084        loadIM.prototype.searchUser                     = searchUser
1085        loadIM.prototype.setAutorization        = setAutorization;
1086        loadIM.prototype.setMessageStatus       = setMessageStatus;
1087        loadIM.prototype.setPreferences         = setPreferences;
1088        loadIM.prototype.setPresence            = setPresence;
1089        loadIM.prototype.setStatusJabber        = setStatusJabber;
1090        loadIM.prototype.setSelectEditable      = setSelectEditable;
1091        loadIM.prototype.setUserCurrent         = setUserCurrent;
1092        loadIM.prototype.removeContact          = removeContact;
1093        loadIM.prototype.removeElement          = removeElement;
1094        loadIM.prototype.removeGroup            = removeGroup;
1095        loadIM.prototype.renameContact          = renameContact;
1096        loadIM.prototype.renameGroup            = renameGroup;
1097        loadIM.prototype.rosterDiv                      = rosterDiv;
1098       
1099        window.LoadIM = loadIM;
1100       
1101})();
Note: See TracBrowser for help on using the repository browser.