/**************************************************************************\
Início
\**************************************************************************/
function Preferences(){
this.prefeW = new Array;
}
// Cria as divs;
Preferences.prototype.showList = function(){
id = '1';
_this = this;
form_pref = document.createElement("DIV");
form_pref.style.visibility = "hidden";
form_pref.style.position = "absolute";
form_pref.id = "window_confexp";
document.body.appendChild(form_pref);
prefe.showWindow(form_pref);
var form = Element("form_preferences");
if(!form) {
form = document.createElement("FORM");
form.id = "form_preferences";
form.innerHTML = "
";
form_pref.appendChild(form);
var sel_nm = Element("sel_name_box");
var opt = new Option(get_lang("Select the user"),"-1",true,true);
sel_nm.options[sel_nm.length] = opt;
var reg = /user(\.|\/)(.*)$/;
for(var i=0; i < folders.length; i++){
if(reg.test(folders[i].folder_id))
continue;
var level = parseInt(folders[i].folder_id.split(cyrus_delimiter).length);
var ident = '';
for(var j = 2;level > 2 && j < level; j++)
ident += ' - ';
var opt = new Option(ident+lang_folder(folders[i].folder_name),folders[i].folder_id,false,true);
sel_nm.options[sel_nm.length] = opt;
}
sel_nm.options[0].selected = true;
_this.clean_all();
}
_this.load_form();
}
// Preenche os campos no form;
Preferences.prototype.load_form = function(){
var sel_num_max = Element("sel_num_max");
for(var i=0; i < sel_num_max.options.length; i++){
if(sel_num_max.options[i].value == preferences.max_email_per_page){sel_num_max.options[i].selected = true;}
}
var check_save_men = Element("check_save_men");
if( preferences.save_deleted_msg == 1){check_save_men.checked = true;}
var sel_del_men = Element("sel_del_men");
for(var i=0; i < sel_del_men.options.length; i++){
if(sel_del_men.options[i].value == preferences.delete_trash_messages_after_n_days){sel_del_men.options[i].selected = true;}
}
var check_show_previous = Element("check_show_previous");
if( preferences.delete_and_show_previous_message == 1){check_show_previous.checked = true;}
var check_alert = Element("check_alert");
if( preferences.alert_new_msg == 1){check_alert.checked = true;}
var check_view = Element("check_view");
if( preferences.mainscreen_showmail == 1){check_view.checked = true;}
var sel_name_box = Element("sel_name_box");
for(var i=0; i < sel_name_box.options.length; i++){
if(sel_name_box.options[i].value == preferences.save_in_folder){sel_name_box.options[i].selected = true;}
}
var check_menu = Element("check_menu");
if( preferences.hide_folders == 1){check_menu.checked = true;}
var sel_height_line = Element("sel_height_line");
for(var i=0; i < sel_height_line.options.length; i++){
if( sel_height_line.options[i].value == preferences.line_height){sel_height_line.options[i].selected = true;}
}
var sel_size_font = Element("sel_size_font");
for(var i=0; i < sel_size_font.options.length; i++){
if(sel_size_font.options[i].value == preferences.font_size){sel_size_font.options[i].selected = true;}
}
var use_dynamic_contacts = Element("use_dynamic_contacts");
if (preferences.use_dynamic_contacts == 1) {
use_dynamic_contacts.checked = true;
}
var use_signature = Element("use_signature");
if( preferences.use_signature == 1){
use_signature.checked = true;
}
var txt_signature = Element("txt_signature");
txt_signature.value = preferences.signature;
if ((preferences.number_of_contacts < 1) || isNaN(preferences.number_of_contacts)){
Element("use_dynamic_contacts").checked = false;
Element("use_dynamic_contacts").disabled = 'disabled';
}
if( preferences.use_shortcuts == 1) Element("use_shortcuts").checked = true;
if( preferences.auto_save_draft == 1) Element("auto_save_draft").checked = true;
}
// Salva as opções do form;
Preferences.prototype.save_form = function(){
var _this = this;
//var prefe_string;
var reload_page = false;
if(preferences.max_email_per_page != Element("sel_num_max").value)
reload_page = true;
else if(preferences.delete_trash_messages_after_n_days != Element("sel_del_men").value)
reload_page = true;
else if(preferences.hide_folders != Element("check_menu").checked)
reload_page = true;
else if(preferences.line_height != Element("sel_height_line").value)
reload_page = true;
else if(preferences.font_size != Element("sel_size_font").value)
reload_page = true;
else if(preferences.use_shortcuts != Element("use_shortcuts").checked)
reload_page = true;
else if(preferences.auto_save_draft != Element("auto_save_draft").checked)
reload_page = true;
else if(preferences.use_dynamic_contacts != Element("use_dynamic_contacts").checked) {
reload_page = true;
_this.delete_dynamic_contacts();
}
preferences.max_email_per_page = Element("sel_num_max").value;
preferences.save_deleted_msg = Element("check_save_men").checked ? 1 : 0;
preferences.delete_trash_messages_after_n_days = Element("sel_del_men").value;
preferences.delete_and_show_previous_message = Element("check_show_previous").checked ? 1 : 0;
preferences.alert_new_msg = Element("check_alert").checked ? 1 : 0;
preferences.mainscreen_showmail = Element("check_view").checked ? 1 : 0;
preferences.save_in_folder = Element("sel_name_box").value;
preferences.hide_folders = Element("check_menu").checked ? 1 : 0;
preferences.line_height = Element("sel_height_line").value;
preferences.font_size = Element("sel_size_font").value;
preferences.use_signature = Element("use_signature").checked ? 1 : 0;
preferences.signature = Element("txt_signature").value;
preferences.use_dynamic_contacts = Element("use_dynamic_contacts").checked ? 1 : 0;
preferences.use_shortcuts = Element("use_shortcuts").checked ? 1 : 0;
preferences.auto_save_draft = Element("auto_save_draft").checked ? 1 : 0;
var handler_preferences = function(data){
if(data && data.success){
if(reload_page)
window.location.reload(true);
else
_this.close_win();
}else{
alert(data);
}
}
var args = "$this.db_functions.update_preferences";
var params = "prefe_string="+url_encode(connector.serialize(preferences));
cExecute(args,handler_preferences,params);
}
//Fecha a janela
Preferences.prototype.close_win = function(){
this.prefeW['window_confexp'].close();
}
// Salva uma unica preferencia
Preferences.prototype.save = function(key, value){
var _this = this;
var handler_preferences = function(data){
if(data && data.success)
return;
else
alert(data);
}
preferences[key] = value;
var args = "$this.db_functions.update_preferences";
var params = "prefe_string="+url_encode(connector.serialize(preferences));
cExecute(args,handler_preferences,params);
}
//Limpa os campos
Preferences.prototype.clean_all = function(){
document.getElementById('check_save_men').checked = false;
document.getElementById('check_show_previous').value = false;
document.getElementById('check_alert').checked = false;
document.getElementById('check_view').checked = false;
document.getElementById('check_menu').checked = false;
document.getElementById("sel_name_box").options[0].selected = true;
document.getElementById("use_signature").checked = false;
document.getElementById('txt_signature').value = "";
document.getElementById("use_dynamic_contacts").checked = false;
}
//Monta a janela principal da aplicação;
Preferences.prototype.showWindow = function(div){
if(! this.prefeW[div.id]) {
div.style.height = is_ie ? "385px" : "370px";
div.style.width = "515px";
div.style.visibility = "hidden";
div.style.position = "absolute";
div.style.paddingLeft = "10px";
var title = get_lang("ExpressoMail 1.2 Configuration");
var wHeight = "480px";
var wWidth = "530px";
win = new dJSWin({
id: 'cc_'+div.id,
content_id: div.id,
width: wWidth,
height: wHeight,
title_color: '#3978d6',
bg_color: '#eee',
title: title,
title_text_color: 'white',
button_x_img: '../phpgwapi/images/winclose.gif',
border: true });
this.prefeW[div.id] = win;
win.draw();
}
else {
win = this.prefeW[div.id];
}
win.open();
}
Preferences.prototype.delete_dynamic_contacts = function(){
var handler = function(data){}
var args = "$this.dynamic_contacts.delete_dynamic_contacts";
var params = "";
cExecute(args,handler,params);
}
// Cria o objeto
var prefe;
prefe = new Preferences();