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

Revision 2491, 15.7 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Implementado a parte de autorização ( to, from, both ). Ainda em teste.

  • 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      = '99999';
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 getUserCurrent()
187        {
188                return userCurrent;
189        }
190       
191        function getZindex()
192        {
193                return zIndex++;
194        }
195       
196        function groupsHidden()
197        {
198                if( arguments.length > 0 )
199                {
200                        var _element = arguments[0];
201                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif')no-repeat center left";
202                                _element.onclick = function(){ groupsVisible(_element);};
203                               
204                                // Hidden all
205                                var _elementNext = _element.nextSibling;
206                               
207                                while( _elementNext )
208                                {       
209                                        _elementNext.style.display = "none";
210                                        _elementNext = _elementNext.nextSibling;
211                                }
212                }
213        }
214       
215        function groupsVisible()
216        {
217                if( arguments.length > 0 )
218                {
219                        var _element = arguments[0];
220                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif')no-repeat center left";
221                                _element.onclick = function(){ groupsHidden(_element);};
222
223                                // Display all
224                                var _elementNext = _element.nextSibling;
225                               
226                                while( _elementNext )
227                                {       
228                                        _elementNext.style.display = "block";
229                                        _elementNext = _elementNext.nextSibling;
230                                }
231                }
232        }
233       
234        function keyPressSearch()
235        {
236                if( arguments.length > 0 )
237                {
238                        var ev          = arguments[0];
239                        var element     = arguments[1];
240       
241                        if ( ev.keyCode == 13 )
242                                if( element.value.length >= 3 )
243                                        searchUser( element.value );   
244                                else
245                                        alert('Your search argument must be longer than 3 characters.');
246                }
247        }
248
249       
250        function loginPage()
251        {
252                var winLoginPage =
253                {       
254                         id_window              : "window_login_page",
255                         width                  : 260,
256                         height                 : 150,
257                         top                    : 100,
258                         left                   : 400,
259                         draggable              : true,
260                         visible                : "display",
261                         resizable              : true,
262                         zindex                 : zIndex++,
263                         title                  : "Login - Expresso Messenger",
264                         closeAction    : "remove",
265                         content                : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl")       
266                };
267
268                _winBuild( winLoginPage );
269        }
270
271        function loadScripts(pFiles)
272        {
273                // Load JavaScript
274                var loadJavaScript = function(pJs)
275                {
276                        var newScript = document.createElement("script");
277                                newScript.setAttribute("type", "text/javascript");
278                                newScript.setAttribute("src", pJs );
279                               
280                        return newScript;
281                };
282               
283                // Load CSS
284                var loadStyleSheet = function(pCss)
285                {
286                        var newStyle = document.createElement("link");
287                                newStyle.setAttribute("rel", "stylesheet");
288                                newStyle.setAttribute("type", "text/css");
289                                newStyle.setAttribute("href", pCss);
290                               
291                        return newStyle;
292                };
293               
294                for(var i = 0; i < pFiles.length; i++)
295                {
296                        if( pFiles[i].indexOf(".js") > -1 )
297                                document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
298                               
299                        if( pFiles[i].indexOf(".css") > -1 )
300                                document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
301                }
302        }
303
304        function optionsItensContact()
305        {
306                if( arguments.length > 0 )
307                {
308                        var jid         = arguments[0];
309                        var index       = arguments[1];
310                        var element = document.getElementById('itenContact_' + jid + '_' + index );
311                       
312                        if( showhidden == null )
313                                showhidden = new ShowHidden(300);
314
315                        var _options = [
316                                                ['Autorizar', 'loadIM.setAutorization(\''+jid+'\',\''+index+'\')'],
317                                                ['Remover', 'loadIM.removeContact(\''+jid+'\',\''+index+'\')'],
318                                                ['Renomear', 'Renomear : ' + jid],
319                                                ['Trocar grupo', 'Trocar grupo : ' + jid],
320                                                   ];
321
322                        var _itens = "";
323                       
324                        for( var i in _options )
325                        {
326                                _itens += '<img src="'+arrow_right.src+'"/>';
327                                _itens += '<span style="cursor:pointer;margin:3px;font-weight:normal;" onclick='+_options[i][1]+'>';
328                                _itens += _options[i][0] + '</span><br/>';
329                        }
330                       
331                        var _optionsItens = document.createElement("div");
332                                _optionsItens.setAttribute("style", "margin: -10px 0px 0px 20px;");
333                                _optionsItens.className         = "x-menu";
334                                _optionsItens.style.zIndex      = '99999';
335                                _optionsItens.innerHTML         = _itens; 
336                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };       
337                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
338                               
339                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
340                               
341                        element.appendChild(_optionsItens);
342                }
343        }
344
345        function parse()
346        {
347                if( arguments.length == 2 )
348                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
349               
350                if( arguments.length === 3 )
351                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
352        }
353       
354        function removeContact(jid, index)
355        {
356                setTimeout(function()
357                {
358                        TrophyIM.removeContact(jid, index);
359                       
360                },300);
361        }
362       
363        function removeGroup()
364        {
365                var _parent = arguments[0];
366               
367                if( _parent.childNodes.length <= 2 )
368                        _parent.parentNode.removeChild(_parent);
369        }
370       
371        function rosterDiv()
372        {
373                var paramListContact =
374                {
375                        'path_jabberit' : path_jabberit,
376                        'full_name'             : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "..."))
377                };
378               
379                var winRosterDiv =
380                {
381                         id_window              : "window_Roster_im",
382                         width                  : 250,
383                         height                 : 410,
384                         top                    : 50,
385                         left                   : 50,
386                         draggable              : true,
387                         visible                : "display",
388                         resizable              : true,
389                         zindex                 : zIndex++,
390                         title                  : "Contatos - Expresso Messenger",
391                         closeAction    : "hidden",
392                         content                : Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)       
393                };
394               
395                _winBuild( winRosterDiv );
396        }
397
398        function searchUser()
399        {
400                var _input      = document.getElementById('search_user_jabber');
401               
402                if( _input.value.length >= 3 )
403                        addUser.search();
404                else
405                        alert('Your search argument must be longer than 3 characters.');
406        }
407       
408        function setAutorization(jidTo, indexTo)
409        {
410        var divItenContact = null;
411       
412        if( ( divItenContact = document.getElementById('itenContact_' + jidTo + '_' + indexTo )))
413        {       
414                var subscription = divItenContact.getAttribute('subscription');
415               
416                switch(subscription)
417                {
418                        case 'from':
419                        case 'not-in-roster':
420                                        TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribe');
421                                        break;
422                        case 'to' :
423                                        TrophyIM.setAutorization( jidTo, this.getUserCurrent().jid, 'subscribed');
424                                break;
425                }
426        }       
427        }
428       
429        function setPresence()
430        {
431                if( arguments.length > 0 )
432                {
433                        var element = arguments[0];
434                       
435                        if( showhidden == null )
436                                showhidden = new ShowHidden(300);
437                       
438                        var _status = [
439                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
440                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
441                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
442                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
443                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
444                                          ];
445                       
446                        var _itens = "";
447                       
448                        for( var i in _status )
449                        {
450                                _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadIM.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
451                                _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
452                        }
453                       
454                        var _statusItens = document.createElement("div");
455                                _statusItens.setAttribute("style", "margin: 62px 0px 0px 76px;");
456                                _statusItens.className          = "x-menu";
457                                _statusItens.style.zIndex       = '99999';
458                                _statusItens.innerHTML          = _itens; 
459                                _statusItens.onclick            = function(){ showhidden.hiddenObject(false); };
460                                                                                 
461                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
462                               
463                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
464                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
465                        element.parentNode.appendChild(_statusItens);
466                }
467        }
468
469        function setSelectEditable(element)
470        {
471                if( document.getElementById('selectBox0') == null )
472                        selectEditable.create(element);
473        }
474
475        function setStatusJabber()
476        {
477                if( arguments.length > 0 )
478                {
479                        var _text       = arguments[0];
480                        var _img        = arguments[1];
481                       
482                        getElement('statusJabberImg').setAttribute("style", "background-image: url('"+path_jabberit+"templates/default/images/"+_img+".gif'); margin-left: 13px;width:15px; height:15px;");
483                        getElement('statusJabberText').innerHTML = _text;
484                        getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
485                }       
486        }
487       
488        function setUserCurrent( _jid , _password )
489        {
490                userCurrent =
491                {
492                        'jid'           : _jid,
493                        'password'      : _password
494                }
495        }
496
497        function loadIM()
498        {
499                if( arguments.length > 0 )
500                {
501                        var files = [
502                                                path_jabberit + 'js/connector.js',
503                                                path_jabberit + 'js/xtools.js',
504                                                path_jabberit + 'js/dragdrop.js',
505                                                path_jabberit + 'js/makeW.js',
506                                                path_jabberit + 'js/show_hidden.js',
507                                                path_jabberit + 'js/trophyim.js',
508                                                path_jabberit + 'js/AddUser.js',
509                                                path_jabberit + 'js/SelectEditable.js',
510                                                path_jabberit + 'templates/default/css/button.css',
511                                                path_jabberit + 'templates/default/css/common.css',
512                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
513                                                path_jabberit + 'templates/default/css/' + theme_jabberit
514                                    ];
515                        // FullName
516                        fullName = arguments[0];
517                       
518                        loadScripts(files);
519                       
520                        // User & Password Jabber;
521                        setUserCurrent( arguments[1], arguments[2]);
522                       
523                        setTimeout(function()
524                        {
525                                // Object Xtools       
526                                if( Xtools == null )
527                                        Xtools = new xtools(path_jabberit);
528                               
529                                // Object Conector
530                                if( conn == null )
531                                        conn = new AjaxConnector(path_jabberit);
532                               
533                                // Object Add User
534                                if( addUser == null )
535                                        addUser = new addUserIM(Xtools, conn);
536
537                               
538                                // Object SelectEditable
539                                if( selectEditable == null )
540                                        selectEditable = new SelectEditable();
541                                       
542                                // Add Jabber in StatusBar;
543                                addIcon();
544                               
545                        }, 1000);
546                }
547        }
548       
549        loadIM.prototype.actionButton           = actionButton;
550        loadIM.prototype.addContact                     = addContact;
551        loadIM.prototype.configEvents           = configEvents;
552        loadIM.prototype.getUserCurrent         = getUserCurrent;
553        loadIM.prototype.getZIndex                      = getZindex;
554        loadIM.prototype.groupsHidden           = groupsHidden;
555        loadIM.prototype.groupsVisible          = groupsVisible;
556        loadIM.prototype.keyPressSearch         = keyPressSearch;       
557        loadIM.prototype.loginPage                      = loginPage;
558        loadIM.prototype.parse                          = parse;
559        loadIM.prototype.searchUser                     = searchUser
560        loadIM.prototype.setAutorization        = setAutorization;
561        loadIM.prototype.setPresence            = setPresence;
562        loadIM.prototype.setStatusJabber        = setStatusJabber;
563        loadIM.prototype.setSelectEditable      = setSelectEditable;
564        loadIM.prototype.removeContact          = removeContact;
565        loadIM.prototype.removeGroup            = removeGroup;
566        loadIM.prototype.rosterDiv                      = rosterDiv;
567       
568        window.loadIM = loadIM;
569       
570})();
Note: See TracBrowser for help on using the repository browser.