(function(){u8.Base.WidgetBuilder=function(i,t){$.extend(this,t);if(!this.id){this.id=i.id||"wb"}this._widgetsToBuild=[];this._element=i;this._elWindow=$w(i);this.$=this._elWindow.$};$.extend(u8.Base.WidgetBuilder.prototype,{autoAddWidgets:function(){var i=this;$$(this._element).find("[u8\\:type]").each(t);function t(){var t=this.getAttribute("u8:type");if(!t){return}var e=this.getAttribute("u8:buildorder");if(typeof e=="undefined"||e===null){e=99999999}var d=this.getAttribute("id");if(!d){d=u8.Base.Dom.uniqueId();this.setAttribute("id",d)}i.addWidget({id:d,type:t,order:e})}},addWidget:function(i){if(!i||!i.id){$error("A widget having the build attribute must have an id.")}this._widgetsToBuild.push(i)},dispose:function(){if(this._isDisposed){return}this._isDisposed=true;this._widgetsToBuild=null;this._element=null;this._elWindow=null;this.$=null},build:function(t){var e=this._widgetsToBuild.length;if(e<=0){if(t){t()}this.dispose();return}this._log("WidgetBuilder("+this.id+"): Starting to build "+e+" widgets.");this._widgetsToBuild.sort(i);this._loadTypes(function(){if(this._isDisposed){return}this._buildWidgets();if(t){t()}this.dispose()}.bind(this))},_loadTypes:function(i){var t=[];for(var e=0;e<this._widgetsToBuild.length;e++){var d=this._widgetsToBuild[e];var s=u8.Base.WidgetBuilder._registeredWidgets[d.type];if(s){continue}t.push(d.type)}u8.services.factory.load(t,i)},_buildWidgets:function(){for(var i=0;i<this._widgetsToBuild.length;i++){var t=this._widgetsToBuild[i];if(u8.debug.useTryCatch){try{this._buildWidget(t)}catch(i){var e="WidgetBuilder("+this.id+'): exception "'+i.message+'" on building  "'+t.id+'" ('+t.type+").";u8.log.exception("widgets",e,i)}}else{this._buildWidget(t)}}},_buildWidget:function(i){var t=this._elWindow.$el(i.id);if(!t){$error("WidgetBuilder("+this.id+'): DOM element "'+i.id+'" not found.')}var e=$w(t);var d=t.getAttribute("u8:o");if(d){d=e.evalValue(d)}d=$.extend(d,{parent:this.parent},i.options);var s=u8.Base.WidgetBuilder._registeredWidgets[i.type];if(!s){var u=u8.services.factory.getType(i.type);if(!u){$error("WidgetBuilder("+this.id+"): Don't know how to build type \""+i.type+'".')}return new u["constructor_"](t,d)}else{return s(this,t,d)}},_log:function(i){if(!u8.debug.level){return}u8.log.debug("widgets",i)}});$.extend(u8.Base.WidgetBuilder,{_registeredWidgets:{},registerWidget:function(i,t){u8.Base.WidgetBuilder._registeredWidgets[i]=t}});var i=u8._.cmp("order")})();