define(["jquery","cilantro/define/chart","cilantro/define/form","cilantro/utils/frontdesk","cilantro/vendor/base"],function(a,b,c,d){var e=Base.extend({constructor:function(b,c){this.viewset=b,this.fd=new d,this.view=a('<div class="view"></div>'),this.name=c;var e=this.view,f=a(this);e.bind("UpdateElementEvent",jQuery.proxy(this.updateElement,this)),e.bind("HideDependentsEvent ShowDependentsEvent",jQuery.proxy(this.toggleDependents,this)),e.bind("UpdateQueryButtonClicked",jQuery.proxy(this.constructQuery,this)),e.bind("UpdateDSEvent GainedFocusEvent LostFocusEvent RegisterElementsEvent",jQuery.proxy(this.notifyChildren,this)),a(this).bind("GainedFocusEvent LostFocusEvent UpdateQueryButtonClicked HideDependentsEvent RegisterElementsEvent ShowDependentsEvent UpdateDSEvent",jQuery.proxy(this.eventPassThru,this)),this.render()},render:function(){var d=this.viewset,f=this.view,g=this.fd;d.elements[0].type!=="chart"&&f.append("<h2>"+this.name+"</h2>"),a.each(this.viewset.elements,function(h,i){var j=null;switch(i.type){case"form":j=new c(i,d.concept_id),f.append(j.dom),g.checkIn(h,j.dom),g.checkOut(h);break;case"chart":var k=i.data.datatype;k==="number"?(j=new b.LineChart(i,d.concept_id),f.append(j.dom),g.checkIn(h,j.dom),g.checkOut(h)):k==="nullboolean"||k==="boolean"?(j=new b.PieChart(i,d.concept_id),f.append(j.dom),g.checkIn(h,j.dom),g.checkOut(h)):(j=new b.BarChart(i,d.concept_id),f.append(j.dom),g.checkIn(h,j.dom),g.checkOut(h));break;case"custom":i.css&&e.loadCss(i.css),g.checkIn(h);var l=d.elements[0].type==="chart"?0:1;require([i.js],function(b){var c=new b(i,d.concept_id);f.children().length-1<h+l?f.append(c.dom):a(f.children()[h]).prepend(c.dom),g.checkOut(h,c.dom)});break;default:f.append(a("<p>Undefined View!</p>"))}})},updateElement:function(b){var c=this.fd;a.each(this.viewset.elements,function(a){c.leaveMessage(a,"triggerHandler",b)}),b.stopPropagation()},toggleDependents:function(b){var c=this.fd;b.target===this.view.children().get(0)&&a.each(this.viewset.elements,function(a){if(a===0)return;c.leaveMessage(a,"triggerHandler",b)}),b.stopPropagation()},constructQuery:function(a){this.view.trigger("ConstructQueryEvent"),a.stopPropagation()},notifyChildren:function(b,c){var d=this.fd;a.each(this.viewset.elements,function(a){d.leaveMessage(a,"triggerHandler",b,c)}),b.stopPropagation()},eventPassThru:function(a,b){this.view.triggerHandler(a,b),a.stopPropagation()},dom:function(){return this.view}},{loadCss:function(a){var b=document.createElement("link");b.type="text/css",b.rel="stylesheet",b.href=a,document.getElementsByTagName("head")[0].appendChild(b)}});return e})