commit/galaxy-central: carlfeberhard: History panel: use SessionStorageModel, remove PersistentStorage
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/01b5a1a68ae6/ Changeset: 01b5a1a68ae6 User: carlfeberhard Date: 2013-11-25 20:24:14 Summary: History panel: use SessionStorageModel, remove PersistentStorage Affected #: 5 files diff -r 0e1d539dcfcb3246f144258514a43e07a514b52e -r 01b5a1a68ae6901936b6948769aa66b446e52e53 static/scripts/mvc/base-mvc.js --- a/static/scripts/mvc/base-mvc.js +++ b/static/scripts/mvc/base-mvc.js @@ -92,18 +92,30 @@ /** Backbone model that syncs to the browser's sessionStorage API. */ var SessionStorageModel = Backbone.Model.extend({ - initialize : function( hash, x, y, z ){ - if( !hash || !hash.hasOwnProperty( 'id' ) ){ - throw new Error( 'SessionStorageModel needs an id on init' ); - } - // immed. save the passed in model and save on any change to it - this.save(); + initialize : function( initialAttrs ){ + // create unique id if none provided + initialAttrs.id = ( !_.isString( initialAttrs.id ) )?( _.uniqueId() ):( initialAttrs.id ); + this.id = initialAttrs.id; + + // load existing from storage (if any), clear any attrs set by bbone before init is called, + // layer initial over existing and defaults, and save + var existing = ( !this.isNew() )?( this._read( this ) ):( {} ); + this.clear({ silent: true }); + this.save( _.extend( {}, this.defaults, existing, initialAttrs ), { silent: true }); + + // save on any change to it immediately this.on( 'change', function(){ this.save(); }); }, + + /** override of bbone sync to save to sessionStorage rather than REST + * bbone options (success, errror, etc.) should still apply + */ sync : function( method, model, options ){ - model.trigger('request', model, {}, options); + if( !options.silent ){ + model.trigger( 'request', model, {}, options ); + } var returned; switch( method ){ case 'create' : returned = this._create( model ); break; @@ -118,23 +130,41 @@ } return returned; }, + + /** set storage to the stringified item */ _create : function( model ){ var json = model.toJSON(), set = sessionStorage.setItem( model.id, JSON.stringify( json ) ); return ( set === null )?( set ):( json ); }, + + /** read and parse json from storage */ _read : function( model ){ - return JSON.parse( sessionStorage.getItem( model.id, JSON.stringify( model.toJSON() ) ) ); + return JSON.parse( sessionStorage.getItem( model.id ) ); }, + + /** set storage to the item (alias to create) */ _update : function( model ){ return model._create( model ); }, + + /** remove the item from storage */ _delete : function( model ){ return sessionStorage.removeItem( model.id ); }, + + /** T/F whether sessionStorage contains the model's id (data is present) */ isNew : function(){ return !sessionStorage.hasOwnProperty( this.id ); + }, + + _log : function(){ + return JSON.stringify( this.toJSON(), null, ' ' ); + }, + toString : function(){ + return 'SessionStorageModel(' + this.id + ')'; } + }); (function(){ SessionStorageModel.prototype = _.omit( SessionStorageModel.prototype, 'url', 'urlRoot' ); @@ -142,136 +172,6 @@ //============================================================================== -/** - * @class persistent storage adapter. - * Provides an easy interface to object based storage using method chaining. - * Allows easy change of the storage engine used (h5's local storage?). - * @augments StorageRecursionHelper - * - * @param {String} storageKey : the key the storage engine will place the storage object under - * @param {Object} storageDefaults : [optional] initial object to set up storage with - * - * @example - * // example of construction and use - * HistoryPanel.storage = new PersistanStorage( HistoryPanel.toString(), { visibleItems, {} }); - * itemView.bind( 'toggleBodyVisibility', function( id, visible ){ - * if( visible ){ - * HistoryPanel.storage.get( 'visibleItems' ).set( id, true ); - * } else { - * HistoryPanel.storage.get( 'visibleItems' ).deleteKey( id ); - * } - * }); - * @constructor - */ -var PersistentStorage = function( storageKey, storageDefaults ){ - if( !storageKey ){ - throw( "PersistentStorage needs storageKey argument" ); - } - storageDefaults = storageDefaults || {}; - - // ~constants for the current engine - var STORAGE_ENGINE = sessionStorage, - STORAGE_ENGINE_GETTER = function sessionStorageGet( key ){ - var item = this.getItem( key ); - return ( item !== null )?( JSON.parse( this.getItem( key ) ) ):( null ); - }, - STORAGE_ENGINE_SETTER = function sessionStorageSet( key, val ){ - return this.setItem( key, JSON.stringify( val ) ); - }, - STORAGE_ENGINE_KEY_DELETER = function sessionStorageDel( key ){ return this.removeItem( key ); }; - - /** Inner, recursive, private class for method chaining access. - * @name StorageRecursionHelper - * @constructor - */ - function StorageRecursionHelper( data, parent ){ - //console.debug( 'new StorageRecursionHelper. data:', data ); - data = data || {}; - parent = parent || null; - - return /** @lends StorageRecursionHelper.prototype */{ - /** get a value from the storage obj named 'key', - * if it's an object - return a new StorageRecursionHelper wrapped around it - * if it's something simpler - return the value - * if this isn't passed a key - return the data at this level of recursion - */ - get : function( key ){ - //console.debug( this + '.get', key ); - if( key === undefined ){ - return data; - } else if( data.hasOwnProperty( key ) ){ - return ( jQuery.type( data[ key ] ) === 'object' )? - ( new StorageRecursionHelper( data[ key ], this ) ) - :( data[ key ] ); - } - return undefined; - }, - /** get the underlying data based on this key */ - // set a value on the current data - then pass up to top to save current entire object in storage - set : function( key, value ){ - //TODO: add parameterless variation setting the data somehow - // ??: difficult bc of obj by ref, closure - //console.debug( this + '.set', key, value ); - data[ key ] = value; - this._save(); - return this; - }, - // remove a key at this level - then save entire (as 'set' above) - deleteKey : function( key ){ - //console.debug( this + '.deleteKey', key ); - delete data[ key ]; - this._save(); - return this; - }, - // pass up the recursion chain (see below for base case) - _save : function(){ - //console.debug( this + '.save', parent ); - return parent._save(); - }, - toString : function(){ - return ( 'StorageRecursionHelper(' + data + ')' ); - } - }; - } - - //??: more readable to make another class? - var returnedStorage = {}, - // attempt to get starting data from engine... - data = STORAGE_ENGINE_GETTER.call( STORAGE_ENGINE, storageKey ); - - // ...if that fails, use the defaults (and store them) - if( data === null || data === undefined ){ - data = jQuery.extend( true, {}, storageDefaults ); - STORAGE_ENGINE_SETTER.call( STORAGE_ENGINE, storageKey, data ); - } - - // the object returned by this constructor will be a modified StorageRecursionHelper - returnedStorage = new StorageRecursionHelper( data ); - jQuery.extend( returnedStorage, /** @lends PersistentStorage.prototype */{ - /** The base case for save()'s upward recursion - save everything to storage. - * @private - * @param {Any} newData data object to save to storage - */ - _save : function( newData ){ - //console.debug( returnedStorage, '._save:', JSON.stringify( returnedStorage.get() ) ); - return STORAGE_ENGINE_SETTER.call( STORAGE_ENGINE, storageKey, returnedStorage.get() ); - }, - /** Delete function to remove the entire base data object from the storageEngine. - */ - destroy : function(){ - //console.debug( returnedStorage, '.destroy:' ); - return STORAGE_ENGINE_KEY_DELETER.call( STORAGE_ENGINE, storageKey ); - }, - /** String representation. - */ - toString : function(){ return 'PersistentStorage(' + storageKey + ')'; } - }); - - return returnedStorage; -}; - - -//============================================================================== var HiddenUntilActivatedViewMixin = /** @lends hiddenUntilActivatedMixin# */{ /** */ diff -r 0e1d539dcfcb3246f144258514a43e07a514b52e -r 01b5a1a68ae6901936b6948769aa66b446e52e53 static/scripts/mvc/dataset/hda-base.js --- a/static/scripts/mvc/dataset/hda-base.js +++ b/static/scripts/mvc/dataset/hda-base.js @@ -93,8 +93,8 @@ var $newRender = $( HDABaseView.templates.skeleton( this.model.toJSON() ) ); $newRender.find( '.dataset-primary-actions' ).append( this._render_titleButtons() ); $newRender.children( '.dataset-body' ).replaceWith( this._render_body() ); + this._setUpBehaviors( $newRender ); //this._renderSelectable( $newRender ); - this._setUpBehaviors( $newRender ); // fade the old render out (if desired) if( fade ){ diff -r 0e1d539dcfcb3246f144258514a43e07a514b52e -r 01b5a1a68ae6901936b6948769aa66b446e52e53 static/scripts/mvc/history/history-panel.js --- a/static/scripts/mvc/history/history-panel.js +++ b/static/scripts/mvc/history/history-panel.js @@ -3,6 +3,44 @@ "mvc/dataset/hda-base", "mvc/dataset/hda-edit" ], function( historyModel, hdaBase, hdaEdit ){ + + +// ============================================================================ +/** session storage for individual history preferences + */ +var HistoryPanelPrefs = SessionStorageModel.extend({ + defaults : { + //TODO:?? expandedHdas to array? + expandedHdas : {}, + //TODO:?? move to user? + show_deleted : false, + show_hidden : false + //TODO: add scroll position? + }, + /** add an hda id to the hash of expanded hdas */ + addExpandedHda : function( id ){ + this.save( 'expandedHdas', _.extend( this.get( 'expandedHdas' ), _.object([ id ], [ true ]) ) ); + }, + /** remove an hda id from the hash of expanded hdas */ + removeExpandedHda : function( id ){ + this.save( 'expandedHdas', _.omit( this.get( 'expandedHdas' ), id ) ); + }, + toString : function(){ + return 'HistoryPanelPrefs(' + this.id + ')'; + } +}); + +/** key string to store each histories settings under */ +HistoryPanelPrefs.historyStorageKey = function historyStorageKey( historyId ){ + // class lvl for access w/o instantiation + if( !historyId ){ + throw new Error( 'HistoryPanelPrefs.historyStorageKey needs valid id: ' + historyId ); + } + // single point of change + return ( 'history:' + historyId ); +}; + + /* ============================================================================= Backbone.js implementation of history panel @@ -216,8 +254,8 @@ // - hdas w/o details will have summary data only (name, hid, deleted, visible, state, etc.)) /** (re-)loads the user's current history & hdas w/ details */ - // implemented as a 'fresh start' or for when there is no model (intial panel render) loadCurrentHistory : function( attributes ){ + // implemented as a 'fresh start' or for when there is no model (intial panel render) var panel = this; return this.loadHistoryWithHDADetails( 'current', attributes ) .then(function( historyData, hdaData ){ @@ -334,7 +372,7 @@ return this; }, - // alias to the model. Updates the hda list only (not the history) + /** alias to the model. Updates the hda list only (not the history) */ refreshHdas : function( detailIds, options ){ if( this.model ){ return this.model.refresh( detailIds, options ); @@ -344,8 +382,6 @@ }, // ------------------------------------------------------------------------ browser stored prefs -//TODO: simplify - /** Set up client side storage. Currently PersistanStorage keyed under 'HistoryPanel.<id>' * @param {Object} initiallyExpanded * @param {Boolean} show_deleted whether to show deleted HDAs (overrides stored) @@ -353,55 +389,31 @@ * @see PersistentStorage */ _setUpWebStorage : function( initiallyExpanded, show_deleted, show_hidden ){ - //this.log( '_setUpWebStorage, initiallyExpanded:', initiallyExpanded, - // 'show_deleted:', show_deleted, 'show_hidden', show_hidden ); + //console.debug( '_setUpWebStorage', initiallyExpanded, show_deleted, show_hidden ); + this.storage = new HistoryPanelPrefs({ + id: HistoryPanelPrefs.historyStorageKey( this.model.get( 'id' ) ) + }); - //TODO: add scroll position? - - // data that needs to be persistent over page refreshes - // (note the key function which uses the history id as well) - this.storage = new PersistentStorage( this._getStorageKey( this.model.get( 'id' ) ), { - expandedHdas : {}, - show_deleted : false, - show_hidden : false - }); - this.log( this + ' (prev) storage:', JSON.stringify( this.storage.get(), null, 2 ) ); - - // expanded Hdas is a map of hda.ids -> a boolean rep'ing whether this hda's body is expanded + // expanded Hdas is a map of hda.ids -> a boolean repr'ing whether this hda's body is already expanded // store any pre-expanded ids passed in - if( initiallyExpanded ){ + if( _.isObject( initiallyExpanded ) ){ this.storage.set( 'exandedHdas', initiallyExpanded ); } - //TODO: should be global pref? (not specific to each history) - - // get the show_deleted/hidden settings giving priority to values passed in, - // using web storage otherwise + // get the show_deleted/hidden settings giving priority to values passed in, using web storage otherwise // if the page has specifically requested show_deleted/hidden, these will be either true or false // (as opposed to undefined, null) - and we give priority to that setting - if( ( show_deleted === true ) || ( show_deleted === false ) ){ - // save them to web storage + if( _.isBoolean( show_deleted ) ){ this.storage.set( 'show_deleted', show_deleted ); } - if( ( show_hidden === true ) || ( show_hidden === false ) ){ + if( _.isBoolean( show_hidden ) ){ this.storage.set( 'show_hidden', show_hidden ); } - // if the page hasn't specified whether to show_deleted/hidden, pull show_deleted/hidden from the web storage - this.show_deleted = this.storage.get( 'show_deleted' ); - this.show_hidden = this.storage.get( 'show_hidden' ); - //this.log( 'this.show_deleted:', this.show_deleted, 'show_hidden', this.show_hidden ); + this.trigger( 'new-storage', this.storage, this ); this.log( this + ' (init\'d) storage:', this.storage.get() ); }, - /** key string to store each histories settings under */ - _getStorageKey : function( id ){ - if( !id ){ - throw new Error( '_getStorageKey needs valid id: ' + id ); - } - return ( 'history:' + id ); - }, - /** clear all stored history panel data */ clearWebStorage : function(){ for( var key in sessionStorage ){ @@ -417,11 +429,11 @@ return ( this.storage )?( this.storage.get() ):( {} ); } //TODO: make storage engine generic - var item = sessionStorage.getItem( this._getStorageKey( historyId ) ); + var item = sessionStorage.getItem( HistoryPanelPrefs.historyStorageKey( historyId ) ); return ( item === null )?( {} ):( JSON.parse( item ) ); }, - /** get all the map of expaneded hda ids for the given history id */ + /** get an array of expanded hda ids for the given history id */ getExpandedHdaIds : function( historyId ){ var expandedHdas = this.getStoredOptions( historyId ).expandedHdas; return (( _.isEmpty( expandedHdas ) )?( [] ):( _.keys( expandedHdas ) )); @@ -509,7 +521,7 @@ */ createHdaView : function( hda ){ var hdaId = hda.get( 'id' ), - expanded = this.storage.get( 'expandedHdas' ).get( hdaId ), + expanded = this.storage.get( 'expandedHdas' )[ hdaId ], hdaView = new this.HDAView({ model : hda, expanded : expanded, @@ -529,10 +541,10 @@ var historyView = this; // maintain a list of hdas whose bodies are expanded hdaView.on( 'body-expanded', function( id ){ - historyView.storage.get( 'expandedHdas' ).set( id, true ); + historyView.storage.addExpandedHda( id ); }); hdaView.on( 'body-collapsed', function( id ){ - historyView.storage.get( 'expandedHdas' ).deleteKey( id ); + historyView.storage.removeExpandedHda( id ); }); //TODO: remove? hdaView.on( 'error', function( model, xhr, options, msg ){ diff -r 0e1d539dcfcb3246f144258514a43e07a514b52e -r 01b5a1a68ae6901936b6948769aa66b446e52e53 static/scripts/packed/mvc/base-mvc.js --- a/static/scripts/packed/mvc/base-mvc.js +++ b/static/scripts/packed/mvc/base-mvc.js @@ -1,1 +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 BaseView=Backbone.View.extend({initialize:function(){this.model.on("change:hidden",this.update_visible,this);this.update_visible()},update_visible:function(){if(this.model.attributes.hidden){this.$el.hide()}else{this.$el.show()}}});var LoggableMixin={logger:null,log:function(){if(this.logger){var a=this.logger.log;if(typeof this.logger.log==="object"){a=Function.prototype.bind.call(this.logger.log,this.logger)}return a.apply(this.logger,arguments)}return undefined}};var SessionStorageModel=Backbone.Model.extend({initialize:function(b,a,d,c){if(!b||!b.hasOwnProperty("id")){throw new Error("SessionStorageModel needs an id on init")}this.save();this.on("change",function(){this.save()})},sync:function(d,b,a){b.trigger("request",b,{},a);var c;switch(d){case"create":c=this._create(b);break;case"read":c=this._read(b);break;case"update":c=this._update(b);break;case"delete":c=this._delete(b);break}if(c!==undefined||c!==null){if(a.success){a.success()}}else{if(a.error){a.error()}}return c},_create:function(a){var b=a.toJSON(),c=sessionStorage.setItem(a.id,JSON.stringify(b));return(c===null)?(c):(b)},_read:function(a){return JSON.parse(sessionStorage.getItem(a.id,JSON.stringify(a.toJSON())))},_update:function(a){return a._create(a)},_delete:function(a){return sessionStorage.removeItem(a.id)},isNew:function(){return !sessionStorage.hasOwnProperty(this.id)}});(function(){SessionStorageModel.prototype=_.omit(SessionStorageModel.prototype,"url","urlRoot")}());var PersistentStorage=function(k,g){if(!k){throw ("PersistentStorage needs storageKey argument")}g=g||{};var i=sessionStorage,c=function j(m){var n=this.getItem(m);return(n!==null)?(JSON.parse(this.getItem(m))):(null)},b=function e(m,n){return this.setItem(m,JSON.stringify(n))},d=function f(m){return this.removeItem(m)};function a(n,m){n=n||{};m=m||null;return{get:function(o){if(o===undefined){return n}else{if(n.hasOwnProperty(o)){return(jQuery.type(n[o])==="object")?(new a(n[o],this)):(n[o])}}return undefined},set:function(o,p){n[o]=p;this._save();return this},deleteKey:function(o){delete n[o];this._save();return this},_save:function(){return m._save()},toString:function(){return("StorageRecursionHelper("+n+")")}}}var l={},h=c.call(i,k);if(h===null||h===undefined){h=jQuery.extend(true,{},g);b.call(i,k,h)}l=new a(h);jQuery.extend(l,{_save:function(m){return b.call(i,k,l.get())},destroy:function(){return d.call(i,k)},toString:function(){return"PersistentStorage("+k+")"}});return l};var HiddenUntilActivatedViewMixin={hiddenUntilActivated:function(a,c){c=c||{};this.HUAVOptions={$elementShown:this.$el,showFn:jQuery.prototype.toggle,showSpeed:"fast"};_.extend(this.HUAVOptions,c||{});this.HUAVOptions.hasBeenShown=this.HUAVOptions.$elementShown.is(":visible");if(a){var b=this;a.on("click",function(d){b.toggle(b.HUAVOptions.showSpeed)})}},toggle:function(){if(this.HUAVOptions.$elementShown.is(":hidden")){if(!this.HUAVOptions.hasBeenShown){if(_.isFunction(this.HUAVOptions.onshowFirstTime)){this.HUAVOptions.hasBeenShown=true;this.HUAVOptions.onshowFirstTime.call(this)}}else{if(_.isFunction(this.HUAVOptions.onshow)){this.HUAVOptions.onshow.call(this)}}}return this.HUAVOptions.showFn.apply(this.HUAVOptions.$elementShown,arguments)}}; \ 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 BaseView=Backbone.View.extend({initialize:function(){this.model.on("change:hidden",this.update_visible,this);this.update_visible()},update_visible:function(){if(this.model.attributes.hidden){this.$el.hide()}else{this.$el.show()}}});var LoggableMixin={logger:null,log:function(){if(this.logger){var a=this.logger.log;if(typeof this.logger.log==="object"){a=Function.prototype.bind.call(this.logger.log,this.logger)}return a.apply(this.logger,arguments)}return undefined}};var SessionStorageModel=Backbone.Model.extend({initialize:function(b){b.id=(!_.isString(b.id))?(_.uniqueId()):(b.id);this.id=b.id;var a=(!this.isNew())?(this._read(this)):({});this.clear({silent:true});this.save(_.extend({},this.defaults,a,b),{silent:true});this.on("change",function(){this.save()})},sync:function(d,b,a){if(!a.silent){b.trigger("request",b,{},a)}var c;switch(d){case"create":c=this._create(b);break;case"read":c=this._read(b);break;case"update":c=this._update(b);break;case"delete":c=this._delete(b);break}if(c!==undefined||c!==null){if(a.success){a.success()}}else{if(a.error){a.error()}}return c},_create:function(a){var b=a.toJSON(),c=sessionStorage.setItem(a.id,JSON.stringify(b));return(c===null)?(c):(b)},_read:function(a){return JSON.parse(sessionStorage.getItem(a.id))},_update:function(a){return a._create(a)},_delete:function(a){return sessionStorage.removeItem(a.id)},isNew:function(){return !sessionStorage.hasOwnProperty(this.id)},_log:function(){return JSON.stringify(this.toJSON(),null," ")},toString:function(){return"SessionStorageModel("+this.id+")"}});(function(){SessionStorageModel.prototype=_.omit(SessionStorageModel.prototype,"url","urlRoot")}());var HiddenUntilActivatedViewMixin={hiddenUntilActivated:function(a,c){c=c||{};this.HUAVOptions={$elementShown:this.$el,showFn:jQuery.prototype.toggle,showSpeed:"fast"};_.extend(this.HUAVOptions,c||{});this.HUAVOptions.hasBeenShown=this.HUAVOptions.$elementShown.is(":visible");if(a){var b=this;a.on("click",function(d){b.toggle(b.HUAVOptions.showSpeed)})}},toggle:function(){if(this.HUAVOptions.$elementShown.is(":hidden")){if(!this.HUAVOptions.hasBeenShown){if(_.isFunction(this.HUAVOptions.onshowFirstTime)){this.HUAVOptions.hasBeenShown=true;this.HUAVOptions.onshowFirstTime.call(this)}}else{if(_.isFunction(this.HUAVOptions.onshow)){this.HUAVOptions.onshow.call(this)}}}return this.HUAVOptions.showFn.apply(this.HUAVOptions.$elementShown,arguments)}}; \ No newline at end of file diff -r 0e1d539dcfcb3246f144258514a43e07a514b52e -r 01b5a1a68ae6901936b6948769aa66b446e52e53 static/scripts/packed/mvc/history/history-panel.js --- a/static/scripts/packed/mvc/history/history-panel.js +++ b/static/scripts/packed/mvc/history/history-panel.js @@ -1,1 +1,1 @@ -define(["mvc/history/history-model","mvc/dataset/hda-base","mvc/dataset/hda-edit"],function(d,b,a){var c=Backbone.View.extend(LoggableMixin).extend({HDAView:a.HDAEditView,tagName:"div",className:"history-panel",fxSpeed:"fast",datasetsSelector:".datasets-list",emptyMsgSelector:".empty-history-message",msgsSelector:".message-container",initialize:function(e){e=e||{};if(e.logger){this.logger=e.logger}this.log(this+".initialize:",e);this._setUpListeners();this.hdaViews={};this.indicator=new LoadingIndicator(this.$el);this.filters=[];if(this.model){this._setUpWebStorage(e.initiallyExpanded,e.show_deleted,e.show_hidden);this._setUpModelEventHandlers()}if(e.onready){e.onready.call(this)}},_setUpListeners:function(){this.on("error",function(f,i,e,h,g){this.errorHandler(f,i,e,h,g)});this.on("loading-history",function(){this.showLoadingIndicator("loading history...")});this.on("loading-done",function(){this.hideLoadingIndicator()});this.once("rendered",function(){this.trigger("rendered:initial",this);return false});this.on("switched-history current-history new-history",function(){if(_.isEmpty(this.hdaViews)){this.trigger("empty-history",this)}});if(this.logger){this.on("all",function(e){this.log(this+"",arguments)},this)}},errorHandler:function(g,j,f,i,h){var e=this._parseErrorMessage(g,j,f,i,h);if(j&&j.status===0&&j.readyState===0){}else{if(j&&j.status===502){}else{if(!this.$el.find(this.msgsSelector).is(":visible")){this.once("rendered",function(){this.displayMessage("error",e.message,e.details)})}else{this.displayMessage("error",e.message,e.details)}}}},_parseErrorMessage:function(h,l,g,k,j){var f=Galaxy.currUser,e={message:this._bePolite(k),details:{user:(f instanceof User)?(f.toJSON()):(f+""),source:(h instanceof Backbone.Model)?(h.toJSON()):(h+""),xhr:l,options:(l)?(_.omit(g,"xhr")):(g)}};_.extend(e.details,j||{});if(l&&_.isFunction(l.getAllResponseHeaders)){var i=l.getAllResponseHeaders();i=_.compact(i.split("\n"));i=_.map(i,function(m){return m.split(": ")});e.details.xhr.responseHeaders=_.object(i)}return e},_bePolite:function(e){e=e||_l("An error occurred while getting updates from the server");return e+". "+_l("Please contact a Galaxy administrator if the problem persists.")},loadCurrentHistory:function(f){var e=this;return this.loadHistoryWithHDADetails("current",f).then(function(h,g){e.trigger("current-history",e)})},switchToHistory:function(h,g){var e=this,f=function(){return jQuery.post(galaxy_config.root+"api/histories/"+h+"/set_as_current")};return this.loadHistoryWithHDADetails(h,g,f).then(function(j,i){e.trigger("switched-history",e)})},createNewHistory:function(g){if(!Galaxy||!Galaxy.currUser||Galaxy.currUser.isAnonymous()){this.displayMessage("error",_l("You must be logged in to create histories"));return $.when()}var e=this,f=function(){return jQuery.post(galaxy_config.root+"api/histories",{current:true})};return this.loadHistory(undefined,g,f).then(function(i,h){e.trigger("new-history",e)})},loadHistoryWithHDADetails:function(h,g,f,j){var e=this,i=function(k){return e.getExpandedHdaIds(k.id)};return this.loadHistory(h,g,f,j,i)},loadHistory:function(h,g,f,k,i){this.trigger("loading-history",this);g=g||{};var e=this;var j=d.History.getHistoryData(h,{historyFn:f,hdaFn:k,hdaDetailIds:g.initiallyExpanded||i});return this._loadHistoryFromXHR(j,g).fail(function(n,l,m){e.trigger("error",e,n,g,_l("An error was encountered while "+l),{historyId:h,history:m||{}})}).always(function(){e.trigger("loading-done",e)})},_loadHistoryFromXHR:function(g,f){var e=this;g.then(function(h,i){e.setModel(h,i,f)});g.fail(function(i,h){e.render()});return g},setModel:function(g,e,f){f=f||{};if(this.model){this.model.clearUpdateTimeout();this.stopListening(this.model);this.stopListening(this.model.hdas)}this.hdaViews={};if(Galaxy&&Galaxy.currUser){g.user=Galaxy.currUser.toJSON()}this.model=new d.History(g,e,f);this._setUpWebStorage(f.initiallyExpanded,f.show_deleted,f.show_hidden);this._setUpModelEventHandlers();this.trigger("new-model",this);this.render();return this},refreshHdas:function(f,e){if(this.model){return this.model.refresh(f,e)}return $.when()},_setUpWebStorage:function(f,e,g){this.storage=new PersistentStorage(this._getStorageKey(this.model.get("id")),{expandedHdas:{},show_deleted:false,show_hidden:false});this.log(this+" (prev) storage:",JSON.stringify(this.storage.get(),null,2));if(f){this.storage.set("exandedHdas",f)}if((e===true)||(e===false)){this.storage.set("show_deleted",e)}if((g===true)||(g===false)){this.storage.set("show_hidden",g)}this.show_deleted=this.storage.get("show_deleted");this.show_hidden=this.storage.get("show_hidden");this.trigger("new-storage",this.storage,this);this.log(this+" (init'd) storage:",this.storage.get())},_getStorageKey:function(e){if(!e){throw new Error("_getStorageKey needs valid id: "+e)}return("history:"+e)},clearWebStorage:function(){for(var e in sessionStorage){if(e.indexOf("history:")===0){sessionStorage.removeItem(e)}}},getStoredOptions:function(f){if(!f||f==="current"){return(this.storage)?(this.storage.get()):({})}var e=sessionStorage.getItem(this._getStorageKey(f));return(e===null)?({}):(JSON.parse(e))},getExpandedHdaIds:function(e){var f=this.getStoredOptions(e).expandedHdas;return((_.isEmpty(f))?([]):(_.keys(f)))},_setUpModelEventHandlers:function(){this.model.on("error error:hdas",function(f,h,e,g){this.errorHandler(f,h,e,g)},this);this.model.on("change:nice_size",this.updateHistoryDiskSize,this);if(Galaxy&&Galaxy.quotaMeter){this.listenTo(this.model,"change:nice_size",function(){Galaxy.quotaMeter.update()})}this.model.hdas.on("add",this.addHdaView,this);this.model.hdas.on("change:deleted",this.handleHdaDeletionChange,this);this.model.hdas.on("change:visible",this.handleHdaVisibleChange,this);this.model.hdas.on("change:purged",function(e){this.model.fetch()},this);this.model.hdas.on("state:ready",function(f,g,e){if((!f.get("visible"))&&(!this.storage.get("show_hidden"))){this.removeHdaView(this.hdaViews[f.id])}},this)},addHdaView:function(h){this.log("add."+this,h);var f=this;if(!h.isVisible(this.storage.get("show_deleted"),this.storage.get("show_hidden"))){return}$({}).queue([function g(j){var i=f.$el.find(f.emptyMsgSelector);if(i.is(":visible")){i.fadeOut(f.fxSpeed,j)}else{j()}},function e(j){f.scrollToTop();var i=f.$el.find(f.datasetsSelector);f.createHdaView(h).$el.hide().prependTo(i).slideDown(f.fxSpeed)}])},createHdaView:function(g){var f=g.get("id"),e=this.storage.get("expandedHdas").get(f),h=new this.HDAView({model:g,expanded:e,hasUser:this.model.hasUser(),logger:this.logger});this._setUpHdaListeners(h);this.hdaViews[f]=h;return h.render()},_setUpHdaListeners:function(f){var e=this;f.on("body-expanded",function(g){e.storage.get("expandedHdas").set(g,true)});f.on("body-collapsed",function(g){e.storage.get("expandedHdas").deleteKey(g)});f.on("error",function(h,j,g,i){e.errorHandler(h,j,g,i)})},handleHdaDeletionChange:function(e){if(e.get("deleted")&&!this.storage.get("show_deleted")){this.removeHdaView(this.hdaViews[e.id])}},handleHdaVisibleChange:function(e){if(e.hidden()&&!this.storage.get("show_hidden")){this.removeHdaView(this.hdaViews[e.id])}},removeHdaView:function(f){if(!f){return}var e=this;f.$el.fadeOut(e.fxSpeed,function(){f.off();f.remove();delete e.hdaViews[f.model.id];if(_.isEmpty(e.hdaViews)){e.$el.find(e.emptyMsgSelector).fadeIn(e.fxSpeed,function(){e.trigger("empty-history",e)})}})},render:function(g,h){g=(g===undefined)?(this.fxSpeed):(g);var e=this,f;if(this.model){f=this.renderModel()}else{f=this.renderWithoutModel()}$(e).queue("fx",[function(i){if(g&&e.$el.is(":visible")){e.$el.fadeOut(g,i)}else{i()}},function(i){e.$el.empty();if(f){e.$el.append(f.children())}i()},function(i){if(g&&!e.$el.is(":visible")){e.$el.fadeIn(g,i)}else{i()}},function(i){if(h){h.call(this)}e.trigger("rendered",this);i()}]);return this},renderWithoutModel:function(){var e=$("<div/>"),f=$("<div/>").addClass("message-container").css({"margin-left":"4px","margin-right":"4px"});return e.append(f)},renderModel:function(){var e=$("<div/>");if(!Galaxy||!Galaxy.currUser||Galaxy.currUser.isAnonymous()){e.append(c.templates.anonHistoryPanel(this.model.toJSON()))}else{e.append(c.templates.historyPanel(this.model.toJSON()));this._renderTags(e);this._renderAnnotation(e)}this._setUpBehaviours(e);this.renderHdas(e);return e},_renderTags:function(e){this.tagsEditor=new TagsEditor({model:this.model,el:e.find(".history-controls .tags-display"),onshowFirstTime:function(){this.render()},$activator:faIconButton({title:_l("Edit history tags"),classes:"history-tag-btn",faIcon:"fa-tags"}).appendTo(e.find(".history-secondary-actions"))})},_renderAnnotation:function(e){this.annotationEditor=new AnnotationEditor({model:this.model,el:e.find(".history-controls .annotation-display"),onshowFirstTime:function(){this.render()},$activator:faIconButton({title:_l("Edit history tags"),classes:"history-annotate-btn",faIcon:"fa-comment"}).appendTo(e.find(".history-secondary-actions"))})},_setUpBehaviours:function(e){e=e||this.$el;e.find("[title]").tooltip({placement:"bottom"});if(!this.model||!Galaxy.currUser||Galaxy.currUser.isAnonymous()){return}var f=this;e.find(".history-name").make_text_editable({on_finish:function(g){e.find(".history-name").text(g);f.model.save({name:g}).fail(function(){e.find(".history-name").text(f.model.previous("name"))})}})},renderHdas:function(g){g=g||this.$el;this.hdaViews={};var f=this,e=g.find(this.datasetsSelector),h=this.model.hdas.getVisible(this.storage.get("show_deleted"),this.storage.get("show_hidden"),this.filters);e.empty();if(h.length){h.each(function(i){e.prepend(f.createHdaView(i).$el)});g.find(this.emptyMsgSelector).hide()}else{g.find(this.emptyMsgSelector).show()}return this.hdaViews},events:{"click .message-container":"clearMessages"},updateHistoryDiskSize:function(){this.$el.find(".history-size").text(this.model.get("nice_size"))},collapseAllHdaBodies:function(){_.each(this.hdaViews,function(e){e.toggleBodyVisibility(null,false)});this.storage.set("expandedHdas",{})},toggleShowDeleted:function(){this.storage.set("show_deleted",!this.storage.get("show_deleted"));this.render();return this.storage.get("show_deleted")},toggleShowHidden:function(){this.storage.set("show_hidden",!this.storage.get("show_hidden"));this.render();return this.storage.get("show_hidden")},renderSearchControls:function(){var e=this;e.model.hdas.fetchAllDetails({silent:true});function g(h){e.searchFor=h;e.filters=[function(i){return i.matchesAll(e.searchFor)}];e.trigger("search:searching",h,e);e.renderHdas()}function f(){e.searchFor="";e.filters=[];e.trigger("search:clear",e);e.renderHdas()}return searchInput({initialVal:e.searchFor,name:"history-search",placeholder:"search datasets",classes:"history-search",onsearch:g,onclear:f}).addClass("history-search-controls").css("padding","0px 0px 8px 0px")},toggleSearchControls:function(){var e=this.$el.find(".history-search-controls");if(!e.size()){e=this.renderSearchControls().hide();this.$el.find(".history-title").before(e)}e.slideToggle(this.fxSpeed)},showSelect:function(e){_.each(this.hdaViews,function(f){f.showSelect(e)})},hideSelect:function(e){_.each(this.hdaViews,function(f){f.hideSelect(e)})},getSelectedHdaViews:function(){return _.filter(this.hdaViews,function(e){return e.selected})},showLoadingIndicator:function(f,e,g){e=(e!==undefined)?(e):(this.fxSpeed);if(!this.indicator){this.indicator=new LoadingIndicator(this.$el,this.$el.parent())}if(!this.$el.is(":visible")){this.indicator.show(0,g)}else{this.$el.fadeOut(e);this.indicator.show(f,e,g)}},hideLoadingIndicator:function(e,f){e=(e!==undefined)?(e):(this.fxSpeed);if(this.indicator){this.indicator.hide(e,f)}},displayMessage:function(j,k,i){var g=this;this.scrollToTop();var h=this.$el.find(this.msgsSelector),e=$("<div/>").addClass(j+"message").html(k);if(!_.isEmpty(i)){var f=$('<a href="javascript:void(0)">Details</a>').click(function(){Galaxy.modal.show(g.messageToModalOptions(j,k,i));return false});e.append(" ",f)}return h.html(e)},messageToModalOptions:function(i,k,h){var e=this,j=$("<div/>"),g={title:"Details"};function f(l){l=_.omit(l,_.functions(l));return["<table>",_.map(l,function(n,m){n=(_.isObject(n))?(f(n)):(n);return'<tr><td style="vertical-align: top; color: grey">'+m+'</td><td style="padding-left: 8px">'+n+"</td></tr>"}).join(""),"</table>"].join("")}if(_.isObject(h)){g.body=j.append(f(h))}else{g.body=j.html(h)}g.buttons={Ok:function(){Galaxy.modal.hide();e.clearMessages()}};return g},clearMessages:function(){var e=this.$el.find(this.msgsSelector);e.empty()},scrollPosition:function(){return this.$el.parent().scrollTop()},scrollTo:function(e){this.$el.parent().scrollTop(e)},scrollToTop:function(){this.$el.parent().scrollTop(0);return this},scrollIntoView:function(f,g){if(!g){this.$el.parent().parent().scrollTop(f);return this}var e=window,h=this.$el.parent().parent(),j=$(e).innerHeight(),i=(j/2)-(g/2);$(h).scrollTop(f-i);return this},scrollToId:function(f){if((!f)||(!this.hdaViews[f])){return this}var e=this.hdaViews[f].$el;this.scrollIntoView(e.offset().top,e.outerHeight());return this},scrollToHid:function(e){var f=this.model.hdas.getByHid(e);if(!f){return this}return this.scrollToId(f.id)},connectToQuotaMeter:function(e){if(!e){return this}this.listenTo(e,"quota:over",this.showQuotaMessage);this.listenTo(e,"quota:under",this.hideQuotaMessage);this.on("rendered rendered:initial",function(){if(e&&e.isOverQuota()){this.showQuotaMessage()}});return this},showQuotaMessage:function(){var e=this.$el.find(".quota-message");if(e.is(":hidden")){e.slideDown(this.fxSpeed)}},hideQuotaMessage:function(){var e=this.$el.find(".quota-message");if(!e.is(":hidden")){e.slideUp(this.fxSpeed)}},connectToOptionsMenu:function(e){if(!e){return this}this.on("new-storage",function(g,f){if(e&&g){e.findItemByHtml(_l("Include Deleted Datasets")).checked=g.get("show_deleted");e.findItemByHtml(_l("Include Hidden Datasets")).checked=g.get("show_hidden")}});return this},toString:function(){return"HistoryPanel("+((this.model)?(this.model.get("name")):(""))+")"}});c.templates={historyPanel:Handlebars.templates["template-history-historyPanel"],anonHistoryPanel:Handlebars.templates["template-history-historyPanel-anon"]};return{HistoryPanel:c}}); \ No newline at end of file +define(["mvc/history/history-model","mvc/dataset/hda-base","mvc/dataset/hda-edit"],function(f,b,a){var c=SessionStorageModel.extend({defaults:{expandedHdas:{},show_deleted:false,show_hidden:false},addExpandedHda:function(g){this.save("expandedHdas",_.extend(this.get("expandedHdas"),_.object([g],[true])))},removeExpandedHda:function(g){this.save("expandedHdas",_.omit(this.get("expandedHdas"),g))},toString:function(){return"HistoryPanelPrefs("+this.id+")"}});c.historyStorageKey=function e(g){if(!g){throw new Error("HistoryPanelPrefs.historyStorageKey needs valid id: "+g)}return("history:"+g)};var d=Backbone.View.extend(LoggableMixin).extend({HDAView:a.HDAEditView,tagName:"div",className:"history-panel",fxSpeed:"fast",datasetsSelector:".datasets-list",emptyMsgSelector:".empty-history-message",msgsSelector:".message-container",initialize:function(g){g=g||{};if(g.logger){this.logger=g.logger}this.log(this+".initialize:",g);this._setUpListeners();this.hdaViews={};this.indicator=new LoadingIndicator(this.$el);this.filters=[];if(this.model){this._setUpWebStorage(g.initiallyExpanded,g.show_deleted,g.show_hidden);this._setUpModelEventHandlers()}if(g.onready){g.onready.call(this)}},_setUpListeners:function(){this.on("error",function(h,k,g,j,i){this.errorHandler(h,k,g,j,i)});this.on("loading-history",function(){this.showLoadingIndicator("loading history...")});this.on("loading-done",function(){this.hideLoadingIndicator()});this.once("rendered",function(){this.trigger("rendered:initial",this);return false});this.on("switched-history current-history new-history",function(){if(_.isEmpty(this.hdaViews)){this.trigger("empty-history",this)}});if(this.logger){this.on("all",function(g){this.log(this+"",arguments)},this)}},errorHandler:function(i,l,h,k,j){var g=this._parseErrorMessage(i,l,h,k,j);if(l&&l.status===0&&l.readyState===0){}else{if(l&&l.status===502){}else{if(!this.$el.find(this.msgsSelector).is(":visible")){this.once("rendered",function(){this.displayMessage("error",g.message,g.details)})}else{this.displayMessage("error",g.message,g.details)}}}},_parseErrorMessage:function(j,n,i,m,l){var h=Galaxy.currUser,g={message:this._bePolite(m),details:{user:(h instanceof User)?(h.toJSON()):(h+""),source:(j instanceof Backbone.Model)?(j.toJSON()):(j+""),xhr:n,options:(n)?(_.omit(i,"xhr")):(i)}};_.extend(g.details,l||{});if(n&&_.isFunction(n.getAllResponseHeaders)){var k=n.getAllResponseHeaders();k=_.compact(k.split("\n"));k=_.map(k,function(o){return o.split(": ")});g.details.xhr.responseHeaders=_.object(k)}return g},_bePolite:function(g){g=g||_l("An error occurred while getting updates from the server");return g+". "+_l("Please contact a Galaxy administrator if the problem persists.")},loadCurrentHistory:function(h){var g=this;return this.loadHistoryWithHDADetails("current",h).then(function(j,i){g.trigger("current-history",g)})},switchToHistory:function(j,i){var g=this,h=function(){return jQuery.post(galaxy_config.root+"api/histories/"+j+"/set_as_current")};return this.loadHistoryWithHDADetails(j,i,h).then(function(l,k){g.trigger("switched-history",g)})},createNewHistory:function(i){if(!Galaxy||!Galaxy.currUser||Galaxy.currUser.isAnonymous()){this.displayMessage("error",_l("You must be logged in to create histories"));return $.when()}var g=this,h=function(){return jQuery.post(galaxy_config.root+"api/histories",{current:true})};return this.loadHistory(undefined,i,h).then(function(k,j){g.trigger("new-history",g)})},loadHistoryWithHDADetails:function(j,i,h,l){var g=this,k=function(m){return g.getExpandedHdaIds(m.id)};return this.loadHistory(j,i,h,l,k)},loadHistory:function(j,i,h,m,k){this.trigger("loading-history",this);i=i||{};var g=this;var l=f.History.getHistoryData(j,{historyFn:h,hdaFn:m,hdaDetailIds:i.initiallyExpanded||k});return this._loadHistoryFromXHR(l,i).fail(function(p,n,o){g.trigger("error",g,p,i,_l("An error was encountered while "+n),{historyId:j,history:o||{}})}).always(function(){g.trigger("loading-done",g)})},_loadHistoryFromXHR:function(i,h){var g=this;i.then(function(j,k){g.setModel(j,k,h)});i.fail(function(k,j){g.render()});return i},setModel:function(i,g,h){h=h||{};if(this.model){this.model.clearUpdateTimeout();this.stopListening(this.model);this.stopListening(this.model.hdas)}this.hdaViews={};if(Galaxy&&Galaxy.currUser){i.user=Galaxy.currUser.toJSON()}this.model=new f.History(i,g,h);this._setUpWebStorage(h.initiallyExpanded,h.show_deleted,h.show_hidden);this._setUpModelEventHandlers();this.trigger("new-model",this);this.render();return this},refreshHdas:function(h,g){if(this.model){return this.model.refresh(h,g)}return $.when()},_setUpWebStorage:function(h,g,i){this.storage=new c({id:c.historyStorageKey(this.model.get("id"))});if(_.isObject(h)){this.storage.set("exandedHdas",h)}if(_.isBoolean(g)){this.storage.set("show_deleted",g)}if(_.isBoolean(i)){this.storage.set("show_hidden",i)}this.trigger("new-storage",this.storage,this);this.log(this+" (init'd) storage:",this.storage.get())},clearWebStorage:function(){for(var g in sessionStorage){if(g.indexOf("history:")===0){sessionStorage.removeItem(g)}}},getStoredOptions:function(h){if(!h||h==="current"){return(this.storage)?(this.storage.get()):({})}var g=sessionStorage.getItem(c.historyStorageKey(h));return(g===null)?({}):(JSON.parse(g))},getExpandedHdaIds:function(g){var h=this.getStoredOptions(g).expandedHdas;return((_.isEmpty(h))?([]):(_.keys(h)))},_setUpModelEventHandlers:function(){this.model.on("error error:hdas",function(h,j,g,i){this.errorHandler(h,j,g,i)},this);this.model.on("change:nice_size",this.updateHistoryDiskSize,this);if(Galaxy&&Galaxy.quotaMeter){this.listenTo(this.model,"change:nice_size",function(){Galaxy.quotaMeter.update()})}this.model.hdas.on("add",this.addHdaView,this);this.model.hdas.on("change:deleted",this.handleHdaDeletionChange,this);this.model.hdas.on("change:visible",this.handleHdaVisibleChange,this);this.model.hdas.on("change:purged",function(g){this.model.fetch()},this);this.model.hdas.on("state:ready",function(h,i,g){if((!h.get("visible"))&&(!this.storage.get("show_hidden"))){this.removeHdaView(this.hdaViews[h.id])}},this)},addHdaView:function(j){this.log("add."+this,j);var h=this;if(!j.isVisible(this.storage.get("show_deleted"),this.storage.get("show_hidden"))){return}$({}).queue([function i(l){var k=h.$el.find(h.emptyMsgSelector);if(k.is(":visible")){k.fadeOut(h.fxSpeed,l)}else{l()}},function g(l){h.scrollToTop();var k=h.$el.find(h.datasetsSelector);h.createHdaView(j).$el.hide().prependTo(k).slideDown(h.fxSpeed)}])},createHdaView:function(i){var h=i.get("id"),g=this.storage.get("expandedHdas")[h],j=new this.HDAView({model:i,expanded:g,hasUser:this.model.hasUser(),logger:this.logger});this._setUpHdaListeners(j);this.hdaViews[h]=j;return j.render()},_setUpHdaListeners:function(h){var g=this;h.on("body-expanded",function(i){g.storage.addExpandedHda(i)});h.on("body-collapsed",function(i){g.storage.removeExpandedHda(i)});h.on("error",function(j,l,i,k){g.errorHandler(j,l,i,k)})},handleHdaDeletionChange:function(g){if(g.get("deleted")&&!this.storage.get("show_deleted")){this.removeHdaView(this.hdaViews[g.id])}},handleHdaVisibleChange:function(g){if(g.hidden()&&!this.storage.get("show_hidden")){this.removeHdaView(this.hdaViews[g.id])}},removeHdaView:function(h){if(!h){return}var g=this;h.$el.fadeOut(g.fxSpeed,function(){h.off();h.remove();delete g.hdaViews[h.model.id];if(_.isEmpty(g.hdaViews)){g.$el.find(g.emptyMsgSelector).fadeIn(g.fxSpeed,function(){g.trigger("empty-history",g)})}})},render:function(i,j){i=(i===undefined)?(this.fxSpeed):(i);var g=this,h;if(this.model){h=this.renderModel()}else{h=this.renderWithoutModel()}$(g).queue("fx",[function(k){if(i&&g.$el.is(":visible")){g.$el.fadeOut(i,k)}else{k()}},function(k){g.$el.empty();if(h){g.$el.append(h.children())}k()},function(k){if(i&&!g.$el.is(":visible")){g.$el.fadeIn(i,k)}else{k()}},function(k){if(j){j.call(this)}g.trigger("rendered",this);k()}]);return this},renderWithoutModel:function(){var g=$("<div/>"),h=$("<div/>").addClass("message-container").css({"margin-left":"4px","margin-right":"4px"});return g.append(h)},renderModel:function(){var g=$("<div/>");if(!Galaxy||!Galaxy.currUser||Galaxy.currUser.isAnonymous()){g.append(d.templates.anonHistoryPanel(this.model.toJSON()))}else{g.append(d.templates.historyPanel(this.model.toJSON()));this._renderTags(g);this._renderAnnotation(g)}this._setUpBehaviours(g);this.renderHdas(g);return g},_renderTags:function(g){this.tagsEditor=new TagsEditor({model:this.model,el:g.find(".history-controls .tags-display"),onshowFirstTime:function(){this.render()},$activator:faIconButton({title:_l("Edit history tags"),classes:"history-tag-btn",faIcon:"fa-tags"}).appendTo(g.find(".history-secondary-actions"))})},_renderAnnotation:function(g){this.annotationEditor=new AnnotationEditor({model:this.model,el:g.find(".history-controls .annotation-display"),onshowFirstTime:function(){this.render()},$activator:faIconButton({title:_l("Edit history tags"),classes:"history-annotate-btn",faIcon:"fa-comment"}).appendTo(g.find(".history-secondary-actions"))})},_setUpBehaviours:function(g){g=g||this.$el;g.find("[title]").tooltip({placement:"bottom"});if(!this.model||!Galaxy.currUser||Galaxy.currUser.isAnonymous()){return}var h=this;g.find(".history-name").make_text_editable({on_finish:function(i){g.find(".history-name").text(i);h.model.save({name:i}).fail(function(){g.find(".history-name").text(h.model.previous("name"))})}})},renderHdas:function(i){i=i||this.$el;this.hdaViews={};var h=this,g=i.find(this.datasetsSelector),j=this.model.hdas.getVisible(this.storage.get("show_deleted"),this.storage.get("show_hidden"),this.filters);g.empty();if(j.length){j.each(function(k){g.prepend(h.createHdaView(k).$el)});i.find(this.emptyMsgSelector).hide()}else{i.find(this.emptyMsgSelector).show()}return this.hdaViews},events:{"click .message-container":"clearMessages"},updateHistoryDiskSize:function(){this.$el.find(".history-size").text(this.model.get("nice_size"))},collapseAllHdaBodies:function(){_.each(this.hdaViews,function(g){g.toggleBodyVisibility(null,false)});this.storage.set("expandedHdas",{})},toggleShowDeleted:function(){this.storage.set("show_deleted",!this.storage.get("show_deleted"));this.render();return this.storage.get("show_deleted")},toggleShowHidden:function(){this.storage.set("show_hidden",!this.storage.get("show_hidden"));this.render();return this.storage.get("show_hidden")},renderSearchControls:function(){var g=this;g.model.hdas.fetchAllDetails({silent:true});function i(j){g.searchFor=j;g.filters=[function(k){return k.matchesAll(g.searchFor)}];g.trigger("search:searching",j,g);g.renderHdas()}function h(){g.searchFor="";g.filters=[];g.trigger("search:clear",g);g.renderHdas()}return searchInput({initialVal:g.searchFor,name:"history-search",placeholder:"search datasets",classes:"history-search",onsearch:i,onclear:h}).addClass("history-search-controls").css("padding","0px 0px 8px 0px")},toggleSearchControls:function(){var g=this.$el.find(".history-search-controls");if(!g.size()){g=this.renderSearchControls().hide();this.$el.find(".history-title").before(g)}g.slideToggle(this.fxSpeed)},showSelect:function(g){_.each(this.hdaViews,function(h){h.showSelect(g)})},hideSelect:function(g){_.each(this.hdaViews,function(h){h.hideSelect(g)})},getSelectedHdaViews:function(){return _.filter(this.hdaViews,function(g){return g.selected})},showLoadingIndicator:function(h,g,i){g=(g!==undefined)?(g):(this.fxSpeed);if(!this.indicator){this.indicator=new LoadingIndicator(this.$el,this.$el.parent())}if(!this.$el.is(":visible")){this.indicator.show(0,i)}else{this.$el.fadeOut(g);this.indicator.show(h,g,i)}},hideLoadingIndicator:function(g,h){g=(g!==undefined)?(g):(this.fxSpeed);if(this.indicator){this.indicator.hide(g,h)}},displayMessage:function(l,m,k){var i=this;this.scrollToTop();var j=this.$el.find(this.msgsSelector),g=$("<div/>").addClass(l+"message").html(m);if(!_.isEmpty(k)){var h=$('<a href="javascript:void(0)">Details</a>').click(function(){Galaxy.modal.show(i.messageToModalOptions(l,m,k));return false});g.append(" ",h)}return j.html(g)},messageToModalOptions:function(k,m,j){var g=this,l=$("<div/>"),i={title:"Details"};function h(n){n=_.omit(n,_.functions(n));return["<table>",_.map(n,function(p,o){p=(_.isObject(p))?(h(p)):(p);return'<tr><td style="vertical-align: top; color: grey">'+o+'</td><td style="padding-left: 8px">'+p+"</td></tr>"}).join(""),"</table>"].join("")}if(_.isObject(j)){i.body=l.append(h(j))}else{i.body=l.html(j)}i.buttons={Ok:function(){Galaxy.modal.hide();g.clearMessages()}};return i},clearMessages:function(){var g=this.$el.find(this.msgsSelector);g.empty()},scrollPosition:function(){return this.$el.parent().scrollTop()},scrollTo:function(g){this.$el.parent().scrollTop(g)},scrollToTop:function(){this.$el.parent().scrollTop(0);return this},scrollIntoView:function(h,i){if(!i){this.$el.parent().parent().scrollTop(h);return this}var g=window,j=this.$el.parent().parent(),l=$(g).innerHeight(),k=(l/2)-(i/2);$(j).scrollTop(h-k);return this},scrollToId:function(h){if((!h)||(!this.hdaViews[h])){return this}var g=this.hdaViews[h].$el;this.scrollIntoView(g.offset().top,g.outerHeight());return this},scrollToHid:function(g){var h=this.model.hdas.getByHid(g);if(!h){return this}return this.scrollToId(h.id)},connectToQuotaMeter:function(g){if(!g){return this}this.listenTo(g,"quota:over",this.showQuotaMessage);this.listenTo(g,"quota:under",this.hideQuotaMessage);this.on("rendered rendered:initial",function(){if(g&&g.isOverQuota()){this.showQuotaMessage()}});return this},showQuotaMessage:function(){var g=this.$el.find(".quota-message");if(g.is(":hidden")){g.slideDown(this.fxSpeed)}},hideQuotaMessage:function(){var g=this.$el.find(".quota-message");if(!g.is(":hidden")){g.slideUp(this.fxSpeed)}},connectToOptionsMenu:function(g){if(!g){return this}this.on("new-storage",function(i,h){if(g&&i){g.findItemByHtml(_l("Include Deleted Datasets")).checked=i.get("show_deleted");g.findItemByHtml(_l("Include Hidden Datasets")).checked=i.get("show_hidden")}});return this},toString:function(){return"HistoryPanel("+((this.model)?(this.model.get("name")):(""))+")"}});d.templates={historyPanel:Handlebars.templates["template-history-historyPanel"],anonHistoryPanel:Handlebars.templates["template-history-historyPanel-anon"]};return{HistoryPanel:d}}); \ No newline at end of file Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org