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)}};define(["underscore","backbone","common/models/state","cilantro/types/domain/views"],function(a,b,c,d){var e,f,g,h;return e=function(){function a(){a.__super__.constructor.apply(this,arguments)}return __extends(a,c.Model),a}(),f=function(){function c(){c.__super__.constructor.apply(this,arguments)}return __extends(c,b.Collection),c.prototype.model=e,c.prototype.url=App.endpoints.domains,c.prototype.initialize=function(){return this.bind("active",this.activate),this.bind("inactive",this.inactivate),App.hub.subscribe("domain/request",__bind(function(a){var b,c;return b=this.get(a),b?b.activate():(c=this.subdomains.get(a),b=this.get(c.get("parent").id),b.activate(),c.activate())},this))},c.prototype.comparator=function(a){return a.get("order")},c.prototype.parse=function(b,c){var e,f,g,i,j;f=a.groupBy(b,function(a){var b;return((b=a["parent"])!=null?b.id:void 0)||null}),this.subdomains=new h,new d.SubdomainCollectionView({collection:this.subdomains}),e=f["null"],delete f["null"],j=a.flatten(a.values(f));for(i in f)g=parseInt(i),j.push({id:g,name:"All",parent:{id:g}});return this.subdomains.reset(j),e},c.prototype.activate=function(a){return App.hub.publish("domain/active",a.id),this.chain().without(a).map(function(a){return a.inactivate()})},c.prototype.inactivate=function(a){return App.hub.publish("domain/inactive",a.id)},c}(),g=function(){function a(){a.__super__.constructor.apply(this,arguments)}return __extends(a,e),a}(),h=function(){function b(){this.toggleEnableByDomain=__bind(this.toggleEnableByDomain,this),b.__super__.constructor.apply(this,arguments)}return __extends(b,f),b.prototype.model=g,b.prototype.initialize=function(){return App.hub.subscribe("domain/active",this.toggleEnableByDomain),this.bind("reset",this.groupByDomain),this.bind("active",this.activate),this.bind("inactive",this.inactivate)},b.prototype.comparator=function(a){return a.get("order")},b.prototype.groupByDomain=function(){return this._byDomain=this.groupBy(function(a){return a.get("parent").id})},b.prototype.toggleEnableByDomain=function(a){var b;b=!1,this.map(__bind(function(c){if(c.get("parent").id!==a)return c.disable();c.enable({reactivate:!0});if(c.isActive())return b=!0},this));if(!b&&this._byDomain[a])return this.get(a).activate()},b.prototype.activate=function(b){return App.hub.publish("subdomain/active",b.id),a(this._byDomain[b.get("parent").id]).without(b).map(function(a){return a.inactivate()})},b.prototype.inactivate=function(a){return App.hub.publish("subdomain/inactive",a.id)},b}(),{Model:e,Collection:f}})