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

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