source: sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js @ 2577

Revision 2577, 17.9 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Alterado a parte de autorizacao, informando se o usuario esta permitido ou nao na lista.

  • Property svn:executable set to *
Line 
1(function()
2{
3        var fullName            = "";
4        var path                        = "";
5        var addUser                     = null;
6        var conn                        = null;
7        var selectEditable      = null;
8        var showhidden          = null;
9        var userCurrent         = null;
10        var Xtools                      = null;
11        var zIndex                      = 9001;
12       
13        // Images
14        var add_user = new Image();
15        add_user.src = path_jabberit + 'templates/default/images/adduser_azul.png';
16
17        var arrow_down = new Image();
18        arrow_down.src = path_jabberit + 'templates/default/images/arrow_down.gif';
19
20        var arrow_right = new Image();
21        arrow_right.src = path_jabberit + 'templates/default/images/arrow_right.gif';
22       
23        function actionButton()
24        {
25                if( arguments.length > 0 )
26                {
27                        var e           = arguments[0];
28                        var jid         = arguments[1];
29                        var index       = arguments[2];
30                        var coord       = null;
31               
32                        if ( !e )
33                                var e = window.event;
34
35                        var _X = e.clientX + document.body.scrollLeft - document.body.clientLeft;
36                        var _Y = e.clientY + document.body.scrollTop  - document.body.clientTop;
37                               
38                        coord = { X : _X, Y : _Y };
39                       
40                        window.document.oncontextmenu = function()
41                        {
42                                return false;
43                        };
44       
45                        if ( ( e.which && e.which > 1 ) || ( e.button && e.button > 1 ) )
46                        {
47                                optionsItensContact( jid, index, coord );
48                        }
49                        else
50                        {
51                                if ( e.target.id )
52                                        TrophyIM.rosterClick(jid);
53                        }
54                }
55        }
56
57        function addContact()
58        {
59                if( arguments.length > 0 )
60                        addUser.add();
61                else
62                        addUser.show();
63        }
64       
65        function addIcon()
66        {
67                var StatusBar = getElement('divStatusBar');
68
69                /**
70                 * @quando estiver habilitada a opção fora de escritório nos filtros.
71                 */
72               
73                if( div_write_msg = getElement('em_div_write_msg') )
74                {               
75                        var StatusBarIM = getElement('JabberMessenger');
76                                StatusBarIM.style.paddingLeft = '33px';
77                       
78                        div_write_msg.parentNode.insertBefore( StatusBarIM, div_write_msg );
79                       
80                        return;                 
81                }
82               
83                if( StatusBar )
84                {
85                        StatusBar.style.paddingLeft = '33px';
86                       
87                        var _div = document.createElement('div');
88                                _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
89                       
90                                StatusBar.parentNode.insertBefore( _div, StatusBar);
91                       
92                        var divJabber = document.createElement('div');
93                                divJabber.setAttribute('id', 'JabberMessenger');
94                       
95                        var _fastMenu = top.document.createElement('div');
96                                _fastMenu.setAttribute('id', 'fast_menu_jabber_expresso');
97                                _fastMenu.style.background              = 'no-repeat';
98                                _fastMenu.style.backgroundImage = 'url(' + arrow_down.src + ')';
99                                _fastMenu.style.float                   = 'left';
100                                _fastMenu.style.height                  = '15px';
101                                _fastMenu.style.left                    = '7px';
102                                _fastMenu.style.margin                  = '8 0 0 10px';
103                                _fastMenu.style.padding                 = '0px';
104                                _fastMenu.style.position                = 'absolute';
105                                _fastMenu.style.width                   = '15px';
106                                _fastMenu.style.cursor                  = 'pointer';
107
108                        divJabber.insertBefore( _fastMenu, divJabber.firstChild );
109                       
110                        // Add event onclick element _fastMenu
111                        configEvents( _fastMenu, 'onclick', function(){ fastMenu(_fastMenu); });
112
113                        var _statusJabber = top.document.createElement('div');
114                                _statusJabber.setAttribute('id','status_jabber_expresso');
115                                _statusJabber.style.background          = 'no-repeat';
116                                _statusJabber.style.backgroundImage = 'url(' + add_user.src +')';
117                                _statusJabber.style.float                       = 'left';
118                                _statusJabber.style.height                      = '18px';
119                                _statusJabber.style.left                        = '19px';
120                                _statusJabber.style.margin                      = '0 0 0 10px';
121                                _statusJabber.style.padding                     = '0px';
122                                _statusJabber.style.position            = 'absolute';
123                                _statusJabber.style.width                       = '18px';
124                                _statusJabber.style.cursor                      = 'pointer';
125                                _statusJabber.style.zindex                      = '999999';
126                       
127                        divJabber.insertBefore( _statusJabber, divJabber.firstChild );
128                       
129                        StatusBar.insertBefore( divJabber, StatusBar.firstChild );
130
131                        // Add event onclick element _statusJabber
132                        configEvents( _statusJabber, 'onclick', function(){ TrophyIM.load();});
133                }
134        }
135
136        function configEvents(pObj, pEvent, pHandler)
137        {
138                if ( typeof pObj == 'object' )
139                {
140                        if ( pEvent.substring(0, 2) == 'on' )
141                                pEvent = pEvent.substring(2, pEvent.length);
142
143                        if ( pObj.addEventListener )
144                                pObj.addEventListener(pEvent, pHandler, false);
145                        else if ( pObj.attachEvent )
146                                pObj.attachEvent('on' + pEvent, pHandler);
147                }
148        }
149       
150        function fastMenu()
151        {
152                if( arguments.length > 0 )
153                {
154                        var element = arguments[0];
155                       
156                        if( showhidden == null )
157                                showhidden = new ShowHidden(300);
158
159                        var _options = [
160                                                ['Adicionar Contato', 'loadIM.addContact();' ],
161                                                ['Ajuda', 'alert("2")' ],
162                                                ['Preferências', 'alert("3")'],
163                                                   ];
164
165                        var _itens = "";
166                       
167                        for( var i in _options )
168                        {
169                                _itens += '<img src="'+arrow_right.src+'"/>';
170                                _itens += '<span style="cursor:pointer; margin:3px;" onclick='+_options[i][1]+'>';
171                                _itens += _options[i][0] + '</span><br/>';
172                        }
173                       
174                        var _optionsItens = document.createElement("div");
175                                _optionsItens.setAttribute("style", "margin: 20px 0px 0px -4px;");
176                                _optionsItens.className         = "x-menu";
177                                _optionsItens.style.zIndex      = '999999';
178                                _optionsItens.innerHTML         = _itens; 
179                                                                                 
180                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
181                               
182                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
183                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
184                        element.parentNode.appendChild( _optionsItens );
185                       
186                }
187        }
188       
189        function getElement( elementId )
190        {
191                return document.getElementById( elementId );
192        }
193       
194        function getPhotoUser( jid )
195        {
196                var _divPhoto = getElement( jid + '__photo' );
197
198                if( _divPhoto.style.backgroundImage.indexOf('photo.png') > 0 )
199                {
200                        var _imgUser  = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date );
201                                _imgUser += '&photo_ldap=' + jid;
202
203                        _divPhoto.style.backgroundImage = 'url(' + _imgUser + ')';
204                }
205        }
206       
207        function getUserCurrent()
208        {
209                return userCurrent;
210        }
211       
212        function getZindex()
213        {
214                return zIndex++;
215        }
216       
217        function groupsHidden()
218        {
219                if( arguments.length > 0 )
220                {
221                        var _element = arguments[0];
222                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif')no-repeat center left";
223                                _element.onclick = function(){ groupsVisible(_element);};
224                               
225                                // Hidden all
226                                var _elementNext = _element.nextSibling;
227                               
228                                while( _elementNext )
229                                {       
230                                        _elementNext.style.display = "none";
231                                        _elementNext = _elementNext.nextSibling;
232                                }
233                }
234        }
235       
236        function groupsVisible()
237        {
238                if( arguments.length > 0 )
239                {
240                        var _element = arguments[0];
241                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif')no-repeat center left";
242                                _element.onclick = function(){ groupsHidden(_element);};
243
244                                // Display all
245                                var _elementNext = _element.nextSibling;
246                               
247                                while( _elementNext )
248                                {       
249                                        _elementNext.style.display = "block";
250                                        _elementNext = _elementNext.nextSibling;
251                                }
252                }
253        }
254       
255        function keyPressSearch()
256        {
257                if( arguments.length > 0 )
258                {
259                        var ev          = arguments[0];
260                        var element     = arguments[1];
261       
262                        if ( ev.keyCode == 13 )
263                                if( element.value.length >= 3 )
264                                        searchUser( element.value );   
265                                else
266                                        alert('Your search argument must be longer than 3 characters.');
267                }
268        }
269
270       
271        function loginPage()
272        {
273                var winLoginPage =
274                {       
275                         id_window              : "window_login_page",
276                         width                  : 260,
277                         height                 : 150,
278                         top                    : 100,
279                         left                   : 400,
280                         draggable              : true,
281                         visible                : "display",
282                         resizable              : true,
283                         zindex                 : zIndex++,
284                         title                  : "Login - Expresso Messenger",
285                         closeAction    : "remove",
286                         content                : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl")       
287                };
288
289                _winBuild( winLoginPage );
290        }
291
292        function loadScripts(pFiles)
293        {
294                // Load JavaScript
295                var loadJavaScript = function(pJs)
296                {
297                        var newScript = document.createElement("script");
298                                newScript.setAttribute("type", "text/javascript");
299                                newScript.setAttribute("src", pJs );
300                               
301                        return newScript;
302                };
303               
304                // Load CSS
305                var loadStyleSheet = function(pCss)
306                {
307                        var newStyle = document.createElement("link");
308                                newStyle.setAttribute("rel", "stylesheet");
309                                newStyle.setAttribute("type", "text/css");
310                                newStyle.setAttribute("href", pCss);
311                               
312                        return newStyle;
313                };
314               
315                for(var i = 0; i < pFiles.length; i++)
316                {
317                        if( pFiles[i].indexOf(".js") > -1 )
318                                document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
319                               
320                        if( pFiles[i].indexOf(".css") > -1 )
321                                document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
322                }
323        }
324
325        function optionsItensContact()
326        {
327                if( arguments.length > 0 )
328                {
329                        var jid         = arguments[0];
330                        var index       = arguments[1];
331                        var coord       = arguments[2];
332                        var element = getElement('itenContact_' + jid + '_' + index );
333
334                       
335                        if( showhidden == null )
336                                showhidden = new ShowHidden(300);
337
338                        var _options = [
339                                                ['Autorizar', 'loadIM.setAutorization(\''+jid+'\',\''+index+'\')'],
340                                                ['Remover', 'loadIM.removeContact(\''+jid+'\',\''+index+'\')'],
341                                                ['Renomear', 'loadIM.rename()'],
342                                                ['Trocar grupo', 'loadIM.rename()'],
343                                                   ];
344
345                        var _itens = "";
346                       
347                        for( var i in _options )
348                        {
349                                _itens += '<img src="'+arrow_right.src+'"/>';
350                                _itens += '<span style="cursor:pointer;margin:3px;font-weight:normal;" onclick='+_options[i][1]+'>';
351                                _itens += _options[i][0] + '</span><br/>';
352                        }
353                       
354                        var _optionsItens = document.createElement("div");
355                                _optionsItens.className         = "x-menu";
356                                _optionsItens.style.top         = coord.Y;
357                                _optionsItens.style.left        = ( coord.X - element.offsetLeft );
358                                _optionsItens.style.zIndex      = getZindex();
359                                _optionsItens.innerHTML         = _itens; 
360                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
361                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };       
362                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
363                               
364                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
365                               
366                        window.document.body.appendChild(_optionsItens);
367                       
368                       
369                        setTimeout(function()
370                        {
371                                window.document.oncontextmenu = function()
372                                {
373                                        return true;
374                                };
375                               
376                        },500);
377                }
378        }
379
380        function parse()
381        {
382                if( arguments.length == 2 )
383                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
384               
385                if( arguments.length === 3 )
386                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
387        }
388       
389        function removeContact(jid, index)
390        {
391                setTimeout(function()
392                {
393                        TrophyIM.removeContact(jid, index);
394                       
395                },300);
396        }
397       
398        function removeElement( )
399        {
400                if( arguments.length > 0 )
401                {
402                        var _element = arguments[0]
403                        var _parent  = _element.parentNode;
404       
405                        _parent.removeChild( _element );
406                }
407        }
408       
409        function removeGroup()
410        {
411                var _parent = arguments[0];
412               
413                if( _parent.childNodes.length <= 2 )
414                        _parent.parentNode.removeChild(_parent);
415        }
416       
417        function rename()
418        {
419                alert("Rename");
420        }
421       
422        function rosterDiv()
423        {
424                var paramListContact =
425                {
426                        'idUser'                : getUserCurrent().jid,
427                        'full_name'             : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "...")),
428                        'path_jabberit' : path_jabberit,
429                        'zIndex_'               : zIndex++
430                };
431               
432                var winRosterDiv =
433                {
434                         id_window              : "window_Roster_im",
435                         width                  : 250,
436                         height                 : 410,
437                         top                    : 50,
438                         left                   : 50,
439                         draggable              : true,
440                         visible                : "display",
441                         resizable              : true,
442                         zindex                 : zIndex++,
443                         title                  : "Contatos - Expresso Messenger",
444                         closeAction    : "hidden",
445                         content                : Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)       
446                };
447               
448                _winBuild( winRosterDiv );
449
450                // Photo User
451                getPhotoUser(getUserCurrent().jid);
452        }
453
454        function searchUser()
455        {
456                var _input      = getElement('search_user_jabber');
457               
458                if( _input.value.length >= 3 )
459                        addUser.search();
460                else
461                        alert('Your search argument must be longer than 3 characters.');
462        }
463       
464        function setAutorization(jidTo, indexTo)
465        {
466        var divItenContact = null;
467       
468        if( ( divItenContact = getElement('itenContact_' + jidTo + '_' + indexTo )))
469        {       
470                var subscription = divItenContact.getAttribute('subscription');
471               
472                switch(subscription)
473                {
474                        case 'from':
475                               
476                                alert('SUBSCRIPTION FROM');
477                                //TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribed');
478                                //TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribe');
479                                break;
480
481                        case 'none' :
482                       
483                                TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribe');
484                                TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribed');
485                               
486                                break;
487
488                        case 'not-in-roster':
489                                       
490                                setTimeout(function()
491                                        {
492                                        var _add = "";
493                               
494                                        if( ( _add = confirm("Deseja adicionar o usuario!")) )         
495                                        {
496                                                addUser.add( jidTo, indexTo );
497                                        }
498                                       
499                                        },100);
500                               
501                                        break;
502                                       
503                        case 'to' :
504                               
505                                TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribed');
506                                       
507                        case 'subscribe' :
508                               
509                                TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribe');
510                               
511                                        break;
512                }
513        }       
514        }
515       
516        function setPresence()
517        {
518                if( arguments.length > 0 )
519                {
520                        var element = arguments[0];
521                       
522                        if( showhidden == null )
523                                showhidden = new ShowHidden(300);
524                       
525                        var _status = [
526                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
527                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
528                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
529                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
530                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
531                                               ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />']                                               
532                                          ];
533                       
534                        var _itens = "";
535                       
536                        for( var i in _status )
537                        {
538                                _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadIM.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
539                                _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
540                        }
541                       
542                        var _statusItens = document.createElement("div");
543                                _statusItens.setAttribute("style", "margin: 62px 0px 0px 76px;");
544                                _statusItens.className          = "x-menu";
545                                _statusItens.style.zIndex       = '99999';
546                                _statusItens.innerHTML          = _itens; 
547                                _statusItens.onclick            = function(){ showhidden.hiddenObject(false); };
548                                                                                 
549                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
550                               
551                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
552                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
553                        element.parentNode.appendChild(_statusItens);
554                }
555        }
556
557        function setSelectEditable(element)
558        {
559                if( getElement('selectBox0') == null )
560                        selectEditable.create(element);
561        }
562
563        function setStatusJabber()
564        {
565                if( arguments.length > 0 )
566                {
567                        if( arguments[1] != 'status' )
568                        {
569                                var _text       = arguments[0];
570                                var _img        = arguments[1];
571                               
572                                getElement('statusJabberImg').setAttribute("style", "background-image: url('"+path_jabberit+"templates/default/images/"+_img+".gif'); margin-left: 13px;width:15px; height:15px;");
573                                getElement('statusJabberText').innerHTML = _text;
574                                getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
575                        }
576                }       
577        }
578       
579        function setUserCurrent( _jid , _password )
580        {
581                userCurrent =
582                {
583                        'jid'           : _jid,
584                        'password'      : _password
585                }
586        }
587
588        function loadIM()
589        {
590                if( arguments.length > 0 )
591                {
592                        var files = [
593                                                path_jabberit + 'js/connector.js',
594                                                path_jabberit + 'js/xtools.js',
595                                                path_jabberit + 'js/dragdrop.js',
596                                                path_jabberit + 'js/makeW.js',
597                                                path_jabberit + 'js/show_hidden.js',
598                                                path_jabberit + 'js/trophyim.js',
599                                                path_jabberit + 'js/AddUser.js',
600                                                path_jabberit + 'js/SelectEditable.js',
601                                                path_jabberit + 'templates/default/css/button.css',
602                                                path_jabberit + 'templates/default/css/common.css',
603                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
604                                                path_jabberit + 'templates/default/css/' + theme_jabberit
605                                    ];
606                        // FullName
607                        fullName = arguments[0];
608                       
609                        loadScripts(files);
610                       
611                        // User & Password Jabber;
612                        setUserCurrent( arguments[1], arguments[2]);
613                       
614                        setTimeout(function()
615                        {
616                                // Object Xtools       
617                                if( Xtools == null )
618                                        Xtools = new xtools(path_jabberit);
619                               
620                                // Object Conector
621                                if( conn == null )
622                                        conn = new AjaxConnector(path_jabberit);
623                               
624                                // Object Add User
625                                if( addUser == null )
626                                        addUser = new addUserIM(Xtools, conn);
627
628                               
629                                // Object SelectEditable
630                                if( selectEditable == null )
631                                        selectEditable = new SelectEditable();
632                                       
633                                // Add Jabber in StatusBar;
634                                addIcon();
635                               
636                        }, 1000);
637                }
638        }
639       
640        loadIM.prototype.actionButton           = actionButton;
641        loadIM.prototype.addContact                     = addContact;
642        loadIM.prototype.configEvents           = configEvents;
643        loadIM.prototype.getPhotoUser           = getPhotoUser;
644        loadIM.prototype.getUserCurrent         = getUserCurrent;
645        loadIM.prototype.getZIndex                      = getZindex;
646        loadIM.prototype.groupsHidden           = groupsHidden;
647        loadIM.prototype.groupsVisible          = groupsVisible;
648        loadIM.prototype.keyPressSearch         = keyPressSearch;       
649        loadIM.prototype.loginPage                      = loginPage;
650        loadIM.prototype.parse                          = parse;
651        loadIM.prototype.searchUser                     = searchUser
652        loadIM.prototype.setAutorization        = setAutorization;
653        loadIM.prototype.setPresence            = setPresence;
654        loadIM.prototype.setStatusJabber        = setStatusJabber;
655        loadIM.prototype.setSelectEditable      = setSelectEditable;
656        loadIM.prototype.removeContact          = removeContact;
657        loadIM.prototype.removeElement          = removeElement;
658        loadIM.prototype.removeGroup            = removeGroup;
659        loadIM.prototype.rename                         = rename;
660        loadIM.prototype.rosterDiv                      = rosterDiv;
661       
662        window.loadIM = loadIM;
663       
664})();
Note: See TracBrowser for help on using the repository browser.