source: trunk/instant_messenger/js/preferences.js @ 318

Revision 318, 6.1 KB checked in by niltonneto, 16 years ago (diff)

Commit feito pelo desenvolvedor (rodrigosouza).

  • Property svn:executable set to *
Line 
1(function(){
2
3        // Conector, Xtools , Janelas
4        var     _conn   = new IMConnector(path_im);
5        var     _xtools = new XTools(path_im);
6        var _im_content = top.document.getElementById('instant_messenger_content');
7        var     _window         = new Windows(_xtools, _im_content);
8        var _cookies    = new IMCookies;
9        var idTimeout   = "";
10        var Timeout             = "";
11
12        function _config(pObj, pEvent, pHandler)
13        {
14                if ( typeof pObj == 'object' )
15                {
16                        if ( pEvent.substring(0, 2) == 'on' )
17                                pEvent = pEvent.substring(2, pEvent.length);
18
19                        if ( pObj.addEventListener )
20                                pObj.addEventListener(pEvent, pHandler, false);
21                        else if ( pObj.attachEvent )
22                                pObj.attachEvent('on' + pEvent, pHandler);
23                }
24        }
25
26        function _load_window()
27        {
28                var _win_preferences = "";
29
30                _win_preferences = _window.load('preferences_window');
31                _win_preferences.title('.:: Expresso Messenger - ' + imGetLang('Preferences') + ' ::.');
32                _win_preferences.size(400, 350);
33                _win_preferences.position(150, 70, false);
34                _win_preferences.icon(im_console_prefs.src);
35
36                _win_preferences.bz.style.display = 'none';
37                _win_preferences.bx.style.display = 'none';
38                _win_preferences.wc.style.padding = '5px';
39               
40                var _params = {
41                        'lang1':imGetLang('Options'),
42                        'lang2':imGetLang('Show users offline'),
43                        'lang3':imGetLang('Away'),
44                        'lang4':imGetLang('Ficar ausente depois de'),
45                        'lang5':imGetLang('Minutes'),
46                        'lang6':imGetLang('Ativar aviso de mensagem recebida'),
47                        'lang7':imGetLang('Normal'),
48                        'lang8':imGetLang('Treme Tela'),
49                        'lang9':imGetLang('Save'),
50                        'lang10':imGetLang('Close')
51                };
52
53                _win_preferences.content(_xtools.parse(_xtools.xml('settings'), 'mysettings.xsl', _params));
54
55                _config(_win_preferences.wc.childNodes[2], 'onclick', setPreferences);
56                _config(_win_preferences.wc.childNodes[3], 'onclick',
57                        function()
58                        {
59                                _win_preferences.button(_win_preferences.bc);
60                        }
61                );
62
63                // Carrega as preferências;
64            getPreferences();
65        }
66
67        function focus_select()
68    {
69        arguments[0].focus();
70        arguments[0].select();
71    }
72
73        function _preferences()
74        {
75                _cookies.set('preferences_im', arguments[0]);
76                var preferences = arguments[0].split(';');
77                        preferences.pop();
78               
79                for(var i in preferences)
80                {
81                        var field = preferences[i].substring(0,preferences[i].indexOf(':'));
82                        var value = preferences[i].substring(preferences[i].indexOf(':') + 1, preferences[i].length);
83
84                        if( value === 'true' || value === 'false')
85                        {
86                                if(top.document.getElementById(field))
87                                        top.document.getElementById(field).checked = eval(value);
88                                else if( field === 'ch_offline')
89                                        if(eval(value))
90                                                _cookies.set('IM_unavailable', 'show');
91                                        else
92                                                _cookies.set('IM_unavailable', 'hidden');
93                        }
94                        else
95                        {
96                                Timeout = ( parseInt(value) > 0 ) ? value : "1";
97                                if( top.document.getElementById(field) )
98                                        top.document.getElementById(field).value = Timeout;
99                        }
100                }
101        }
102
103        function getPreferences()
104        {
105                var preferences = "";
106               
107                if((preferences = _cookies.get('preferences_im')))
108                        _preferences(preferences);
109                else
110                        _conn.go('$this.db_im.get_preferences', _preferences);
111        }
112
113        function setPreferences()
114        {
115                _win_preferences = _window.get('preferences_window');
116       
117                var preferences = "";
118                var numbers = /^\d+$/;
119               
120                // Offline
121        if (top.document.getElementById('ch_offline').checked)
122                {
123                        preferences = 'ch_offline:true;';
124                        _cookies.set('IM_unavailable', 'show');
125                }
126                else
127                {
128                        preferences = 'ch_offline:false;';
129                        _cookies.set('IM_unavailable', 'hidden');
130                }
131       
132                // TimeOut
133                if(numbers.test(top.document.getElementById('time_xa_im').value) && top.document.getElementById('time_xa_im').value != "0")
134                {
135            preferences += "time_xa_im:" + top.document.getElementById('time_xa_im').value + ";";
136                        Timeout = top.document.getElementById('time_xa_im').value;
137                }
138        else
139                {
140            preferences += "time_xa_im:1;";
141                        Timeout = 1;
142                }
143       
144                // New Message
145                if(top.document.getElementById('rd_nm').checked)
146                {
147                        preferences += 'rd_nm:true;';
148                        _cookies.set('IM_screen','nm');
149                }
150                else
151                        preferences += 'rd_nm:false;';
152       
153                if(top.document.getElementById('rd_ch').checked)
154                {
155                        preferences += 'rd_ch:true;';
156                        _cookies.set('IM_screen','rd');
157                }
158                else
159                        preferences += 'rd_ch:false;';
160
161                // Write Cookie
162                _cookies.set('preferences_im', preferences );
163
164        _conn.go('$this.db_im.set_preferences',
165                                 function(dataString)
166                                 {
167                                        if( !eval(dataString))
168                                                alert('Erro : Preferências não foram salvas !');
169                                 },
170                                 'preferences='+preferences
171                                );
172
173                if ( _win_preferences )
174                        _win_preferences.button(_win_preferences.bc);
175        }
176
177        function _setPresence()
178        {
179                var _presence = false;
180                var _pPresence;
181                if ( arguments.length == 0 )
182                {
183                        if ( !(_pPresence = _cookies.get('IM_presence')) )
184                                _pPresence = 'available';
185                }
186                else
187                        _pPresence = arguments[0];
188
189                _cookies.set('IM_presence', _pPresence);
190
191                switch ( _pPresence )
192                {
193                        case 'away':
194                        case 'dnd':
195                        case 'xa':
196                                _presence = 'show=' + _pPresence;
197                        break;
198                        case 'available':
199                        case 'unavailable':
200                                _presence = 'type=' + _pPresence;
201                        break;
202                }
203
204                if ( _presence )
205                {
206                        var _img_status = eval('im_' + _pPresence + '.src');
207
208                        var _status = top.document.getElementById('im_status');
209                        if ( _status )
210                                _status.style.backgroundImage = 'url(' + _img_status + ')';
211
212                        var _win_contacts = _window.get('contact_list');
213                        if ( _win_contacts )
214                                _win_contacts.icon(_img_status);
215
216                        _conn.go('$this.Ujabber.setPresence', _presence);
217                }
218        }
219
220        function _setTimeOut()
221        {
222                _setPresence('xa');
223                idTimeout = setTimeout('top.window.im_preferences.timeOut();', parseInt(Timeout) * 60000);
224        }
225
226        function _timeOut()
227        {
228                if(idTimeout)
229                {
230                        clearTimeout(idTimeout);
231                        var _status = '';
232               
233                        if((_status = _cookies.get('IM_presence')) === 'xa')
234                                _setPresence('available');
235                }
236               
237                idTimeout = setTimeout('top.window.im_preferences._setTimeOut("xa");', parseInt(Timeout) * 60000);
238        }
239
240        function Preferences()
241        {
242                getPreferences();
243                _timeOut();
244        }
245       
246        Preferences.prototype._setTimeOut        = _setTimeOut;
247        Preferences.prototype.timeOut            = _timeOut;
248        Preferences.prototype.load                       = _load_window;
249        Preferences.prototype.getfocus           = focus_select;
250        top.window.im_preferences                        = new Preferences;
251        top.window.document.onmousemove          = _timeOut;
252
253})();
Note: See TracBrowser for help on using the repository browser.