Files
galaxy/static/scripts/mvc/dataset/dataset-model.js
T

2 lines
3.9 KiB
JavaScript

define(["mvc/dataset/states","mvc/base-mvc","utils/localization"],function(a,b,c){var d=b.SearchableModelMixin,e=Backbone.Model.extend(b.LoggableMixin).extend(b.mixin(d,{defaults:{state:a.NEW,deleted:!1,purged:!1,name:"(unnamed dataset)",accessible:!0,data_type:"",file_ext:"",file_size:0,meta_files:[],misc_blurb:"",misc_info:"",tags:[]},initialize:function(b,c){this.debug(this+"(Dataset).initialize",b,c),this.get("accessible")||this.set("state",a.NOT_VIEWABLE),this.urls=this._generateUrls(),this._setUpListeners()},_generateUrls:function(){var a=this.get("id");if(!a)return{};var b={purge:"datasets/"+a+"/purge_async",display:"datasets/"+a+"/display/?preview=True",edit:"datasets/"+a+"/edit",download:"datasets/"+a+"/display?to_ext="+this.get("file_ext"),report_error:"dataset/errors?id="+a,rerun:"tool_runner/rerun?id="+a,show_params:"datasets/"+a+"/show_params",visualization:"visualization",meta_download:"dataset/get_metadata_file?hda_id="+a+"&metadata_name="},c=window.galaxy_config&&galaxy_config.root?galaxy_config.root:"/";return _.each(b,function(a,d){b[d]=c+a}),this.urls=b,b},_setUpListeners:function(){this.on("change:state",function(a,b){this.log(this+" has changed state:",a,b),this.inReadyState()&&this.trigger("state:ready",a,b,this.previous("state"))}),this.on("change:id change:file_ext",function(){this._generateUrls()})},toJSON:function(){var a=Backbone.Model.prototype.toJSON.call(this);return _.extend(a,{urls:this.urls})},isDeletedOrPurged:function(){return this.get("deleted")||this.get("purged")},inReadyState:function(){var b=_.contains(a.READY_STATES,this.get("state"));return this.isDeletedOrPurged()||b},hasDetails:function(){return _.has(this.attributes,"genome_build")},hasData:function(){return this.get("file_size")>0},fetch:function(a){var b=this;return Backbone.Model.prototype.fetch.call(this,a).always(function(){b._generateUrls()})},"delete":function(a){return this.get("deleted")?jQuery.when():this.save({deleted:!0},a)},undelete:function(a){return!this.get("deleted")||this.get("purged")?jQuery.when():this.save({deleted:!1},a)},purge:function(a){if(this.get("purged"))return jQuery.when();a=a||{},a.url=this.urls.purge;var b=this,d=jQuery.ajax(a);return d.done(function(){b.set({deleted:!0,purged:!0})}),d.fail(function(d){var e=c("Unable to purge dataset"),f="Removal of datasets by users is not allowed in this Galaxy instance";d.responseJSON&&d.responseJSON.error?e=d.responseJSON.error:-1!==d.responseText.indexOf(f)&&(e=f),d.responseText=e,b.trigger("error",b,d,a,c(e),{error:e})}),d},searchAttributes:["name","file_ext","genome_build","misc_blurb","misc_info","annotation","tags"],searchAliases:{title:"name",format:"file_ext",database:"genome_build",blurb:"misc_blurb",description:"misc_blurb",info:"misc_info",tag:"tags"},toString:function(){var a=this.get("id")||"";return this.get("name")&&(a='"'+this.get("name")+'",'+a),"Dataset("+a+")"}})),f=Backbone.Collection.extend(b.LoggableMixin).extend({model:e,urlRoot:(window.galaxy_config&&galaxy_config.root?galaxy_config.root:"/")+"api/datasets",url:function(){return this.urlRoot},ids:function(){return this.map(function(a){return a.get("id")})},notReady:function(){return this.filter(function(a){return!a.inReadyState()})},haveDetails:function(){return this.all(function(a){return a.hasDetails()})},ajaxQueue:function(a,b){var c=jQuery.Deferred(),d=this.length,e=[];if(!d)return c.resolve([]),c;var f=this.chain().reverse().map(function(g,h){return function(){var i=a.call(g,b);i.done(function(a){c.notify({curr:h,total:d,response:a,model:g})}),i.always(function(a){e.push(a),f.length?f.shift()():c.resolve(e)})}}).value();return f.shift()(),c},matches:function(a){return this.filter(function(b){return b.matches(a)})},toString:function(){return["DatasetAssociationCollection(",this.length,")"].join("")}});return{DatasetAssociation:e,DatasetAssociationCollection:f}});
//# sourceMappingURL=../../../maps/mvc/dataset/dataset-model.js.map