define(["cilantro/define/criteria"],function(a){var b='<button id="submit-query">Get Report</button>',c=$("#condition-list-pane"),d={},e=c.find("#condition-list"),f=c.find(".content"),g=c.find("#clear-conditions"),h=App.urls.session.scope,i=App.urls.report,j=App.urls.session.scope;e.append('<div class="message warning">You have not defined any conditions</div>');var k,l=$(b);return l.click(function(){window.location=App.urls.report}),g.click(function(){for(var a in d)d.hasOwnProperty(a)&&App.hub.publish("CriteriaRemovedEvent",d[a])}),App.hub.subscribe("UpdateQueryEvent",function(b,c){var g=b.concept_id,i;$.isEmptyObject(d)&&(k=e.children().detach(),f.append(l)),l.attr("disabled","true"),c?(i=a.Criteria(b,h,c),e.append(i),App.hub.publish("ConceptAddedEvent",g),d[g]=i,l.removeAttr("disabled")):$.ajax({url:h,type:"PATCH",data:d.hasOwnProperty(g)?JSON.stringify({replace:b}):JSON.stringify({add:b}),contentType:"application/json",success:function(c){l.removeAttr("disabled");var f=$.isEmptyObject(d);d.hasOwnProperty(g)?(i=a.Criteria(b,h,c),d[g].replaceWith(i),i.fadeTo(300,.5,function(){i.fadeTo("fast",1)})):(i=a.Criteria(b,h,c),e.append(i),App.hub.publish("ConceptAddedEvent",g)),d[g]=i,i.addClass("selected"),i.siblings().removeClass("selected"),f&&$(e.children()[0]).find(".field-anchor").click()}})}),App.hub.subscribe("CriteriaRemovedEvent",function(a){var b=a.data("constraint");d[b.concept_id].remove(),delete d[b.concept_id],$.ajax({url:h,type:"PATCH",data:JSON.stringify({remove:b}),contentType:"application/json"}),App.hub.publish("ConceptDeletedEvent",b.concept_id),$.isEmptyObject(d)&&(e.append(k),l.detach())}),App.hub.subscribe("concept/active",function(a){d[a.id]&&d[a.id].siblings().removeClass("selected"),d[a.id]&&d[a.id].addClass("selected")}),$.getJSON(j,function(a){var b={};if(a.store===null||$.isEmptyObject(a.store))return;$.each(a.conditions,function(){b[this.concept_id]=this}),a.store.hasOwnProperty("concept_id")?App.hub.publish("UpdateQueryEvent",a.store,a.conditions[0]):$.each(a.store.children,function(a,c){App.hub.publish("UpdateQueryEvent",c,b[c.concept_id])}),e.children().last().click()}),{retrieveCriteriaDS:function(a){var b=null;return a&&$.each(e.children(),function(c,d){if(!$(d).data("constraint"))return;$(d).data("constraint").concept_id==a&&(b=$(d).data("constraint"))}),b}}})