var __hasProp=Object.prototype.hasOwnProperty,__extends=function(a,b){function d(){this.constructor=a}for(var c in b)__hasProp.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a},__bind=function(a,b){return function(){return a.apply(b,arguments)}},__indexOf=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(this[b]===a)return b;return-1};define(["underscore","backbone","common/models/state"],function(a,b,c){var d,e;return d=function(){function a(){a.__super__.constructor.apply(this,arguments)}return __extends(a,c.Model),a.prototype.url=function(){return a.__super__.url.apply(this,arguments)+"/"},a}(),e=function(){function c(){this.toggleEnableByDomain=__bind(this.toggleEnableByDomain,this),c.__super__.constructor.apply(this,arguments)}return __extends(c,b.Collection),c.prototype.model=d,c.prototype.url=App.endpoints.criteria,c.prototype.initialize=function(){return App.hub.subscribe("domain/active",this.toggleEnableByDomain),App.hub.subscribe("subdomain/active",this.toggleEnableByDomain),this.bind("reset",this.groupByDomain),this.bind("active",this.activate),this.bind("inactive",this.inactivate),App.hub.subscribe("concept/request",__bind(function(a){var b;b=this.get(a);if(b)return App.hub.publish("domain/request",b.get("domain").id),b.activate()},this)),this._activeByDomain={},this._activeDomain=null},c.prototype.groupByDomain=function(){return this._byDomain={},this._bySubdomain={},this.each(__bind(function(a){var b,c,d,e,f,g,h,i,j,k;return b=a.get("domain"),b.parent?(((i=(c=this._bySubdomain)[f=b.id])!=null?i:c[f]=[]).push(a),((j=(d=this._byDomain)[g=b.parent.id])!=null?j:d[g]=[]).push(a)):((k=(e=this._byDomain)[h=b.id])!=null?k:e[h]=[]).push(a)},this))},c.prototype.toggleEnableByDomain=function(a){var b,c;this._activeDomain=a,b=this._bySubdomain[a]||this._byDomain[a],this.map(function(a){return __indexOf.call(b,a)<0?a.disable():(a.enable(),a.inactivate())});if(c=this._activeByDomain[a])return c.activate()},c.prototype.activate=function(b){var c;return this._activeByDomain[this._activeDomain]=b,c=this._bySubdomain[this._activeDomain]||this._byDomain[this._activeDomain],a(c).without(b).map(function(a){return a.inactivate()})},c.prototype.inactivate=function(a){},c}(),{Model:d,Collection:e}})