package SGN::View::Mason::Commands;
use strict;
use vars qw($m $c);
HTML::Mason::Component::FileBased->new(
'code' => sub {
use utf8; local $SGN::View::Mason::Commands::m = $HTML::Mason::Commands::m;
$m->debug_hook( $m->current_comp->path ) if ( HTML::Mason::Compiler::IN_PERL_DB() );

#line 1 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '
' );
#line 4 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '
' );
#line 5 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->comp(   '/util/import_javascript.mas', classes => [ 'jquery', 'jquery.dataTables', 'jquery.dataTables-select-min' ]   
); #line 5 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '
' );
#line 6 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->comp(   '/util/import_css.mas', paths => ['/documents/inc/datatables/jquery.dataTables.css', '/documents/inc/datatables/custom_datatable_select_styles.css']   
); #line 6 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '

' );
#line 8 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->comp(   '/page/page_title.mas', title => "Trait Search"   
); #line 8 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '

    ' );
#line 10 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->comp( { content => sub {
#line 10 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '
        <div id="trait_search_form" class="form-horizontal well">
            <div class="form-group form-group-sm">
                <label class="col-sm-3 control-label">Select Ontology Name(s): </label>
                <div class="col-sm-9" >
                    <div id="trait_search_ontology_select"></div>
                </div>
            </div>
            <div class="form-group form-group-sm">
                <label class="col-sm-3 control-label">Search Trait Name: </label>
                <div class="col-sm-9" >
                    <input type="text" class="form-control" id="trait_search_name" placeholder="Search any trait name or piece of name"/>
                </div>
            </div>
            <div class="form-group form-group-sm">
                <label class="col-sm-3 control-label">Search Definition: </label>
                <div class="col-sm-9" >
                    <input type="text" class="form-control" id="trait_search_definition" placeholder="Search any word or piece of definition"/>
                </div>
            </div>
            <div class="form-group form-group-sm">
                <label class="col-sm-3 control-label">Subset Traits: </label>
                <div class="col-sm-9" >
                    <div id="trait_search_list_select">
                        [LOADING...]
                    </div>
                </div>
            </div>
        </div>

        <center>
            <button class="btn btn-primary" id="submit_trait_search" />Search</button>
        </center>
    ' );
#line 43 "/home/production/cxgn/sgn/mason/search/traits.mas"
} }, '/page/info_section.mas', title => 'Search', collapsible=>1, collapsed=>0
 );
#line 43 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '

    ' );
#line 45 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->comp( { content => sub {
#line 45 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '

        <div class="well well-sm">
            <div class="panel panel-default">
                <div class="panel-body">

                    <table id="trait_search_results" width="100%" class="table table-hover table-striped">
                    <thead>
                      <tr>
                        <th>Select</th>
                        <th>Copy Name|ID</th>
                        <th>Trait ID</th>
                        <th>Trait Name</th>
                        <th>Definition</th>
                        <th>Trait&nbsp;Usage</th>
                      </tr>
                    </thead>
                    </table>

                    <button type="button" class="selectAll-dt">Select All</button>
                    <button type="button" class="deselectAll-dt">Deselect All</button>

                </div>
            </div>

            <div class="panel panel-default">
                <div class="panel-body">

                    ' );
#line 73 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->comp( { content => sub {
#line 73 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '
                    <br>
                    <p><em><span id="trait_result_count">0</span> trait(s) selected.</em></p>
                    <div style="text-align:right" id="traits_to_list_menu"></div>
                    <div id="trait_result_names" style="display: none;"></div>
                    ' );
#line 78 "/home/production/cxgn/sgn/mason/search/traits.mas"
} }, '/page/info_section.mas', title => 'Copy Selected Results to a List', collapsible=>1, collapsed=>0, subtitle=>'<i>Copy the trait names currently selected in the search results table to a new or exisiting list</i>'
 );
#line 78 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '

                </div>
            </div>
        </div>
    ' );
#line 83 "/home/production/cxgn/sgn/mason/search/traits.mas"
} }, '/page/info_section.mas', title => 'Results', collapsible=>1, collapsed=>0
 );
#line 83 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '

' );
#line 85 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->comp(   '/breeders_toolbox/add_new_trait_dialogs.mas'  
); #line 85 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '

    ' );
#line 87 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->comp( { content => sub {
#line 87 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '
        <div class="well well-sm">
            <div class="panel panel-default">
                <div class="panel-body">
                    <h2>Is the trait you are looking for not here?</h2>

' );
#line 93 "/home/production/cxgn/sgn/mason/search/traits.mas"
  if ($c->config->{allow_observation_variable_submission_interface}) {
$m->print( '                        <button class="btn btn-primary" name="add_new_observation_variable_button">Add A New Observation Variable To the Database</button>
' );
#line 95 "/home/production/cxgn/sgn/mason/search/traits.mas"
  } else {
$m->print( '                        <p>Please submit your new trait <a href="http://submit.rtbbase.org/">using the trait submission form</a>.</p>
                        <p>To speed up addition of your trait into the database please contact us using the <a href="/contact/form">Contact Form</a>.</p>
' );
#line 98 "/home/production/cxgn/sgn/mason/search/traits.mas"
  }
$m->print( '                </div>
            </div>
        </div>
    ' );
#line 102 "/home/production/cxgn/sgn/mason/search/traits.mas"
} }, '/page/info_section.mas', title => 'Help', collapsible=>1, collapsed=>0
 );
