// //********************************************************************** // TWidget - funkce pro praci s s widgety //********************************************************************** function dpa() { var str=''; for(var r in arguments) str=str+arguments[r]+"\n"; alert(str); } function dpc(a) { var c=''; for(var b in a) c=c+b+": "+a[b]+"\n"; alert(c); } function TWidget() {} TWidget.init = function(okno) { if(okno.TWidget && okno.TWidget.proxies) { TWidget=okno.TWidget; } else { TWidget.proxies=new TProxies(); TWidget.browser = TWidget.getBrowser(); TWidget.cache=new TCaches(); TWidget.okno=okno; TWidget.document=okno.document; TWidget.ActionsID=0; TWidget.RunningCount=0; } } TWidget.initDetect = function(okno) { if(typeof(WidgetMainWindow)=='undefined') { var oldokno=okno; while(okno.parent!=okno && (okno.TWidget==undefined || okno.TWidget.proxies==undefined)) okno=okno.parent; if(okno.TWidget==undefined) okno=oldokno; } else okno=WidgetMainWindow; TWidget.init(okno); TCache = TWidget.okno.TCache; TCaches = TWidget.okno.TCaches; TAction = TWidget.okno.TAction; TActions = TWidget.okno.TActions; TProxy = TWidget.okno.TProxy; TProxies = TWidget.okno.TProxies; TSavedWidget = TWidget.okno.TSavedWidget; if(TWidget.okno.sid !=undefined) TWidget.sid = TWidget.okno.sid; } TWidget.getElement=function(id) { return TWidget.document.getElementById(id); } TWidget.documentBody=function() { return TWidget.document.getElementsByTagName('body')[0] } TWidget.getBrowser = function() { var n=navigator.appName if(navigator.appName == "Microsoft Internet Explorer") return 0; return 1; } //********************************************************************** // TCache - objekt k ukladani Html fragmentu //********************************************************************** function TCache() { this.cache = new Object(); } TCache.prototype.get = function(key) { if(this.cache[key]!=undefined) return this.cache[key]; return null; } TCache.prototype.add = function(proxy,masterKey) { this.addData(masterKey,new TSavedWidget(proxy)); } TCache.prototype.addData = function(key,data) { this.cache[key]=data; } TCache.prototype.invalidate=function(key) { this.cache[key]=undefined; } TCache.prototype.clear = function() { this.cache=new Object; } TCache.prototype.restore = function(masterKey) { var data=this.get(masterKey); if(data) //obnovuji z cache { data.restore(); return true; } return false; } ////***************************************///// function TCaches() { this.objs=new Object(); } TCaches.prototype.init=function(id) { if(!this.objs[id]) this.objs[id]=new TCache; } TCaches.prototype.exchange=function(id,id2) { this.init(id2); var a=this.cache[id]; this.objs[id]=this.objs[id2]; this.objs[id2]=a; } TCaches.prototype.get=function(id) { return this.objs[id]; } TCaches.prototype.cache = function(proxy,masterKey) { this.get(proxy.id).add(proxy,masterKey); } TCaches.prototype.restore = function(proxy,newKey) { var cache=this.get(proxy.id); proxy.updating=undefined; return cache.restore(newKey); } //********************************************************************** //TSavedWidget - informace o ulozenem widgetu (content, proxy) //********************************************************************** function TSavedWidget(proxy) { this.id = proxy.id; this.content = proxy.getElement().innerHTML; this.proxies=Array(); this.addProxies(proxy); } TSavedWidget.prototype.restore = function() { var w=TWidget.getElement(this.id); w.innerHTML = this.content; for(var i in this.proxies) { var proxy=TWidget.proxies.get(i); proxy.safeCallAction("restore",proxy,this.proxies[i]); } var proxy=TWidget.proxies.get(this.id); if(proxy.slaves) for(var i in proxy.slaves) proxy.slaves[i].safeCallAction("update",proxy.store.key); } TSavedWidget.prototype.addProxies = function(proxy) { this.proxies[proxy.id]=proxy.safeCallAction("cache",proxy); if(proxy.members) for(var i in proxy.members) { if(TWidget.getElement(i)) this.addProxies(proxy.members[i]); } } function widget_cache(id,proxy) { return cloneObject(proxy.store); } function widget_restore(id,proxy,storeObject) { proxy.store=cloneObject(storeObject); } //********************************************************************** // TAction - objekt odesilajici pozadavky skriptu //********************************************************************** function TAction(id,name,addAction) { if(typeof id == 'object') id=id.id; this.id = id; this.name = name; this.params = new Object(); this.toAdd = addAction; this.action=TActions.get(); this.zarazena = false; } TAction.prototype.addParam = function(name,value) { this.params[name]=value; } TAction.prototype.cancel = function() { if(this.zarazena) this.action.remove(this); this.action.close(); } TAction.prototype.zarad = function() { if(this.zarazena) return; if(this.toAdd) this.action.add(this); else this.action.replace(this); this.zarazena=true; } TAction.prototype.close = function() { this.zarad(); return this.action.close(); } TAction.prototype.submit = function() { this.zarad(); this.action.submit(); } function TActions() { this.objects = new Object(); this.actions = Array(); this.toSubmit = false; this.leases = 0; } TActions.prototype.add = function(co) { if(!this.objects[co.id]) this.objects[co.id]=new Object; this.objects[co.id]=this.actions.push(co)-1; } TActions.prototype.remove = function(co) { if(!this.objects[co.id]) return; if(this.objects[co.id][co.name]!=undefined) this.objects[co.id][co.name]=undefined; } TActions.prototype.replace = function(co) { if(!this.objects[co.id]) this.objects[co.id]=new Object; else if(this.objects[co.id][co.name]!=undefined) { this.actions[this.objects[co.id][co.name]]=co; return this.objects[co.id][co.name]; } return this.objects[co.id][co.name]=this.actions.push(co)-1; } TActions.prototype.submit = function() { this.toSubmit = true; this.close(); } TActions.beginUpdate = function() { if(TWidget.RunningCount++==0) { var x=TWidget.getElement('widget_actionActive'); if(x) x.style.display='block'; x=TWidget.getElement('widget_actionDone'); if(x) x.style.display='none'; } } TActions.endUpdate = function() { if(--TWidget.RunningCount==0) { var x=TWidget.getElement('widget_actionActive'); if(x) x.style.display='none'; x=TWidget.getElement('widget_actionDone'); if(x) x.style.display='block'; } } TActions.SendUrl = function(url) { var i=TWidget.document.createElement('iframe'); var body=TWidget.documentBody(); i.style.display='none'; //i.style.position = 'absolute'; i.id='widget:iframe:'+(TWidget.ActionsID++); body.appendChild(i); //TWidget.document.getElementById('menu').innerHTML = url+'&frame='+i.id; i.src=url+'&frame='+i.id; TActions.beginUpdate(); } TActions.removeActionFrame = function(id) { var iff=TWidget.getElement(id); TWidget.documentBody().removeChild(TWidget.getElement(id)); TActions.endUpdate(); } TActions.prototype.send= function() { if(TWidget.document.widgetActions == this) TWidget.document.widgetActions = undefined; var url=location.href.replace("&session:new=","&w:session:new="); if(url.indexOf('?')>=0) url=url+'&'; else url=url+'?'; for(var i=0;i selem.scrollTop + selem.clientHeight) { selem.scrollTop = off-(selem.clientHeight - el.offsetHeight )/2; } } TWidget.initDetect(this);