
/*
	"Hemi" JavaScript Framework
	Engine for Web Applications 3.1
	Composite file "hemi.comp.js" release: 3.1.1
	Copyright 2002 - 2010. All Rights Reserved.
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
	Project: http://www.whitefrost.com/Hemi/
	BSD License: http://www.whitefrost.com/Hemi.license.txt
*/
(function(){H.include("hemi.util");H.include("hemi.util.logger");H.include("hemi.event");H.include("hemi.transaction");H.include("hemi.app.space");H.include("hemi.data.stack");H.namespace("app.comp",H,{p:{c:"acid",g:"accfgid",k:"appcomp_path",r:"acrid",p:"participant-id",q:"appcomp_path",x:"component",t:"template"},bindComponent:
function(o,i,c,p,a){var _a=H.app.comp,z,q=o,r;r=_a.p.r;if(typeof q==D.S){q=H.registry.service.getObject(o);if(q!=null&&typeof q.getContainer==D.F)q=q.getContainer();}if(typeof q!=D.O||q==null){H.message.service.S("Invalid ID reference '"+o+"' in bindComponent","200.4");return 0;}if(typeof q[r]==D.S){H.message.service.S("Object is already bound to '"+q[r]+"'","200.4");return 0;}z=_a.newInstance(0,0,o,0,p,1);z.setAsync(!a);z.loadComponent(i,c);if(typeof q.setAttribute==D.U)q[r]=z.i;else q.setAttribute(r,z.i);H.message.service.S("Bind to application component "+z.getObjectId(),"200.1");return z;},newInstance:
function(i,o,c,f,p,b){var n=H.newObject("application_component","3.1.1");if(typeof o==D.F)f=o;if(typeof o!=D.O)o=0;if(typeof i!=D.S)i=0;if(typeof p!=D.S)p=0;if(typeof c==D.U)c=0;else if(D.TO(c)&&D.TF(c.getObjectId))c=c.getObjectId();if(typeof b==D.U)b=0;n.o={tp:[],ts:H.data.stack.service};n.p={eic:1,edc:1,te:0,ei:0,c:0,n:0,e:c,i:1,p:"application-components",m:"application-component",a:1,h:f,b:b,eb:"change,focus,blur,mouseover,mouseout,mouseup,mousedown,click",t:1,TransactionName:p,TransactionId:0};if(i&&1)n.i=i;n.sigterm=function(){this.destroy();};n.setLoadHandler=function(f){this.p.h=f;if(this.r==4)f("oncomponentload",this);};n._handle_xhtml_token=function(i,s){var r=s;if(i==2||i==3){if(!r||!r.length||!r.match(/\$/))return r;r=r.replace(/\$\{this\}/g,"H.registry.service.getObject('"+n.i+"')");r=r.replace(/\$\{this\.id\}/g,n.i);r=r.replace(/\$\{hemi\.hemi_base\}/g,H.hemi_base);if(typeof n.local_handle_xhtml_token==D.F)r=n.local_handle_xhtml_token(i,r);}else if(i==1&&s.match(/^embedded-script$/i))return 0;return r;};n.destroy=function(){var t=this,o,i;if(t.r<5){H.message.service.unsubscribe(this,"onspaceconfigload","_handle_spaceconfig_load");H.message.service.unsubscribe(t,"onloadxml","HLX");if(typeof t.component_destroy==D.F)t.component_destroy();t.cleanTemplate();t.r=5;if(typeof this.p.e==D.S&&(o=H.registry.service.getObject(this.p.e))&&typeof o.destroy==D.F)o.destroy();var oE=this.getTemplateSpace();if(oE){H.app.space.service.clearAppSpace(oE);}H.data.stack.service.clear(t);if(H.transaction.service.isRegistered(this))H.transaction.service.removeTransactionParticipant(t,t.getPacket());H.registry.service.removeObject(t);for(i in t.o)t.o[i]=null;}};n.getDataStack=function(){return this.o.ts;};n.setAsync=function(b){this.p.a=b;};n.release=function(){this.r=2;};n.post_init=function(o,i){if(typeof this.component_post_init==D.F)this.component_post_init();};n.setTemplateIsSpace=function(b){if(b)this.getContainer().removeAttribute("space-id");this.p.te=b;};n.getTemplateSpace=function(){var _s=this.p;if(!_s.te||!_s.ei)return 0;return H.app.space.service.getSpace(_s.ei);};n.setBindingEnabled=function(b){this.p.b=b;};n.getBindingEnabled=function(){return this.p.b;};n.getDefinitionId=function(){return this.p.n;};n.setContainerId=function(s){this.p.e=s;};n.getContainerId=function(s){return this.p.e;};n.getComponentName=function(){return this.p.n;};n.getContainer=function(){var o=this.p.e;if(!o)return 0;if(typeof o==D.S)o=H.registry.service.getObject(o);if(o!=null&&typeof o.getContainer==D.F)o=o.getContainer();return o;};n.loadComponent=function(l,c){var t=this,_s,_x=H.xml,_p;_s=t.p,_p=t.o;if(typeof c!=D.S||typeof l!=D.S)return 0;_s.c=c;_s.n=l;_x.getXml(c,null,_s.a,(_s.a?t.i:c),1);};n.init=function(o){var t=this,_s;_s=t.p;H.event.addScopeBuffer(t);this.scopeHandler("load_template",0,0,1);t.r=1;if(typeof o==D.O)t.importNodeDefinition(o);};n.HLX=function(s,v){var t=this,o,_x=H.xml,x,_s;_s=t.p;if(v.id==(_s.a?t.i:_s.c)&&t.r<4){x=v.xdom;o=_x.queryNode(x.documentElement,_s.m,0,"id",_s.n);if(o!=null)t.importNodeDefinition(o);else{H.message.service.S("Invalid component definition for '"+_s.n+"' in '"+_s.m+"'","200.4");}}};n.importNodeDefinition=function(x){var i,t=this,_s,p;_s=t.p;t.r=3;if(typeof x!=D.O||x==null){H.message.service.S("Invalid object in importNodeDefinition","200.1");return 0;}i=x.getAttribute("id");p=x.getAttribute(H.app.comp.p.p);return n.importComponentDefinition(H.xml.getCDATAValue(x),i,p);};n.importComponentDefinition=function(s,i,pn){var t=this,_s,p;_s=t.p;if(typeof s!=D.S)return 0;if(typeof t.component_destroy==D.F)t.component_destroy();t.cleanTemplate();t.r=3;if(i)_s.n=i;else _s.n=H.guid();if(pn)_s.TransactionName=pn;else if(!_s.TransactionName){if(this.getReferenceId())_s.TransactionName=this.getReferenceId();else _s.TransactionName=_s.n;}s='{'+s+'}';H.util.merge(t,_s.n,s);var a,l,h,o=_s.e,ph;if(_s.b&&_s.eb&&o){if(typeof o==D.S)o=H.registry.service.getObject(o);if(o){if(typeof o.getContainer==D.F)o=o.getContainer();a=_s.eb.split(",");for(l=0;l<a.length;l++){h='_handle_'+a[l];ph='_prehandle_'+a[l];if(typeof t[ph]==D.F){H.event.removeEventListener(o,a[l],t[ph]);t[ph]=null;}if(typeof t[h]==D.F){t.scopeHandler(a[l],0,0,1);H.event.addEventListener(o,a[l],t[ph]);}}}}if(_s.t)t.joinTransactionPacket();if(typeof t.component_init==D.F)t.component_init();t.r=4;if(typeof _s.h==D.F)_s.h("oncomponentload",t);H.message.service.publish("oncomponentload",t);};n._handle_template_processor=function(o,n){if(typeof n==D.O&&n.nodeType==1){this.importEmbeddedScript(n,1);}};n.importEmbeddedScript=function(oX,b){var j,j2,a=oX.getElementsByTagName("embedded-script"),_p=this.o,i,t,x;for(i=a.length-1;i>=0;i--){t=H.xml.getInnerText(a[i]);if(!b)a[i].parentNode.removeChild(a[i]);try{eval("x={"+t+"}");for(j in x){j2=j;if(j2.match(/^embedded_init$/)){j2="embedded_init_"+this.p.eic++;}else if(j2.match(/^embedded_destroy$/)){j2="embedded_destroy_"+this.p.edc++;}_p.tp[_p.tp.length]=j2;this[j2]=x[j];}}catch(e){alert("Error:"+(e.description?e.description:e.message));}}};n._handle_spaceconfig_load=function(s,v){if(v&&v.space_element&&v.space_element.getAttribute("acrid")==this.i){this.p.ei=v.space_id;this.InitializeTemplate();}};n.InitializeTemplate=function(){for(var i=1;i<this.p.eic;i++){this["embedded_init_"+i]();this["embedded_init_"+i]=0;}if(typeof this.template_init==D.F)this.template_init();this.template_init=0;this.p.eic=1;if(typeof this.local_template_init==D.F)this.local_template_init(this);H.message.service.publish("ontemplateload",this);};n._handle_load_template=function(s,v){H.logDebug("Handle load template");if(v&&v.xdom)this.loadTemplateFromNode(v.xdom.documentElement);};n.loadTemplateFromNode=function(oX){var a,o=this.getContainer(),x,i,t,_p=this.o,b=this.p.te,q,z;if(!oX)return;q=oX;z=this.p.tid;if(q.nodeName.match(/^Template$/)!=null){if(z&&q.getAttribute("id")!=z)return;}else{a=oX.getElementsByTagName("Template");if(!a.length)return;if(!z)q=a[0];else{q=0;for(i=0;i<a.length;i++){if(a[i].getAttribute("id")==z){q=a[i];break;}}if(!q)return;}}this.p.tid=0;if(typeof this.setTitle==D.F)this.setTitle(q.getAttribute("Title"));this.importEmbeddedScript(q);if(typeof this.getTemplateContainer==D.F)o=this.getTemplateContainer();H.xml.removeChildren(o);a=q.childNodes;for(i=0;i<a.length;)H.xml.setInnerXHTML(o,a[i++],1,0,0,0,0,this._handle_xhtml_token);if(b){o.setAttribute("space-config","self");if(!this.p.ei){H.message.service.subscribe(this,"onspaceconfigload","_handle_spaceconfig_load");o.setAttribute("acrid",this.i);o.setAttribute("is-space","1");this.scopeHandler("template_processor",0,0,1);var oSpace=H.app.space.service.createSpace(o,0,this._prehandle_template_processor,this._handle_xhtml_token);}else{x=H.app.space.service.getSpace(this.p.ei);H.app.space.service.configureSpace(x,"self");}}else this.InitializeTemplate();};n.getTemplateObjectByName=function(i){var e=this.getTemplateSpace(),o;if(!e)return 0;o=e.getSpaceObjectByName(i);if(!o||!o.object||!o.object.getContainer)return 0;return o.object.getContainer();};n.loadTemplate=function(s,i){if(!s||!s.length)return;H.logDebug("Load Template "+s);this.cleanTemplate();if(i)this.p.tid=i;H.xml.getXml(s,this._prehandle_load_template,1);};n.cleanTemplate=function(){var _p=this.o,i;if(typeof this.template_destroy==D.F)this.template_destroy();this.template_destroy=0;for(i=1;i<this.p.edc;i++){this["embedded_destroy_"+i]();this["embedded_destroy_"+i]=0;}this.p.edc=1;for(i=0;i<_p.tp.length;){if(_p.tp[i++])this[_p.tp[i++]]=null;}_p.tp=[];};n.evaluateWireReference=function(b,n,a){if(typeof a!=D.O)a=0;var t=this,o,_e=H.app.space.service,w,i,e,s;o=t.getContainer();if(!o||o.nodeType!=1)return 0;w=(n?n:o.getAttribute("wire"));i=o.getAttribute("space-id");e=_e.getSpace(i);if(_e.isSpace(e)&&e.getPrimitiveWire(w)){s=_e.getWireService();if(s.invokeHardWireAction(e,w,a)){if(!b)s.invokeHardWireHandler(e,w);return 1;}}return 0;};n.getReferenceId=function(){var c=H.registry.service.getObject(this.getContainerId());if(!c||!D.TF(c.getReferenceId))return 0;return c.getReferenceId();};n.getContainerComponentId=function(){var c=H.registry.service.getObject(this.getContainerId());if(!c||c.t!="xhtml_component")return 0;return c.getComponentId();};if(H.registry.service.addObject(n)){H.message.service.subscribe(n,"onloadxml","HLX");if(n.p.t)H.transaction.service.register(n,1);n.init(o);}else{H.message.service.S("Could not add application component to registry","200.4");}return n;}});}());
/* End Hemi Framework 3.1 */
