/* Copyright 2006 por Connecty Networks. Todos os direitos reservados */
function PopMail() { this.init(); this.cfg = { hasSettingsBtn: true, title: "E-mail POP", module: "PopMail"
}
this.domSettings = [ { tag: "div", className: "settings_section", childs: [ { tag: "span", className: "settings_label", innerHTML: "N&uacute;mero de e-mails a mostrar: "}, { tag: "select", id: "select_news_count", className: "settings_control", options: [ { value:"3", text: "3"}, { value:"5", text: "5"}, { value:"8", text: "8"}, { value:"10", text: "10"}, { value:"12", text: "12"}, { value:"15", text: "15"}, { value:"20", text: "20"}
]
}, { tag: "input", type: "button", value: " Definir ", events: {onclick: "setNewsCount()"}, className: "settings_control"}
]
}, { tag: "div", className: "settings_section", align: "center", innerHTML: "<b>Defini&ccedil;&otilde;es de conta:</b>"}, { tag: "div", className: "settings_section", childs: [ { tag: "span", className: "settings_label", innerHTML: "Login: "}, { tag: "input", id: "select_login", type: "text", size: "15", className: "settings_control"} ]}, { tag: "div", className: "settings_section", childs: [ { tag: "span", className: "settings_label", innerHTML: "Palavra-Chave: "}, { tag: "input", id: "select_password", type: "password", size: "15", className: "settings_control"} ]}, { tag: "div", className: "settings_section", childs: [ { tag: "span", className: "settings_label", innerHTML: "Protocolo: "}, { tag: "select", id: "select_protocol", className: "settings_control", events: {onchange: "setPort()"}, options: [ { value: "pop3", text: "POP3" }, { value: "imap", text: "IMAP4" }, ]
}
]
}, { tag: "div", className: "settings_section", childs: [ { tag: "span", className: "settings_label", innerHTML: "SSL (Seguro): "}, { tag: "input", type: "checkbox", id: "select_secure", events: {onclick: "setPort()"}, className: "settings_control"} ]}, { tag: "div", className: "settings_section", childs: [ { tag: "span", className: "settings_label", innerHTML: "Servidor de e-mail: "}, { tag: "input", id: "select_server", type: "text", size: "15", className: "settings_control"} ]}, { tag: "div", className: "settings_section", childs: [ { tag: "span", className: "settings_label", innerHTML: "Porta: "}, { tag: "input", id: "select_port", type: "text", size: "5", value: "110"} ]}, { tag: "div", className: "settings_section", align: "center", childs: [ { tag: "input", type: "button", value: " Guardar ", events: {onclick: "saveProfile()"}} ]}
]
this.domContent = [ { tag: "div", className: "menu_panel", id: "messages", display: false, childs: [ { tag: "div", childs: [ createTableDom([{content: "<img src=\"widgets/popmail/ico.gif\" align=left>", width: "1%"}, {content: "<b>Mensagens&nbsp;novas:</b>", width: "1%"}, {content: {tag: "span", id: "total_messages"}, width: "100%"} ])
]
}, { tag: "div", id: "mail_list"}
]
}, { tag: "div", className: "menu_panel", id: "loading_note", childs: [ createTableDom([{content: "<img src=\"widgets/popmail/ico.gif\" align=left>", width: "1%"}, {content: "A verificar e-mails...", width: "100%"}])
]
}, { tag: "div", className: "menu_panel", id: "config_note", display: false, childs: [ createTableDom([{content: "<img src=\"widgets/popmail/ico.gif\" align=left>", width: "1%"}, {content: "A sua conta de e-mail ainda n&atilde;o foi configurada. Use o bot&atilde;o 'Editar' para configurar a sua conta.", width: "100%"}])
]
}, { tag: "div", className: "menu_panel", id: "no_messages_note", childs: [ createTableDom([{content: "<img src=\"widgets/popmail/ico.gif\" align=left>", width: "1%"}, {content: "Sem novos e-mails.", width: "100%"}])
]
}
]
this.defaultProfile["login"] = ""; this.defaultProfile["password"] = ""; this.defaultProfile["protocol"] = "pop3"; this.defaultProfile["secure"] = "0"; this.defaultProfile["server"] = ""; this.defaultProfile["port"] = "110"; this.defaultProfile["title"] = "E-mail POP"; this.defaultProfile["news_count"] = "8"; this.onBuildInterface = function() { this.buildDomModel(this.elements.settings, this.domSettings); this.buildDomModel(this.elements.content, this.domContent); this.elements.select_login.value = this.profile.login; this.elements.select_protocol.value = this.profile.protocol; this.elements.select_secure.checked = this.profile.secure == 1; this.elements.select_server.value = this.profile.server; this.elements.select_port.value = this.profile.port; this.elements.select_news_count.value = this.profile.news_count; this.setTitle(this.profile.title);}
this.setPort = function() { }
this.isProfileEmpty = function() { return this.profile.login == "" || this.profile.password == "" || this.profile.server == "";}
this.setContent = function(section) { var sections = ["config_note", "loading_note", "messages", "no_messages_note"]; for(var i = 0; i<sections.length; i++) { if(section == sections[i]) { showEl(this.elements[sections[i]]);} else { hideEl(this.elements[sections[i]]);}
}
}
this.saveProfile = function() { this.profile.login = trim(this.elements.select_login.value); this.profile.password = trim(this.elements.select_password.value); this.profile.protocol = this.elements.select_protocol.value; this.profile.secure = this.elements.select_secure.checked ? 1 : 0; this.profile.server = trim(this.elements.select_server.value); this.profile.port = trim(this.elements.select_port.value); this.save(); if(this.isProfileEmpty()) { this.setContent("config_note");} else { this.setContent("loading_note");}
this.refresh();}
this.setNewsCount = function() { this.profile.newsCount = this.elements.select_news_count.value; this.save(); this.renderMessages();}
this.onOpen = function() { kernel.processTimer(this.id, 30000);}
this.timerHandler = function() { if(this.isProfileEmpty()) { this.setContent("config_note");} else { this.refresh();}
}
this.refresh = function() { if(!this.isProfileEmpty()) { this.setContent("loading_note"); var protocol = "/" + this.profile.protocol + ((this.profile.secure == 1) ? "/ssl" : "") + "/novalidate-cert"; request.send({ login: this.profile.login, password: this.profile.password, protocol: protocol, server: this.profile.server, port: this.profile.port }, this);}
}
this.renderMessages = function() { if(this.data) { this.setContent("messages"); this.elements.total_messages.innerHTML = "<b>" + this.totalMessages + "<b>"; this.elements.mail_list.innerHTML = ''; for(var i=0; i<this.profile.news_count; i++) { this.buildDomModel(this.elements.mail_list, { tag: "div", className: "menu_panel", innerHTML: "<b>" + this.data[i].from + "</b>", childs: [ { tag: "div", className: "note", innerHTML: this.data[i].subj }
]
});}
}
}
this.dispatchMsg = function(msg) { switch(msg.status) { case "empty":
this.setContent("no_messages_note"); break; case "data":
this.data = msg.data; this.totalMessages = msg.total; this.renderMessages(); break; case "error":
this.setContent("config_note"); break;}
}
}
PopMail.prototype = new Widget();