#line 102 "/home/production/cxgn/sgn/mason/search/traits.mas"
$m->print( '

</div>

<script>

jQuery(document).ready(function () {

    get_select_box(\'trait_variable_ontologies\', \'trait_search_ontology_select\', { \'name\' : \'trait_search_ontology_select_id\', \'cvprop_type_name\':JSON.stringify([\'trait_ontology\',\'composed_trait_ontology\']) });

    jQuery(\'[data-toggle="tooltip"]\').tooltip();

    var lo = new CXGN.List();
    jQuery(\'#trait_search_list_select\').html(lo.listSelect(\'trait_search_list_select\', [ \'traits\' ], \'Leave blank to see all traits\', undefined, undefined));

    jQuery(document).on(\'change\', \'#trait_search_list_select\', function(){
        _draw_trait_search_result_table();
    });

    jQuery(\'#submit_trait_search\').click(function(){
        _draw_trait_search_result_table();
    });

    jQuery(\'#trait_search_form\').keypress(function(e){
        var code = e.keyCode || e.which;
        if( code == 13 ) {
             jQuery(\'#submit_trait_search\').click();
        }
    });

    parseArgs();

    var trait_table;
    _draw_trait_search_result_table();

    function _draw_trait_search_result_table (){
        var selectedontologies = [];
        jQuery(document).find(\'input[name="trait_search_ontology_select_id"]:checked\').each(function (i, ob) {
            selectedontologies.push(jQuery(ob).val());
        });

        trait_table = jQuery(\'#trait_search_results\').DataTable({
            \'destroy\': true,
            \'searching\' : false,
            \'ordering\'  : false,
            \'processing\': true,
            \'serverSide\': true,
            \'lengthMenu\': [10,20,50],
            \'columnDefs\': [ {
                \'orderable\': false,
                \'className\': \'select-checkbox\',
                \'targets\':   0
            } ],
            \'select\': {
                \'style\':    \'multi\',
                \'selector\': \'td:not(:nth-child(2))\',
            },
            \'ajax\': {
                \'url\': \'/ajax/search/traits\',
                \'data\': function(d) {
                    d.trait_search_list_id  = jQuery(\'#trait_search_list_select_list_select\').val();
                    d.trait_any_name  = jQuery(\'#trait_search_name\').val();
                    d.trait_definition  = jQuery(\'#trait_search_definition\').val();
                    d.ontology_db_id = selectedontologies;
                }
            },
            "order": [[ 1, "asc" ]]
        });
    }

   jQuery(\'.selectAll-dt\').click(function(){
     trait_table.rows().select();
     return false;
   });
   jQuery(\'.deselectAll-dt\').click(function(){
     trait_table.rows().deselect();
     return false;
   });
   var selection_changed = function () {
     var selected_rows = trait_table.rows({\'selected\':true});
     jQuery("#trait_result_count").text(selected_rows.count());
     //console.log(selected_rows.data());

     var name_links = selected_rows.data().map(function(row){
         return [row[6], row[7]];
         trait_table.rows().deselect();
     });

     var names = [];
     for (var i = 0; i < name_links.length; i++) { //extract and combine trait name and id from anchor tags
       names.push(name_links[i][0] + \'|\' + name_links[i][1] + \'\\n\');
     }

     jQuery(\'#trait_result_names\').html(names);
     addToListMenu(\'traits_to_list_menu\', \'trait_result_names\', {
       listType: \'traits\'
     });
   };
   trait_table.on( \'deselect\', selection_changed);
   trait_table.on( \'select\', selection_changed);

});


/**
 * Parse query params sent to the page
 * - name = trait name to search on
 */
function parseArgs() {
    const params = new URLSearchParams(window.location.search);
    if ( params.has(\'name\') ) {
        jQuery("#trait_search_name").val(params.get(\'name\'));
    }
}

/**
 * Copy the specifed trait information to the user\'s clipboard
 * - name = trait name
 * - accession = trait accession term
 * - id = trait cvterm id
 */
async function copy(name, accession, id) {
    try {
        await navigator.clipboard.writeText([name, accession].join(\'|\'));
        jQuery(".btn-" + id).removeClass("btn-info").addClass("btn-success").html("<span class=\'glyphicon glyphicon-ok\'></span>");
    }
    catch (err) {
        jQuery(".btn-" + id).removeClass("btn-info").addClass("btn-danger").html("<span class=\'glyphicon glyphicon-remove\'></span>");
    }
    finally {
        setTimeout(() => {
            jQuery(".btn-" + id).removeClass("btn-success btn-danger").addClass("btn-info").html("<span class=\'glyphicon glyphicon-copy\'></span>");
        }, 2500)
    }
    return false;
}

</script>


<style type="text/css">
    #trait_search_results td:nth-child(2) {
        vertical-align: middle;
    }
</style>
' );
;return;
},
'load_time' => 1763225412,

)
;