/* Copyright 2006 por Connecty Networks. Todos os direitos reservados */
cfgWidget = { hasIcon: true, hasSizeBtn: true, hasCloseBtn: true, hasRefreshBtn: true, hasSettingsBtn: true, hasDrag: true, hasOnCloseConfirm: false, hasProfile: true, isOpenHidden: false, isSystem: false, title: "Origo widget", module: "base", saveMethod: "GET"
}
SYSWIDGET_WKEY = 5000; domTitleSettings = [ { tag: "div", className: "settings_section", childs: [ {tag: "span", innerHTML: "Título:", className: "settings_label"}, {tag: "input", id: "input_title", type: "text", size: "15", className: "settings_control"}, {tag: "input", type: "button", value: " Guardar ", events: {onclick: "settingsSetTitle()"}, className: "settings_control"} ]}
]
function Widget() { this.defaultProfile = { title: "Origo widget", titleColor: ""
}
this.init = function() { this.elements = {}; this.id = null; this.isReduced = false; this.isSettingsReduced = true; this.profile = {}; this.domModel = { tag: "div", className: "panel", id: "window", childs: { caption: { tag: "div", className: "caption", id: "caption", childs: { caption_table: { tag: "table", className: "sys_table", width: "100%", childs: { caption_tr: { tag: "tr", childs: {}
}}
}}}, settings: { tag: "div", className: "settings", id: "settings" }, content: { tag: "div", className: "content", id: "content" }
}
}
}
this.init(); this.open = function(parent, id, profile) { this.id = id ? id : kernel.getUniqueId(); for(c in cfgWidget) { if(typeof(this.cfg[c]) == "undefined") { this.cfg[c] = cfgWidget[c];}
}
if(this.cfg.hasProfile) { profiler.addWidget(this); if(profile) { for(p in profile) { this.profile[p] = profile[p];}
}
}
this.buildWindow(parent); this.buildInterface(); if(this.elements.window) { this.elements.window.wid = this.id;}
kernel.addWidget(this); this.onOpen();}
this.setParent = function(parentEl) { this.elements.window.parentNode.removeChild(this.elements.window); parentEl.appendChild(this.elements.window);}
this.buildWindow = function(parent) { this.domModel.display = !this.cfg.isOpenHidden; with(this.domModel.childs.caption.childs.caption_table.childs.caption_tr) { if(this.cfg.hasSizeBtn) { childs.size_td = { tag: "td", width: 18, childs: [ { tag: "a", href: "void" ,events: {onclick: "switchSize()"}, childs: [ {tag: "img", id: "btn_hide", src: theme.icons.hide}, {tag: "img", id: "btn_show", src: theme.icons.show, display: false}]
}] };}
if(this.cfg.hasIcon) { childs.icon_td = { tag: "td", width: 18, childs: [{tag: "img", id: "icon", src: "widgets/"+this.cfg.module.toLowerCase()+"/ico.gif"}] };}
childs.title = { tag: "td", width: "100%", childs: [{ tag: "div", align: "left", id: "title", className: "caption_title"}] }; if(this.cfg.hasSettingsBtn) { childs.settings_td = { tag: "td", width: 18, childs: [ createButtonDom(false, "switchSettings()", theme.icons.edit) ]
};}
if(this.cfg.hasRefreshBtn) { childs.refresh_td = { tag: "td", width: 18, childs: [ createButtonDom(false, "refresh()", theme.icons.refresh) ]
}
}
if(this.cfg.hasCloseBtn) { childs.close_td = { tag: "td", width: 18, childs: [ createButtonDom(false, "close()", theme.icons.close) ]
};}
}
this.buildDomModel(parent, this.domModel);}
this.buildInterface = function() { if(this.cfg.hasDrag) { this.elements.caption.style.cursor = 'move'; this.elements.window.drag = new Drag(this.elements.caption, this.elements.window);}
this.buildDomModel(this.elements.settings, domTitleSettings); this.setCaptionColor(this.profile.titleColor); this.onBuildInterface();}
this.close = function() { var flag = this.cfg.hasOnCloseConfirm ? confirm('Tem a certeza que deseja fechar este widget '+this.cfg.title+' ?') : true; if(flag) { kernel.freeWidget(this.id); this.onClose(); if(this.elements.window.parentNode) { this.elements.window.parentNode.removeChild(this.elements.window);}
this.elements.window.innerHTML = ''; this.elements.window = null;}
this.profile = false; this.save(); desktop.savePanels();}
this.setTitle = function(html) { this.elements.title.innerHTML = html;}
this.switchSize = function() { if(this.isReduced) { this.show();} else { this.hide();}
}
this.show = function() { hideEl(this.elements.btn_show); showEl(this.elements.btn_hide); if(this.elements.content) { showEl(this.elements.content);}
this.onShow(); this.isReduced = false;}
this.hide = function() { hideEl(this.elements.btn_hide); showEl(this.elements.btn_show); if(this.elements.content) { hideEl(this.elements.content);}
this.isReduced = true; this.hideSettings(); this.onHide();}
this.switchSettings = function() { if(this.isSettingsReduced) { this.showSettings();} else { this.hideSettings();}
this.isSettingsReduced = !this.isSettingsReduced;}
this.showSettings = function() { this.onShowSettings(); showEl(this.elements.settings);}
this.hideSettings = function() { if(this.elements.settings) { hideEl(this.elements.settings);}
}
this.getSignature = function() { return this.id;}
this.buildDomModel = function(parentEl, data) { if(data['tag']) { var el = document.createElement(data.tag); for (p in data) { switch(p) { case null, "tag", "childs": break; case "id":
this.elements[data.id] = el; break; case "style":
for(var s in data.style) { el.style[s] = data.style[s];}
break; case "options":
for(var i in data.options) { el.options.add(new Option(data.options[i].text, data.options[i].value));}
break; case "src":
var src = data.src; if(src.indexOf("http") == -1) { src = "http://"+baseUrl+src;}
if(ie_nav) { var setSrc = function() { el.src = src }
setTimeout(setSrc, 200);} else { el.src = src;}
break; case "display":
if(!data[p]) { el.style.display = 'none';}
break; case "href":
if(data.events && data.events.onclick) { data.href = "void";}
el.href = "javascript:"+ ((data.href == "void") ? "void(0);" : "kernel.getWidget("+this.id+")."+data.href+";"); break; case "sysHref":
el.href = data.sysHref; break; case "events":
var wid = this.id; if(typeof(data.events) == "object") { for(var e in data.events) { if(mozilla_nav) { el.setAttribute(e, "kernel.getWidget("+wid+")."+data.events[e]+";");} else { el[e] = new Function("kernel.getWidget("+wid+")."+data.events[e]+";");}
}
}
break; case "sysEvents":
if(typeof(data.sysEvents) == "object") { for(var e in data.sysEvents) { el.setAttribute(e, data.sysEvents[e]+";");}
}
break; default:
el[p] = data[p]; break;}
}
parentEl.appendChild(el); if(data.tag == "table") { parentEl = el; var el = document.createElement("tbody"); if(data.id) { this.elements[data.id+"_tbody"] = el;}
parentEl.appendChild(el);}
if(data.childs) { this.buildDomModel(el, data.childs);}
} else { for(var e in data) { this.buildDomModel(parentEl, data[e]);}
}
}
this.settingsSetTitle = function() { this.profile.title = trim(this.elements.input_title.value); this.setTitle(this.profile.title); this.save();}
this.setCaptionColor = function(color) { this.elements.caption.style.backgroundColor = color;}
this.actionSetCaptionColor = function(color) { this.profile.titleColor = color; this.setCaptionColor(color); this.save();}
this.save = function() { profiler.saveProfile(this);}
this.currentPopup = false; this.showPopup = function(btnEl, popupEl) { if(this.currentPopup) { if(this.currentPopup == popupEl) return; this.closePopup(this.currentPopup);}
this.currentPopup = popupEl; var pos = {left: getLeft(this.elements[btnEl]) + 16, top: getTop(this.elements[btnEl]) + 16}; showEl(this.elements[popupEl]); setElPos(this.elements[popupEl], pos);}
this.closePopup = function(popupEl) { hideEl(this.elements[popupEl]); this.currentPopup = false;}
this.selectColor = function(popupEl, target, color) { this.closePopup(popupEl); this.onSelectColor(target, color);}
this.selectFont = function(popupEl, target, font) { this.closePopup(popupEl); this.onSelectFont(target, font);}
this.selectFontSize = function(popupEl, target, fontSize) { this.closePopup(popupEl); this.onSelectFontSize(target, fontSize);}
this.onOpen = function() {}
this.onBuildInterface = function() {}
this.onClose = function() {}
this.onShow = function() {}
this.onHide = function() {}
this.onShowSettings = function() {}
this.onDrag = function() {}
this.onSelectColor = function(target, color) {}
this.onSelectFont = function(target, font) {}
this.onSelectFontSize = function(target, fontSize) {}
this.timerHandler = function() {}
this.refresh = function() {}
this.dispatchMsg = function() {}
}