added management_factor_types param in related masons
[sgn.git] / mason / breeders_toolbox / trialtreefolders.mas
blob779c94811443437f67844ef2504c73556d37d746
2 <%args>
3 @locations => ()
4 $breeding_programs
5 $preferred_species
6 $editable_stock_props
7 $timestamp
8 $management_factor_types => ()
9 </%args>
11 <& /util/import_javascript.mas, classes => [ 'jstree.dist.jstree', 'bootstrap_min.js', 'jquery.iframe-post-form', 'CXGN.List', 'CXGN.BreedersToolbox.AddTrial','CXGN.BreedersToolbox.UploadTrial','CXGN.BreedersToolbox.Trial', 'CXGN.Trial','CXGN.BreedersToolbox.GenotypingTrial','CXGN.BreedersToolbox.Accessions', 'CXGN.BreedersToolbox.UploadPedigrees','CXGN.BreedersToolbox.Crosses','CXGN.BreedersToolbox.FieldBook','CXGN.BreedersToolbox.UploadPhenotype', 'CXGN.BreederSearch', 'CXGN.Trial','CXGN.TrialTreeFolders' ] &>
13 <& /util/import_css.mas, paths => ['/static/documents/inc/jstree_theme/jstree-bstheme-min.css'] &>
15 <& /breeders_toolbox/folder/folder_set.mas, project_type => 'Trials and Analyses' &>
16 <& /breeders_toolbox/folder/folder_new.mas &>
17 <& /breeders_toolbox/folder/folder_move.mas &>
18 <& /breeders_toolbox/folder/folders_edit.mas, folder_tree_type => 'Trial', folder_tree_identifier => 'trial_list', folder_tree_refresh_name => 'refresh_jstree_html' &>
20 <& /breeders_toolbox/trial/trial_create_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs, management_factor_types => $management_factor_types &>
22 <& /breeders_toolbox/trial/download_trials_phenotypes_dialog.mas &>
24 <& /breeders_toolbox/trial/trial_upload_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs &>
25 <& /breeders_toolbox/add_accessions_dialogs.mas, preferred_species=>$preferred_species, editable_stock_props=>$editable_stock_props &>
26 <& /breeders_toolbox/upload_seedlots_dialogs.mas &>
27 <& /breeders_toolbox/add_seedlot_dialogs.mas, timestamp=>$timestamp &>
29 <table class="table table-bordered">
30   <thead>
31     <tr>
32       <th>Information</th>
33       <th>Breeding Programs -- Folders -- Trials&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-sm btn-default" id="refresh_jstree_html_trialtree_button" name="refresh_jstree_html">Refresh</button></th>
34     </tr>
35   </thead>
36   <tbody>
37   <tr>
38     <td>
39         <h4>Search</h4>
40         <input type="text" class="form-control input-sm" id="trial_tree_search" placeholder="Search" />
41         <hr>
42       <h4>Download Trial Phenotypes</h4>
43       <h5><i>Select multiple trials by holding 'Ctrl'.</i></h5>
44       <button class="btn btn-primary" id="trials_download_phenotypes_button" disabled="disabled" title="First Select Trial(s) to Download">Download Phenotypes</button>
45       <hr>
46       <h5><i>Double click<br />trial (&nbsp;<span class="glyphicon glyphicon-leaf text-success"></span>&nbsp;) or folder (&nbsp;<span class="glyphicon glyphicon-folder-open text-danger"></span>&nbsp;)<br/>to view detail page.</i></h5>
47       <h5><i>Breeding programs (&nbsp;<span class="glyphicon glyphicon-briefcase text-info"></span>&nbsp;)</i></h5>
48       <h5><i>Genotyping data projects (&nbsp;<span class="glyphicon glyphicon-align-left text-warning"></span>&nbsp;)</i></h5>
49       <h5><i>Analyses (&nbsp;<span class="glyphicon glyphicon-stats text-success"></span>&nbsp;)</i></h5>
50       <hr>
51       <h4>Folders</h4>
52       <button class="btn btn-sm btn-default" id="new_folder_dialog_link">Create new folder</button><br/><br/>
53       <button class="btn btn-sm btn-default" id="open_folder_dialog_link">Move trial(s) and analyses to folder</button><br/><br/>
54       <button class="btn btn-sm btn-default" id="move_folder_dialog_link">Move folder</button>
56       <div id="folder_edit_options" style="display:none">
57           <hr>
58           <h5><i>Select multiple folders by holding 'Ctrl'.</i></h5>
59           <button class="btn btn-primary" id="edit_folders_button" title="First Select Folder(s) to Edit">Edit Folder(s)</button>
60           <br/>
61       </div>
63       <!--<button id="delete" disabled="disabled" >Delete</button -->
64       <br />
65     </td>
66     <td>
67         <div id="trial_list" >[loading...]</div>
68     </td>
69   </tr>
70   </tbody>
71 </table>
74 <script>
76   jQuery.noConflict();
78   jQuery(document).ready(function($) {
80     jQuery.ajax( {
81       url: '/ajax/breeders/get_trials_with_folders_cached?type=trial',
82       success: function(response) {
83         var html = '<ul>'+response.html+'</ul>';
85         jQuery('#trial_list').html(html);
86         //console.log(html);
87         jQuery('#trial_list').jstree( {
88             "core": { 'themes': { 'name': 'proton', 'responsive': true}},
89             "valid_children" : [ "folder", "trial", "breeding_program", "genotyping_data_project", "analyses" ],
90             "types" : {
91                 "breeding_program" : {
92                     "icon": 'glyphicon glyphicon-briefcase text-info',
93                 },
94                 "folder" : {
95                     "icon": 'glyphicon glyphicon-folder-open text-danger',
96                 },
97                 "trial" : {
98                     "icon": 'glyphicon glyphicon-leaf text-success',
99                 },
100                 "genotyping_data_project" : {
101                     "icon": 'glyphicon glyphicon-align-left text-warning',
102                 },
103                 "analyses" : {
104                     "icon": 'glyphicon glyphicon-stats text-success',
105                 }
106             },
107             "search" : {
108                  "case_insensitive" : true,
109              },
110           "plugins" : ["html_data","types","search"],
112         });
114       },
115       error: function(response) {
116         alert("An error occurred while loading the trial data.");
117       }
118   });
120   jQuery('#refresh_jstree_html_trialtree_button').click(function(){
121       jQuery.ajax( {
122         url: '/ajax/breeders/get_trials_with_folders_cached?type=trial',
123         success: function(response) {
124           var html = '<ul>'+response.html+'</ul>';
126           jQuery('#trial_list').html(html);
127           //console.log(html);
128           jQuery('#trial_list').jstree( {
129               "core": { 'themes': { 'name': 'proton', 'responsive': true}},
130               "valid_children" : [ "folder", "trial", "breeding_program", "genotyping_data_project", "analyses" ],
131               "types" : {
132                   "breeding_program" : {
133                       "icon": 'glyphicon glyphicon-briefcase text-info',
134                   },
135                   "folder" : {
136                       "icon": 'glyphicon glyphicon-folder-open text-danger',
137                   },
138                   "trial" : {
139                       "icon": 'glyphicon glyphicon-leaf text-success',
140                   },
141                   "genotyping_data_project" : {
142                       "icon": 'glyphicon glyphicon-align-left text-warning',
143                   },
144                   "analyses" : {
145                       "icon": 'glyphicon glyphicon-stats text-success',
146                   }
147               },
148               "search" : {
149                    "case_insensitive" : true,
150                },
151             "plugins" : ["html_data","types","search"],
153           });
155         },
156         error: function(response) {
157           alert("An error occurred while loading the trial data.");
158         }
159     });
160   });
162     jQuery("#trial_tree_search").keyup(function() {
163         var v = jQuery("#trial_tree_search").val();
164         jQuery("#trial_list").jstree(true).search(v);
165     });
169   jQuery('#trial_list').on("changed.jstree", function (e, data) {
170     //console.log(data);
171        if ($('#trial_list').jstree('is_leaf', data.node) && data.node.data.jstree.type == 'trial') {
172          jQuery('#trials_download_phenotypes_button').removeAttr('disabled');
173          jQuery("#folder_edit_options").hide();
174        }
175        else if ($('#trial_list').jstree('is_leaf', data.node) && data.node.data.jstree.type == 'folder') {
176          jQuery('#trials_download_phenotypes_button').attr('disabled', 'disabled');
177          jQuery("#folder_edit_options").show();
178        }
179        else {
180          jQuery('#trials_download_phenotypes_button').attr('disabled', 'disabled');
181          jQuery("#folder_edit_options").hide();
182        }
183     });
186     $("#trial_list").delegate("li", "dblclick", function(event){
187       var node = $("#trial_list").jstree("get_node", this);
188       //console.log(node);
189       if (node.id.substr(0,1) !== 'j') {
190         if (node.type == 'folder') {
191             window.open('/folder/'+node.id);
192             event.stopPropagation();
193         } else if (node.type == 'breeding_program') {
194             window.open('/breeders/program/'+node.id);
195             event.stopPropagation();
196         } else if (node.type == 'analyses') {
197             window.open('/analyses/'+node.id);
198             event.stopPropagation();
199         } else if (node.type == 'genotyping_data_project') {
200             window.open('/breeders_toolbox/trial/'+node.id);
201             event.stopPropagation();
202         } else if (node.type == 'trial') {
203             window.open('/breeders_toolbox/trial/'+node.id);
204             event.stopPropagation();
205         }
206       }
207     });
208   });
210 </script>