/* Copyright 2006 por Connecty Networks. Todos os direitos reservados */
function YahooMail() { this.init(); this.cfg = { hasSettingsBtn: true, title: "Yahoo! mail", module: "YahooMail"
}
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;s 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", 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/yahoomail/yahoo.gif\" align=left>", width: "1%"}, {content: "<b>Novas&nbsp;mensagens:</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/yahoomail/yahoo.gif\" align=left>", width: "1%"}, {content: "A verificar novos e-mails...", width: "100%"}])
]
}, { tag: "div", className: "menu_panel", id: "config_note", display: false, childs: [ createTableDom([{content: "<img src=\"widgets/yahoomail/yahoo.gif\" align=left>", width: "1%"}, {content: "O seu Yahoo! ainda nao foi configurado, use o bot&atilde;o 'Editar' para definir a sua conta e palavra-chave.", width: "100%"}])
]
}, { tag: "div", className: "menu_panel", id: "no_messages_note", childs: [ createTableDom([{content: "<img src=\"widgets/yahoomail/yahoo.gif\" align=left>", width: "1%"}, {content: "Sem novas mensagens.", width: "100%"}])
]
}
]
this.defaultProfile["login"] = ""; this.defaultProfile["password"] = ""; this.defaultProfile["title"] = "Yahoo! Mail"; 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_news_count.value = this.profile.news_count; this.setTitle(this.profile.title);}
this.onOpen = function() { kernel.processTimer(this.id, 30000);}
this.timerHandler = function() { if(this.isProfileEmpty()) { this.setContent("config_note");} else { this.refresh();}
}
this.isProfileEmpty = function() { return this.profile.login == "" || this.profile.password == "";}
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.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.refresh = function() { if(!this.isProfileEmpty()) { this.setContent("loading_note"); request.send({ login: this.profile.login, password: this.profile.password, protocol: "/pop3", server: "pop.mail.yahoo.fr", port: "110" }, 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;}
}
}
YahooMail.prototype = new Widget();