1 | /**************************************************************************\ |
---|
2 | Início |
---|
3 | \**************************************************************************/ |
---|
4 | function Preferences(){ |
---|
5 | this.prefeW = new Array; |
---|
6 | } |
---|
7 | // Cria as divs; |
---|
8 | Preferences.prototype.showList = function(){ |
---|
9 | |
---|
10 | id = '1'; |
---|
11 | _this = this; |
---|
12 | |
---|
13 | form_pref = document.createElement("DIV"); |
---|
14 | form_pref.style.visibility = "hidden"; |
---|
15 | form_pref.style.position = "absolute"; |
---|
16 | form_pref.id = "window_confexp"; |
---|
17 | document.body.appendChild(form_pref); |
---|
18 | prefe.showWindow(form_pref); |
---|
19 | var form = Element("form_preferences"); |
---|
20 | |
---|
21 | if(!form) { |
---|
22 | form = document.createElement("FORM"); |
---|
23 | form.id = "form_preferences"; |
---|
24 | form.innerHTML = "<table border='0' cellpading='0' cellspacing='0'>"+ |
---|
25 | "<tr><td colspan='2'><center>" + get_lang('Config for expressoMail') + "</center></td></tr>"+ |
---|
26 | "<tr><td nowrap> - " + get_lang('What is the maximum number of messages per page?') + "</td>"+ |
---|
27 | "<td> <select id='sel_num_max' name='sel_num_max'>"+ |
---|
28 | "<option value='25'>25</option>"+ |
---|
29 | "<option value='50'>50</option>"+ |
---|
30 | "<option value='75'>75</option>"+ |
---|
31 | "<option value='100'>100</option>"+ |
---|
32 | "</select></td>"+ |
---|
33 | "</tr>"+ |
---|
34 | "<tr><td nowrap> - " + get_lang('Save deleted messages in trash folder?') + "</td>"+ |
---|
35 | "<td><input type='checkBox' id='check_save_men' name='check_save_men'></td>"+ |
---|
36 | "</tr>"+ |
---|
37 | "<tr><td nowrap> - " + get_lang('Delete trash messages after how many days?') + "</td>"+ |
---|
38 | "<td> <select id='sel_del_men' name='sel_del_men'>"+ |
---|
39 | "<option value='0'>" + get_lang('None') + "</option>"+ |
---|
40 | "<option value='1'>"+get_lang("1 day")+"</option>"+ |
---|
41 | "<option value='2'>"+get_lang("2 days")+"</option>"+ |
---|
42 | "<option value='3'>"+get_lang("3 days")+"</option>"+ |
---|
43 | "<option value='4'>"+get_lang("4 days")+"</option>"+ |
---|
44 | "<option value='5'>"+get_lang("5 days")+"</option>"+ |
---|
45 | "</select></td>"+ |
---|
46 | "</tr>"+ |
---|
47 | "<tr><td nowrap> - " + get_lang('Show previous message, after delete actual message?') + "</td>"+ |
---|
48 | "<td><input type='checkBox' id='check_show_previous' name='check_show_previous'></td>"+ |
---|
49 | "</tr>"+ |
---|
50 | "<tr><td nowrap> - " + get_lang('Do you wanna receive an alert for new messages?') + "</td>"+ |
---|
51 | "<td><input type='checkBox' id='check_alert' name='check_alert'></td>"+ |
---|
52 | "</tr>"+ |
---|
53 | "<tr><td nowrap> - " + get_lang('Show default view on main screen?') + "</td>"+ |
---|
54 | "<td><input type='checkBox' id='check_view' name='check_view'></td>"+ |
---|
55 | "</tr>"+ |
---|
56 | "<tr><td nowrap> - " + get_lang('Save sent messages in folder') + "</td>"+ |
---|
57 | "<td> <select style='width:125px' id='sel_name_box' name='sel_name_box'></select></td>"+ |
---|
58 | "</tr>"+ |
---|
59 | "<tr><td> - " + get_lang('Hide menu folders?') + "</td>"+ |
---|
60 | "<td><input type='checkBox' id='check_menu' name='check_menu'></td>"+ |
---|
61 | "</tr>"+ |
---|
62 | "<tr><td> - " + get_lang('What is the height of the lines in the list of messages?') + "</td>"+ |
---|
63 | "<td> <select id='sel_height_line' name='sel_height_line'>"+ |
---|
64 | "<option value='20'>"+get_lang("Normal")+"</option>"+ |
---|
65 | "<option value='30'>"+get_lang("Medium")+"</option>"+ |
---|
66 | "<option value='40'>"+get_lang("Big")+"</option>"+ |
---|
67 | "</select></td>"+ |
---|
68 | "</tr>"+ |
---|
69 | "<tr><td> - " + get_lang('What the font size in the list of messages?') + "</td>"+ |
---|
70 | "<td> <select id='sel_size_font' name='sel_size_font'>"+ |
---|
71 | "<option value='10'>"+get_lang("Small")+"</option>"+ |
---|
72 | "<option value='11'>"+get_lang("Normal")+"</option>"+ |
---|
73 | "<option value='15'>"+get_lang("Big")+"</option>"+ |
---|
74 | "</select></td></tr>"+ |
---|
75 | "<tr><td> - " + get_lang("Use dynamic contacts?") + "</td>"+ |
---|
76 | "<td><input type='checkBox' id='use_dynamic_contacts' name='use_dynamic_contacts'></td></tr>"+ |
---|
77 | "<tr><td> - " + get_lang("Auto save draft") + "?</td>"+ |
---|
78 | "<td><input type='checkBox' id='auto_save_draft' name='auto_save_draft'></td></tr>"+ |
---|
79 | "<tr><td> - " + get_lang("Use shortcuts?") + "</td>"+ |
---|
80 | "<td><input type='checkBox' id='use_shortcuts' name='use_shortcuts'></td></tr>"+ |
---|
81 | "<tr><td nowrap> - " + get_lang('Insert signature automatically in new messages?') + "</td>"+ |
---|
82 | "<td><input type='checkBox' id='use_signature' name='use_signature'></td>"+ |
---|
83 | "</tr>"+ |
---|
84 | "<tr><td colspan='2'> - " + get_lang('Signature') + "<br>"+ |
---|
85 | "<textarea id='txt_signature' name='txt_signature' rows='3' cols='59'></textarea></td>"+ |
---|
86 | "</tr>"+ |
---|
87 | "<tr><td><input type='button' value='"+get_lang("Cancel")+"' onclick='prefe.close_win();'>"+ |
---|
88 | "<td align='left'><input type='button' value='"+get_lang("Save")+"' onclick='prefe.save_form()'>"+ |
---|
89 | "</tr>"+ |
---|
90 | "</table>"; |
---|
91 | form_pref.appendChild(form); |
---|
92 | var sel_nm = Element("sel_name_box"); |
---|
93 | var opt = new Option(get_lang("Select the user"),"-1",true,true); |
---|
94 | sel_nm.options[sel_nm.length] = opt; |
---|
95 | var reg = /user(\.|\/)(.*)$/; |
---|
96 | for(var i=0; i < folders.length; i++){ |
---|
97 | if(reg.test(folders[i].folder_id)) |
---|
98 | continue; |
---|
99 | var level = parseInt(folders[i].folder_id.split(cyrus_delimiter).length); |
---|
100 | var ident = ''; |
---|
101 | for(var j = 2;level > 2 && j < level; j++) |
---|
102 | ident += ' - '; |
---|
103 | var opt = new Option(ident+lang_folder(folders[i].folder_name),folders[i].folder_id,false,true); |
---|
104 | sel_nm.options[sel_nm.length] = opt; |
---|
105 | } |
---|
106 | sel_nm.options[0].selected = true; |
---|
107 | _this.clean_all(); |
---|
108 | } |
---|
109 | _this.load_form(); |
---|
110 | } |
---|
111 | |
---|
112 | // Preenche os campos no form; |
---|
113 | Preferences.prototype.load_form = function(){ |
---|
114 | var sel_num_max = Element("sel_num_max"); |
---|
115 | for(var i=0; i < sel_num_max.options.length; i++){ |
---|
116 | if(sel_num_max.options[i].value == preferences.max_email_per_page){sel_num_max.options[i].selected = true;} |
---|
117 | } |
---|
118 | var check_save_men = Element("check_save_men"); |
---|
119 | if( preferences.save_deleted_msg == 1){check_save_men.checked = true;} |
---|
120 | var sel_del_men = Element("sel_del_men"); |
---|
121 | for(var i=0; i < sel_del_men.options.length; i++){ |
---|
122 | if(sel_del_men.options[i].value == preferences.delete_trash_messages_after_n_days){sel_del_men.options[i].selected = true;} |
---|
123 | } |
---|
124 | var check_show_previous = Element("check_show_previous"); |
---|
125 | if( preferences.delete_and_show_previous_message == 1){check_show_previous.checked = true;} |
---|
126 | var check_alert = Element("check_alert"); |
---|
127 | if( preferences.alert_new_msg == 1){check_alert.checked = true;} |
---|
128 | var check_view = Element("check_view"); |
---|
129 | if( preferences.mainscreen_showmail == 1){check_view.checked = true;} |
---|
130 | var sel_name_box = Element("sel_name_box"); |
---|
131 | for(var i=0; i < sel_name_box.options.length; i++){ |
---|
132 | if(sel_name_box.options[i].value == preferences.save_in_folder){sel_name_box.options[i].selected = true;} |
---|
133 | } |
---|
134 | var check_menu = Element("check_menu"); |
---|
135 | if( preferences.hide_folders == 1){check_menu.checked = true;} |
---|
136 | var sel_height_line = Element("sel_height_line"); |
---|
137 | for(var i=0; i < sel_height_line.options.length; i++){ |
---|
138 | if( sel_height_line.options[i].value == preferences.line_height){sel_height_line.options[i].selected = true;} |
---|
139 | } |
---|
140 | var sel_size_font = Element("sel_size_font"); |
---|
141 | for(var i=0; i < sel_size_font.options.length; i++){ |
---|
142 | if(sel_size_font.options[i].value == preferences.font_size){sel_size_font.options[i].selected = true;} |
---|
143 | } |
---|
144 | var use_dynamic_contacts = Element("use_dynamic_contacts"); |
---|
145 | if (preferences.use_dynamic_contacts == 1) { |
---|
146 | use_dynamic_contacts.checked = true; |
---|
147 | } |
---|
148 | var use_signature = Element("use_signature"); |
---|
149 | if( preferences.use_signature == 1){ |
---|
150 | use_signature.checked = true; |
---|
151 | } |
---|
152 | var txt_signature = Element("txt_signature"); |
---|
153 | txt_signature.value = preferences.signature; |
---|
154 | |
---|
155 | if ((preferences.number_of_contacts < 1) || isNaN(preferences.number_of_contacts)){ |
---|
156 | Element("use_dynamic_contacts").checked = false; |
---|
157 | Element("use_dynamic_contacts").disabled = 'disabled'; |
---|
158 | } |
---|
159 | if( preferences.use_shortcuts == 1) Element("use_shortcuts").checked = true; |
---|
160 | if( preferences.auto_save_draft == 1) Element("auto_save_draft").checked = true; |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | // Salva as opções do form; |
---|
165 | Preferences.prototype.save_form = function(){ |
---|
166 | |
---|
167 | var _this = this; |
---|
168 | //var prefe_string; |
---|
169 | var reload_page = false; |
---|
170 | |
---|
171 | if(preferences.max_email_per_page != Element("sel_num_max").value) |
---|
172 | reload_page = true; |
---|
173 | else if(preferences.delete_trash_messages_after_n_days != Element("sel_del_men").value) |
---|
174 | reload_page = true; |
---|
175 | else if(preferences.hide_folders != Element("check_menu").checked) |
---|
176 | reload_page = true; |
---|
177 | else if(preferences.line_height != Element("sel_height_line").value) |
---|
178 | reload_page = true; |
---|
179 | else if(preferences.font_size != Element("sel_size_font").value) |
---|
180 | reload_page = true; |
---|
181 | else if(preferences.use_shortcuts != Element("use_shortcuts").checked) |
---|
182 | reload_page = true; |
---|
183 | else if(preferences.auto_save_draft != Element("auto_save_draft").checked) |
---|
184 | reload_page = true; |
---|
185 | else if(preferences.use_dynamic_contacts != Element("use_dynamic_contacts").checked) { |
---|
186 | reload_page = true; |
---|
187 | _this.delete_dynamic_contacts(); |
---|
188 | } |
---|
189 | |
---|
190 | preferences.max_email_per_page = Element("sel_num_max").value; |
---|
191 | preferences.save_deleted_msg = Element("check_save_men").checked ? 1 : 0; |
---|
192 | preferences.delete_trash_messages_after_n_days = Element("sel_del_men").value; |
---|
193 | preferences.delete_and_show_previous_message = Element("check_show_previous").checked ? 1 : 0; |
---|
194 | preferences.alert_new_msg = Element("check_alert").checked ? 1 : 0; |
---|
195 | preferences.mainscreen_showmail = Element("check_view").checked ? 1 : 0; |
---|
196 | preferences.save_in_folder = Element("sel_name_box").value; |
---|
197 | preferences.hide_folders = Element("check_menu").checked ? 1 : 0; |
---|
198 | preferences.line_height = Element("sel_height_line").value; |
---|
199 | preferences.font_size = Element("sel_size_font").value; |
---|
200 | preferences.use_signature = Element("use_signature").checked ? 1 : 0; |
---|
201 | preferences.signature = Element("txt_signature").value; |
---|
202 | preferences.use_dynamic_contacts = Element("use_dynamic_contacts").checked ? 1 : 0; |
---|
203 | preferences.use_shortcuts = Element("use_shortcuts").checked ? 1 : 0; |
---|
204 | preferences.auto_save_draft = Element("auto_save_draft").checked ? 1 : 0; |
---|
205 | |
---|
206 | |
---|
207 | var handler_preferences = function(data){ |
---|
208 | if(data && data.success){ |
---|
209 | if(reload_page) |
---|
210 | window.location.reload(true); |
---|
211 | else |
---|
212 | _this.close_win(); |
---|
213 | }else{ |
---|
214 | alert(data); |
---|
215 | } |
---|
216 | } |
---|
217 | var args = "$this.db_functions.update_preferences"; |
---|
218 | var params = "prefe_string="+url_encode(connector.serialize(preferences)); |
---|
219 | cExecute(args,handler_preferences,params); |
---|
220 | } |
---|
221 | //Fecha a janela |
---|
222 | Preferences.prototype.close_win = function(){ |
---|
223 | this.prefeW['window_confexp'].close(); |
---|
224 | } |
---|
225 | |
---|
226 | // Salva uma unica preferencia |
---|
227 | Preferences.prototype.save = function(key, value){ |
---|
228 | var _this = this; |
---|
229 | var handler_preferences = function(data){ |
---|
230 | if(data && data.success) |
---|
231 | return; |
---|
232 | else |
---|
233 | alert(data); |
---|
234 | } |
---|
235 | preferences[key] = value; |
---|
236 | var args = "$this.db_functions.update_preferences"; |
---|
237 | var params = "prefe_string="+url_encode(connector.serialize(preferences)); |
---|
238 | cExecute(args,handler_preferences,params); |
---|
239 | } |
---|
240 | |
---|
241 | //Limpa os campos |
---|
242 | Preferences.prototype.clean_all = function(){ |
---|
243 | document.getElementById('check_save_men').checked = false; |
---|
244 | document.getElementById('check_show_previous').value = false; |
---|
245 | document.getElementById('check_alert').checked = false; |
---|
246 | document.getElementById('check_view').checked = false; |
---|
247 | document.getElementById('check_menu').checked = false; |
---|
248 | document.getElementById("sel_name_box").options[0].selected = true; |
---|
249 | document.getElementById("use_signature").checked = false; |
---|
250 | document.getElementById('txt_signature').value = ""; |
---|
251 | document.getElementById("use_dynamic_contacts").checked = false; |
---|
252 | } |
---|
253 | |
---|
254 | //Monta a janela principal da aplicação; |
---|
255 | Preferences.prototype.showWindow = function(div){ |
---|
256 | |
---|
257 | if(! this.prefeW[div.id]) { |
---|
258 | div.style.height = is_ie ? "385px" : "370px"; |
---|
259 | div.style.width = "515px"; |
---|
260 | div.style.visibility = "hidden"; |
---|
261 | div.style.position = "absolute"; |
---|
262 | div.style.paddingLeft = "10px"; |
---|
263 | var title = get_lang("ExpressoMail 1.2 Configuration"); |
---|
264 | var wHeight = "480px"; |
---|
265 | var wWidth = "530px"; |
---|
266 | |
---|
267 | win = new dJSWin({ |
---|
268 | id: 'cc_'+div.id, |
---|
269 | content_id: div.id, |
---|
270 | width: wWidth, |
---|
271 | height: wHeight, |
---|
272 | title_color: '#3978d6', |
---|
273 | bg_color: '#eee', |
---|
274 | title: title, |
---|
275 | title_text_color: 'white', |
---|
276 | button_x_img: '../phpgwapi/images/winclose.gif', |
---|
277 | border: true }); |
---|
278 | |
---|
279 | this.prefeW[div.id] = win; |
---|
280 | win.draw(); |
---|
281 | } |
---|
282 | else { |
---|
283 | win = this.prefeW[div.id]; |
---|
284 | |
---|
285 | } |
---|
286 | win.open(); |
---|
287 | } |
---|
288 | Preferences.prototype.delete_dynamic_contacts = function(){ |
---|
289 | var handler = function(data){} |
---|
290 | var args = "$this.dynamic_contacts.delete_dynamic_contacts"; |
---|
291 | var params = ""; |
---|
292 | cExecute(args,handler,params); |
---|
293 | } |
---|
294 | // Cria o objeto |
---|
295 | var prefe; |
---|
296 | prefe = new Preferences(); |
---|