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

Revision 2754, 30.3 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Quando se trocava o status para xa e movia o mouse o status voltava para available.

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