5 <& /util/import_javascript.mas, classes => [ 'jquery', 'jquery.dataTables', 'jquery.dataTables-select-min' ] &>
6 <& /util/import_css.mas, paths => ['/documents/inc/datatables/jquery.dataTables.css', '/documents/inc/datatables/custom_datatable_select_styles.css'] &>
8 <& /page/page_title.mas, title => "Trait Search" &>
10 <&| /page/info_section.mas, title => 'Search', collapsible=>1, collapsed=>0 &>
11 <div id="trait_search_form" class="form-horizontal well">
12 <div class="form-group form-group-sm">
13 <label class="col-sm-3 control-label">Select Ontology Name(s): </label>
14 <div class="col-sm-9" >
15 <div id="trait_search_ontology_select"></div>
18 <div class="form-group form-group-sm">
19 <label class="col-sm-3 control-label">Search Trait Name: </label>
20 <div class="col-sm-9" >
21 <input type="text" class="form-control" id="trait_search_name" placeholder="Search any trait name or piece of name"/>
24 <div class="form-group form-group-sm">
25 <label class="col-sm-3 control-label">Search Definition: </label>
26 <div class="col-sm-9" >
27 <input type="text" class="form-control" id="trait_search_definition" placeholder="Search any word or piece of definition"/>
30 <div class="form-group form-group-sm">
31 <label class="col-sm-3 control-label">Subset Traits: </label>
32 <div class="col-sm-9" >
33 <div id="trait_search_list_select">
41 <button class="btn btn-primary" id="submit_trait_search" />Search</button>
45 <&| /page/info_section.mas, title => 'Results', collapsible=>1, collapsed=>0 &>
47 <div class="well well-sm">
48 <div class="panel panel-default">
49 <div class="panel-body">
51 <table id="trait_search_results" width="100%" class="table table-hover table-striped">
59 <th>Trait Usage</th>
64 <button type="button" class="selectAll-dt">Select All</button>
65 <button type="button" class="deselectAll-dt">Deselect All</button>
70 <div class="panel panel-default">
71 <div class="panel-body">
73 <&| /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>'&>
75 <p><em><span id="trait_result_count">0</span> trait(s) selected.</em></p>
76 <div style="text-align:right" id="traits_to_list_menu"></div>
77 <div id="trait_result_names" style="display: none;"></div>
85 <& /breeders_toolbox/add_new_trait_dialogs.mas &>
87 <&| /page/info_section.mas, title => 'Help', collapsible=>1, collapsed=>0 &>
88 <div class="well well-sm">
89 <div class="panel panel-default">
90 <div class="panel-body">
91 <h2>Is the trait you are looking for not here?</h2>
93 % if ($c->config->{allow_observation_variable_submission_interface}) {
94 <button class="btn btn-primary" name="add_new_observation_variable_button">Add A New Observation Variable To the Database</button>
96 <p>Please submit your new trait <a href="http://submit.rtbbase.org/">using the trait submission form</a>.</p>
97 <p>To speed up addition of your trait into the database please contact us using the <a href="/contact/form">Contact Form</a>.</p>
108 jQuery(document).ready(function () {
110 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']) });
112 jQuery('[data-toggle="tooltip"]').tooltip();
114 var lo = new CXGN.List();
115 jQuery('#trait_search_list_select').html(lo.listSelect('trait_search_list_select', [ 'traits' ], 'Leave blank to see all traits', undefined, undefined));
117 jQuery(document).on('change', '#trait_search_list_select', function(){
118 _draw_trait_search_result_table();
121 jQuery('#submit_trait_search').click(function(){
122 _draw_trait_search_result_table();
125 jQuery('#trait_search_form').keypress(function(e){
126 var code = e.keyCode || e.which;
128 jQuery('#submit_trait_search').click();
135 _draw_trait_search_result_table();
137 function _draw_trait_search_result_table (){
138 var selectedontologies = [];
139 jQuery(document).find('input[name="trait_search_ontology_select_id"]:checked').each(function (i, ob) {
140 selectedontologies.push(jQuery(ob).val());
143 trait_table = jQuery('#trait_search_results').DataTable({
149 'lengthMenu': [10,20,50],
152 'className': 'select-checkbox',
157 'selector': 'td:not(:nth-child(2))',
160 'url': '/ajax/search/traits',
161 'data': function(d) {
162 d.trait_search_list_id = jQuery('#trait_search_list_select_list_select').val();
163 d.trait_any_name = jQuery('#trait_search_name').val();
164 d.trait_definition = jQuery('#trait_search_definition').val();
165 d.ontology_db_id = selectedontologies;
168 "order": [[ 1, "asc" ]]
172 jQuery('.selectAll-dt').click(function(){
173 trait_table.rows().select();
176 jQuery('.deselectAll-dt').click(function(){
177 trait_table.rows().deselect();
180 var selection_changed = function () {
181 var selected_rows = trait_table.rows({'selected':true});
182 jQuery("#trait_result_count").text(selected_rows.count());
183 //console.log(selected_rows.data());
185 var name_links = selected_rows.data().map(function(row){
186 return [row[6], row[7]];
187 trait_table.rows().deselect();
191 for (var i = 0; i < name_links.length; i++) { //extract and combine trait name and id from anchor tags
192 names.push(name_links[i][0] + '|' + name_links[i][1] + '\n');
195 jQuery('#trait_result_names').html(names);
196 addToListMenu('traits_to_list_menu', 'trait_result_names', {
200 trait_table.on( 'deselect', selection_changed);
201 trait_table.on( 'select', selection_changed);
207 * Parse query params sent to the page
208 * - name = trait name to search on
210 function parseArgs() {
211 const params = new URLSearchParams(window.location.search);
212 if ( params.has('name') ) {
213 jQuery("#trait_search_name").val(params.get('name'));
218 * Copy the specifed trait information to the user's clipboard
219 * - name = trait name
220 * - accession = trait accession term
221 * - id = trait cvterm id
223 async function copy(name, accession, id) {
225 await navigator.clipboard.writeText([name, accession].join('|'));
226 jQuery(".btn-" + id).removeClass("btn-info").addClass("btn-success").html("<span class='glyphicon glyphicon-ok'></span>");
229 jQuery(".btn-" + id).removeClass("btn-info").addClass("btn-danger").html("<span class='glyphicon glyphicon-remove'></span>");
233 jQuery(".btn-" + id).removeClass("btn-success btn-danger").addClass("btn-info").html("<span class='glyphicon glyphicon-copy'></span>");
242 <style type="text/css">
243 #trait_search_results td:nth-child(2) {
244 vertical-align: middle;