source: branches/2.2/jabberit_messenger/jmessenger/js/jscode/loadIM.js @ 5155

Revision 5155, 62.1 KB checked in by alexandrecorreia, 12 years ago (diff)

Ticket #2298 - Corrigido problema de identificação dos navegadores

  • Property svn:executable set to *
RevLine 
[3102]1(function()
[4475]2    {
3        var _autoStatus;
4        var _autoStatusTime             = 60000; // 1 minuto
5        var addUser                     = null;
6        var conn                        = null;
7        var fullName                    = "";
8        var path                        = "";
[4442]9        var path_phpgwapi               = "";
[4475]10        var _preferencesIM              = "";
11        var selectEditable              = null;
12        var showhidden                  = null;
13        var statusUserIM                = "";
14        var _statusMessage              = "";
15        var timeoutId                   = null;
16        var userCurrent                 = null;
17        var _timeOutNotification        = "";
18        var Xtools                      = null;
19        var zIndex                      = 9001;
20        var windowPopUp                 = [];
[3102]21       
[4475]22        // Images
23        var add_user = new Image();
24        add_user.src = path_jabberit + 'templates/default/images/adduser_azul.png';
[3102]25
[4475]26        var arrow_down = new Image();
27        arrow_down.src = path_jabberit + 'templates/default/images/arrow_down.gif';
[3102]28
[4475]29        var arrow_right = new Image();
30        arrow_right.src = path_jabberit + 'templates/default/images/arrow_right.gif';
[3102]31       
[4475]32        function actionButton()
33        {
34            if( arguments.length > 0 )
35            {
36                var e                   = arguments[0];
37                var _element    = ( e.target ) ? e.target : e.srcElement;
38                var jid         = arguments[1];
39                var coord       = null;
[3102]40
[4475]41                if ( !e )
42                    e = window.event;
[3102]43
[4475]44                var _X = e.clientX + document.body.scrollLeft - document.body.clientLeft;
45                var _Y = e.clientY + document.body.scrollTop  - document.body.clientTop;
[3102]46                               
[4475]47                coord = {
48                    X : _X,
49                    Y : _Y
50                };
[3102]51               
52
[4475]53                var _onContextMenu = function()
54                {
55                    return false;
56                };
[3102]57                       
[4475]58                window.document.oncontextmenu   = _onContextMenu;
[3102]59                       
[4475]60                if( e.button )
61                {
62                    if( e.button > 1 )
63                        optionsItensContact( jid, coord );
64                    else
65                        TrophyIM.rosterClick(jid);
66                }       
67                else if( e.which )
68                {
69                    if( e.which > 1 )
70                        optionsItensContact( jid, coord );
71                    else
72                    if( e.target.id )
73                        TrophyIM.rosterClick(jid);
74                }
[3102]75                       
[4475]76                setTimeout(function()
77                {
78                    window.document.oncontextmenu = function()
79                    {
80                        return true;
81                    };
[3102]82                               
[4475]83                },500);
84            }
85        }
[3102]86
[4475]87        function addContact()
88        {
89            if( arguments.length > 0 )
90                addUser.add();
91            else
92                addUser.show();
93        }
[3102]94       
[4475]95        function addIcon()
96        {
[3102]97               
[4475]98            var div_write_msg   = ( getElement('em_div_write_msg') != null ) ? getElement('em_div_write_msg') : null ;
99            var StatusBar               = ( getElement('divStatusBar') != null ) ? getElement('divStatusBar') : null ;
100            var StatusBarIM             = ( getElement('JabberMessenger') != null ) ?  getElement('JabberMessenger') : null;
[3102]101               
[4475]102            /**************************************************************************
[3102]103                 *
104                 * Quando estiver habilitada a opção fora de escritório nos filtros.
105                 * 
106                 */
107
[4475]108            if( ( div_write_msg && StatusBarIM ) != null )
109            {           
110                div_write_msg.parentNode.insertBefore(StatusBarIM, div_write_msg);
111                StatusBarIM.style.paddingLeft = '33px';
112                return;
113            }
[3102]114               
[4475]115            /**************************************************************************/
[3102]116               
[4475]117            if ( !StatusBarIM )
118            {
119                StatusBarIM = document.createElement('div');
120                StatusBarIM.setAttribute('id', 'JabberMessenger');
121            }
[3102]122               
[4475]123            if( StatusBar )
124            {
125                StatusBar.style.paddingLeft = '33px';
[3102]126                       
[4475]127                var _div = document.createElement('div');
128                _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
[3102]129                       
[4475]130                StatusBar.parentNode.insertBefore( _div, StatusBar);
[3102]131                       
[4475]132                var _fastMenu = top.document.createElement('div');
133                _fastMenu.setAttribute('id', 'fast_menu_jabber_expresso');
134                _fastMenu.style.background              = 'no-repeat';
135                _fastMenu.style.backgroundImage = 'url(' + arrow_down.src + ')';
136                _fastMenu.style.float                   = 'left';
137                _fastMenu.style.height                  = '15px';
138                _fastMenu.style.left                    = '7px';
139                _fastMenu.style.margin                  = '8 0 0 10px';
140                _fastMenu.style.padding                 = '0px';
141                _fastMenu.style.position                = 'absolute';
142                _fastMenu.style.width                   = '15px';
143                _fastMenu.style.cursor                  = 'pointer';
[3102]144
[4475]145                StatusBarIM.insertBefore( _fastMenu, StatusBarIM.firstChild );
[3102]146                       
[4475]147                // Add event onclick element _fastMenu
148                configEvents( _fastMenu, 'onclick', function(){
149                    fastMenu(_fastMenu);
150                });
[3102]151
[4475]152                var _statusJabber = top.document.createElement('div');
153                _statusJabber.setAttribute('id','status_jabber_expresso');
154                _statusJabber.style.background          = 'no-repeat';
155                _statusJabber.style.backgroundImage = 'url(' + add_user.src +')';
156                _statusJabber.style.float                       = 'left';
157                _statusJabber.style.height                      = '18px';
158                _statusJabber.style.left                        = '19px';
159                _statusJabber.style.margin                      = '0 0 0 10px';
160                _statusJabber.style.padding                     = '0px';
161                _statusJabber.style.position            = 'absolute';
162                _statusJabber.style.width                       = '18px';
163                _statusJabber.style.cursor                      = 'pointer';
164                _statusJabber.style.zindex                      = '999999';
[3102]165                       
[4475]166                StatusBarIM.insertBefore( _statusJabber, StatusBarIM.firstChild );
[3102]167                       
[4475]168                StatusBar.insertBefore( StatusBarIM, StatusBar.firstChild );
[3102]169
[4475]170                // Add event onclick element _statusJabber
171                if( _preferencesIM[0] == "openWindowJabberit:true" )
172                {
173                    configEvents( _statusJabber, 'onclick', function(){
174                        rosterDiv();
175                    });
176                }
177                else
178                {
179                    configEvents( _statusJabber, 'onclick', function(){
180                        TrophyIM.load();
181                    });
182                }
183            }
184        }
[3102]185
[4475]186        function addNewUser()
187        {
188            addUser.newUser();
189        }
[3102]190       
[4475]191        function autoStatus()
192        {
193            var _div_status = ( getElement('status_jabber_expresso') != null ) ?  getElement('status_jabber_expresso') : null;
[3102]194               
[4475]195            if ( _autoStatus )
196                clearTimeout(_autoStatus);
[3102]197
[4475]198            if ( _div_status != null )
199            {
200                var _status = _div_status.style.backgroundImage;
201                _status = _status.substr(_status.lastIndexOf('/') + 1);
202                _status = _status.substr(0, _status.indexOf('.'));
[3102]203                               
[4475]204                if( _status == "xa" && _div_status.getAttribute('autoStatus') )
205                {
206                    if( getStatusMessage() != "")
207                        TrophyIM.setPresence("available", getStatusMessage());
208                    else
209                        TrophyIM.setPresence("available");
[3102]210                               
[4475]211                    _div_status.removeAttribute('autoStatus');
212                    loadscript.setStatusJabber("Disponível","available");
213                }
214            }
[3102]215               
[4475]216            var TimeStatus = _preferencesIM[2].split(':');
[3102]217
[4475]218            if( TimeStatus[1] )
219                _autoStatus = setTimeout( function(){
220                    autoStatusHandler();
221                }, parseInt(TimeStatus[1]) * _autoStatusTime );
222            else
223                _autoStatus = setTimeout( function(){
224                    autoStatusHandler();
225                }, parseInt(_autoStatusTime));
226        }
[3102]227       
[4475]228        function autoStatusHandler()
229        {
230            var _div_status = ( getElement('status_jabber_expresso') != null ) ?  getElement('status_jabber_expresso') : null;
[3102]231               
[4475]232            if ( _div_status != null )
233            {
234                var _status = _div_status.style.backgroundImage;
235                _status = _status.substr(_status.lastIndexOf('/') + 1);
236                _status = _status.substr(0, _status.indexOf('.'));
[3102]237                       
[4475]238                if( _status == "available" )
239                {
240                    if(getStatusMessage() != "")
241                        TrophyIM.setPresence("xa", getStatusMessage());
242                    else
243                        TrophyIM.setPresence("xa");
[3102]244
[4475]245                    _div_status.setAttribute('autoStatus','true');
[3102]246                               
[4475]247                    loadscript.setStatusJabber("Não Disponível","xa");
248                }
249            }
250        }
[3102]251
[4475]252        function clrAllContacts()
253        {
254            getElement("JabberIMRoster").innerHTML = "";
255        }
[3102]256       
[4475]257        function configEvents(pObj, pEvent, pHandler)
258        {
259            if ( typeof pObj == 'object' )
260            {
261                if ( pEvent.substring(0, 2) == 'on' )
262                    pEvent = pEvent.substring(2, pEvent.length );
[3102]263
[4475]264                if ( arguments.length == 3 )
265                {
266                    if ( pObj.addEventListener )
267                        pObj.addEventListener(pEvent, pHandler, false );
268                    else if ( pObj.attachEvent )
269                        pObj.attachEvent( 'on' + pEvent, pHandler );
270                }
271                else if ( arguments.length == 4 )
272                {
273                    if ( pObj.removeEventListener )
274                        pObj.removeEventListener( pEvent, pHandler, false );
275                    else if ( pObj.detachEvent )
276                        pObj.detachEvent( 'on' + pEvent, pHandler );
277                }
278            }
279        }
[3102]280
[4475]281        function disabledNotificationNewUsers()
282        {
283            var _notification   = getElement('notification_new_users_jabber') ;
284            var _statusJabber   = getElement('status_jabber_expresso');
[3102]285
[4475]286            _notification.style.display = 'none';
[3102]287               
[4475]288            _statusJabber.style.background = "url('"+path_jabberit+"templates/default/images/" + statusUserIM + ".gif') no-repeat";
[3102]289               
[4475]290            if( _timeOutNotification )
291                clearTimeout(_timeOutNotification );
[3102]292               
[4475]293            TrophyIM.controll.notificationNewUsers = 0;
294        }
[3102]295       
[4475]296        function enabledNotificationNewUsers()
297        {
298            var _notification   = getElement('notification_new_users_jabber') ;
299            var _statusJabber   = getElement('status_jabber_expresso');
[3102]300       
[4475]301            if( _notification && _statusJabber )
302            {   
303                if ( _notification.style.display == 'none' )
304                {
305                    _notification.style.display = 'block';
[3102]306                               
[4475]307                    _statusJabber.style.background = "url('"+path_jabberit+"templates/default/images/alert_mini.png') no-repeat";
[3102]308                               
[4475]309                    if( _timeOutNotification )
310                        clearTimeout(_timeOutNotification );
[3102]311
[4475]312                    _timeOutNotification = setTimeout( function(){
313                        enabledNotificationNewUsers();
314                    }, 2000 );
315                }
316                else
317                {
318                    _notification.style.display = 'none';
[3102]319                               
[4475]320                    _statusJabber.style.background = "url('"+path_jabberit+"templates/default/images/" + statusUserIM + ".gif') no-repeat";
[3102]321                               
[4475]322                    if( _timeOutNotification )
323                        clearTimeout(_timeOutNotification );
[3102]324
[4475]325                    _timeOutNotification = setTimeout( function(){
326                        enabledNotificationNewUsers();
327                    }, 800 );
328                }
329            }
330        }
[3102]331
[4475]332        function fastMenu()
333        {
334            if( arguments.length > 0 )
335            {
336                var element = arguments[0];
[3102]337
[4475]338                if( showhidden == null )
339                    showhidden = new ShowHidden(300);
[3102]340
[4475]341                var _options =  [
342                ['Adicionar Contato', 'loadscript.addContact();' ],
343                ['Preferências', 'loadscript.preferences();']
344                ];
[3102]345
[4475]346                if( im_chatroom == "false" )   
347                {       
348                    _options[2] = [ 'Sala(s) de Bate-Papo','loadscript.getListRooms();'];
349                }
[3680]350
[4475]351                var _itens = "";
[3102]352                       
[4475]353                for( var i in _options )
354                {
355                    if( _options[i].constructor == Function )
356                        continue;
[3102]357                               
[4475]358                    _itens += '<img src="'+arrow_right.src+'"/>';
359                    _itens += '<span style="cursor:pointer; margin:3px;" onclick='+_options[i][1]+'>';
360                    _itens += _options[i][0] + '</span><br/>';
361                }
[3102]362                       
[4475]363                var _optionsItens = document.createElement("div");
364                _optionsItens.id        = "fastMenu_Jabber";                           
365                _optionsItens.style.marginTop   = "19px";
366                _optionsItens.style.marginLeft  = "-8px";
367                _optionsItens.className         = "x-menu";
368                _optionsItens.style.zIndex      = '999999';
369                _optionsItens.innerHTML         = _itens;
370                _optionsItens.onclick           = function(){
371                    showhidden.hiddenObject(false);
372                };
373                _optionsItens.onmouseout        = function(){
374                    showhidden.hiddenObject(false);
375                };
376                _optionsItens.onmouseover       = function(){
377                    showhidden.hiddenObject(true);
378                };     
[3102]379                                                                                 
[4475]380                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
[3102]381                               
[4475]382                element.parentNode.appendChild( _optionsItens );
383            }
384        }
[3102]385       
[4475]386        function getElement( elementId )
387        {
388            return document.getElementById( elementId );
389        }
[3102]390       
[4475]391        function getBrowserCompatible()
392        {
[5057]393            return SnifferBrowser.isLoadApp('firefox');
[4475]394        }
[4479]395       
[4475]396        function getPhotoUser( jid )
397        {
398            try
399            {
400                var _divPhoto = getElement( jid + '__photo' );
[3102]401       
[4475]402                if( _divPhoto.style.backgroundImage.indexOf('photo.png') > 0 )
403                {
404                    var _imgUser  = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date );
405                    _imgUser += '&photo_ldap=' + jid;
[3308]406       
[4475]407                    _divPhoto.style.backgroundImage = 'url(' + _imgUser + ')';
408                }
409            }catch(e){}
410        }
[3308]411       
[4475]412        function getShowContactsOffline()
413        {
414            if( _preferencesIM[3] )
415            {
416                var showOffline = _preferencesIM[3].split(":");
[3102]417                       
[4475]418                if( showOffline[1] === "true")
419                    return true;
420                else
421                    return false;
422            }
[3102]423               
[4475]424            return true;
425        }
[3102]426       
[4475]427        function getSmiles( String )
428        {
429            String = String.replace( /:\)|:-\)/g        , " <img src='"+path_jabberit+"templates/default/images/smiles/1.gif'/> ");
430            String = String.replace( /:-D/g                     , " <img src='"+path_jabberit+"templates/default/images/smiles/2.gif'/> ");
431            String = String.replace( /;-\)/g            , " <img src='"+path_jabberit+"templates/default/images/smiles/3.gif'/> ");
432            String = String.replace( /=-O/g                     , " <img src='"+path_jabberit+"templates/default/images/smiles/4.gif'/> ");
433            String = String.replace( /:P/g                      , " <img src='"+path_jabberit+"templates/default/images/smiles/5.gif'/> ");
434            String = String.replace( /8-\)/g            , " <img src='"+path_jabberit+"templates/default/images/smiles/6.gif'/> ");
435            String = String.replace( /\>:o/g            , " <img src='"+path_jabberit+"templates/default/images/smiles/7.gif'/> ");
436            String = String.replace( /:-\$/g            , " <img src='"+path_jabberit+"templates/default/images/smiles/8.gif'/> ");
437            String = String.replace( /:s|:-X/g          , " <img src='"+path_jabberit+"templates/default/images/smiles/9.gif'/> ");
438            String = String.replace( /:-\(/g            , " <img src='"+path_jabberit+"templates/default/images/smiles/10.gif'/> ");
439            String = String.replace( /:\'\(/g           , " <img src='"+path_jabberit+"templates/default/images/smiles/11.gif'/> ");
440            String = String.replace( /:\|/g                     , " <img src='"+path_jabberit+"templates/default/images/smiles/12.gif'/> ");
441            String = String.replace( /O:-\)/g           , " <img src='"+path_jabberit+"templates/default/images/smiles/13.gif'/> ");
442            String = String.replace( /\*\*@#%/g         , " <img src='"+path_jabberit+"templates/default/images/smiles/14.gif'/> ");
443            String = String.replace( /\(I\)/g           , " <img src='"+path_jabberit+"templates/default/images/smiles/15.gif'/> ");
444            String = String.replace( /C28I/g            , " <img src='"+path_jabberit+"templates/default/images/smiles/16.gif'/> ");
445            String = String.replace( /CS2A/g            , " <img src='"+path_jabberit+"templates/default/images/smiles/17.gif' style='width:42px;height:36px;'/> ");
446            String = String.replace( /\(CzzzzI\)/g              , " <img src='"+path_jabberit+"templates/default/images/smiles/18.gif'/> ");               
[3102]447 
[4475]448            return String;
449        }
[3102]450       
[4475]451        function getStatusUserIM()
452        {
453            return statusUserIM;
454        }
[3102]455       
[4475]456        function getStatusMessage()
457        {
458            return _statusMessage;
459        }
[3102]460       
[4475]461        function getUserCurrent()
462        {
463            return userCurrent;
464        }
[3102]465       
[4475]466        function getZindex()
467        {
468            return zIndex++;
469        }
[3102]470       
[4475]471        function groupsHidden()
472        {
473            if( arguments.length > 0 )
474            {
475                var _element = arguments[0];
476                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif') no-repeat center left";
477                _element.onclick = function(){
478                    groupsVisible(_element);
479                };
[3102]480                               
[4475]481                // Hidden all
482                var _elementNext = _element.nextSibling;
[3102]483                               
[4475]484                while( _elementNext )
485                {       
486                    if( _elementNext.nodeType == 1 )
487                        _elementNext.style.display = "none";
[3102]488                                       
[4475]489                    _elementNext = _elementNext.nextSibling;
490                }
491            }
492        }
[3102]493       
[4475]494        function groupsVisible()
495        {
496            if( arguments.length > 0 )
497            {
498                var _element = arguments[0];
499                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif') no-repeat center left";
500                _element.onclick = function(){
501                    groupsHidden(_element);
502                };
[3102]503
[4475]504                // Display all
505                var _elementNext = _element.nextSibling;
[3102]506                               
[4475]507                while( _elementNext )
508                {       
509                    if( _elementNext.nodeType == 1 && _elementNext.nodeName.toLowerCase() == "div" )
510                    {
511                        var is_off = _elementNext.style.backgroundImage.indexOf("unavailable");
[3102]512
[4475]513                        if( is_off > 0 && !getShowContactsOffline())
514                        {
515                            _elementNext.style.display = "none";
516                            getElement("span_show_" + _elementNext.id ).style.display = "none";
[3102]517                                                       
[4475]518                        }
519                        else
520                        {
521                            _elementNext.style.display = "block";
522                            getElement("span_show_" + _elementNext.id ).style.display = "block";
523                        }
524                    }
[3102]525
[4475]526                    _elementNext = _elementNext.nextSibling;
527                }
528            }
529        }
[3102]530       
[4475]531        function keyPressSearch()
532        {
533            if( arguments.length > 0 )
534            {
535                var ev          = arguments[0];
536                var element     = arguments[1];
[3102]537       
[4475]538                if ( ev.keyCode == 13 )
539                    if( element.value.length >= 3 )
540                        searchUser( element.value );   
541                    else
542                        alert( i18n.YOUR_SEARCH_ARGUMENT_MUST_BE_LONGER_THAN_3_CHARACTERS + '.' );
543            }
544        }
[3102]545
546       
[4475]547        function loginPage()
548        {
549            var paramsLoginPage =
550            {
551                'username' : ((( Base64.decode(getUserCurrent().jid) )) ? Base64.decode(getUserCurrent().jid) : ""),
552                'password' : ((( Base64.decode(getUserCurrent().password) )) ? Base64.decode(getUserCurrent().password) : "")
553            }
[3102]554               
[4475]555            var winLoginPage =
556            {   
557                id_window               : "window_login_page",
558                width                   : 260,
559                height                  : 120,
560                top                     : 100,
561                left                    : 400,
562                draggable               : true,
563                visible         : "display",
564                resizable               : true,
565                zindex                  : zIndex++,
566                title                   : "Expresso Messenger - Login",
567                closeAction     : "remove",
568                content         : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl", paramsLoginPage)     
569            };
[3102]570
[4475]571            _winBuild( winLoginPage );
572        }
[3102]573
[4475]574        function loadScripts(pFiles)
575        {
576            // Load JavaScript
577            var loadJavaScript = function(pJs)
578            {
579                var newScript = document.createElement("script");
580                newScript.setAttribute("type", "text/javascript");
581                newScript.setAttribute("src", pJs );
[3102]582                               
[4475]583                return newScript;
584            };
[3102]585               
[4475]586            // Load CSS
587            var loadStyleSheet = function(pCss)
588            {
589                var newStyle = document.createElement("link");
590                newStyle.setAttribute("rel", "stylesheet");
591                newStyle.setAttribute("type", "text/css");
592                newStyle.setAttribute("href", pCss);
[3102]593                               
[4475]594                return newStyle;
595            };
[3102]596               
[4475]597            for(var i = 0; i < pFiles.length; i++)
598            {
599                if( pFiles[i].indexOf(".js") > -1 )
600                    document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
[3102]601                               
[4475]602                if( pFiles[i].indexOf(".css") > -1 )
603                    document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
604            }
605        }
[3102]606       
[4475]607        function notificationNewMessage()
608        {
609            var _doc            = document;
610            var _id                     = arguments[0];
611            var _win_name       = _id.replace( /\W/g, '' );
[3102]612               
[4475]613            if ( windowPOPUP( _id ) )
614            {
615                _doc = windowPopUp[_win_name].document;
616            }
[3102]617               
[4475]618            var oldTitle        = _doc.title;
619            var newTitle        = "## NOVA MENSAGEM ##";
[3102]620
[4475]621            if( timeoutId == null )
622            {
623                timeoutId = setInterval(function()
624                {
625                    _doc.title = ( _doc.title == newTitle ) ? oldTitle : newTitle;
626                }, 1000);
[3102]627                       
[4475]628                configEvents( _doc, 'onclick', function()
629                {
630                    clearInterval(timeoutId);
631                    _doc.title  = oldTitle;
632                    timeoutId           = null;
633                });
[3102]634                       
[4475]635                configEvents( _doc, 'onkeypress', function()
636                {
637                    clearInterval(timeoutId);
638                    _doc.title  = oldTitle;
639                    timeoutId           = null;
640                });
641            }
642        }
[3102]643
[4475]644        function optionsItensContact()
645        {
646            if( arguments.length > 0 )
647            {
648                var jid         = arguments[0];
649                var coord       = arguments[1];
650                var element = getElement('itenContact_' + jid );
651                var action      = ( element.getAttribute("subscription") === "not-in-roster" ) ? "Adicionar" : "Autorizar";     
[3102]652                       
[4475]653                if( showhidden == null )
654                    showhidden = new ShowHidden(300);
[3102]655
[4475]656                var _options = [
657                [ action , 'loadscript.setAutorization(\''+jid+'\')'],
658                ['Remover' , 'loadscript.removeContact(\''+jid+'\')'],
659                ['Renomear' , 'loadscript.renameContact(\''+jid+'\')'],
660                ['Trocar grupo' , 'loadscript.renameGroup(\''+jid+'\')']
661                ];
[3102]662
[4475]663                var _itens = "";
[3102]664                       
[4475]665                for( var i in _options )
666                {
667                    if( typeof(_options[i]) == "object")
668                    {
669                        _itens += '<img src="'+arrow_right.src+'"/>';
670                        _itens += '<span style="cursor:pointer;margin:3px;font-weight:normal;" onclick='+_options[i][1]+'>';
671                        _itens += _options[i][0] + '</span><br/>';
672                    }
673                }
[3102]674                       
[4475]675                var _optionsItens = document.createElement("div");
676                _optionsItens.className         = "x-menu";
677                _optionsItens.style.top         = coord.Y;
678                _optionsItens.style.left        = ( coord.X - element.offsetLeft );
679                _optionsItens.style.zIndex      = getZindex();
680                _optionsItens.innerHTML         = _itens; 
681                _optionsItens.onclick           = function(){
682                    showhidden.hiddenObject(false);
683                };
684                _optionsItens.onmouseout        = function(){
685                    showhidden.hiddenObject(false);
686                };     
687                _optionsItens.onmouseover       = function(){
688                    showhidden.hiddenObject(true);
689                };
[3102]690                               
[4475]691                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
[3102]692                               
[4475]693                window.document.body.appendChild(_optionsItens);
694            }
695        }
[3102]696
[4475]697        function parse()
698        {
699            if( arguments.length == 2 )
700                return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
[3102]701               
[4475]702            if( arguments.length === 3 )
703                return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
704        }
[3102]705       
[4475]706        function preferences()
707        {
708            var paramPreferences =
709            {
710                'path'  : path,
711                'lang1' : 'Suas Preferências',
712                'lang2' : 'Conexão',   
713                'lang3' : 'Conectar Automaticamente o IM',
714                'lang4' : 'Usuários OffLine',
715                'lang5' : 'Exibir amigos Offline',
716                'lang6' : 'Salvar',
717                'lang7' : 'Cancelar',
718                'lang8' : 'Janela de Contatos',
719                'lang9' : 'Abrir janela como Pop-up',
720                'lang10' : 'Ausente',
721                'lang11' : 'Definir status de ausente depois de',
722                'lang12' : 'minutos',   
723                'lang13' : 'Mostrar Contatos', 
724                'lang14' : 'Mostrar contatos desconectados',
725                'langYes': 'Sim',
726                'langNo' : 'Não'                                                                                           
727            };
[3102]728               
729               
[4475]730            var _win_preferences =
731            {
732                id_window        : "jabberit_preferences",
733                width            : 430,
734                height           : 350,
735                top                      : 150,
736                left             : 100,
737                draggable        : true,
738                visible          : "display",
739                resizable        : true,
740                zindex           : zIndex++,
741                title            : 'Expresso Messenger - Preferências',
742                closeAction  : "remove",
743                content          : Xtools.parse(Xtools.xml('preferences'), 'preferences.xsl', paramPreferences)
744            };
[3102]745
[4475]746            _winBuild(_win_preferences);
[3102]747               
748               
[4475]749            var _pButtons = {
750                'lang1' : 'Salvar',
751                'lang2' : 'Fechar',
752                'onclickClose' : '_winBuild("jabberit_preferences","remove");',
753                'onclickSubmit' : 'javascript:loadscript.setPreferences();'
754            };
[3102]755               
[4475]756            document.getElementById('buttons_preferences_jabberit').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
[3102]757               
[4475]758            // Element openWindowJabberit
759            var value1                  = _preferencesIM[0].split(':');
760            var element1                = document.getElementById(value1[0]);
761            var valueSelect1    = value1[1];
[3102]762               
[4475]763            for(var i = 0; i < element1.options.length; i++)
764                if( element1.options[i].value == valueSelect1 )
765                    element1.options[i].selected = true;
[3102]766
[4475]767            // Element openWindowJabberitPopUp
768            var value2                  = _preferencesIM[1].split(':');
[3102]769                       
[4475]770            // Element flagAwayIM
771            var value3          = _preferencesIM[2].split(':');
772            var element3        = document.getElementById(value3[0]);
773            element3.value      = value3[1];
[3102]774               
[4475]775            // Element showContactsOfflineJabberit
776            var value4                  = _preferencesIM[3].split(':');
777            var element4                = document.getElementById(value4[0]);
778            var valueSelect4    = value4[1];
779            for(var i = 0; i < element4.options.length; i++)
780                if( element4.options[i].value == valueSelect4 )
781                    element4.options[i].selected = true;
782        }
[3102]783       
[4475]784        function removeContact( jid )
785        {
786            TrophyIM.removeContact( jid );
787        }
[3102]788       
[4475]789        function removeElement( )
790        {
791            if( arguments.length > 0 )
792            {
793                var _element = arguments[0]
[3102]794                       
[4475]795                if( _element != null )
796                {
797                    _element.parentNode.removeChild( _element );
798                }
799            }
800        }
[3102]801       
[4475]802        function removeGroup()
803        {
804            var _parent = arguments[0];
[3102]805               
[4475]806            if( _parent.childNodes.length <= 2 )
807                _parent.parentNode.removeChild(_parent);
808        }
[3102]809       
[4475]810        function renameContact()
811        {
812            if( arguments.length > 0 )
813            {
814                var _jid        = arguments[0];
[3102]815                       
[4475]816                TrophyIM.renameContact( _jid );
817            }
818        }
[3102]819       
[4475]820        function renameGroup()
821        {
822            if( arguments.length > 0 )
823            {
824                var _jid        = arguments[0];
[3102]825                       
[4475]826                TrophyIM.renameGroup( _jid );
827            }
828        }
[3102]829       
[4475]830        function rosterDiv()
831        {
832            var _rosterDiv = function()
833            {
[3228]834
[4475]835                var winRosterDiv =
836                {
837                    id_window           : "window_Roster_im",
838                    width                       : 250,
839                    height                      : 410,
840                    top                 : 50,
841                    left                        : -1500,
842                    leftOld             : 50,
843                    draggable           : true,
844                    visible             : "display",
845                    resizable           : true,
846                    zindex                      : zIndex++,
847                    title                       : "Expresso Messenger - Contatos",
848                    closeAction : "hidden",
849                    content             : ""   
850                };
[3228]851
[4475]852                if( _preferencesIM[0] == "openWindowJabberit:false" )
853                {
854                    winRosterDiv.left           = 50;
855                    winRosterDiv.leftOld        = -1500;
856                }
[3228]857                       
[5057]858                if( SnifferBrowser.isLoadApp() )
[4475]859                {       
[5057]860                        var _idUser     = Base64.decode(getUserCurrent().jid);
[3102]861                               
[4475]862                    var paramListContact =
863                    {
864                        'idUser'        : _idUser,
865                        'full_name'     : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "...")),
866                        'path_jabberit' : path_jabberit,
867                        'help_expresso' : help_expresso,
868                        'zIndex_'               : zIndex++
869                    };
[3228]870               
[4475]871                    winRosterDiv.content = Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)       
[3228]872                               
[4475]873                }
874                else
875                {
876                    var paramList =
877                    {
878                        'path' : path_phpgwapi
879                    };
[3228]880                               
[4475]881                    winRosterDiv.width          = 280;
882                    winRosterDiv.height         = 430;
883                    winRosterDiv.content        = Xtools.parse( Xtools.xml("navigator"), path_phpgwapi + "templates/default/xsl/navigatorCompatible.xsl" , paramList);
884                }
[3102]885                       
[4475]886                _winBuild( winRosterDiv );                             
[3228]887
[4475]888                // Photo User
889                getPhotoUser(_idUser);
890            }
[3102]891               
[4475]892            setTimeout( function(){
893                _rosterDiv();
894            }, 200 );
895        }
[3102]896
[4475]897        function searchUser()
898        {
899            var _input  = getElement('search_user_jabber');
[3102]900               
[4475]901            if( _input.value.length >= 3 )
902                addUser.search();
903            else
904                alert( i18n.YOUR_SEARCH_ARGUMENT_MUST_BE_LONGER_THAN_3_CHARACTERS + '.' );
905        }
[3102]906       
[4475]907        function setAutorization()
908        {
909            var divItenContact = null;
[3102]910               
[4475]911            if( arguments.length > 0 )
912            {
913                var jidTo = arguments[0];
[3102]914               
[4475]915                if( getElement('itenContact_' + jidTo) )
916                    divItenContact = getElement('itenContact_' + jidTo );
917            }
[3102]918               
[4475]919            if( divItenContact )
920            {   
921                var subscription = divItenContact.getAttribute('subscription');
[3102]922
[4475]923                switch(subscription)
924                {
925                    case 'from':
[3102]926                                       
[4475]927                        TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid ), 'subscribe');
928                        break;
[3102]929
[4475]930                    case 'subscribe' :
[3102]931                                       
[4475]932                        TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid ), 'subscribed');
933                        break;
[3102]934                               
[4475]935                    case 'none' :                                       
[3102]936                               
[4475]937                        TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid ), 'subscribe');
938                        break;
[3102]939                               
[4475]940                    case 'to' :                         
[3102]941                               
[4475]942                        TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid ), 'subscribed');                             
943                        removeElement( getElement('itenContactNotification_' + jidTo ) );                               
944                        break;
[3102]945
[4475]946                    case 'not-in-roster':
[3102]947                                       
[4475]948                        TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
949                        addUser.add( jidTo );
950                        break;
951                }
952            }
953        }
[3102]954       
[4475]955        function setMessageStatus()
956        {
957            if( arguments.length > 0 )
958            {
959                var _element = arguments[0];
960                var _parent      = _element.parentNode;                 
[3102]961
[4475]962                if( _element.nodeName.toLowerCase() == "label")
963                {
964                    var _input                          = document.createElement("input");
965                    _input.size                 = "35";
966                    _input.maxlength    = "35";
967                    _input.style.border = "0";
968                    _input.value                = _element.innerHTML;
[3102]969                                       
[4475]970                    // OnkeyUp
971                    configEvents( _input, "onkeyup", function(e)
972                    {
973                        if( e.keyCode == 13 ) loadscript.setMessageStatus(_input, _element);
974                    }
975                    );
[3102]976                               
[4475]977                    // Onblur   
978                    configEvents(_input, "onblur", function(){
979                        loadscript.setMessageStatus(_input, _element)
980                        });             
[3102]981
982                           
[4475]983                    if( _parent != null )
984                    {   
985                        // Remove label
986                        if( _element != null )
987                            _parent.removeChild( _element );
[3102]988                                               
[4475]989                        // Add Input
990                        if( _input != null )
991                            _parent.appendChild( _input );
992                    }
[3102]993
[4475]994                    _input.focus();
995                    _input.select();
996                }
997                else
998                {
999                    var _label          = arguments[1];
1000                    _statusMessage      = _element.value.replace(/^\(+|\)+$/g,"");
[3102]1001                               
[4475]1002                    if( ( _statusMessage = _statusMessage.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "")
1003                        _label.innerHTML = "( " + _statusMessage + " )";
1004                    else
1005                        _label.innerHTML = "( " + i18n.TYPE_YOUR_MESSAGE_HERE_STATUS + " )";
[3102]1006                               
[4475]1007                    if( _parent != null )
1008                    {   
1009                        // Remove Input
1010                        if( _element != null )
1011                            _parent.removeChild( _element );
[3102]1012                                               
[4475]1013                        // Add Label
1014                        if( _label != null )
1015                            _parent.appendChild( _label );
1016                    }
[3102]1017                               
[4475]1018                    // Send Status Message
1019                    _statusMessage = ( ( _statusMessage !=  i18n.TYPE_YOUR_MESSAGE_HERE_STATUS ) ? _statusMessage : "" );                               
[3102]1020                               
[4475]1021                    TrophyIM.setPresence("status", _statusMessage );
1022                }       
1023            }
1024        }
[3102]1025       
[4475]1026        function setPreferences()
1027        {
1028            // Element openWindowJabberit
1029            var elementOpenW    = document.getElementById('openWindowJabberit');
1030            var value                   = '';
[3102]1031               
[4475]1032            for(var i = 0 ; i < elementOpenW.options.length; i++)
1033                if( elementOpenW.options[i].selected == true)
1034                {
1035                    value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
1036                    _preferencesIM[0] = 'openWindowJabberit:' + elementOpenW.options[i].value;
1037                }
[3102]1038
[4475]1039            // Element openWindowJabberitPopUp
1040            value += '&preferences2=openWindowJabberitPopUp:false';
1041            _preferencesIM[1] = 'openWindowJabberitPopUp:false';
[3102]1042               
[4475]1043            // Element flagAwayIM
1044            var elementFlagIM = document.getElementById('flagAwayIM');
[3102]1045               
[4475]1046            if( elementFlagIM.value.length > 0 && parseInt(elementFlagIM.value) > 0 )
1047            {
1048                _preferencesIM[2] = 'flagAwayIM:' + elementFlagIM.value;
1049                value += '&preferences3=flagAwayIM:' + elementFlagIM.value;
1050            }
1051            else
1052            {
1053                alert('Informe um valor igual ou maior que 1!');
1054                return false;
1055            }
[3102]1056
[4475]1057            // Element showContactsOfflineJabberit
1058            var elementShowOffline      = document.getElementById('showContactsOfflineJabberit');
[3102]1059               
[4475]1060            for(var i = 0 ; i < elementShowOffline.options.length; i++)
1061                if( elementShowOffline.options[i].selected == true)
1062                {
1063                    _preferencesIM[3] = 'showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
1064                    value += '&preferences4=showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
1065                }
[3102]1066               
[4475]1067            // Save Preferences
1068            conn.go('p.pf.setPreferences',
1069                function(data)
1070                {
1071                    if( data == 'false' )
1072                    {
1073                        alert('Erro salvando suas preferências!');
1074                    }
[3102]1075
[4475]1076                    _winBuild('jabberit_preferences', 'remove');
1077                },
1078                value);
1079        }
[3102]1080       
[4475]1081        function setPresence()
1082        {
1083            if( arguments.length > 0 )
1084            {
1085                var element = arguments[0];
[3102]1086                       
[4475]1087                if( showhidden == null )
1088                    showhidden = new ShowHidden(300);
[3102]1089                       
[4475]1090                var _status = [
1091                ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
1092                ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
1093                ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
1094                ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
1095                ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
1096                ['Desconectado', 'unavailable', '<img src="'+path_jabberit+'templates/default/images/unavailable.gif" />'],
1097                ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />'],                                             
1098                ];
[3102]1099                       
[4475]1100                var _itens = "";
[3102]1101                       
[4475]1102                for( var i in _status )
1103                {
1104                    if( typeof( _status[i]) == "object" )
1105                    {
1106                        _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadscript.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
1107                        _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
1108                    }
1109                }
[3102]1110                       
[4475]1111                var _statusItens = document.createElement("div");
1112                _statusItens.style.marginTop    = "65px";
1113                _statusItens.style.marginLeft   = "67px";
1114                _statusItens.className                  = "x-menu";
1115                _statusItens.style.zIndex               = '99999';
1116                _statusItens.innerHTML                  = _itens; 
1117                _statusItens.onclick                    = function(){
1118                    showhidden.hiddenObject(false);
1119                };
[3102]1120                                                                                 
[4475]1121                showhidden.action('onmouseover', 'onmouseout', _statusItens);
[3102]1122                               
[4475]1123                element.parentNode.onmouseout   = function(){
1124                    showhidden.hiddenObject(false);
1125                };
1126                element.parentNode.onmouseover  = function(){
1127                    showhidden.hiddenObject(true);
1128                };
1129                element.parentNode.appendChild(_statusItens);
1130            }
1131        }
[3102]1132
[4475]1133        function setSelectEditable(element, top, left )
1134        {
1135            if( getElement('selectBox0') == null )
1136                selectEditable.create(element, top, left );
1137        }
[3102]1138
[4475]1139        function setStatusJabber()
1140        {
1141            if( arguments.length > 0 )
1142            {
1143                if( arguments[1] != 'status' )
1144                {
1145                    var _text   = arguments[0];
1146                    var _img    = statusUserIM = arguments[1];
[3102]1147                               
[4475]1148                    getElement('statusJabberText').innerHTML            = _text;
1149                    getElement('statusJabberImg').style.background      = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')";
1150                    getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
1151                }
1152            }   
1153        }
[3102]1154
[4475]1155        function _setUserCurrent( _user )
1156        {
1157            userCurrent =
1158            {
1159                'jid'           : _user.jid.substring(11, _user.jid.length),
1160                'password'      : _user.password.substring(11, _user.password.length)
1161            }           
1162        }
[3102]1163       
[4475]1164        function setUserCurrent()
1165        {
1166            if( getUserCurrent() == null )
1167            {
1168                conn.go('p.ff.data_0',
1169                    function(_User)
1170                    {
1171                        conn.go('p.ff.data_1',
1172                            function(_pass)
1173                            {
1174                                _setUserCurrent( {
1175                                    jid : _User,
1176                                    password : _pass
1177                                } );
1178                            });
1179                    });
1180            }
1181        }
[3102]1182
[4475]1183        var _stylesheets = [ ];
1184        var _links = document.getElementsByTagName( 'link' );
[3102]1185       
[4475]1186        for ( var i = 0; i < _links.length; i++ )
1187            if ( _links.item( i ).type && _links.item( i ).type.toLowerCase( ) == 'text/css' )
1188                _stylesheets[ _stylesheets.length ] = _links.item( i ); 
[3102]1189       
[4475]1190        function windowPOPUP()
1191        {
1192            var _id = arguments[0];
1193            var _win_name = _id.replace( /\W/g, '' );
[3102]1194
[4475]1195            if ( arguments.length == 1 )
1196            {
1197                if ( windowPopUp[_win_name] )
1198                    return true;
1199                else
1200                    return false;
1201            }
[3102]1202               
[4475]1203            if( arguments.length == 2 )
1204            {   
1205                if( !windowPopUp[_win_name] )
1206                {
1207                    windowPopUp[_win_name] = window.open( '', _win_name + '__popup', 'height=355,width=380,top=50,left=50,toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no,titlebar=no');
1208                    var tmp = windowPopUp[_win_name].document;
[3102]1209                               
[4475]1210                    tmp.write('<html><head>');
1211                    tmp.write('</head><body>');
1212                    tmp.write('</body></html>');
1213                    tmp.close();
[3102]1214                               
[4475]1215                    for ( var i = 0; i < _stylesheets.length; i++ )
1216                        tmp.documentElement.getElementsByTagName( 'head' ).item(0).appendChild( _stylesheets[ i ].cloneNode( true ) );
[3102]1217
[4475]1218                    var divPOP = getElement( _id + "__popUp" );
1219                    divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_down.png') no-repeat";
1220                    divPOP.innerHTML = "PopIn";
[3102]1221                                       
[4475]1222                    function _close( )
1223                    {
1224                        windowPopUp[_win_name].close();
1225                        configEvents( divPOP ,'onclick', _close, true );
1226                    }
[3102]1227                                       
[4475]1228                    configEvents( divPOP ,'onclick', _close );
[3102]1229
[4475]1230                    var _content = tmp.documentElement.getElementsByTagName( 'body' ).item(0).appendChild( getElement(_id + '__chatBox' ).parentNode );
[3102]1231
[4475]1232                    _content.firstChild.scrollTop = _content.firstChild.scrollHeight;
[3102]1233
[4475]1234                    configEvents( windowPopUp[_win_name] ,'onbeforeunload', function()
1235                    {
1236                        delete windowPopUp[_win_name];
1237                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_up.png') no-repeat";
1238                        divPOP.innerHTML = "PopUp";
1239                        divPOP.onclick  = function(){
1240                            loadscript.windowPOPUP( _id , true );
1241                        };
1242                        _winBuild( 'window_chat_area_' + _id, "display" ).content( true );
1243                    });
[3102]1244
[4475]1245                    _winBuild( 'window_chat_area_' + _id, 'hidden' );
1246                }
1247            }
1248        }
[3102]1249       
[4475]1250        function windowNotificationNewUsers()
1251        {
1252            var _users = Xtools.xml('notification_new_users');
[3102]1253               
[4475]1254            for( var user in TrophyIM.rosterObj.roster )
1255            {
1256                if ( TrophyIM.rosterObj.roster[ user ].constructor == Function )
1257                    continue;
[3102]1258
[4475]1259                if( TrophyIM.rosterObj.roster[ user ].contact.jid != Base64.decode( loadscript.getUserCurrent().jid) )
1260                {
1261                    var _subscription = TrophyIM.rosterObj.roster[user].contact.subscription;
[3102]1262                               
[4475]1263                    if ( _subscription == 'to' || _subscription == 'not-in-roster' )
1264                    {
1265                        var _user       = _users.createElement('user');
1266                        var _jid        = _users.createElement('jid');
1267                        var _status     = _users.createElement('status');
1268                        _jid.appendChild( _users.createTextNode(TrophyIM.rosterObj.roster[user].contact.jid) );
1269                        _status.appendChild( _users.createTextNode( _subscription ) );
1270                        _user.appendChild( _jid );
1271                        _user.appendChild( _status );
1272                        _users.documentElement.appendChild( _user );
1273                    }
1274                }
1275            }
[3102]1276               
[4475]1277            var paramsNotification =
1278            {
1279                'lang_1' : "Notificação",       
1280                'lang_2' : "O(s) usuário(s) abaixo pedem sua autorização.",
1281                'lang_3' : "Autorizar",
1282                'lang_4' : "Remover"
1283            };
[3102]1284               
[4475]1285            var winNotification =
1286            {   
1287                id_window               : "window_notification_new_users",
1288                width                   : 400,
1289                height                  : 300,
1290                top                     : 100,
1291                left                    : 400,
1292                draggable               : true,
1293                visible         : "display",
1294                resizable               : true,
1295                zindex                  : zIndex++,
1296                title                   : "Expresso Messenger - Notificação de Novos Usuários",
1297                closeAction     : "remove",
1298                content         : Xtools.parse( _users , "notificationNewUsers.xsl", paramsNotification )       
1299            };
[3102]1300
[4475]1301            _winBuild( winNotification );
1302        }
[3102]1303
[4475]1304        function createChatRooms()
1305        {
1306            _winBuild("window_List_Rooms_jabberit_messenger","remove");
[3129]1307               
[4475]1308            var paramCreateChatRoom =
1309            {
1310                'lang_nameChatRoom'     : "Nome da Sala",
1311                'lang_nickName'         : "Apelido"
1312            };
[3102]1313               
[4475]1314            var winCreateChatRooms =
1315            {   
1316                id_window               : "window_create_chat_rooms",
1317                width                   : 360,
1318                height                  : 160,
1319                top                     : 100,
1320                left                    : 410,
1321                draggable               : true,
1322                visible         : "display",
1323                resizable               : true,
1324                zindex                  : loadscript.getZIndex(),
1325                title                   : "Expresso Messenger - Criar Sala de Bate Papo",
1326                closeAction     : "remove",
1327                content         : Xtools.parse( Xtools.xml("create_chat_room"), "createChatRoom.xsl", paramCreateChatRoom )
1328            };
[3102]1329               
[4475]1330            _winBuild( winCreateChatRooms );
[3102]1331
[4475]1332            var _pButtons =
1333            {
1334                'lang1'                 : 'Ingressar',
1335                'lang2'                 : 'Fechar',
1336                'onclickClose'  : '_winBuild("window_create_chat_rooms","remove");',
1337                'onclickSubmit' : 'TrophyIM.createChatRooms(); _winBuild("window_create_chat_rooms","remove");'
1338            };
[3102]1339
[4475]1340            // Add Buttons
1341            document.getElementById('buttons_createChatRoom').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
[3102]1342               
[4475]1343        }
[3102]1344       
[4475]1345        function listRooms( element )
1346        {
1347            element = element.getElementsByTagName( 'item' );
[3102]1348
[4475]1349            var _roomsCount     = 0;
1350            var _xml            = Xtools.xml('listRooms');
1351            var _listRooms      = _xml.documentElement;
[3102]1352               
[4475]1353            var show = function( )
1354            {
1355                if ( _roomsCount != element.length )
1356                    return false;
[3102]1357                       
[4475]1358                var paramsListRooms =
1359                {
1360                    "path_jabberit" : path_jabberit     
1361                };
[3102]1362                       
[4475]1363                var winListRooms =
1364                {       
1365                    id_window           : "window_List_Rooms_jabberit_messenger",
1366                    width                       : 450,
1367                    height                      : 300,
1368                    top                 : 100,
1369                    left                        : 400,
1370                    draggable           : true,
1371                    visible             : "display",
1372                    resizable           : true,
1373                    zindex                      : loadscript.getZIndex(),
1374                    title                       : "Expresso Messenger - Salas de Bate Papo",
1375                    closeAction : "remove",
1376                    content             : Xtools.parse( _xml, "listRooms.xsl", paramsListRooms )
1377                };
[3102]1378                       
[4475]1379                _winBuild( winListRooms );
[3102]1380                       
[4475]1381                var _pButtons =
1382                {
1383                    'lang1'             : 'Criar Nova Sala',
1384                    'lang2'                     : 'Fechar',
1385                    'onclickClose'      : '_winBuild("window_List_Rooms_jabberit_messenger","remove");',
1386                    'onclickSubmit'     : 'loadscript.createChatRooms();'
1387                };
[3102]1388
[4475]1389                // Add Buttons
1390                document.getElementById('buttons_addChatRoom').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
1391            };
[3102]1392
[4475]1393            var _add_room = function( _room )
1394            {
1395                _roomsCount++;
[3102]1396
[4475]1397                var _ROOM               = _xml.createElement('room');
1398                var _JIDROOM    = _xml.createElement('jidRoom');
1399                var nameRoom    = _room.getAttribute( 'from' );
[3177]1400
[4475]1401                _ROOM.setAttribute( 'nameRoom', unescape((nameRoom.substring(0, nameRoom.indexOf("@"))).toUpperCase()) );
1402                _JIDROOM.appendChild( _xml.createTextNode(nameRoom) );
1403                _ROOM.appendChild( _JIDROOM );
[3177]1404
[4475]1405                // Get fields elements;
1406                var _fields = _room.getElementsByTagName( 'field' );
[3177]1407
[4475]1408                for ( var f = 0; f < _fields.length; f++ )
1409                {
1410                    if ( _fields[ f ].getAttribute( 'var' ) )
1411                    {
1412                        if ( _fields[ f ].firstChild.hasChildNodes( ) && _fields[ f ].getAttribute( 'var' ) == 'muc#roominfo_description' )
1413                        {
1414                            var _description    = _xml.createElement("description");
1415                            _description.appendChild( _xml.createTextNode( _fields[ f ].firstChild.firstChild.nodeValue ) );
1416                            _ROOM.appendChild( _description );
1417                        }
[3102]1418
[4475]1419                        if ( _fields[ f ].firstChild.hasChildNodes( ) && _fields[ f ].getAttribute( 'var' ) == 'muc#roominfo_occupants' )
1420                        {
1421                            var _occupants = _xml.createElement("occupants")
1422                            _occupants.appendChild( _xml.createTextNode( _fields[ f ].firstChild.firstChild.nodeValue) );
1423                            _ROOM.appendChild( _occupants );
1424                        }
1425                    }
1426                }
[3102]1427
[4475]1428                // Get feature elements;
1429                var _feature = _room.getElementsByTagName( 'feature' );
[3102]1430                       
[4475]1431                for( var f = 0 ; f < _feature.length; f++ )
1432                {
1433                    if ( _feature[ f ].getAttribute( 'var' ) )
1434                    {
1435                        if( _feature[ f ].getAttribute( 'var' ) == 'muc_unsecured' )
1436                        {
1437                            var _password = _xml.createElement("password");
1438                            _password.appendChild( _xml.createTextNode("false") );
1439                            _ROOM.appendChild( _password );
1440                        }
1441                        else if( _feature[ f ].getAttribute( 'var' ) == 'muc_passwordprotected' )
1442                        {
1443                            var _password = _xml.createElement("password");
1444                            _password.appendChild( _xml.createTextNode("true") );
1445                            _ROOM.appendChild( _password );
1446                        }       
1447                    }
1448                }
[3102]1449                       
[4475]1450                _listRooms.appendChild( _ROOM );
[3102]1451                       
[4475]1452                show( );
1453            };
[3102]1454               
[4475]1455            var _get_room_info = function( _room )
1456            {
1457                TrophyIM.connection.sendIQ(
1458                    $iq( {
1459                        "to" : _room,
1460                        "type" : "get"
1461                    } ).c( "query",{
1462                        xmlns: Strophe.NS.DISCO_INFO
1463                    } ),
1464                    _add_room,
1465                    function( a )
1466                    {
1467                        _roomsCount++;
[3102]1468                               
[4475]1469                        show( );
[3124]1470                                       
[4475]1471                    }, 500 );
1472            };
[3102]1473
[4475]1474            if( element.length > 0 )
1475            {
1476                for ( var i = 0; i < element.length; i++ )
1477                {
1478                    _get_room_info( element[ i ].getAttribute( 'jid' ) );
1479                }
1480            }
1481            else
1482            {
1483                show();
1484            }
1485        }
[3102]1486       
[4475]1487        function getListRooms()
1488        {
1489            TrophyIM.getListRooms();   
1490        }
[3102]1491       
[4475]1492        function joinRoom( jidRoom, nameRoom )
1493        {
1494            var append_nick = function( room, nick )
1495            {
1496                var room_nick = room;
[3102]1497               
[4475]1498                if ( nick )
1499                {
1500                    room_nick += "/" + nick;
1501                }
[3102]1502               
[4475]1503                return room_nick;
1504            }
[3102]1505               
[4475]1506            if( document.getElementById( 'window_chat_room_' + jidRoom + '__main' ) != null )
1507            {
1508                _winBuild('window_chat_room_' + jidRoom, 'display');
1509            }
1510            else
1511            {
1512                var nickName = Base64.decode( loadscript.getUserCurrent().jid );
1513                nickName = nickName.substring(0, nickName.indexOf('@'));
[3102]1514                   
[4475]1515                var _prompt = prompt("Deseja informar um Apelido ?", nickName );
[3102]1516                   
[4475]1517                if( _prompt )
1518                {       
1519                    _prompt = _prompt.replace(/^\s+|\s+$|^\n|\n$/g,"");
[3102]1520                           
[4475]1521                    var room_nick       = append_nick( jidRoom, nickName );
[3320]1522                           
[4475]1523                    var nickChat        = nickName.toString();
[3102]1524                               
[4475]1525                    if( _prompt && _prompt != "" )
1526                    {
1527                        nickChat                = _prompt.toString();
1528                        var room_nick   = append_nick( jidRoom, _prompt );
1529                    }
[3102]1530                           
[4475]1531                    TrophyIM.makeChatRoom( jidRoom , nameRoom );
[3122]1532
[4475]1533                    TrophyIM.activeChatRoom.name[ TrophyIM.activeChatRoom.name.length ] = room_nick;
[3102]1534                           
[4475]1535                    TrophyIM.joinChatRoom( room_nick);
[3320]1536                         
[4475]1537                    setTimeout(function()
1538                    {
1539                        var _message    =  nickName.toUpperCase() + " entrou como : "  + nickChat;
[3320]1540                                   
[4475]1541                        TrophyIM.sendMessageChatRoom( jidRoom , _message );
[3320]1542                                   
[4475]1543                    }, 500);
[3320]1544                           
[4475]1545                }
1546            }
[3129]1547           
[4475]1548            _winBuild("window_List_Rooms_jabberit_messenger","remove");
1549        }
[3102]1550       
[4475]1551        function loadIM()
1552        {
1553            if( arguments.length > 0 )
1554            {
1555                var files = [
1556                path_jabberit + 'templates/default/css/button.css',
1557                path_jabberit + 'templates/default/css/common.css',
1558                path_jabberit + 'templates/default/css/selectEditableStyle.css',
1559                path_jabberit + 'templates/default/css/' + theme_jabberit
1560                ];
1561                // FullName
1562                fullName = arguments[0];
[3102]1563                       
[4475]1564                // Preferences
1565                _preferencesIM = arguments[1].split(";");
[4442]1566                       
[4475]1567                //Path Phpgwapi
1568                path_phpgwapi = arguments[2];
[4442]1569                       
[4475]1570                if( !_preferencesIM[3] ) _preferencesIM[3] = "showContactsOfflineJabberit:true";
[3102]1571                       
[4475]1572                loadScripts(files);
[3102]1573                       
[4475]1574                setTimeout(function()
1575                {
1576                    // Object Xtools   
1577                    if( Xtools == null )
1578                        Xtools = new xtools(path_jabberit);
[3102]1579                               
[4475]1580                    // Object Conector
1581                    if( conn == null )
1582                        conn = new AjaxConnector(path_jabberit);
[3102]1583                               
[4475]1584                    // Object Add User
1585                    if( addUser == null )
1586                        addUser = new addUserIM(Xtools, conn);
[3102]1587
1588                               
[4475]1589                    // Object SelectEditable
1590                    if( selectEditable == null )
1591                        selectEditable = new SelectEditable();
[3102]1592                                       
[4475]1593                    // Add Jabber in StatusBar;
1594                    addIcon();
[3228]1595                               
[4475]1596                    // Auto Connect
1597                    setTimeout(function()
1598                    {
1599                        if( _preferencesIM[0] === 'openWindowJabberit:true' )
1600                        {
[5057]1601                            if( SnifferBrowser.isLoadApp() )
1602                            {
1603                                TrophyIM.load();
1604                            }
[4475]1605                        }
[3102]1606                                       
[4475]1607                    },1500);
[3102]1608                               
[4475]1609                    // Auto Status
1610                    autoStatus();
1611                    configEvents( document, 'onmousemove', autoStatus );
1612                    configEvents( document, 'onkeypress', autoStatus );
[3102]1613                               
[4475]1614                }, 2000);
1615            }
1616        }
[3102]1617
[5057]1618        loadIM.prototype.adIcon                         = addIcon;
[4475]1619        loadIM.prototype.actionButton           = actionButton;
[5057]1620        loadIM.prototype.addContact                     = addContact;
1621        loadIM.prototype.addNewUser                     = addNewUser;
[4475]1622        loadIM.prototype.clrAllContacts         = clrAllContacts;
1623        loadIM.prototype.configEvents           = configEvents;
1624        loadIM.prototype.createChatRooms        = createChatRooms;
1625        loadIM.prototype.disabledNotificationNewUsers   = disabledNotificationNewUsers;
1626        loadIM.prototype.enabledNotificationNewUsers    = enabledNotificationNewUsers; 
[4479]1627        loadIM.prototype.getListRooms           = getListRooms;
[4475]1628        loadIM.prototype.getBrowserCompatible   = getBrowserCompatible;
1629        loadIM.prototype.getPhotoUser           = getPhotoUser;
[5057]1630        loadIM.prototype.getSmiles                      = getSmiles;
[4475]1631        loadIM.prototype.getStatusUserIM        = getStatusUserIM;
1632        loadIM.prototype.getStatusMessage       = getStatusMessage;
1633        loadIM.prototype.getShowContactsOffline = getShowContactsOffline;
1634        loadIM.prototype.getUserCurrent         = getUserCurrent;
[5057]1635        loadIM.prototype.getZIndex                      = getZindex;
[4475]1636        loadIM.prototype.groupsHidden           = groupsHidden;
1637        loadIM.prototype.groupsVisible          = groupsVisible;
[5057]1638        loadIM.prototype.joinRoom                       = joinRoom;     
[4475]1639        loadIM.prototype.keyPressSearch         = keyPressSearch;       
[5057]1640        loadIM.prototype.listRooms                      = listRooms;
1641        loadIM.prototype.loginPage                      = loginPage;
[4475]1642        loadIM.prototype.notification           = notificationNewMessage;
[5057]1643        loadIM.prototype.parse                          = parse;
[4475]1644        loadIM.prototype.preferences            = preferences;
[5057]1645        loadIM.prototype.searchUser                     = searchUser
[4475]1646        loadIM.prototype.setAutorization        = setAutorization;
1647        loadIM.prototype.setMessageStatus       = setMessageStatus;
1648        loadIM.prototype.setPreferences         = setPreferences;
1649        loadIM.prototype.setPresence            = setPresence;
1650        loadIM.prototype.setStatusJabber        = setStatusJabber;
1651        loadIM.prototype.setSelectEditable      = setSelectEditable;
1652        loadIM.prototype.setUserCurrent         = setUserCurrent;
1653        loadIM.prototype.removeContact          = removeContact;
1654        loadIM.prototype.removeElement          = removeElement;
1655        loadIM.prototype.removeGroup            = removeGroup;
1656        loadIM.prototype.renameContact          = renameContact;
1657        loadIM.prototype.renameGroup            = renameGroup;
[5057]1658        loadIM.prototype.rosterDiv                      = rosterDiv;
[4475]1659        loadIM.prototype.windowNotificationNewUsers  = windowNotificationNewUsers;
1660        loadIM.prototype.windowPOPUP            = windowPOPUP;
[3102]1661       
[4475]1662        window.LoadIM = loadIM;
[3102]1663       
[4475]1664        // Necessário para não ocasionar problema no ExpressoMail
1665        // quando os itens abaixo não são criados pelo próprio ExpressoMail
[5155]1666        if( SnifferBrowser.isLoadApp('msie') )
[4475]1667        {
1668            configEvents( window, 'onload', function( )
1669            {
1670                if ( ! document.getElementById( 'cc_msg_err_serialize_data_unknown' ) )
1671                {
1672                    var fix     = document.createElement('input');
1673                    fix.type    = 'hidden';
1674                    fix.id              = 'cc_msg_err_serialize_data_unknown';
[3102]1675                               
[4475]1676                    document.appendChild( fix );
1677                }
1678                if ( ! window.showMessage )
1679                    window.showMessage = function(){};
1680            });
1681        }
[3102]1682       
[4475]1683    })();
Note: See TracBrowser for help on using the repository browser.