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

Revision 323, 5.1 KB checked in by niltonneto, 16 years ago (diff)
  • 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 Timeout             = "";
10
11        function _config(pObj, pEvent, pHandler)
12        {
13                if ( typeof pObj == 'object' )
14                {
15                        if ( pEvent.substring(0, 2) == 'on' )
16                                pEvent = pEvent.substring(2, pEvent.length);
17
18                        if ( pObj.addEventListener )
19                                pObj.addEventListener(pEvent, pHandler, false);
20                        else if ( pObj.attachEvent )
21                                pObj.attachEvent('on' + pEvent, pHandler);
22                }
23        }
24
25        function _load_window()
26        {
27                var _win_preferences = "";
28
29                _win_preferences = _window.load('preferences_window');
30                _win_preferences.title('.:: Expresso Messenger - ' + imGetLang('Preferences') + ' ::.');
31                _win_preferences.size(400, 350);
32                _win_preferences.position(150, 70, false);
33                _win_preferences.icon(im_console_prefs.src);
34
35                _win_preferences.bz.style.display = 'none';
36                _win_preferences.bx.style.display = 'none';
37                _win_preferences.wc.style.padding = '5px';
38
39                var _params = {
40                        'lang1':imGetLang('Options'),
41                        'lang2':imGetLang('Show users offline'),
42                        'lang3':imGetLang('Away'),
43                        'lang4':imGetLang('Ficar ausente depois de'),
44                        'lang5':imGetLang('Minutes'),
45                        'lang6':imGetLang('Ativar aviso de mensagem recebida'),
46                        'lang7':imGetLang('Normal'),
47                        'lang8':imGetLang('Treme Tela'),
48                        'lang9':imGetLang('Save'),
49                        'lang10':imGetLang('Close')
50                };
51
52                _win_preferences.content(_xtools.parse(_xtools.xml('settings'), 'mysettings.xsl', _params));
53
54                _config(_win_preferences.wc.childNodes[2], 'onclick', setPreferences);
55                _config(_win_preferences.wc.childNodes[3], 'onclick',
56                        function()
57                        {
58                                _win_preferences.button(_win_preferences.bc);
59                        }
60                );
61
62                // Carrega as preferências;
63            getPreferences();
64        }
65
66        function focus_select()
67    {
68        arguments[0].focus();
69        arguments[0].select();
70    }
71
72        function _preferences()
73        {
74                _cookies.set('preferences_im', arguments[0]);
75                var preferences = arguments[0].split(';');
76                        preferences.pop();
77
78                for(var i in preferences)
79                {
80                        var field = preferences[i].substring(0,preferences[i].indexOf(':'));
81                        var value = preferences[i].substring(preferences[i].indexOf(':') + 1, preferences[i].length);
82
83                        if( value === 'true' || value === 'false')
84                        {
85                                if(top.document.getElementById(field))
86                                        top.document.getElementById(field).checked = eval(value);
87                                else if( field === 'ch_offline')
88                                        if(eval(value))
89                                                _cookies.set('IM_unavailable', 'show');
90                                        else
91                                                _cookies.set('IM_unavailable', 'hidden');
92                        }
93                        else
94                        {
95                                Timeout = ( parseInt(value) > 0 ) ? value : "1";
96                                if( top.document.getElementById(field) )
97                                        top.document.getElementById(field).value = Timeout;
98                        }
99                }
100        }
101
102        function getPreferences()
103        {
104                var preferences = "";
105
106                if((preferences = _cookies.get('preferences_im')))
107                        _preferences(preferences);
108                else
109                        _conn.go('$this.db_im.get_preferences', _preferences);
110        }
111
112        function setPreferences()
113        {
114                _win_preferences = _window.get('preferences_window');
115
116                var preferences = "";
117                var numbers = /^\d+$/;
118
119                // Offline
120        if (top.document.getElementById('ch_offline').checked)
121                {
122                        preferences = 'ch_offline:true;';
123                        _cookies.set('IM_unavailable', 'show');
124                }
125                else
126                {
127                        preferences = 'ch_offline:false;';
128                        _cookies.set('IM_unavailable', 'hidden');
129                }
130
131                // TimeOut
132                if(numbers.test(top.document.getElementById('time_xa_im').value) && top.document.getElementById('time_xa_im').value != "0")
133                {
134            preferences += "time_xa_im:" + top.document.getElementById('time_xa_im').value + ";";
135                        Timeout = top.document.getElementById('time_xa_im').value;
136                }
137        else
138                {
139            preferences += "time_xa_im:1;";
140                        Timeout = 1;
141                }
142
143                // New Message
144                if(top.document.getElementById('rd_nm').checked)
145                {
146                        preferences += 'rd_nm:true;';
147                        _cookies.set('IM_screen','nm');
148                }
149                else
150                        preferences += 'rd_nm:false;';
151
152                if(top.document.getElementById('rd_ch').checked)
153                {
154                        preferences += 'rd_ch:true;';
155                        _cookies.set('IM_screen','rd');
156                }
157                else
158                        preferences += 'rd_ch:false;';
159
160                // Write Cookie
161                _cookies.set('preferences_im', preferences );
162
163        _conn.go('$this.db_im.set_preferences',
164                                 function(dataString)
165                                 {
166                                        if( !eval(dataString))
167                                                alert('Erro : Preferências não foram salvas !');
168                                 },
169                                 'preferences='+preferences
170                                );
171
172                if ( _win_preferences )
173                        _win_preferences.button(_win_preferences.bc);
174        }
175
176        var _changed = false;
177        var _id_timeout = "";
178        function _setTimeOut()
179        {
180                _changed = true;
181                InstantMessengerPresence('auto');
182        }
183
184        function _timeOut()
185        {
186                if ( _id_timeout )
187                        clearTimeout(_id_timeout);
188
189                if ( _changed )
190                {
191                        _changed = false;
192                        InstantMessengerPresence();
193                }
194
195                _id_timeout = setTimeout(_setTimeOut, parseInt(Timeout) * 60000);
196        }
197
198        function Preferences()
199        {
200                getPreferences();
201                _timeOut();
202        }
203
204        Preferences.prototype._setTimeOut        = _setTimeOut;
205        Preferences.prototype.timeOut            = _timeOut;
206        Preferences.prototype.load                       = _load_window;
207        Preferences.prototype.getfocus           = focus_select;
208        top.window.im_preferences                        = new Preferences;
209        _config(top.window.document, 'onmousemove', _timeOut);
210
211})();
Note: See TracBrowser for help on using the repository browser.