From 3b08d37b98094e5c2a0ec6191c7789f82e9ea71c Mon Sep 17 00:00:00 2001 From: Jeremy Goecks Date: Sun, 1 Jul 2012 22:04:40 -0400 Subject: [PATCH] Enhancements to enable paramamonster to be used via accessible/published visualizations. Pack scripts. --- lib/galaxy/web/controllers/tracks.py | 5 +++-- static/scripts/packed/libs/backbone-relational.js | 2 +- static/scripts/packed/mvc/data.js | 1 + static/scripts/packed/mvc/tools.js | 2 +- static/scripts/packed/mvc/ui.js | 2 +- static/scripts/packed/viz/paramamonster.js | 2 +- static/scripts/packed/viz/trackster.js | 2 +- static/scripts/packed/viz/trackster_ui.js | 2 +- static/scripts/packed/viz/visualization.js | 2 +- static/scripts/viz/trackster.js | 2 -- templates/base_panels.mako | 11 ++++++----- templates/display_base.mako | 6 +++--- templates/tracks/browser.mako | 3 +-- 13 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 static/scripts/packed/mvc/data.js diff --git a/lib/galaxy/web/controllers/tracks.py b/lib/galaxy/web/controllers/tracks.py index 1f80e47c1d4..2911d23f923 100644 --- a/lib/galaxy/web/controllers/tracks.py +++ b/lib/galaxy/web/controllers/tracks.py @@ -470,8 +470,10 @@ class TracksController( BaseUIController, UsesVisualizationMixin, UsesHistoryDat return self.tracks_grid( trans, **kwargs ) @web.expose - @web.require_login( "use Galaxy visualizations", use_panels=True ) def paramamonster( self, trans, id=None, hda_ldda=None, dataset_id=None, regions=None ): + # Need to create history if necessary in order to create tool form. + trans.get_history( create=True ) + if id: # Loading a shared visualization. viz = self.get_visualization( trans, id ) @@ -495,7 +497,6 @@ class TracksController( BaseUIController, UsesVisualizationMixin, UsesHistoryDat return trans.fill_template_mako( "visualization/paramamonster.mako", config=viz_config ) @web.expose - @web.require_login( "use Galaxy visualizations", use_panels=True ) def circster( self, trans, hda_ldda, dataset_id ): # Get dataset. dataset = self.get_hda_or_ldda( trans, hda_ldda, dataset_id ) diff --git a/static/scripts/packed/libs/backbone-relational.js b/static/scripts/packed/libs/backbone-relational.js index b386486dd96..47d73029bcd 100644 --- a/static/scripts/packed/libs/backbone-relational.js +++ b/static/scripts/packed/libs/backbone-relational.js @@ -1 +1 @@ -(function(g){var d,h,b;if(typeof window==="undefined"){d=require("underscore");h=require("backbone");b=module.exports=h}else{var d=window._;h=window.Backbone;b=window}h.Relational={showWarnings:true};h.Semaphore={_permitsAvailable:null,_permitsUsed:0,acquire:function(){if(this._permitsAvailable&&this._permitsUsed>=this._permitsAvailable){throw new Error("Max permits acquired")}else{this._permitsUsed++}},release:function(){if(this._permitsUsed===0){throw new Error("All permits released")}else{this._permitsUsed--}},isLocked:function(){return this._permitsUsed>0},setAvailablePermits:function(i){if(this._permitsUsed>i){throw new Error("Available permits cannot be less than used permits")}this._permitsAvailable=i}};h.BlockingQueue=function(){this._queue=[]};d.extend(h.BlockingQueue.prototype,h.Semaphore,{_queue:null,add:function(i){if(this.isBlocked()){this._queue.push(i)}else{i()}},process:function(){while(this._queue&&this._queue.length){this._queue.shift()()}},block:function(){this.acquire()},unblock:function(){this.release();if(!this.isBlocked()){this.process()}},isBlocked:function(){return this.isLocked()}});h.Relational.eventQueue=new h.BlockingQueue();h.Store=function(){this._collections=[];this._reverseRelations=[]};d.extend(h.Store.prototype,h.Events,{_collections:null,_reverseRelations:null,addReverseRelation:function(j){var i=d.any(this._reverseRelations,function(k){return d.all(j,function(m,l){return m===k[l]})});if(!i&&j.model&&j.type){this._reverseRelations.push(j);if(!j.model.prototype.relations){j.model.prototype.relations=[]}j.model.prototype.relations.push(j);this.retroFitRelation(j)}},retroFitRelation:function(j){var i=this.getCollection(j.model);i.each(function(k){new j.type(k,j)},this)},getCollection:function(i){var j=d.detect(this._collections,function(k){return i===k.model||i.constructor===k.model});if(!j){j=this._createCollection(i)}return j},getObjectByName:function(i){var j=d.reduce(i.split("."),function(k,l){return k[l]},b);return j!==b?j:null},_createCollection:function(j){var i;if(j instanceof h.RelationalModel){j=j.constructor}if(j.prototype instanceof h.RelationalModel.prototype.constructor){i=new h.Collection();i.model=j;this._collections.push(i)}return i},resolveIdForItem:function(i,j){var k=d.isString(j)||d.isNumber(j)?j:null;if(k==null){if(j instanceof h.RelationalModel){k=j.id}else{if(d.isObject(j)){k=j[i.prototype.idAttribute]}}}return k},find:function(j,k){var l=this.resolveIdForItem(j,k);var i=this.getCollection(j);return i&&i.get(l)},register:function(j){var i=j.collection;var k=this.getCollection(j);k&&k.add(j);j.bind("destroy",this.unregister,this);j.collection=i},update:function(i){var j=this.getCollection(i);j._onModelEvent("change:"+i.idAttribute,i,j)},unregister:function(i){i.unbind("destroy",this.unregister);var j=this.getCollection(i);j&&j.remove(i)}});h.Relational.store=new h.Store();h.Relation=function(i,j){this.instance=i;j=(typeof j==="object"&&j)||{};this.reverseRelation=d.defaults(j.reverseRelation||{},this.options.reverseRelation);this.reverseRelation.type=!d.isString(this.reverseRelation.type)?this.reverseRelation.type:h[this.reverseRelation.type]||h.Relational.store.getObjectByName(this.reverseRelation.type);this.model=j.model||this.instance.constructor;this.options=d.defaults(j,this.options,h.Relation.prototype.options);this.key=this.options.key;this.keySource=this.options.keySource||this.key;this.keyDestination=this.options.keyDestination||this.options.keySource||this.key;this.relatedModel=this.options.relatedModel;if(d.isString(this.relatedModel)){this.relatedModel=h.Relational.store.getObjectByName(this.relatedModel)}if(!this.checkPreconditions()){return false}if(i){this.keyContents=this.instance.get(this.keySource);if(this.key!==this.keySource){this.instance.unset(this.keySource,{silent:true})}this.instance._relations.push(this)}if(!this.options.isAutoRelation&&this.reverseRelation.type&&this.reverseRelation.key){h.Relational.store.addReverseRelation(d.defaults({isAutoRelation:true,model:this.relatedModel,relatedModel:this.model,reverseRelation:this.options},this.reverseRelation))}d.bindAll(this,"_modelRemovedFromCollection","_relatedModelAdded","_relatedModelRemoved");if(i){this.initialize();h.Relational.store.getCollection(this.instance).bind("relational:remove",this._modelRemovedFromCollection);h.Relational.store.getCollection(this.relatedModel).bind("relational:add",this._relatedModelAdded).bind("relational:remove",this._relatedModelRemoved)}};h.Relation.extend=h.Model.extend;d.extend(h.Relation.prototype,h.Events,h.Semaphore,{options:{createModels:true,includeInJSON:true,isAutoRelation:false},instance:null,key:null,keyContents:null,relatedModel:null,reverseRelation:null,related:null,_relatedModelAdded:function(k,l,j){var i=this;k.queue(function(){i.tryAddRelated(k,j)})},_relatedModelRemoved:function(j,k,i){this.removeRelated(j,i)},_modelRemovedFromCollection:function(i){if(i===this.instance){this.destroy()}},checkPreconditions:function(){var n=this.instance,l=this.key,j=this.model,p=this.relatedModel,q=h.Relational.showWarnings&&typeof console!=="undefined";if(!j||!l||!p){q&&console.warn("Relation=%o; no model, key or relatedModel (%o, %o, %o)",this,j,l,p);return false}if(!(j.prototype instanceof h.RelationalModel.prototype.constructor)){q&&console.warn("Relation=%o; model does not inherit from Backbone.RelationalModel (%o)",this,n);return false}if(!(p.prototype instanceof h.RelationalModel.prototype.constructor)){q&&console.warn("Relation=%o; relatedModel does not inherit from Backbone.RelationalModel (%o)",this,p);return false}if(this instanceof h.HasMany&&this.reverseRelation.type===h.HasMany.prototype.constructor){q&&console.warn("Relation=%o; relation is a HasMany, and the reverseRelation is HasMany as well.",this);return false}if(n&&n._relations.length){var o=d.any(n._relations,function(i){var k=this.reverseRelation.key&&i.reverseRelation.key;return i.relatedModel===p&&i.key===l&&(!k||this.reverseRelation.key===i.reverseRelation.key)},this);if(o){q&&console.warn("Relation=%o between instance=%o.%s and relatedModel=%o.%s already exists",this,n,l,p,this.reverseRelation.key);return false}}return true},setRelated:function(j,i){this.related=j;this.instance.acquire();this.instance.set(this.key,j,d.defaults(i||{},{silent:true}));this.instance.release()},createModel:function(i){if(this.options.createModels&&typeof(i)==="object"){return new this.relatedModel(i)}},_isReverseRelation:function(i){if(i.instance instanceof this.relatedModel&&this.reverseRelation.key===i.key&&this.key===i.reverseRelation.key){return true}return false},getReverseRelations:function(i){var j=[];var k=!d.isUndefined(i)?[i]:this.related&&(this.related.models||[this.related]);d.each(k,function(l){d.each(l.getRelations(),function(m){if(this._isReverseRelation(m)){j.push(m)}},this)},this);return j},sanitizeOptions:function(i){i=i?d.clone(i):{};if(i.silent){i=d.extend({},i,{silentChange:true});delete i.silent}return i},unsanitizeOptions:function(i){i=i?d.clone(i):{};if(i.silentChange){i=d.extend({},i,{silent:true});delete i.silentChange}return i},destroy:function(){h.Relational.store.getCollection(this.instance).unbind("relational:remove",this._modelRemovedFromCollection);h.Relational.store.getCollection(this.relatedModel).unbind("relational:add",this._relatedModelAdded).unbind("relational:remove",this._relatedModelRemoved);d.each(this.getReverseRelations(),function(i){i.removeRelated(this.instance)},this)}});h.HasOne=h.Relation.extend({options:{reverseRelation:{type:"HasMany"}},initialize:function(){d.bindAll(this,"onChange");this.instance.bind("relational:change:"+this.key,this.onChange);var j=this.findRelated({silent:true});this.setRelated(j);var i=this;d.each(i.getReverseRelations(),function(k){k.addRelated(i.instance)})},findRelated:function(j){var k=this.keyContents;var i=null;if(k instanceof this.relatedModel){i=k}else{if(k){i=h.Relational.store.find(this.relatedModel,k);if(i&&d.isObject(k)){i.set(k,j)}else{if(!i){i=this.createModel(k)}}}}return i},onChange:function(l,i,k){if(this.isLocked()){return}this.acquire();k=this.sanitizeOptions(k);var o=d.isUndefined(k._related);var m=o?this.related:k._related;if(o){this.keyContents=i;if(i instanceof this.relatedModel){this.related=i}else{if(i){var n=this.findRelated(k);this.setRelated(n)}else{this.setRelated(null)}}}if(m&&this.related!==m){d.each(this.getReverseRelations(m),function(p){p.removeRelated(this.instance,k)},this)}d.each(this.getReverseRelations(),function(p){p.addRelated(this.instance,k)},this);if(!k.silentChange&&this.related!==m){var j=this;h.Relational.eventQueue.add(function(){j.instance.trigger("update:"+j.key,j.instance,j.related,k)})}this.release()},tryAddRelated:function(j,i){if(this.related){return}i=this.sanitizeOptions(i);var k=this.keyContents;if(k){var l=h.Relational.store.resolveIdForItem(this.relatedModel,k);if(j.id===l){this.addRelated(j,i)}}},addRelated:function(j,i){if(j!==this.related){var k=this.related||null;this.setRelated(j);this.onChange(this.instance,j,{_related:k})}},removeRelated:function(j,i){if(!this.related){return}if(j===this.related){var k=this.related||null;this.setRelated(null);this.onChange(this.instance,j,{_related:k})}}});h.HasMany=h.Relation.extend({collectionType:null,options:{reverseRelation:{type:"HasOne"},collectionType:h.Collection,collectionKey:true,collectionOptions:{}},initialize:function(){d.bindAll(this,"onChange","handleAddition","handleRemoval","handleReset");this.instance.bind("relational:change:"+this.key,this.onChange);this.collectionType=this.options.collectionType;if(d(this.collectionType).isString()){this.collectionType=h.Relational.store.getObjectByName(this.collectionType)}if(!this.collectionType.prototype instanceof h.Collection.prototype.constructor){throw new Error("collectionType must inherit from Backbone.Collection")}if(this.keyContents instanceof h.Collection){this.setRelated(this._prepareCollection(this.keyContents))}else{this.setRelated(this._prepareCollection())}this.findRelated({silent:true})},_getCollectionOptions:function(){return d.isFunction(this.options.collectionOptions)?this.options.collectionOptions(this.instance):this.options.collectionOptions},_prepareCollection:function(j){if(this.related){this.related.unbind("relational:add",this.handleAddition).unbind("relational:remove",this.handleRemoval).unbind("relational:reset",this.handleReset)}if(!j||!(j instanceof h.Collection)){j=new this.collectionType([],this._getCollectionOptions())}j.model=this.relatedModel;if(this.options.collectionKey){var i=this.options.collectionKey===true?this.options.reverseRelation.key:this.options.collectionKey;if(j[i]&&j[i]!==this.instance){if(h.Relational.showWarnings&&typeof console!=="undefined"){console.warn("Relation=%o; collectionKey=%s already exists on collection=%o",this,i,this.options.collectionKey)}}else{if(i){j[i]=this.instance}}}j.bind("relational:add",this.handleAddition).bind("relational:remove",this.handleRemoval).bind("relational:reset",this.handleReset);return j},findRelated:function(i){if(this.keyContents){var j=[];if(this.keyContents instanceof h.Collection){j=this.keyContents.models}else{this.keyContents=d.isArray(this.keyContents)?this.keyContents:[this.keyContents];d.each(this.keyContents,function(l){var k=h.Relational.store.find(this.relatedModel,l);if(k&&d.isObject(l)){k.set(l,i)}else{if(!k){k=this.createModel(l)}}if(k&&!this.related.getByCid(k)&&!this.related.get(k)){j.push(k)}},this)}if(j.length){i=this.unsanitizeOptions(i);this.related.add(j,i)}}},onChange:function(l,i,k){k=this.sanitizeOptions(k);this.keyContents=i;d.each(this.getReverseRelations(),function(n){n.removeRelated(this.instance,k)},this);if(i instanceof h.Collection){this._prepareCollection(i);this.related=i}else{var m;if(this.related instanceof h.Collection){m=this.related;m.reset([],{silent:true})}else{m=this._prepareCollection()}this.setRelated(m);this.findRelated(k)}d.each(this.getReverseRelations(),function(n){n.addRelated(this.instance,k)},this);var j=this;h.Relational.eventQueue.add(function(){!k.silentChange&&j.instance.trigger("update:"+j.key,j.instance,j.related,k)})},tryAddRelated:function(j,i){i=this.sanitizeOptions(i);if(!this.related.getByCid(j)&&!this.related.get(j)){var k=d.any(this.keyContents,function(l){var m=h.Relational.store.resolveIdForItem(this.relatedModel,l);return m&&m===j.id},this);if(k){this.related.add(j,i)}}},handleAddition:function(k,l,j){if(!(k instanceof h.Model)){return}j=this.sanitizeOptions(j);d.each(this.getReverseRelations(k),function(m){m.addRelated(this.instance,j)},this);var i=this;h.Relational.eventQueue.add(function(){!j.silentChange&&i.instance.trigger("add:"+i.key,k,i.related,j)})},handleRemoval:function(k,l,j){if(!(k instanceof h.Model)){return}j=this.sanitizeOptions(j);d.each(this.getReverseRelations(k),function(m){m.removeRelated(this.instance,j)},this);var i=this;h.Relational.eventQueue.add(function(){!j.silentChange&&i.instance.trigger("remove:"+i.key,k,i.related,j)})},handleReset:function(k,j){j=this.sanitizeOptions(j);var i=this;h.Relational.eventQueue.add(function(){!j.silentChange&&i.instance.trigger("reset:"+i.key,i.related,j)})},addRelated:function(k,j){var i=this;j=this.unsanitizeOptions(j);k.queue(function(){if(i.related&&!i.related.getByCid(k)&&!i.related.get(k)){i.related.add(k,j)}})},removeRelated:function(j,i){i=this.unsanitizeOptions(i);if(this.related.getByCid(j)||this.related.get(j)){this.related.remove(j,i)}}});h.RelationalModel=h.Model.extend({relations:null,_relations:null,_isInitialized:false,_deferProcessing:false,_queue:null,constructor:function(j,k){var i=this;if(k&&k.collection){this._deferProcessing=true;var l=function(m){if(m===i){i._deferProcessing=false;i.processQueue();k.collection.unbind("relational:add",l)}};k.collection.bind("relational:add",l);d.defer(function(){l(i)})}this._queue=new h.BlockingQueue();this._queue.block();h.Relational.eventQueue.block();h.Model.prototype.constructor.apply(this,arguments);h.Relational.eventQueue.unblock()},trigger:function(j){if(j.length>5&&"change"===j.substr(0,6)){var i=this,k=arguments;h.Relational.eventQueue.add(function(){h.Model.prototype.trigger.apply(i,k)})}else{h.Model.prototype.trigger.apply(this,arguments)}return this},initializeRelations:function(){this.acquire();this._relations=[];d.each(this.relations,function(i){var j=!d.isString(i.type)?i.type:h[i.type]||h.Relational.store.getObjectByName(i.type);if(j&&j.prototype instanceof h.Relation.prototype.constructor){new j(this,i)}else{h.Relational.showWarnings&&typeof console!=="undefined"&&console.warn("Relation=%o; missing or invalid type!",i)}},this);this._isInitialized=true;this.release();this.processQueue()},updateRelations:function(i){if(this._isInitialized&&!this.isLocked()){d.each(this._relations,function(j){var k=this.attributes[j.key];if(j.related!==k){this.trigger("relational:change:"+j.key,this,k,i||{})}},this)}},queue:function(i){this._queue.add(i)},processQueue:function(){if(this._isInitialized&&!this._deferProcessing&&this._queue.isBlocked()){this._queue.unblock()}},getRelation:function(i){return d.detect(this._relations,function(j){if(j.key===i){return true}},this)},getRelations:function(){return this._relations},fetchRelated:function(n,p){p||(p={});var l,j=[],o=this.getRelation(n),q=o&&o.keyContents,m=q&&d.select(d.isArray(q)?q:[q],function(r){var s=h.Relational.store.resolveIdForItem(o.relatedModel,r);return s&&!h.Relational.store.find(o.relatedModel,s)},this);if(m&&m.length){var k=d.map(m,function(t){var s;if(typeof(t)==="object"){s=new o.relatedModel(t)}else{var r={};r[o.relatedModel.prototype.idAttribute]=t;s=new o.relatedModel(r)}return s},this);if(o.related instanceof h.Collection&&d.isFunction(o.related.url)){l=o.related.url(k)}if(l&&l!==o.related.url()){var i=d.defaults({error:function(){var r=arguments;d.each(k,function(s){s.trigger("destroy",s,s.collection,p);p.error&&p.error.apply(s,r)})},url:l},p,{add:true});j=[o.related.fetch(i)]}else{j=d.map(k,function(r){var s=d.defaults({error:function(){r.trigger("destroy",r,r.collection,p);p.error&&p.error.apply(r,arguments)}},p);return r.fetch(s)},this)}}return j},set:function(l,m,k){h.Relational.eventQueue.block();var j;if(d.isObject(l)||l==null){j=l;k=m}else{j={};j[l]=m}var i=h.Model.prototype.set.apply(this,arguments);if(!this._isInitialized&&!this.isLocked()){h.Relational.store.register(this);this.initializeRelations()}else{if(j&&this.idAttribute in j){h.Relational.store.update(this)}}if(j){this.updateRelations(k)}h.Relational.eventQueue.unblock();return i},unset:function(k,j){h.Relational.eventQueue.block();var i=h.Model.prototype.unset.apply(this,arguments);this.updateRelations(j);h.Relational.eventQueue.unblock();return i},clear:function(j){h.Relational.eventQueue.block();var i=h.Model.prototype.clear.apply(this,arguments);this.updateRelations(j);h.Relational.eventQueue.unblock();return i},change:function(k){var i=this,j=arguments;h.Relational.eventQueue.add(function(){h.Model.prototype.change.apply(i,j)})},clone:function(){var i=d.clone(this.attributes);if(!d.isUndefined(i[this.idAttribute])){i[this.idAttribute]=null}d.each(this.getRelations(),function(j){delete i[j.key]});return new this.constructor(i)},toJSON:function(){if(this.isLocked()){return this.id}this.acquire();var i=h.Model.prototype.toJSON.call(this);d.each(this._relations,function(j){var k=i[j.key];if(j.options.includeInJSON===true&&k&&d.isFunction(k.toJSON)){i[j.keyDestination]=k.toJSON()}else{if(d.isString(j.options.includeInJSON)){if(k instanceof h.Collection){i[j.keyDestination]=k.pluck(j.options.includeInJSON)}else{if(k instanceof h.Model){i[j.keyDestination]=k.get(j.options.includeInJSON)}}}else{delete i[j.key]}}if(j.keyDestination!==j.key){delete i[j.key]}},this);this.release();return i}});d.extend(h.RelationalModel.prototype,h.Semaphore);var f=h.Collection.prototype.__add=h.Collection.prototype.add;h.Collection.prototype.add=function(k,i){i||(i={});if(!d.isArray(k)){k=[k]}var j=[];d.each(k,function(m){if(!(m instanceof h.Model)){var l=h.Relational.store.find(this.model,m[this.model.prototype.idAttribute]);if(l){l.set(l.parse?l.parse(m):m,i);m=l}else{m=h.Collection.prototype._prepareModel.call(this,m,i)}}if(m instanceof h.Model&&!this.get(m)&&!this.getByCid(m)){j.push(m)}},this);if(j.length){f.call(this,j,i);d.each(j,function(l){this.trigger("relational:add",l,this,i)},this)}return this};var a=h.Collection.prototype.__remove=h.Collection.prototype.remove;h.Collection.prototype.remove=function(j,i){i||(i={});if(!d.isArray(j)){j=[j]}d.each(j,function(k){k=this.getByCid(k)||this.get(k);if(k instanceof h.Model){a.call(this,k,i);this.trigger("relational:remove",k,this,i)}},this);return this};var e=h.Collection.prototype.__reset=h.Collection.prototype.reset;h.Collection.prototype.reset=function(j,i){e.call(this,j,i);this.trigger("relational:reset",j,i);return this};var c=h.Collection.prototype.__trigger=h.Collection.prototype.trigger;h.Collection.prototype.trigger=function(j){if(j==="add"||j==="remove"||j==="reset"){var i=this,k=arguments;h.Relational.eventQueue.add(function(){c.apply(i,k)})}else{c.apply(this,arguments)}return this};h.RelationalModel.extend=function(j,k){var l=h.Model.extend.apply(this,arguments);var i=(j&&j.relations)||[];d.each(i,function(m){if(m.reverseRelation){m.model=l;var o=true;if(d.isString(m.relatedModel)){var n=h.Relational.store.getObjectByName(m.relatedModel);o=n&&(n.prototype instanceof h.RelationalModel.prototype.constructor)}var p=!d.isString(m.type)?m.type:h[m.type]||h.Relational.store.getObjectByName(m.type);if(o&&p&&p.prototype instanceof h.Relation.prototype.constructor){new p(null,m)}}});return l}})(); \ No newline at end of file +(function(b){var h,g,c;if(typeof window==="undefined"){h=require("underscore");g=require("backbone");c=module.exports=g}else{h=window._;g=window.Backbone;c=window}g.Relational={showWarnings:true};g.Semaphore={_permitsAvailable:null,_permitsUsed:0,acquire:function(){if(this._permitsAvailable&&this._permitsUsed>=this._permitsAvailable){throw new Error("Max permits acquired")}else{this._permitsUsed++}},release:function(){if(this._permitsUsed===0){throw new Error("All permits released")}else{this._permitsUsed--}},isLocked:function(){return this._permitsUsed>0},setAvailablePermits:function(j){if(this._permitsUsed>j){throw new Error("Available permits cannot be less than used permits")}this._permitsAvailable=j}};g.BlockingQueue=function(){this._queue=[]};h.extend(g.BlockingQueue.prototype,g.Semaphore,{_queue:null,add:function(j){if(this.isBlocked()){this._queue.push(j)}else{j()}},process:function(){while(this._queue&&this._queue.length){this._queue.shift()()}},block:function(){this.acquire()},unblock:function(){this.release();if(!this.isBlocked()){this.process()}},isBlocked:function(){return this.isLocked()}});g.Relational.eventQueue=new g.BlockingQueue();g.Store=function(){this._collections=[];this._reverseRelations=[];this._subModels=[];this._modelScopes=[c]};h.extend(g.Store.prototype,g.Events,{addModelScope:function(j){this._modelScopes.push(j)},addSubModels:function(j,k){this._subModels.push({superModelType:k,subModels:j})},setupSuperModel:function(j){h.find(this._subModels,function(k){return h.find(k.subModels,function(m,n){var l=this.getObjectByName(m);if(j===l){k.superModelType._subModels[n]=j;j._superModel=k.superModelType;j._subModelTypeValue=n;j._subModelTypeAttribute=k.superModelType.prototype.subModelTypeAttribute;return true}},this)},this)},addReverseRelation:function(l){var k=h.any(this._reverseRelations,function(m){return h.all(l,function(o,n){return o===m[n]})});if(!k&&l.model&&l.type){this._reverseRelations.push(l);var j=function(m,n){if(!m.prototype.relations){m.prototype.relations=[]}m.prototype.relations.push(n);h.each(m._subModels,function(o){j(o,n)},this)};j(l.model,l);this.retroFitRelation(l)}},retroFitRelation:function(k){var j=this.getCollection(k.model);j.each(function(l){if(!(l instanceof k.model)){return}new k.type(l,k)},this)},getCollection:function(k){if(k instanceof g.RelationalModel){k=k.constructor}var j=k;while(j._superModel){j=j._superModel}var l=h.detect(this._collections,function(m){return m.model===j});if(!l){l=this._createCollection(k)}return l},getObjectByName:function(j){var l=j.split("."),k=null;h.find(this._modelScopes,function(m){k=h.reduce(l,function(n,o){return n[o]},m);if(k&&k!==m){return true}},this);return k},_createCollection:function(k){var j;if(k instanceof g.RelationalModel){k=k.constructor}if(k.prototype instanceof g.RelationalModel){j=new g.Collection();j.model=k;this._collections.push(j)}return j},resolveIdForItem:function(j,k){var l=h.isString(k)||h.isNumber(k)?k:null;if(l==null){if(k instanceof g.RelationalModel){l=k.id}else{if(h.isObject(k)){l=k[j.prototype.idAttribute]}}}return l},find:function(k,l){var n=this.resolveIdForItem(k,l);var j=this.getCollection(k);if(j){var m=j.get(n);if(m instanceof k){return m}}return null},register:function(k){var j=k.collection;var l=this.getCollection(k);l&&l.add(k);k.bind("destroy",this.unregister,this);k.collection=j},update:function(j){var k=this.getCollection(j);k._onModelEvent("change:"+j.idAttribute,j,k)},unregister:function(j){j.unbind("destroy",this.unregister);var k=this.getCollection(j);k&&k.remove(j)}});g.Relational.store=new g.Store();g.Relation=function(j,k){this.instance=j;k=h.isObject(k)?k:{};this.reverseRelation=h.defaults(k.reverseRelation||{},this.options.reverseRelation);this.reverseRelation.type=!h.isString(this.reverseRelation.type)?this.reverseRelation.type:g[this.reverseRelation.type]||g.Relational.store.getObjectByName(this.reverseRelation.type);this.model=k.model||this.instance.constructor;this.options=h.defaults(k,this.options,g.Relation.prototype.options);this.key=this.options.key;this.keySource=this.options.keySource||this.key;this.keyDestination=this.options.keyDestination||this.keySource||this.key;this.relatedModel=this.options.relatedModel;if(h.isString(this.relatedModel)){this.relatedModel=g.Relational.store.getObjectByName(this.relatedModel)}if(!this.checkPreconditions()){return false}if(j){this.keyContents=this.instance.get(this.keySource);if(this.key!==this.keySource){this.instance.unset(this.keySource,{silent:true})}this.instance._relations.push(this)}if(!this.options.isAutoRelation&&this.reverseRelation.type&&this.reverseRelation.key){g.Relational.store.addReverseRelation(h.defaults({isAutoRelation:true,model:this.relatedModel,relatedModel:this.model,reverseRelation:this.options},this.reverseRelation))}h.bindAll(this,"_modelRemovedFromCollection","_relatedModelAdded","_relatedModelRemoved");if(j){this.initialize();g.Relational.store.getCollection(this.instance).bind("relational:remove",this._modelRemovedFromCollection);g.Relational.store.getCollection(this.relatedModel).bind("relational:add",this._relatedModelAdded).bind("relational:remove",this._relatedModelRemoved)}};g.Relation.extend=g.Model.extend;h.extend(g.Relation.prototype,g.Events,g.Semaphore,{options:{createModels:true,includeInJSON:true,isAutoRelation:false},instance:null,key:null,keyContents:null,relatedModel:null,reverseRelation:null,related:null,_relatedModelAdded:function(l,m,k){var j=this;l.queue(function(){j.tryAddRelated(l,k)})},_relatedModelRemoved:function(k,l,j){this.removeRelated(k,j)},_modelRemovedFromCollection:function(j){if(j===this.instance){this.destroy()}},checkPreconditions:function(){var n=this.instance,l=this.key,j=this.model,p=this.relatedModel,q=g.Relational.showWarnings&&typeof console!=="undefined";if(!j||!l||!p){q&&console.warn("Relation=%o; no model, key or relatedModel (%o, %o, %o)",this,j,l,p);return false}if(!(j.prototype instanceof g.RelationalModel)){q&&console.warn("Relation=%o; model does not inherit from Backbone.RelationalModel (%o)",this,n);return false}if(!(p.prototype instanceof g.RelationalModel)){q&&console.warn("Relation=%o; relatedModel does not inherit from Backbone.RelationalModel (%o)",this,p);return false}if(this instanceof g.HasMany&&this.reverseRelation.type===g.HasMany){q&&console.warn("Relation=%o; relation is a HasMany, and the reverseRelation is HasMany as well.",this);return false}if(n&&n._relations.length){var o=h.any(n._relations,function(k){var m=this.reverseRelation.key&&k.reverseRelation.key;return k.relatedModel===p&&k.key===l&&(!m||this.reverseRelation.key===k.reverseRelation.key)},this);if(o){q&&console.warn("Relation=%o between instance=%o.%s and relatedModel=%o.%s already exists",this,n,l,p,this.reverseRelation.key);return false}}return true},setRelated:function(k,j){this.related=k;this.instance.acquire();this.instance.set(this.key,k,h.defaults(j||{},{silent:true}));this.instance.release()},_isReverseRelation:function(j){if(j.instance instanceof this.relatedModel&&this.reverseRelation.key===j.key&&this.key===j.reverseRelation.key){return true}return false},getReverseRelations:function(j){var k=[];var l=!h.isUndefined(j)?[j]:this.related&&(this.related.models||[this.related]);h.each(l,function(m){h.each(m.getRelations(),function(n){if(this._isReverseRelation(n)){k.push(n)}},this)},this);return k},sanitizeOptions:function(j){j=j?h.clone(j):{};if(j.silent){j.silentChange=true;delete j.silent}return j},unsanitizeOptions:function(j){j=j?h.clone(j):{};if(j.silentChange){j.silent=true;delete j.silentChange}return j},destroy:function(){g.Relational.store.getCollection(this.instance).unbind("relational:remove",this._modelRemovedFromCollection);g.Relational.store.getCollection(this.relatedModel).unbind("relational:add",this._relatedModelAdded).unbind("relational:remove",this._relatedModelRemoved);h.each(this.getReverseRelations(),function(j){j.removeRelated(this.instance)},this)}});g.HasOne=g.Relation.extend({options:{reverseRelation:{type:"HasMany"}},initialize:function(){h.bindAll(this,"onChange");this.instance.bind("relational:change:"+this.key,this.onChange);var j=this.findRelated({silent:true});this.setRelated(j);h.each(this.getReverseRelations(),function(k){k.addRelated(this.instance)},this)},findRelated:function(k){var l=this.keyContents;var j=null;if(l instanceof this.relatedModel){j=l}else{if(l){j=this.relatedModel.findOrCreate(l,{create:this.options.createModels})}}return j},onChange:function(m,j,l){if(this.isLocked()){return}this.acquire();l=this.sanitizeOptions(l);var p=h.isUndefined(l._related);var n=p?this.related:l._related;if(p){this.keyContents=j;if(j instanceof this.relatedModel){this.related=j}else{if(j){var o=this.findRelated(l);this.setRelated(o)}else{this.setRelated(null)}}}if(n&&this.related!==n){h.each(this.getReverseRelations(n),function(q){q.removeRelated(this.instance,l)},this)}h.each(this.getReverseRelations(),function(q){q.addRelated(this.instance,l)},this);if(!l.silentChange&&this.related!==n){var k=this;g.Relational.eventQueue.add(function(){k.instance.trigger("update:"+k.key,k.instance,k.related,l)})}this.release()},tryAddRelated:function(k,j){if(this.related){return}j=this.sanitizeOptions(j);var l=this.keyContents;if(l){var m=g.Relational.store.resolveIdForItem(this.relatedModel,l);if(k.id===m){this.addRelated(k,j)}}},addRelated:function(k,j){if(k!==this.related){var l=this.related||null;this.setRelated(k);this.onChange(this.instance,k,{_related:l})}},removeRelated:function(k,j){if(!this.related){return}if(k===this.related){var l=this.related||null;this.setRelated(null);this.onChange(this.instance,k,{_related:l})}}});g.HasMany=g.Relation.extend({collectionType:null,options:{reverseRelation:{type:"HasOne"},collectionType:g.Collection,collectionKey:true,collectionOptions:{}},initialize:function(){h.bindAll(this,"onChange","handleAddition","handleRemoval","handleReset");this.instance.bind("relational:change:"+this.key,this.onChange);this.collectionType=this.options.collectionType;if(h.isString(this.collectionType)){this.collectionType=g.Relational.store.getObjectByName(this.collectionType)}if(!this.collectionType.prototype instanceof g.Collection){throw new Error("collectionType must inherit from Backbone.Collection")}if(this.keyContents instanceof g.Collection){this.setRelated(this._prepareCollection(this.keyContents))}else{this.setRelated(this._prepareCollection())}this.findRelated({silent:true})},_getCollectionOptions:function(){return h.isFunction(this.options.collectionOptions)?this.options.collectionOptions(this.instance):this.options.collectionOptions},_prepareCollection:function(k){if(this.related){this.related.unbind("relational:add",this.handleAddition).unbind("relational:remove",this.handleRemoval).unbind("relational:reset",this.handleReset)}if(!k||!(k instanceof g.Collection)){k=new this.collectionType([],this._getCollectionOptions())}k.model=this.relatedModel;if(this.options.collectionKey){var j=this.options.collectionKey===true?this.options.reverseRelation.key:this.options.collectionKey;if(k[j]&&k[j]!==this.instance){if(g.Relational.showWarnings&&typeof console!=="undefined"){console.warn("Relation=%o; collectionKey=%s already exists on collection=%o",this,j,this.options.collectionKey)}}else{if(j){k[j]=this.instance}}}k.bind("relational:add",this.handleAddition).bind("relational:remove",this.handleRemoval).bind("relational:reset",this.handleReset);return k},findRelated:function(j){if(this.keyContents){var k=[];if(this.keyContents instanceof g.Collection){k=this.keyContents.models}else{this.keyContents=h.isArray(this.keyContents)?this.keyContents:[this.keyContents];h.each(this.keyContents,function(m){var l=null;if(m instanceof this.relatedModel){l=m}else{l=this.relatedModel.findOrCreate(m,{create:this.options.createModels})}if(l&&!this.related.getByCid(l)&&!this.related.get(l)){k.push(l)}},this)}if(k.length){j=this.unsanitizeOptions(j);this.related.add(k,j)}}},onChange:function(m,j,l){l=this.sanitizeOptions(l);this.keyContents=j;h.each(this.getReverseRelations(),function(o){o.removeRelated(this.instance,l)},this);if(j instanceof g.Collection){this._prepareCollection(j);this.related=j}else{var n;if(this.related instanceof g.Collection){n=this.related;n.remove(n.models)}else{n=this._prepareCollection()}this.setRelated(n);this.findRelated(l)}h.each(this.getReverseRelations(),function(o){o.addRelated(this.instance,l)},this);var k=this;g.Relational.eventQueue.add(function(){!l.silentChange&&k.instance.trigger("update:"+k.key,k.instance,k.related,l)})},tryAddRelated:function(k,j){j=this.sanitizeOptions(j);if(!this.related.getByCid(k)&&!this.related.get(k)){var l=h.any(this.keyContents,function(m){var n=g.Relational.store.resolveIdForItem(this.relatedModel,m);return n&&n===k.id},this);if(l){this.related.add(k,j)}}},handleAddition:function(l,m,k){if(!(l instanceof g.Model)){return}k=this.sanitizeOptions(k);h.each(this.getReverseRelations(l),function(n){n.addRelated(this.instance,k)},this);var j=this;g.Relational.eventQueue.add(function(){!k.silentChange&&j.instance.trigger("add:"+j.key,l,j.related,k)})},handleRemoval:function(l,m,k){if(!(l instanceof g.Model)){return}k=this.sanitizeOptions(k);h.each(this.getReverseRelations(l),function(n){n.removeRelated(this.instance,k)},this);var j=this;g.Relational.eventQueue.add(function(){!k.silentChange&&j.instance.trigger("remove:"+j.key,l,j.related,k)})},handleReset:function(l,k){k=this.sanitizeOptions(k);var j=this;g.Relational.eventQueue.add(function(){!k.silentChange&&j.instance.trigger("reset:"+j.key,j.related,k)})},addRelated:function(l,k){var j=this;k=this.unsanitizeOptions(k);l.queue(function(){if(j.related&&!j.related.getByCid(l)&&!j.related.get(l)){j.related.add(l,k)}})},removeRelated:function(k,j){j=this.unsanitizeOptions(j);if(this.related.getByCid(k)||this.related.get(k)){this.related.remove(k,j)}}});g.RelationalModel=g.Model.extend({relations:null,_relations:null,_isInitialized:false,_deferProcessing:false,_queue:null,subModelTypeAttribute:"type",subModelTypes:null,constructor:function(k,l){var j=this;if(l&&l.collection){this._deferProcessing=true;var m=function(n){if(n===j){j._deferProcessing=false;j.processQueue();l.collection.unbind("relational:add",m)}};l.collection.bind("relational:add",m);h.defer(function(){m(j)})}this._queue=new g.BlockingQueue();this._queue.block();g.Relational.eventQueue.block();g.Model.apply(this,arguments);g.Relational.eventQueue.unblock()},trigger:function(k){if(k.length>5&&"change"===k.substr(0,6)){var j=this,l=arguments;g.Relational.eventQueue.add(function(){g.Model.prototype.trigger.apply(j,l)})}else{g.Model.prototype.trigger.apply(this,arguments)}return this},initializeRelations:function(){this.acquire();this._relations=[];h.each(this.relations,function(j){var k=!h.isString(j.type)?j.type:g[j.type]||g.Relational.store.getObjectByName(j.type);if(k&&k.prototype instanceof g.Relation){new k(this,j)}else{g.Relational.showWarnings&&typeof console!=="undefined"&&console.warn("Relation=%o; missing or invalid type!",j)}},this);this._isInitialized=true;this.release();this.processQueue()},updateRelations:function(j){if(this._isInitialized&&!this.isLocked()){h.each(this._relations,function(k){var l=this.attributes[k.keySource]||this.attributes[k.key];if(k.related!==l){this.trigger("relational:change:"+k.key,this,l,j||{})}},this)}},queue:function(j){this._queue.add(j)},processQueue:function(){if(this._isInitialized&&!this._deferProcessing&&this._queue.isBlocked()){this._queue.unblock()}},getRelation:function(j){return h.detect(this._relations,function(k){if(k.key===j){return true}},this)},getRelations:function(){return this._relations},fetchRelated:function(p,r,n){r||(r={});var m,k=[],q=this.getRelation(p),s=q&&q.keyContents,o=s&&h.select(h.isArray(s)?s:[s],function(t){var u=g.Relational.store.resolveIdForItem(q.relatedModel,t);return u&&(n||!g.Relational.store.find(q.relatedModel,u))},this);if(o&&o.length){var l=h.map(o,function(v){var u;if(h.isObject(v)){u=q.relatedModel.build(v)}else{var t={};t[q.relatedModel.prototype.idAttribute]=v;u=q.relatedModel.build(t)}return u},this);if(q.related instanceof g.Collection&&h.isFunction(q.related.url)){m=q.related.url(l)}if(m&&m!==q.related.url()){var j=h.defaults({error:function(){var t=arguments;h.each(l,function(u){u.trigger("destroy",u,u.collection,r);r.error&&r.error.apply(u,t)})},url:m},r,{add:true});k=[q.related.fetch(j)]}else{k=h.map(l,function(t){var u=h.defaults({error:function(){t.trigger("destroy",t,t.collection,r);r.error&&r.error.apply(t,arguments)}},r);return t.fetch(u)},this)}}return k},set:function(m,n,l){g.Relational.eventQueue.block();var k;if(h.isObject(m)||m==null){k=m;l=n}else{k={};k[m]=n}var j=g.Model.prototype.set.apply(this,arguments);if(!this._isInitialized&&!this.isLocked()){this.constructor.initializeModelHierarchy();g.Relational.store.register(this);this.initializeRelations()}else{if(k&&this.idAttribute in k){g.Relational.store.update(this)}}if(k){this.updateRelations(l)}g.Relational.eventQueue.unblock();return j},unset:function(l,k){g.Relational.eventQueue.block();var j=g.Model.prototype.unset.apply(this,arguments);this.updateRelations(k);g.Relational.eventQueue.unblock();return j},clear:function(k){g.Relational.eventQueue.block();var j=g.Model.prototype.clear.apply(this,arguments);this.updateRelations(k);g.Relational.eventQueue.unblock();return j},change:function(l){var j=this,k=arguments;g.Relational.eventQueue.add(function(){g.Model.prototype.change.apply(j,k)})},clone:function(){var j=h.clone(this.attributes);if(!h.isUndefined(j[this.idAttribute])){j[this.idAttribute]=null}h.each(this.getRelations(),function(k){delete j[k.key]});return new this.constructor(j)},toJSON:function(){if(this.isLocked()){return this.id}this.acquire();var j=g.Model.prototype.toJSON.call(this);if(this.constructor._superModel&&!(this.constructor._subModelTypeAttribute in j)){j[this.constructor._subModelTypeAttribute]=this.constructor._subModelTypeValue}h.each(this._relations,function(k){var m=j[k.key];if(k.options.includeInJSON===true){if(m&&h.isFunction(m.toJSON)){j[k.keyDestination]=m.toJSON()}else{j[k.keyDestination]=null}}else{if(h.isString(k.options.includeInJSON)){if(m instanceof g.Collection){j[k.keyDestination]=m.pluck(k.options.includeInJSON)}else{if(m instanceof g.Model){j[k.keyDestination]=m.get(k.options.includeInJSON)}else{j[k.keyDestination]=null}}}else{if(h.isArray(k.options.includeInJSON)){if(m instanceof g.Collection){var l=[];m.each(function(o){var n={};h.each(k.options.includeInJSON,function(p){n[p]=o.get(p)});l.push(n)});j[k.keyDestination]=l}else{if(m instanceof g.Model){var l={};h.each(k.options.includeInJSON,function(n){l[n]=m.get(n)});j[k.keyDestination]=l}else{j[k.keyDestination]=null}}}else{delete j[k.key]}}}if(k.keyDestination!==k.key){delete j[k.key]}});this.release();return j}},{setup:function(j){this.prototype.relations=(this.prototype.relations||[]).slice(0);this._subModels={};this._superModel=null;if(this.prototype.hasOwnProperty("subModelTypes")){g.Relational.store.addSubModels(this.prototype.subModelTypes,this)}else{this.prototype.subModelTypes=null}h.each(this.prototype.relations,function(k){if(!k.model){k.model=this}if(k.reverseRelation&&k.model===this){var m=true;if(h.isString(k.relatedModel)){var l=g.Relational.store.getObjectByName(k.relatedModel);m=l&&(l.prototype instanceof g.RelationalModel)}var n=!h.isString(k.type)?k.type:g[k.type]||g.Relational.store.getObjectByName(k.type);if(m&&n&&n.prototype instanceof g.Relation){new n(null,k)}}},this)},build:function(l,n){var m=this;this.initializeModelHierarchy();if(this._subModels&&this.prototype.subModelTypeAttribute in l){var k=l[this.prototype.subModelTypeAttribute];var j=this._subModels[k];if(j){m=j}}return new m(l,n)},initializeModelHierarchy:function(){if(h.isUndefined(this._superModel)||h.isNull(this._superModel)){g.Relational.store.setupSuperModel(this);if(this._superModel){if(this._superModel.prototype.relations){var j=h.any(this.prototype.relations,function(k){return k.model&&k.model!==this},this);if(!j){this.prototype.relations=this._superModel.prototype.relations.concat(this.prototype.relations)}}}else{this._superModel=false}}if(this.prototype.subModelTypes&&h.keys(this.prototype.subModelTypes).length!==h.keys(this._subModels).length){h.each(this.prototype.subModelTypes,function(l){var k=g.Relational.store.getObjectByName(l);k&&k.initializeModelHierarchy()})}},findOrCreate:function(j,l){var k=g.Relational.store.find(this,j);if(h.isObject(j)){if(k){k.set(j,l)}else{if(!l||(l&&l.create!==false)){k=this.build(j,l)}}}return k}});h.extend(g.RelationalModel.prototype,g.Semaphore);g.Collection.prototype.__prepareModel=g.Collection.prototype._prepareModel;g.Collection.prototype._prepareModel=function(l,k){k||(k={});if(!(l instanceof g.Model)){var j=l;k.collection=this;if(typeof this.model.build!=="undefined"){l=this.model.build(j,k)}else{l=new this.model(j,k)}if(!l._validate(l.attributes,k)){l=false}}else{if(!l.collection){l.collection=this}}return l};var i=g.Collection.prototype.__add=g.Collection.prototype.add;g.Collection.prototype.add=function(l,j){j||(j={});if(!h.isArray(l)){l=[l]}var k=[];h.each(l,function(n){if(!(n instanceof g.Model)){var m=g.Relational.store.find(this.model,n[this.model.prototype.idAttribute]);if(m){m.set(m.parse?m.parse(n):n,j);n=m}else{n=g.Collection.prototype._prepareModel.call(this,n,j)}}if(n instanceof g.Model&&!this.get(n)&&!this.getByCid(n)){k.push(n)}},this);if(k.length){i.call(this,k,j);h.each(k,function(m){this.trigger("relational:add",m,this,j)},this)}return this};var e=g.Collection.prototype.__remove=g.Collection.prototype.remove;g.Collection.prototype.remove=function(k,j){j||(j={});if(!h.isArray(k)){k=[k]}else{k=k.slice(0)}h.each(k,function(l){l=this.getByCid(l)||this.get(l);if(l instanceof g.Model){e.call(this,l,j);this.trigger("relational:remove",l,this,j)}},this);return this};var f=g.Collection.prototype.__reset=g.Collection.prototype.reset;g.Collection.prototype.reset=function(k,j){f.call(this,k,j);this.trigger("relational:reset",this,j);return this};var d=g.Collection.prototype.__sort=g.Collection.prototype.sort;g.Collection.prototype.sort=function(j){d.call(this,j);this.trigger("relational:reset",this,j);return this};var a=g.Collection.prototype.__trigger=g.Collection.prototype.trigger;g.Collection.prototype.trigger=function(k){if(k==="add"||k==="remove"||k==="reset"){var j=this,l=arguments;g.Relational.eventQueue.add(function(){a.apply(j,l)})}else{a.apply(this,arguments)}return this};g.RelationalModel.extend=function(j,k){var l=g.Model.extend.apply(this,arguments);l.setup(this);return l}})(); \ No newline at end of file diff --git a/static/scripts/packed/mvc/data.js b/static/scripts/packed/mvc/data.js new file mode 100644 index 00000000000..5cec43154a0 --- /dev/null +++ b/static/scripts/packed/mvc/data.js @@ -0,0 +1 @@ +var Dataset=Backbone.RelationalModel.extend({defaults:{id:"",type:"",name:"",hda_ldda:"hda"}});var DatasetCollection=Backbone.Collection.extend({model:Dataset}); \ No newline at end of file diff --git a/static/scripts/packed/mvc/tools.js b/static/scripts/packed/mvc/tools.js index b41377b1f51..2c0a1c55da3 100644 --- a/static/scripts/packed/mvc/tools.js +++ b/static/scripts/packed/mvc/tools.js @@ -1 +1 @@ -var BaseModel=Backbone.RelationalModel.extend({defaults:{name:null,hidden:false},show:function(){this.set("hidden",false)},hide:function(){this.set("hidden",true)},is_visible:function(){return !this.attributes.hidden}});var Tool=BaseModel.extend({defaults:{description:null,target:null,inputs:[]},relations:[{type:Backbone.HasMany,key:"inputs",relatedModel:"ToolInput",reverseRelation:{key:"tool"}}],urlRoot:galaxy_paths.attributes.root_path+"api/tools",apply_search_results:function(a){(_.indexOf(a,this.attributes.id)!==-1?this.show():this.hide());return this.is_visible()}});var ToolInput=Backbone.RelationalModel.extend({defaults:{name:null,type:null},initialize:function(){this.attributes.html=unescape(this.attributes.html)},get_samples:function(b){var c=this.get("type"),a=[];if(c==="number"){a=d3.scale.linear().domain([this.get("min"),this.get("max")]).ticks(b)}else{if(c==="select"){a=_.map(this.get("options"),function(d){return d[0]})}}return new ParamSamples({param:this,samples:a})}});var ParamSamples=Backbone.Model.extend({defaults:{param:null,samples:null}});var ToolCollection=Backbone.Collection.extend({model:Tool});var ToolPanelLabel=BaseModel.extend({});var ToolPanelSection=BaseModel.extend({defaults:{elems:[],open:false},clear_search_results:function(){_.each(this.attributes.elems,function(a){a.show()});this.show();this.set("open",false)},apply_search_results:function(b){var c=true,a;_.each(this.attributes.elems,function(d){if(d instanceof ToolPanelLabel){a=d;a.hide()}else{if(d instanceof Tool){if(d.apply_search_results(b)){c=false;if(a){a.show()}}}}});if(c){this.hide()}else{this.show();this.set("open",true)}}});var ToolSearch=BaseModel.extend({defaults:{spinner_url:"",search_url:"",visible:true,query:"",results:null},initialize:function(){this.on("change:query",this.do_search)},do_search:function(){var c=this.attributes.query;if(c.length<3){this.set("results",null);return}var b=c+"*";if(this.timer){clearTimeout(this.timer)}$("#search-spinner").show();var a=this;this.timer=setTimeout(function(){$.get(a.attributes.search_url,{query:b},function(d){a.set("results",d);$("#search-spinner").hide()},"json")},200)}});var ToolPanel=Backbone.Collection.extend({url:"/tools",tools:new ToolCollection(),parse:function(a){var b=function(e){var d=e.type;if(d==="tool"){return new Tool(e)}else{if(d==="section"){var c=_.map(e.elems,b);e.elems=c;return new ToolPanelSection(e)}else{if(d==="label"){return new ToolPanelLabel(e)}}}};return _.map(a,b)},initialize:function(a){this.tool_search=a.tool_search;this.tool_search.on("change:results",this.apply_search_results,this);this.on("reset",this.populate_tools,this)},populate_tools:function(){var a=this;a.tools=new ToolCollection();this.each(function(b){if(b instanceof ToolPanelSection){_.each(b.attributes.elems,function(c){if(c instanceof Tool){a.tools.push(c)}})}else{if(b instanceof Tool){a.tools.push(b)}}})},clear_search_results:function(){this.each(function(a){if(a instanceof ToolPanelSection){a.clear_search_results()}else{a.show()}})},apply_search_results:function(){var b=this.tool_search.attributes.results;if(b===null){this.clear_search_results();return}var a=null;this.each(function(c){if(c instanceof ToolPanelLabel){a=c;a.hide()}else{if(c instanceof Tool){if(c.apply_search_results(b)){if(a){a.show()}}}else{a=null;c.apply_search_results(b)}}})}});var BaseView=Backbone.View.extend({initialize:function(){this.model.on("change:hidden",this.update_visible,this);this.update_visible()},update_visible:function(){(this.model.attributes.hidden?this.$el.hide():this.$el.show())}});var ToolLinkView=BaseView.extend({tagName:"div",template:Handlebars.templates.tool_link,render:function(){this.$el.append(this.template(this.model.toJSON()));return this}});var ToolPanelLabelView=BaseView.extend({tagName:"div",className:"toolPanelLabel",render:function(){this.$el.append($("").text(this.model.attributes.name));return this}});var ToolPanelSectionView=BaseView.extend({tagName:"div",className:"toolSectionWrapper",template:Handlebars.templates.panel_section,initialize:function(){BaseView.prototype.initialize.call(this);this.model.on("change:open",this.update_open,this)},render:function(){this.$el.append(this.template(this.model.toJSON()));var a=this.$el.find(".toolSectionBody");_.each(this.model.attributes.elems,function(b){if(b instanceof Tool){var c=new ToolLinkView({model:b,className:"toolTitle"});c.render();a.append(c.$el)}else{if(b instanceof ToolPanelLabel){var d=new ToolPanelLabelView({model:b});d.render();a.append(d.$el)}else{}}});return this},events:{"click .toolSectionTitle > a":"toggle"},toggle:function(){this.model.set("open",!this.model.attributes.open)},update_open:function(){(this.model.attributes.open?this.$el.children(".toolSectionBody").slideDown("fast"):this.$el.children(".toolSectionBody").slideUp("fast"))}});var ToolSearchView=Backbone.View.extend({tagName:"div",id:"tool-search",className:"bar",template:Handlebars.templates.tool_search,events:{click:"focus_and_select","keyup :input":"query_changed"},render:function(){this.$el.append(this.template(this.model.toJSON()));if(!this.model.is_visible()){this.$el.hide()}return this},focus_and_select:function(){this.$el.find(":input").focus().select()},query_changed:function(){this.model.set("query",this.$el.find(":input").val())}});var ToolPanelView=Backbone.View.extend({tagName:"div",className:"toolMenu",initialize:function(){this.collection.tool_search.on("change:results",this.handle_search_results,this)},render:function(){var a=this;var b=new ToolSearchView({model:this.collection.tool_search});b.render();a.$el.append(b.$el);this.collection.each(function(d){if(d instanceof ToolPanelSection){var c=new ToolPanelSectionView({model:d});c.render();a.$el.append(c.$el)}else{if(d instanceof Tool){var e=new ToolLinkView({model:d,className:"toolTitleNoSection"});e.render();a.$el.append(e.$el)}else{if(d instanceof ToolPanelLabel){var f=new ToolPanelLabelView({model:d});f.render();a.$el.append(f.$el)}}}});a.$el.find("a.tool-link").click(function(f){var d=$(this).attr("class").split(/\s+/)[0],c=a.collection.tools.get(d);a.trigger("tool_link_click",f,c)});return this},handle_search_results:function(){var a=this.collection.tool_search.attributes.results;if(a&&a.length===0){$("#search-no-results").show()}else{$("#search-no-results").hide()}}});var ToolFormView=Backbone.View.extend({className:"toolForm",template:Handlebars.templates.tool_form,render:function(){this.$el.children().remove();this.$el.append(this.template(this.model.toJSON()))}});var IntegratedToolMenuAndView=Backbone.View.extend({className:"toolMenuAndView",initialize:function(){this.tool_panel_view=new ToolPanelView({collection:this.collection});this.tool_form_view=new ToolFormView()},render:function(){this.tool_panel_view.render();this.tool_panel_view.$el.css("float","left");this.$el.append(this.tool_panel_view.$el);this.tool_form_view.$el.hide();this.$el.append(this.tool_form_view.$el);var a=this;this.tool_panel_view.on("tool_link_click",function(c,b){c.preventDefault();a.show_tool(b)})},show_tool:function(b){var a=this;b.fetch().done(function(){a.tool_form_view.model=b;a.tool_form_view.render();a.tool_form_view.$el.show();$("#left").width("650px")})}}); \ No newline at end of file +var BaseModel=Backbone.RelationalModel.extend({defaults:{name:null,hidden:false},show:function(){this.set("hidden",false)},hide:function(){this.set("hidden",true)},is_visible:function(){return !this.attributes.hidden}});var Tool=BaseModel.extend({defaults:{description:null,target:null,inputs:[]},relations:[{type:Backbone.HasMany,key:"inputs",relatedModel:"ToolInput",reverseRelation:{key:"tool",includeInJSON:false}}],urlRoot:galaxy_paths.get("tool_url"),copy:function(b){var c=new Tool(this.toJSON());if(b){var a=new Backbone.Collection();c.get("inputs").each(function(d){if(d.get_samples()){a.push(d)}});c.set("inputs",a)}return c},apply_search_results:function(a){(_.indexOf(a,this.attributes.id)!==-1?this.show():this.hide());return this.is_visible()},set_input_value:function(a,b){this.get("inputs").find(function(c){return c.get("name")===a}).set("value",b)},set_input_values:function(b){var a=this;_.each(_.keys(b),function(c){a.set_input_value(c,b[c])})},run:function(){return this._run()},rerun:function(b,a){return this._run({action:"rerun",target_dataset_id:b.id,regions:a})},get_inputs_dict:function(){var a={};this.get("inputs").each(function(b){a[b.get("name")]=b.get("value")});return a},_run:function(c){var d=_.extend({tool_id:this.id,inputs:this.get_inputs_dict()},c);var b=$.Deferred(),a=new ServerStateDeferred({ajax_settings:{url:this.urlRoot,data:JSON.stringify(d),dataType:"json",contentType:"application/json",type:"POST"},interval:2000,success_fn:function(e){return e!=="pending"}});$.when(a.go()).then(function(e){b.resolve(new DatasetCollection().reset(e))});return b}});var ToolInput=Backbone.RelationalModel.extend({defaults:{name:null,label:null,type:null,value:null,num_samples:5},initialize:function(){this.attributes.html=unescape(this.attributes.html)},copy:function(){return new ToolInput(this.toJSON())},get_samples:function(){var b=this.get("type"),a=null;if(b==="number"){a=d3.scale.linear().domain([this.get("min"),this.get("max")]).ticks(this.get("num_samples"))}else{if(b==="select"){a=_.map(this.get("options"),function(c){return c[0]})}}return a}});var ToolCollection=Backbone.Collection.extend({model:Tool});var ToolPanelLabel=BaseModel.extend({});var ToolPanelSection=BaseModel.extend({defaults:{elems:[],open:false},clear_search_results:function(){_.each(this.attributes.elems,function(a){a.show()});this.show();this.set("open",false)},apply_search_results:function(b){var c=true,a;_.each(this.attributes.elems,function(d){if(d instanceof ToolPanelLabel){a=d;a.hide()}else{if(d instanceof Tool){if(d.apply_search_results(b)){c=false;if(a){a.show()}}}}});if(c){this.hide()}else{this.show();this.set("open",true)}}});var ToolSearch=BaseModel.extend({defaults:{spinner_url:"",search_url:"",visible:true,query:"",results:null},initialize:function(){this.on("change:query",this.do_search)},do_search:function(){var c=this.attributes.query;if(c.length<3){this.set("results",null);return}var b=c+"*";if(this.timer){clearTimeout(this.timer)}$("#search-spinner").show();var a=this;this.timer=setTimeout(function(){$.get(a.attributes.search_url,{query:b},function(d){a.set("results",d);$("#search-spinner").hide()},"json")},200)}});var ToolPanel=Backbone.Collection.extend({url:"/tools",tools:new ToolCollection(),parse:function(a){var b=function(e){var d=e.type;if(d==="tool"){return new Tool(e)}else{if(d==="section"){var c=_.map(e.elems,b);e.elems=c;return new ToolPanelSection(e)}else{if(d==="label"){return new ToolPanelLabel(e)}}}};return _.map(a,b)},initialize:function(a){this.tool_search=a.tool_search;this.tool_search.on("change:results",this.apply_search_results,this);this.on("reset",this.populate_tools,this)},populate_tools:function(){var a=this;a.tools=new ToolCollection();this.each(function(b){if(b instanceof ToolPanelSection){_.each(b.attributes.elems,function(c){if(c instanceof Tool){a.tools.push(c)}})}else{if(b instanceof Tool){a.tools.push(b)}}})},clear_search_results:function(){this.each(function(a){if(a instanceof ToolPanelSection){a.clear_search_results()}else{a.show()}})},apply_search_results:function(){var b=this.tool_search.attributes.results;if(b===null){this.clear_search_results();return}var a=null;this.each(function(c){if(c instanceof ToolPanelLabel){a=c;a.hide()}else{if(c instanceof Tool){if(c.apply_search_results(b)){if(a){a.show()}}}else{a=null;c.apply_search_results(b)}}})}});var BaseView=Backbone.View.extend({initialize:function(){this.model.on("change:hidden",this.update_visible,this);this.update_visible()},update_visible:function(){(this.model.attributes.hidden?this.$el.hide():this.$el.show())}});var ToolLinkView=BaseView.extend({tagName:"div",template:Handlebars.templates.tool_link,render:function(){this.$el.append(this.template(this.model.toJSON()));return this}});var ToolPanelLabelView=BaseView.extend({tagName:"div",className:"toolPanelLabel",render:function(){this.$el.append($("").text(this.model.attributes.name));return this}});var ToolPanelSectionView=BaseView.extend({tagName:"div",className:"toolSectionWrapper",template:Handlebars.templates.panel_section,initialize:function(){BaseView.prototype.initialize.call(this);this.model.on("change:open",this.update_open,this)},render:function(){this.$el.append(this.template(this.model.toJSON()));var a=this.$el.find(".toolSectionBody");_.each(this.model.attributes.elems,function(b){if(b instanceof Tool){var c=new ToolLinkView({model:b,className:"toolTitle"});c.render();a.append(c.$el)}else{if(b instanceof ToolPanelLabel){var d=new ToolPanelLabelView({model:b});d.render();a.append(d.$el)}else{}}});return this},events:{"click .toolSectionTitle > a":"toggle"},toggle:function(){this.model.set("open",!this.model.attributes.open)},update_open:function(){(this.model.attributes.open?this.$el.children(".toolSectionBody").slideDown("fast"):this.$el.children(".toolSectionBody").slideUp("fast"))}});var ToolSearchView=Backbone.View.extend({tagName:"div",id:"tool-search",className:"bar",template:Handlebars.templates.tool_search,events:{click:"focus_and_select","keyup :input":"query_changed"},render:function(){this.$el.append(this.template(this.model.toJSON()));if(!this.model.is_visible()){this.$el.hide()}return this},focus_and_select:function(){this.$el.find(":input").focus().select()},query_changed:function(){this.model.set("query",this.$el.find(":input").val())}});var ToolPanelView=Backbone.View.extend({tagName:"div",className:"toolMenu",initialize:function(){this.collection.tool_search.on("change:results",this.handle_search_results,this)},render:function(){var a=this;var b=new ToolSearchView({model:this.collection.tool_search});b.render();a.$el.append(b.$el);this.collection.each(function(d){if(d instanceof ToolPanelSection){var c=new ToolPanelSectionView({model:d});c.render();a.$el.append(c.$el)}else{if(d instanceof Tool){var e=new ToolLinkView({model:d,className:"toolTitleNoSection"});e.render();a.$el.append(e.$el)}else{if(d instanceof ToolPanelLabel){var f=new ToolPanelLabelView({model:d});f.render();a.$el.append(f.$el)}}}});a.$el.find("a.tool-link").click(function(f){var d=$(this).attr("class").split(/\s+/)[0],c=a.collection.tools.get(d);a.trigger("tool_link_click",f,c)});return this},handle_search_results:function(){var a=this.collection.tool_search.attributes.results;if(a&&a.length===0){$("#search-no-results").show()}else{$("#search-no-results").hide()}}});var ToolFormView=Backbone.View.extend({className:"toolForm",template:Handlebars.templates.tool_form,render:function(){this.$el.children().remove();this.$el.append(this.template(this.model.toJSON()))}});var IntegratedToolMenuAndView=Backbone.View.extend({className:"toolMenuAndView",initialize:function(){this.tool_panel_view=new ToolPanelView({collection:this.collection});this.tool_form_view=new ToolFormView()},render:function(){this.tool_panel_view.render();this.tool_panel_view.$el.css("float","left");this.$el.append(this.tool_panel_view.$el);this.tool_form_view.$el.hide();this.$el.append(this.tool_form_view.$el);var a=this;this.tool_panel_view.on("tool_link_click",function(c,b){c.preventDefault();a.show_tool(b)})},show_tool:function(b){var a=this;b.fetch().done(function(){a.tool_form_view.model=b;a.tool_form_view.render();a.tool_form_view.$el.show();$("#left").width("650px")})}}); \ No newline at end of file diff --git a/static/scripts/packed/mvc/ui.js b/static/scripts/packed/mvc/ui.js index 78018023600..daaf92b8cc9 100644 --- a/static/scripts/packed/mvc/ui.js +++ b/static/scripts/packed/mvc/ui.js @@ -1 +1 @@ -var create_icon_buttons_menu=function(a){var b=new IconButtonCollection(_.map(a,function(c){return new IconButton(c)}));return new IconButtonMenuView({collection:b})};var GalaxyPaths=Backbone.Model.extend({defaults:{root_path:"",image_path:""}});var IconButton=Backbone.Model.extend({defaults:{title:"",icon_class:"",on_click:null}});var IconButtonCollection=Backbone.Collection.extend({model:IconButton});var IconButtonMenuView=Backbone.View.extend({tagName:"div",render:function(){var a=this;this.collection.each(function(b){$("").attr("href","javascript:void(0)").attr("title",b.attributes.title).addClass("icon-button menu-button").addClass(b.attributes.icon_class).appendTo(a.$el).click(b.attributes.on_click)});return this}});var Grid=Backbone.Collection.extend({});var GridView=Backbone.View.extend({}); \ No newline at end of file +var create_icon_buttons_menu=function(b,a){if(!a){a={}}var c=new IconButtonCollection(_.map(b,function(d){return new IconButton(_.extend(d,a))}));return new IconButtonMenuView({collection:c})};var GalaxyPaths=Backbone.Model.extend({defaults:{root_path:"",image_path:""}});var IconButton=Backbone.Model.extend({defaults:{title:"",icon_class:"",on_click:null,tipsy_config:{}}});var IconButtonCollection=Backbone.Collection.extend({model:IconButton});var IconButtonMenuView=Backbone.View.extend({tagName:"div",initialize:function(){this.render()},render:function(){var a=this;this.collection.each(function(c){var b=$("").attr("href","javascript:void(0)").attr("title",c.attributes.title).addClass("icon-button menu-button").addClass(c.attributes.icon_class).appendTo(a.$el).click(c.attributes.on_click);if(c.attributes.tipsy_config){b.tipsy(c.attributes.tipsy_config)}});return this}});var Grid=Backbone.Collection.extend({});var GridView=Backbone.View.extend({}); \ No newline at end of file diff --git a/static/scripts/packed/viz/paramamonster.js b/static/scripts/packed/viz/paramamonster.js index db08246a253..235c0cbb950 100644 --- a/static/scripts/packed/viz/paramamonster.js +++ b/static/scripts/packed/viz/paramamonster.js @@ -1 +1 @@ -var ToolParameterTree=Backbone.Model.extend({defaults:{tool:null,params:null,num_samples:4},initialize:function(d){var c=this.get("tool"),b=this.get("num_samples"),f=c.get("inputs").map(function(h){return h.get_samples(b)}),a=_.filter(f,function(h){return h.get("samples").length!==0});var g=function(j,h){var m=j[h],l=m.get("param"),k=l.get("name"),i=m.get("samples");if(j.length-1===h){return _.map(i,function(n){return{name:k+"="+n,param:l}})}return _.map(i,function(n){return{name:k+"="+n,param:l,children:g(a,h+1)}})};var e={name:"Parameter Tree for "+c.get("name"),children:g(a,0)};this.set("params",_.map(f,function(h){return h.get("param")}));this.set("tree_data",e)}});var Tile=Backbone.Model.extend({defaults:{track:null,index:null,region:null,resolution:null,data:null,stale:null,html_elt:null},initialize:function(a){}});var Track=Backbone.Model.extend({defaults:{dataset:null}});var FeatureTrack=Track.extend({defaults:{track:null},draw_tile:function(n,r,p,s,d,j,c){var q=this,b=r.canvas,y=d.get("start"),a=d.get("end"),D=25,e=this.left_offset;if(p==="summary_tree"||p==="Histogram"){if(n.dataset_type!=="summary_tree"){var k=this.get_summary_tree_data(n.data,y,a,200);if(n.max){k.max=n.max}n=k}var A=new painters.SummaryTreePainter(n,y,a,this.prefs);A.draw(r,b.width,b.height,j);return new SummaryTreeTile(q,tile_index,s,b,n.data,n.max)}var h=[],o=this.slotters[j].slots;all_slotted=true;if(n.data){var l=this.filters_manager.filters;for(var t=0,v=n.data.length;t").addClass("settings").appendTo(this.$el),b=$("
").addClass("track-info").hide().appendTo(c);b.append($("
").css("font-weight","bold").text("Track Settings"));_.each(_.keys(e),function(g){b.append(g+": "+e[g]+"
")});var a=this,f=$("