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

Revision 2711, 29.7 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Implementado a forma de informar um status de message tb pela lista de contatos.

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