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

Revision 2411, 13.8 KB checked in by alexandrecorreia, 14 years ago (diff)

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