var __hasProp={}.hasOwnProperty,__extends=function(e,t){function r(){this.constructor=e}for(var n in t)__hasProp.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};define(["environ","mediator","underscore","backbone","./channels"],function(e,t,n,r,i){var s,o;return s=function(e){function r(){return r.__super__.constructor.apply(this,arguments)}return __extends(r,e),r.prototype.deferred={save:!0},r.prototype.url=function(){return this.isNew()?r.__super__.url.apply(this,arguments):this.get("_links").self.href},r.prototype.initialize=function(){var e=this;r.__super__.initialize.apply(this,arguments);if(this.isArchived()){this.resolve();return}return this.on("sync",function(){return this.resolve(),t.publish(i.DATAVIEW_SYNCED,this,"success")}),this.on("error",function(){return t.publish(i.DATAVIEW_SYNCED,this,"error")}),this.on("change",function(){return t.publish(i.DATAVIEW_CHANGED,this)}),t.subscribe(i.DATAVIEW_PAUSE,function(t){if(e.id===t||!t&&e.isSession())return e.pending()}),t.subscribe(i.DATAVIEW_RESUME,function(t){if(e.id===t||!t&&e.isSession())return e.resolve()}),t.subscribe(i.DATAVIEW_COLUMNS,function(t,r){var i;n.isArray(t)&&(r=t,t=null);if(e.id===t||!t&&e.isSession())return i=e.get("json")||{},i.columns=r,e.set("json",i),e.save()}),t.subscribe(i.DATAVIEW_ORDERING,function(t,r){var i;n.isArray(t)&&(r=t,t=null);if(e.id===t||!t&&e.isSession())return i=e.get("json")||{},i.ordering=r,e.set("json",i),e.save()}),this.resolve()},r.prototype.isSession=function(){return this.get("session")},r.prototype.isArchived=function(){return this.get("archived")},r.prototype.toJSON=function(){return{id:this.id,json:this.get("json"),session:this.get("session"),archived:this.get("archived"),published:this.get("published")}},r.prototype.save=function(){return r.__super__.save.apply(this,arguments),t.publish(i.DATAVIEW_SYNCING,this),this.pending()},r}(r.Model),o=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.model=s,t.prototype.initialize=function(){return t.__super__.initialize.apply(this,arguments),this.on("reset",function(e){var t,n,r,i;this.resolve(),i=e.models;for(n=0,r=i.length;n<r;n++)t=i[n],t.trigger("sync")})},t.prototype.hasSession=function(){return!!this.filter(function(e){return e.get("session")})[0]},t}(r.Collection),{DataView:s,DataViews:o}})