/* Copyright 2006 por Connecty Networks. Todos os direitos reservados */
function Rss() { this.init(); this.cfg = { title: "Origo RSS Reader", module: "Rss"
}
this.defaultProfile["newsCount"] = 8; this.defaultProfile["open_directly"] = 0; this.defaultProfile["url"] = ""; this.defaultProfile["icon"] = ""; this.defaultProfile["period"] = 300; this.domSettings = [ { tag: "div", className: "settings_section", childs: [ { tag: "span", className: "settings_label", innerHTML: "Not&iacute;cias a mostrar: "}, { tag: "select", id: "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:"9999", text: "Todas"}
]
}, { tag: "input", type: "button", value: " Definir ", events: {onclick: "setNewsCount()"}}
]
}, { tag: "div", className: "settings_section", childs: [ { tag: "span", className: "settings_label", innerHTML: "Verificar not&iacute;cias: "}, { tag: "select", id: "period", className: "settings_control", options: [ { value:"120", text: "2 min"}, { value:"300", text: "5 min"}, { value:"600", text: "10 min"}, { value:"1200", text: "20 min"}, { value:"1800", text: "30 min"}, { value:"3600", text: "1 hora"}, { value:"10800", text: "3 horas"}
]
}, { tag: "input", type: "button", value: " Definir ", events: {onclick: "setPeriod()"}}
]
}, { tag: "div", className: "settings_section", childs: [ { tag: "span", className: "settings_label", innerHTML: "Abrir directamente no site: "}, { tag: "input", type: "checkbox", id: "open_directly", events: { onclick: "setOpenDirectly()"}
}
]
}
]
this.lastRefresh = null
this.isLoading = false; this.onBuildInterface = function() { this.buildDomModel(this.elements.settings, this.domSettings); this.elements.period.value = this.profile.period; this.elements.news_count.value = this.profile.newsCount; this.elements.open_directly.checked = this.profile.open_directly == 1; this.elements.content.style.padding = "6px"; hideEl(this.elements.icon);}
this.setOpenDirectly = function() { this.profile.open_directly = this.elements.open_directly.checked ? 1 : 0; this.save();}
this.setNewsCount = function() { this.profile.newsCount = this.elements.news_count.value; this.save(); this.renderChannel();}
this.setPeriod = function() { this.profile.period = this.elements.period.value; kernel.stopTimer(this.id); kernel.processTimer(this.id, this.profile.period * 1000, true); this.save();}
this.onOpen = function() { kernel.processTimer(this.id, this.profile.period * 1000);}
this.timerHandler = function() { this.refresh();}
this.refresh = function() { var date = new Date(); this.lastRefresh = date.getSeconds(); this.setTitle("A verificar not&iacute;cias..."); var iconEl = this.elements.icon; var wid = this.id; var a = new Image(); if(this.profile.icon) { a.onload = function() { iconEl.src = this.src; showEl(iconEl);}
a.src = this.profile.icon;} else if(!ie_nav) { a.url2 = getIcoSrc("http://"+getDomain(this.profile.url) + "/favicon.ico"); a.onload = function() { iconEl.src = this.src; showEl(iconEl);}
a.onerror = function() { if(this.url2 != null) { iconEl.src = this.url2; showEl(iconEl); this.url2 = null;} else { this.onerror = null;}
}
a.src = getIcoSrc(getDir(this.profile.url) + "/favicon.ico");}
xmlRequest.send(this.profile.url, this, "showChannel"); this.isLoading == true;}
this.openChannel = function(wid, feedId) { if(this.profile.open_directly == 1) { window.open(this.data.items[feedId]["link"]);} else { rssreader.channelLastRefresh = this.lastRefresh; rssreader.openChannel(wid, feedId);}
}
this.showChannel = function(response) { this.isLoading == false; if(response.responseXML && response.responseXML.documentElement) { this.data = XMLParser.xml2hash(response.responseXML.documentElement); this.renderChannel();} else { this.showError();}
}
this.iconLoaded = false; this.renderChannel = function() { if(this.data) { if(!this.iconLoaded) { var icons = [ this.profile.icon, getDir(this.data.siteUrl) + "/favicon.ico", getDomain(this.data.siteUrl) + "/favicon.ico", getDir(this.profile.url) + "/favicon.ico", getDomain(this.profile.url) + "/favicon.ico" ]; loadIcon(this.elements["icon"], icons); this.iconLoaded = true;}
this.elements.title.innerHTML = ''; this.buildDomModel(this.elements.title, createButtonDom(this.data.title.substr(0,25), "openSite()")); var count = Math.min(this.data.items.length, this.profile.newsCount); this.elements.content.innerHTML = ''; for(var i=0; i<count; i++) { this.buildDomModel(this.elements.content, { tag: "div", style: {width: "100%", padding: "0px"}, childs: [ createButtonDom(this.data.items[i].title.wordWrap(38), "openChannel("+this.id+","+i+")", "img/li.gif") ]});}
} else if (!this.isLoading) { this.showError();}
}
this.showError = function() { this.elements.title.innerHTML = 'Erro ao carregar Feed';}
this.openSite = function() { if(this.data) { window.open(this.data.siteUrl);}
}
}
Rss.prototype = new Widget();