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

Revision 2706, 27.7 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Implementado a parte de preferencias para mostrar ou não contatos offline.

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