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

Revision 2421, 14.1 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Adicionado a funcionalidade de procurar contatos no ldap, com templates XSL.

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