source: trunk/instant_messenger/js/templates.js @ 235

Revision 235, 11.4 KB checked in by niltonneto, 16 years ago (diff)
Line 
1function Templates()
2{
3        this.xtools             = new XTools();
4        this.zValue             = 100;
5        this.documentMousedown = null;
6        this.jabber     = new Jabber;
7}
8
9Templates.prototype = {
10
11        "add_user": function()
12        {
13                var XmlDoc = "<adduser>" +
14                                                 "<top>" +
15                                                         "<lang1>" + im.get_lang("Organization Unit")+ "</lang1>" +
16                                                 "</top>" +
17                                                 "<table>"+
18                                                         "<lang1>" + im.get_lang("Jid Contact") + "</lang1>" +
19                                                         "<lang2>" + im.get_lang("Nickname") + "</lang2>" +
20                                                         "<lang3>" + im.get_lang("Group") + "</lang3>" +
21                                                         "<lang4>" + im.get_lang("Add") + "</lang4>" +
22                                                         "<lang5>" + im.get_lang("Close") + "</lang5>" +                                                 
23                                                 "</table>" +
24                                         "</adduser>";
25                im_window.load('add_user_im','instant_messenger_content','<title>.:: Adicionar Novos Contatos ::.</title>','window.xsl','545',true,true,true);
26                im_window.elementC('add_user_im').innerHTML  = this.xtools.parse(XmlDoc,'add_user.xsl');
27                im.ldap();
28        },
29
30        "colors": function(pJid)
31        {
32                var Xmlsmiles = "<colors>" +   
33                                                        "<lang1>Black</lang1>" +
34                                                        "<lang2>Silver</lang2>" +
35                                                        "<lang3>Yellow</lang3>" +
36                                                        "<lang4>Red</lang4>" +
37                                                        "<lang5>Pink</lang5>" +
38                                                        "<lang6>Green</lang6>" +
39                                                        "<lang7>Blue</lang7>" +
40                                                        "<lang8>Magenta</lang8>" +
41                                                        "<path>"+path_im+"</path>" +
42                                                        "<name>"+pJid+"</name>" +
43                                                "</colors>";
44
45                menu_action.menu(pJid + '_button_dest', this.xtools.parse(Xmlsmiles,'colors.xsl'));
46                func.byId(pJid + '_button_dest').style.top = func.byId(pJid + '_button_color').offsetTop + 10;
47                func.byId(pJid + '_button_dest').style.left = func.byId(pJid + '_button_color').offsetLeft + 10;
48                func.byId(pJid + '_button_dest').style.zIndex = this.zValue++;
49                func.byId(pJid + '_button_dest').style.position = "absolute";
50        },
51
52        "fast_menu" : function()
53        {
54                if( document.getElementById('_contacts_im_' + '_window_master') != null )
55                {
56                        var XmlDoc = "<fast_menu>" +   
57                                                        "<lang1>Online</lang1>" +
58                                                        "<lang2>Ausente</lang2>" +
59                                                        "<lang3>Ocupado</lang3>" +
60                                                        "<lang4>Offline</lang4>" +
61                                                        "<lang5>Mensagem</lang5>" +
62                                                        "<img1>"+path_im+"templates/default/images/available.gif</img1>" +
63                                                        "<img2>"+path_im+"templates/default/images/away.gif</img2>" +
64                                                        "<img3>"+path_im+"templates/default/images/dnd.gif</img3>" +
65                                                        "<img4>"+path_im+"templates/default/images/unavailable.gif</img4>" +
66                                                        "<img5>"+path_im+"templates/default/images/icon_edit.gif</img5>" +                                                                                                                                             
67                                                 "</fast_menu>";
68       
69                        menu_action.menu('fast_menu_im', this.xtools.parse(XmlDoc,'fast_menu.xsl'));
70                        document.getElementById('fast_menu_im').style.top = document.getElementById('fast_menu_im').offsetTop + 60;
71                        document.getElementById('fast_menu_im').style.left = document.getElementById('fast_menu_im').offsetLeft + 5;
72                        document.getElementById('fast_menu_im').style.zIndex = this.zValue++;
73                        document.getElementById('fast_menu_im').style.position = "absolute";
74                }
75                else
76                        alert('Aguarde carregando lista de contatos ....');
77                                       
78        },
79       
80        "mysettings": function()
81        {
82                var XmlDoc = "<settings>" +
83                                                "<lang1>Opções</lang1>" +
84                                                "<lang2>Exibir amigos desconectados</lang2>" +
85                                                "<lang3>Ausente</lang3>" +
86                                                "<lang4>Ficar ausente depois de</lang4>" +
87                                                "<lang5>minutos</lang5>" +
88                                                "<lang6>Ativar aviso de mensagens recebidas</lang6>" +
89                                                "<lang7>Normal</lang7>" +                                                                                                                                                                                                                                                                                               
90                                                "<lang8>Treme Tela</lang8>" +
91                                                "<lang9>" + im.get_lang("Save") + "</lang9>" +
92                                                "<lang10>" + im.get_lang("Close") + "</lang10> " +
93                                         "</settings>";
94               
95                im_window.load('my_settings_im','instant_messenger_content','<title>.:: ' + im.get_lang("My Settings") + ' ::.</title>','window.xsl','400',true,true,true);
96                im_window.elementC('my_settings_im').innerHTML = this.xtools.parse(XmlDoc,'mysettings.xsl');
97                im.get_preferences();
98        },
99       
100        "options" : function(pEv, pJid)
101        {
102                try
103                {
104                        var pEvent = pEv;
105
106                        if ( pEvent.button > 1 )
107                        {
108                                document.oncontextmenu = new Function("return false");                         
109                                document.onmousedown = new Function("return false");
110
111                                this.options_button_right(pJid);
112       
113                                document.onmousedown = new Function("return true");                                                     
114                        }
115                        else
116                        {
117                                this.options_button_left(pJid);
118                        }
119
120                }catch(e){}
121
122        },
123       
124        "options_button_left" : function(pJid)
125        {
126                var _this = this;
127
128                if(!(im.nickname_contacts[pJid]))
129                        im.request_vcard(pJid, false);
130
131                if(func.byId('img_' + pJid).src != im_unavailable.src )
132                {
133                        im_window.load(pJid, 'instant_messenger_content', '<title>.:: Expresso Messenger ::.</title>', 'chat.xsl','310',true,true,true);
134                        //im_window.visible(pJid,'block');                     
135                        func.byId(pJid + '_avatar').src = path_im + "/templates/default/images/photo.png";
136
137                        if(func.byId('iframe_' + pJid) != null)
138                                func.byId('iframe_' + pJid).parentNode.removeChild(func.byId('iframe_' + pJid));
139
140                        var win = im_window.elementC(pJid);
141
142                        var iframe = document.createElement('iframe');
143                        iframe.id = 'iframe_' + pJid;
144                        iframe.style.width = '290px';
145                        iframe.style.height = '46px';
146                        iframe.style.border = '0';
147                        iframe.style.margin = '0';
148                        iframe.style.padding = '0'
149
150                        var _messages_ = win.firstChild.firstChild.nextSibling.nextSibling;
151                        _messages_.appendChild(iframe);
152
153                        iframe.contentWindow.document.write('<html><body id="' + pJid + '" style="margin:0px;padding:0px"></body></html>');
154                        iframe.contentWindow.document.close();
155                        iframe.contentWindow.document.designMode = "On";
156                        iframe.contentWindow.focus();
157
158                        function keypress_handler(e)
159                        {
160                                var evt = e.keyCode;
161                                var pId = ( e.srcElement ) ? e.srcElement.id : e.target.getElementsByTagName('body').item(0).id;
162                                switch ( evt )
163                                {
164                                        case 13 :
165                                                if ( !e.shiftKey )
166                                                        _this.jabber.doIt('sendMessage',{'message' : iframe.contentWindow.document.getElementsByTagName('body').item(0), 'from' : pJid });
167                                                return false;
168                                        break;
169                                        case 27 :
170                                                im_window.window_close(pId);
171                                        break;
172                                        default :
173                                        break;
174                                }
175                        }
176                        function keyup_handler(e)
177                        {
178                                var evt = e.keyCode;
179                                var _text = ( e.srcElement ) ? e.srcElement.id : e.target.getElementsByTagName('body').item(0);
180
181                                switch ( evt )
182                                {
183                                        case 13 :
184                                                if ( !e.shiftKey )
185                                                        _text.innerHTML = '';
186                                                return false;
187                                        break;
188                                        default :
189                                        break;
190                                }
191                        }
192                        var obj = iframe.contentWindow.document;
193
194                        if ( obj.addEventListener )
195                        {
196                                obj.addEventListener('keypress', keypress_handler, false);
197                                obj.addEventListener('keyup', keyup_handler, false);
198                        }
199                        else if ( obj.attachEvent )
200                        {
201                                obj.attachEvent('onkeypress', keypress_handler);
202                                obj.attachEvent('onkeyup', keyup_handler);
203                        }
204                       
205                        im.ldap_photo(pJid + "_avatar");
206                }
207        },
208       
209        "options_button_right" : function( pJid )
210        {
211
212                var XmlDoc = "<options>" +     
213                                                "<lang1>" + im.get_lang("Nickname") + "</lang1>" +
214                                                "<lang2>" + im.get_lang("Group") + "</lang2>" +
215                                                "<lang3>" + im.get_lang("Remove") + "</lang3>" +
216                                                "<lang4>" + im.get_lang("It requisition permission")+ "</lang4>" +
217                                                "<lang5>" + im.get_lang("See Info") + "</lang5>" +
218                                                "<jid>" + pJid + "</jid>" +
219                                                "<path>" + path_im + "</path>" +               
220                                         "</options>";
221
222                var posX = parseInt(func.byId('sub_' + pJid).offsetLeft) - parseInt(func.byId('sub_' + pJid).parentNode.scrollLeft);
223                var posY = parseInt(func.byId('sub_' + pJid).offsetTop) - parseInt(func.byId('sub_' + pJid).parentNode.scrollTop);
224
225                menu_action.menu('im_sub_menu', this.xtools.parse(XmlDoc,'options.xsl'));
226            func.byId('im_sub_menu').style.zIndex = '99999';
227                func.byId('im_sub_menu').style.top = posY;
228                func.byId('im_sub_menu').style.left = posX + 20;           
229            func.byId('im_sub_menu').style.position = 'absolute';
230        },
231
232        "preferences": function(pElement)
233        {
234                var XmlDoc = "<preferences>" +
235                                                "<lang1>" + im.get_lang("Add Contact") + "</lang1>" +
236                                                "<function1>templates.add_user();</function1>" +
237                                                "<lang2>" + im.get_lang("Remove Contact") + "</lang2>" +
238                                                "<function2>templates.remove_user();</function2>" +
239                                                "<lang3>" + im.get_lang("Vcard") +"</lang3>" +
240                                                "<function3>im.request_vcard('this',true)</function3>" +
241                                                "<lang4>" + im.get_lang("Preferences") + "</lang4>" +
242                                                "<function4>templates.mysettings()</function4>" +
243                                                "<path>"+ path_im + "</path>" +
244                                         "</preferences>";
245
246                menu_action.menu(pElement, this.xtools.parse(XmlDoc,'preferences.xsl'));
247                document.getElementById(pElement).style.zIndex   = this.zValue++;
248                document.getElementById(pElement).style.position = "absolute";
249        },
250
251        "remove_user": function()
252        {
253                var XmlDoc = "<remove_user>" +
254                                                "<lang1>" + im.get_lang("Contact") + "</lang1>" +
255                                                "<lang2>" + im.get_lang("Remove") +"</lang2>" +
256                                                "<lang3>" + im.get_lang("Close") + "</lang3>" +
257                                         "</remove_user>";
258
259                im_window.load('remove_user_im','instant_messenger_content','<title>.:: Remover Contatos ::.</title>','window.xsl','350',true,true,true);
260                im_window.elementC('remove_user_im').innerHTML = this.xtools.parse(XmlDoc,'remove_user.xsl');
261                im.get_contacts();
262                //im_window.visible('remove_user_im','block');         
263        },
264
265        "smiles": function(pJid)
266        {
267                var Xmlsmiles = "<smiles>" +   
268                                                        "<path>"+path_im+"</path>" +                                                                                                                                                                                                                                                                                                                                           
269                                                        "<pjid>"+pJid+"</pjid>" +
270                                                "</smiles>";
271
272                menu_action.menu(pJid + '_button_dest', this.xtools.parse(Xmlsmiles,'smiles.xsl'));
273                func.byId(pJid + '_button_dest').style.top = func.byId(pJid + '_button_emoticons').offsetTop + 10;
274                func.byId(pJid + '_button_dest').style.left = func.byId(pJid + '_button_emoticons').offsetLeft + 10;
275                func.byId(pJid + '_button_dest').style.zIndex = this.zValue++;
276                func.byId(pJid + '_button_dest').style.position = "absolute";
277        },
278
279        "vcard_contact" : function(pXml)       
280        {
281                im.vcard = false;
282                var title = "Informações do Contato - Expresso";
283                var XmlDoc = "<vcard_contact>" +
284                                                "<lang1>" + im.get_lang("Full Name") + "</lang1>" +
285                                                "<lang2>" + im.get_lang("Nickname") + "</lang2>" +
286                                                "<lang3>" + im.get_lang("Organization") +"</lang3>" +
287                                                "<lang4>" + im.get_lang("Sector") + "</lang4>" +
288                                                "<lang5>" + im.get_lang("Role") + "</lang5>" +
289                                                "<lang6>" + im.get_lang("Birthday") + "</lang6>" +
290                                                "<lang7>" + im.get_lang("Close") + "</lang7>" +                                                                                                                                 
291                                                this.xtools.parse(pXml,'vcard.xsl') +
292                                                "<id>vcard_contact_im</id>"+
293                                        "</vcard_contact>";
294
295                im_window.load('vcard_contact_im','instant_messenger_content','<title>.:: ' + title +' ::.</title>','window.xsl','390',true,true,true);
296                im_window.elementC('vcard_contact_im').innerHTML = this.xtools.parse(XmlDoc,'vcard_contacts.xsl');
297                //im_window.visible('vcard_contact_im','block');               
298        },
299
300        "vcard_user" : function(pXml)
301        {
302                im.vcard = false;
303                var title = "Informações Pessoais - Expresso";
304                var XmlDoc = "<vcard_user>" +   
305                                                "<lang1>" + im.get_lang("Full Name") + "</lang1>" +
306                                                "<lang2>" + im.get_lang("Nickname") + "</lang2>" +
307                                                "<lang3>" + im.get_lang("Organization") + "</lang3>" +
308                                                "<lang4>" + im.get_lang("Sector") + "</lang4>" +
309                                                "<lang5>" + im.get_lang("Role") + "</lang5>" +
310                                                "<lang6>" + im.get_lang("Birthday") + "</lang6>" +
311                                                "<lang7>" + im.get_lang("Save") + "</lang7>" +
312                                                "<lang8>" + im.get_lang("Close") + "</lang8>" +
313                                                this.xtools.parse(pXml,'vcard.xsl') +                                           
314                                                "<id>vcard_user_im</id>"+                                               
315                                         "</vcard_user>";
316                im_window.load('vcard_user_im','instant_messenger_content','<title>.:: ' + title +' ::.</title>','window.xsl','470',true,true,true);
317                im_window.elementC('vcard_user_im').innerHTML = this.xtools.parse(XmlDoc,'vcard_user.xsl');
318                //im_window.visible('vcard_user_im','block');           
319        }
320}
321
322var templates = new Templates();
Note: See TracBrowser for help on using the repository browser.