From f2e3f9db5f81b5da9ed034ce0458803696c5eff5 Mon Sep 17 00:00:00 2001 From: Carl Eberhard Date: Tue, 18 Dec 2012 13:53:55 -0500 Subject: [PATCH] history panel: fix to js behaviors on late-rendered hda bodies --- static/scripts/mvc/dataset/hda-base.js | 22 +++++++++++++++------- static/scripts/mvc/dataset/hda-model.js | 10 +++++++++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/static/scripts/mvc/dataset/hda-base.js b/static/scripts/mvc/dataset/hda-base.js index cdfc453182a..cfe1fc79dc0 100644 --- a/static/scripts/mvc/dataset/hda-base.js +++ b/static/scripts/mvc/dataset/hda-base.js @@ -78,16 +78,12 @@ var HDABaseView = BaseView.extend( LoggableMixin ).extend( itemWrapper.append( this._render_warnings() ); itemWrapper.append( this._render_titleBar() ); + //NOTE: only sets behaviors on title and warnings - body will set up it's own + this._setUpBehaviors( itemWrapper ); + this.body = $( this._render_body() ); itemWrapper.append( this.body ); - //TODO: move to own function: setUpBehaviours - // we can potentially skip this step and call popupmenu directly on the download button - make_popup_menus( itemWrapper ); - - // set up canned behavior on children (bootstrap, popupmenus, editable_text, etc.) - itemWrapper.find( '.tooltip' ).tooltip({ placement : 'bottom' }); - // transition... this.$el.fadeOut( 'fast', function(){ view.$el.children().remove(); @@ -155,6 +151,17 @@ var HDABaseView = BaseView.extend( LoggableMixin ).extend( }); }, + /** set up js behaviors, event handlers for elements within the given container + * @param {jQuery} $container jq object that contains the elements to process (defaults to this.$el) + */ + _setUpBehaviors : function( $container ){ + $container = $container || this.$el; + // set up canned behavior on children (bootstrap, popupmenus, editable_text, etc.) + //TODO: we can potentially skip this step and call popupmenu directly on the download button + make_popup_menus( $container ); + $container.find( '.tooltip' ).tooltip({ placement : 'bottom' }); + }, + // ................................................................................ RENDER titlebar /** Render any hda warnings including: is deleted, is purged, is hidden. * (including links to further actions (undelete, etc.)) @@ -389,6 +396,7 @@ var HDABaseView = BaseView.extend( LoggableMixin ).extend( body.append( $( '
Error: unknown dataset state "' + this.model.get( 'state' ) + '".
' ) ); } body.append( '
' ); + this._setUpBehaviors( body ); }, /** Render inaccessible, not-owned by curr user. diff --git a/static/scripts/mvc/dataset/hda-model.js b/static/scripts/mvc/dataset/hda-model.js index 73873fadd0b..0ba38824eac 100644 --- a/static/scripts/mvc/dataset/hda-model.js +++ b/static/scripts/mvc/dataset/hda-model.js @@ -220,7 +220,15 @@ var HDACollection = Backbone.Collection.extend( LoggableMixin ).extend( * @returns array of encoded ids */ ids : function(){ - return this.map( function( item ){ return item.id; }); + return this.map( function( hda ){ return hda.id; }); + }, + + /** Get the hda with the given hid + * @param {Int} hid the hid to search for + * @returns {HistoryDatasetAssociation} the hda with the given hid or undefined if not found + */ + getByHid : function( hid ){ + return _.first( this.filter( function( hda ){ return hda.get( 'hid' ) === hid; }) ); }, /** If the given hid is in the collection, return it's index. If not, return the insertion point it would need.