function _promote( history, collection_type, options ){
//TODO: seems like this would be better in mvc/collections
        options = options || {};
        options.url = this.url();
        options.type = "POST";
        var full_collection_type = collection_type;
        var element_identifiers = [],
            name = null;

        // This mechanism is rough - no error handling, allows invalid selections, no way
        // for user to pick/override element identifiers. This is only really meant
        if( collection_type === "list" ) {
            this.chain().each( function( hda ) {
                // TODO: Handle duplicate names.
                var name = hda.attributes.name;
                var id = hda.get('id');
                var content_type = hda.attributes.history_content_type;
                if( content_type === "dataset" ) {
                    if( full_collection_type !== "list" ) {
                        this.log( "Invalid collection type" );
                    }
                    element_identifiers.push( { name: name, src: "hda", id: id } );
                } else {
                    if( full_collection_type === "list" ) {
                        full_collection_type = "list:" + hda.attributes.collection_type;
                    } else {
                        if( full_collection_type !== "list:" + hda.attributes.collection_type ) {
                            this.log( "Invalid collection type" );
                        }
                    }
                    element_identifiers.push( { name: name, src: "hdca", id: id } );
                }
            });
            name = "New Dataset List";
        } else if( collection_type === "paired" ) {
            var ids = this.ids();
            if( ids.length !== 2 ){
                // TODO: Do something...
            }
            element_identifiers.push( { name: "forward", src: "hda", id: ids[ 0 ] } );
            element_identifiers.push( { name: "reverse", src: "hda", id: ids[ 1 ] } );
            name = "New Dataset Pair";
        }
        options.data = {
            type: "dataset_collection",
            name: name,
            collection_type: full_collection_type,
            element_identifiers: JSON.stringify( element_identifiers )
        };

        var xhr = jQuery.ajax( options );
        xhr.done( function( message, status, responseObj ){
            history.refresh( );
        });
        xhr.fail( function( xhr, status, message ){
            if( xhr.responseJSON && xhr.responseJSON.error ){
                error = xhr.responseJSON.error;
            } else {
                error = xhr.responseJSON;
            }
            xhr.responseText = error;
            // Do something?
        });
        return xhr;
    }
/** Convert this ad-hoc collection of hdas to a formal collection tracked
        by the server.
    **/
Convert this ad-hoc collection of hdas to a formal collection tracked
by the server.
Convert this ad - hoc collection of hdas to a formal collection tracked by the server .
function _promote( history, collection_type, options ){
        options = options || {};
        options.url = this.url();
        options.type = "POST";
        var full_collection_type = collection_type;
        var element_identifiers = [],
            name = null;
        if( collection_type === "list" ) {
            this.chain().each( function( hda ) {
                var name = hda.attributes.name;
                var id = hda.get('id');
                var content_type = hda.attributes.history_content_type;
                if( content_type === "dataset" ) {
                    if( full_collection_type !== "list" ) {
                        this.log( "Invalid collection type" );
                    }
                    element_identifiers.push( { name: name, src: "hda", id: id } );
                } else {
                    if( full_collection_type === "list" ) {
                        full_collection_type = "list:" + hda.attributes.collection_type;
                    } else {
                        if( full_collection_type !== "list:" + hda.attributes.collection_type ) {
                            this.log( "Invalid collection type" );
                        }
                    }
                    element_identifiers.push( { name: name, src: "hdca", id: id } );
                }
            });
            name = "New Dataset List";
        } else if( collection_type === "paired" ) {
            var ids = this.ids();
            if( ids.length !== 2 ){
            }
            element_identifiers.push( { name: "forward", src: "hda", id: ids[ 0 ] } );
            element_identifiers.push( { name: "reverse", src: "hda", id: ids[ 1 ] } );
            name = "New Dataset Pair";
        }
        options.data = {
            type: "dataset_collection",
            name: name,
            collection_type: full_collection_type,
            element_identifiers: JSON.stringify( element_identifiers )
        };
        var xhr = jQuery.ajax( options );
        xhr.done( function( message, status, responseObj ){
            history.refresh( );
        });
        xhr.fail( function( xhr, status, message ){
            if( xhr.responseJSON && xhr.responseJSON.error ){
                error = xhr.responseJSON.error;
            } else {
                error = xhr.responseJSON;
            }
            xhr.responseText = error;
        });
        return xhr;
    }
function _promote ( history , collection_type , options ) { options = options || { } ; options . url = this . url ( ) ; options . type = "POST" ; var full_collection_type = collection_type ; var element_identifiers = [ ] , name = null ; if ( collection_type === "list" ) { this . chain ( ) . each ( function ( hda ) { var name = hda . attributes . name ; var id = hda . get ( 'id' ) ; var content_type = hda . attributes . history_content_type ; if ( content_type === "dataset" ) { if ( full_collection_type !== "list" ) { this . log ( "Invalid collection type" ) ; } element_identifiers . push ( { name : name , src : "hda" , id : id } ) ; } else { if ( full_collection_type === "list" ) { full_collection_type = "list:" + hda . attributes . collection_type ; } else { if ( full_collection_type !== "list:" + hda . attributes . collection_type ) { this . log ( "Invalid collection type" ) ; } } element_identifiers . push ( { name : name , src : "hdca" , id : id } ) ; } } ) ; name = "New Dataset List" ; } else if ( collection_type === "paired" ) { var ids = this . ids ( ) ; if ( ids . length !== 2 ) { } element_identifiers . push ( { name : "forward" , src : "hda" , id : ids [ 0 ] } ) ; element_identifiers . push ( { name : "reverse" , src : "hda" , id : ids [ 1 ] } ) ; name = "New Dataset Pair" ; } options . data = { type : "dataset_collection" , name : name , collection_type : full_collection_type , element_identifiers : JSON . stringify ( element_identifiers ) } ; var xhr = jQuery . ajax ( options ) ; xhr . done ( function ( message , status , responseObj ) { history . refresh ( ) ; } ) ; xhr . fail ( function ( xhr , status , message ) { if ( xhr . responseJSON && xhr . responseJSON . error ) { error = xhr . responseJSON . error ; } else { error = xhr . responseJSON ; } xhr . responseText = error ; } ) ; return xhr ; }
Convert this ad-hoc collection of hdas to a formal collection tracked
by the server.
Convert this ad - hoc collection of hdas to a formal collection tracked by the server .
//TODO: seems like this would be better in mvc/collections // This mechanism is rough - no error handling, allows invalid selections, no way // for user to pick/override element identifiers. This is only really meant // TODO: Handle duplicate names. // TODO: Do something... // Do something?