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

Revision 2511, 16.4 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Implementado o status de mensagem e a busca da foto no ldap.

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