add addiitional refresh option for all views except genoview
[sgn.git] / mason / breeders_toolbox / trialtreefolders.mas
blob902fc7be4ea82dabf37d5616ae9f68a86a8b52ea
2 <%args>
3 @locations => ()
4 $breeding_programs
5 $preferred_species
6 $editable_stock_props => {}
7 $editable_stock_props_definitions => {}
8 $timestamp
9 $management_factor_types => ()
10 $design_types => ()
11 </%args>
13 <& /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' ] &>
15 <& /util/import_css.mas, paths => ['/static/documents/inc/jstree_theme/jstree-bstheme-min.css'] &>
17 <& /breeders_toolbox/folder/folder_set.mas, project_type => 'field_trial' &>
18 <& /breeders_toolbox/folder/folder_new.mas, project_type => 'field_trial' &>
19 <& /breeders_toolbox/folder/folder_move.mas, project_type => 'field_trial' &>
20 <& /breeders_toolbox/folder/folders_edit.mas, folder_tree_type => 'Trial', folder_tree_identifier => 'trial_list', folder_tree_refresh_name => 'refresh_jstree_html' &>
22 <& /breeders_toolbox/trial/trial_create_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs, management_factor_types => $management_factor_types, design_types => $design_types &>
24 <& /breeders_toolbox/trial/download_trials_phenotypes_dialog.mas &>
26 <& /breeders_toolbox/trial/trial_upload_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs, design_types => $design_types &>
27 <& /breeders_toolbox/add_accessions_dialogs.mas, preferred_species=>$preferred_species, editable_stock_props=>$editable_stock_props, editable_stock_props_definitions=>$editable_stock_props_definitions &>
28 <& /breeders_toolbox/upload_seedlots_dialogs.mas &>
29 <& /breeders_toolbox/add_seedlot_dialogs.mas, timestamp=>$timestamp &>
31 <table class="table table-bordered">
32   <thead>
33     <tr>
34       <th>Information</th>
35       <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>
36     </tr>
37   </thead>
38   <tbody>
39   <tr>
40     <td>
41         <h4>Search</h4>
42         <input type="text" class="form-control input-sm" id="trial_tree_search" placeholder="Search" />
43         <hr>
44       <h4>Download Trial Phenotypes</h4>
45       <h5><i>Select multiple trials by holding 'Ctrl'.</i></h5>
46       <button class="btn btn-primary" id="trials_download_phenotypes_button" disabled="disabled" title="First Select Trial(s) to Download">Download Phenotypes</button>
47       <hr>
48       <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>
49       <h5><i>Breeding programs (&nbsp;<span class="glyphicon glyphicon-briefcase text-info"></span>&nbsp;)</i></h5>
50       <h5><i>Genotyping data projects (&nbsp;<span class="glyphicon glyphicon-align-left text-warning"></span>&nbsp;)</i></h5>
51       <h5><i>Analyses (&nbsp;<span class="glyphicon glyphicon-stats text-success"></span>&nbsp;)</i></h5>
52       <h5><i>Sampling trials (&nbsp;<span class="glyphicon glyphicon-th text-success"></span>&nbsp;)</i></h5>
53       <hr>
54       <h4>Folders</h4>
55       <button class="btn btn-sm btn-default" id="new_folder_dialog_link">Create new folder</button><br/><br/>
56       <button class="btn btn-sm btn-default" id="open_folder_dialog_link">Move trial(s) to folder</button><br/><br/>
57       <button class="btn btn-sm btn-default" id="move_folder_dialog_link">Move folder</button>
59       <div id="folder_edit_options" style="display:none">
60           <hr>
61           <h5><i>Select multiple folders by holding 'Ctrl'.</i></h5>
62           <button class="btn btn-primary" id="edit_folders_button" title="First Select Folder(s) to Edit">Edit Folder(s)</button>
63           <br/>
64       </div>
66       <!--<button id="delete" disabled="disabled" >Delete</button -->
67       <br />
68     </td>
69     <td>
70         <div id="trial_list" >[loading...]</div>
71     </td>
72   </tr>
73   </tbody>
74 </table>
77 <script>
79   jQuery.noConflict();
81   jQuery(document).ready(function($) {
83     jQuery.ajax( {
84       url: '/ajax/breeders/get_trials_with_folders_cached?type=trial',
85       success: function(response) {
86         var html = '<ul>'+response.html+'</ul>';
88         jQuery('#trial_list').html(html);
89         //console.log(html);
90         jQuery('#trial_list').jstree( {
91             "core": { 'themes': { 'name': 'proton', 'responsive': true}},
92             "valid_children" : [ "folder", "trial", "breeding_program", "genotyping_data_project", "analyses" ],
93             "types" : {
94                 "breeding_program" : {
95                     "icon": 'glyphicon glyphicon-briefcase text-info',
96                 },
97                 "folder" : {
98                     "icon": 'glyphicon glyphicon-folder-open text-danger',
99                 },
100                 "trial" : {
101                     "icon": 'glyphicon glyphicon-leaf text-success',
102                 },
103                 "genotyping_data_project" : {
104                     "icon": 'glyphicon glyphicon-align-left text-warning',
105                 },
106                 "analyses" : {
107                     "icon": 'glyphicon glyphicon-stats text-success',
108                 },
109                 "sampling_trial" : {
110                     "icon": 'glyphicon glyphicon-th text-success',
111                 },
112                 "pcr_genotyping_data_project" : {
113                     "icon": 'glyphicon glyphicon-align-left text-warning',
114                 }
115             },
116             "search" : {
117                  "case_insensitive" : true,
118              },
119           "plugins" : ["html_data","types","search"],
121         });
123       },
124       error: function(response) {
125         alert("An error occurred while loading the trial data.");
126       }
127   });
129   jQuery('#refresh_jstree_html_trialtree_button').click(function(){
130       jQuery.ajax( {
131         url: '/ajax/breeders/get_trials_with_folders_cached?type=trial',
132         success: function(response) {
133           var html = '<ul>'+response.html+'</ul>';
135           jQuery('#trial_list').html(html);
136           //console.log(html);
137           jQuery('#trial_list').jstree( {
138               "core": { 'themes': { 'name': 'proton', 'responsive': true}},
139               "valid_children" : [ "folder", "trial", "breeding_program", "genotyping_data_project", "analyses", "sampling_trial" ],
140               "types" : {
141                   "breeding_program" : {
142                       "icon": 'glyphicon glyphicon-briefcase text-info',
143                   },
144                   "folder" : {
145                       "icon": 'glyphicon glyphicon-folder-open text-danger',
146                   },
147                   "trial" : {
148                       "icon": 'glyphicon glyphicon-leaf text-success',
149                   },
150                   "genotyping_data_project" : {
151                       "icon": 'glyphicon glyphicon-align-left text-warning',
152                   },
153                   "analyses" : {
154                       "icon": 'glyphicon glyphicon-stats text-success',
155                   },
156                   "sampling_trial" : {
157                       "icon": 'glyphicon glyphicon-th text-success',
158                   }
159               },
160               "search" : {
161                    "case_insensitive" : true,
162                },
163             "plugins" : ["html_data","types","search"],
165           });
167         },
168         error: function(response) {
169           alert("An error occurred while loading the trial data.");
170         }
171     });
172   });
174     jQuery("#trial_tree_search").keyup(function() {
175         var v = jQuery("#trial_tree_search").val();
176         jQuery("#trial_list").jstree(true).search(v);
177     });
181   jQuery('#trial_list').on("changed.jstree", function (e, data) {
182     //console.log(data);
183        if ($('#trial_list').jstree('is_leaf', data.node) && data.node.data.jstree.type == 'trial') {
184          jQuery('#trials_download_phenotypes_button').removeAttr('disabled');
185          jQuery("#folder_edit_options").hide();
186        }
187        else if ($('#trial_list').jstree('is_leaf', data.node) && data.node.data.jstree.type == 'folder') {
188          jQuery('#trials_download_phenotypes_button').attr('disabled', 'disabled');
189          jQuery("#folder_edit_options").show();
190        }
191        else {
192          jQuery('#trials_download_phenotypes_button').attr('disabled', 'disabled');
193          jQuery("#folder_edit_options").hide();
194        }
195     });
198     $("#trial_list").delegate("li", "dblclick", function(event){
199       var node = $("#trial_list").jstree("get_node", this);
200       //console.log(node);
201       if (node.id.substr(0,1) !== 'j') {
202         if (node.type == 'folder') {
203             window.open('/folder/'+node.id);
204             event.stopPropagation();
205         } else if (node.type == 'breeding_program') {
206             window.open('/breeders/program/'+node.id);
207             event.stopPropagation();
208         } else if (node.type == 'analyses') {
209             window.open('/analyses/'+node.id);
210             event.stopPropagation();
211         } else if (node.type == 'genotyping_data_project') {
212             window.open('/breeders_toolbox/trial/'+node.id);
213             event.stopPropagation();
214         } else if (node.type == 'trial') {
215             window.open('/breeders_toolbox/trial/'+node.id);
216             event.stopPropagation();
217         } else if (node.type == 'sampling_trial') {
218             window.open('/breeders_toolbox/trial/'+node.id);
219             event.stopPropagation();
220         }
221       }
222     });
223   });
225 </script>