Merge pull request #5243 from solgenomics/topic/observations_upload_catch_error
[sgn.git] / mason / breeders_toolbox / crossing_experiment_tree.mas
blob0dd3fe35248aa102c7f82e5f87022bed27ec3e4f
2 <%args>
3 $user_id => undef
4 @programs => ()
5 @locations => ()
6 @roles => ()
7 $odk_service => undef
8 </%args>
10 <& /util/import_javascript.mas, classes => [ 'jquery.iframe-post-form','CXGN.BreedersToolbox.Crosses', 'jstree.dist.jstree', 'CXGN.TrialTreeFolders'] &>
12 <& /util/import_css.mas, paths => ['/static/documents/inc/jstree_theme/jstree-bstheme-min.css'] &>
14 % if ($odk_service eq 'ONA') {
15     <& /breeders_toolbox/cross/cross_wishlist.mas &>
17 <& /breeders_toolbox/cross/add_cross_dialogs.mas, programs=>\@programs, locations=>\@locations &>
18 <& /breeders_toolbox/cross/upload_crosses_dialogs.mas, programs=>\@programs, locations=>\@locations &>
19 <& /breeders_toolbox/cross/add_crossing_trial_dialogs.mas, programs=>\@programs, locations=>\@locations &>
20 <& /breeders_toolbox/folder/folder_set.mas, project_type=>'crossing_experiment' &>
21 <& /breeders_toolbox/folder/folder_new.mas, project_type=>'crossing_experiment' &>
22 <& /breeders_toolbox/folder/folder_move.mas, project_type=>'crossing_experiment' &>
23 <& /breeders_toolbox/folder/folders_edit.mas, folder_tree_type => 'Cross', folder_tree_identifier => 'crosses_list', folder_tree_refresh_name => 'refresh_crosses_jstree_html' &>
25 <table class="table table-bordered">
26     <thead>
27         <tr>
28             <th>Information</th>
29             <th>Breeding Programs -- Folders -- Crossing Experiments&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-sm btn-default" id="refresh_crosses_jstree_html_trialtree_button" name="refresh_crosses_jstree_html">Refresh</button></th>
30         </tr>
31     </thead>
32     <tbody>
33         <tr>
34             <td>
35                 <h4>Search</h4>
36                 <input type="text" class="form-control input-sm" id="cross_tree_search" placeholder="Search" />
37                 <hr>
39                 <h5><i>Double click<br />crossing experiment (&nbsp;<span class="glyphicon glyphicon-grain text-success"></span>&nbsp;) or folder (&nbsp;<span class="glyphicon glyphicon-folder-open text-danger"></span>&nbsp;)<br/>to view detail page.</i></h5>
40                 <h5><i>Breeding programs (&nbsp;<span class="glyphicon glyphicon-briefcase text-info"></span>&nbsp;)</i></h5>
41                 <hr>
43                 <h4>Folders</h4>
44                 <button class="btn btn-sm btn-default" id="new_folder_dialog_link">Create new folder</button><br/><br/>
45                 <button class="btn btn-sm btn-default" id="open_folder_dialog_link">Move crossing experiment(s) to folder</button><br/><br/>
46                 <button class="btn btn-sm btn-default" id="move_folder_dialog_link">Move folder</button>
48                 <div id="folder_edit_options" style="display:none">
49                     <hr>
50                     <h5><i>Select multiple folders by holding 'Ctrl'.</i></h5>
51                     <button class="btn btn-primary" id="edit_folders_button" title="First Select Folder(s) to Edit">Edit Folder(s)</button>
52                     <br/>
53                 </div>
55                 <!--<button id="delete" disabled="disabled" >Delete</button -->
56                 <br />
57             </td>
58             <td>
59                 <div id="crosses_list" >[loading...]</div>
60             </td>
61         </tr>
62     </tbody>
63 </table>
66 <script>
68 jQuery.noConflict();
70 jQuery(document).ready(function($) {
72     jQuery('#crosses_datatable').DataTable({
73         destroy: true,
74         scrollY:        '30vh',
75             scrollCollapse: true,
76             paging:         false,
77     });
79     jQuery.ajax( {
80       url: '/ajax/breeders/get_trials_with_folders_cached?type=cross',
81       success: function(response) {
82         var html = '<ul>'+response.html+'</ul>';
84         jQuery('#crosses_list').html(html);
85         //console.log(html);
86         jQuery('#crosses_list').jstree( {
87             "core": { 'themes': { 'name': 'proton', 'responsive': true}},
88             "valid_children" : [ "folder", "trial", "breeding_program" ],
89             "types" : {
90                 "breeding_program" : {
91                     "icon": 'glyphicon glyphicon-briefcase text-info',
92                 },
93                 "folder" : {
94                     "icon": 'glyphicon glyphicon-folder-open text-danger',
95                 },
96                 "cross" : {
97                     "icon": 'glyphicon glyphicon-grain text-success',
98                 }
99             },
100             "search" : {
101                  "case_insensitive" : true,
102              },
103           "plugins" : ["html_data","types","search"],
105         });
107       },
108       error: function(response) {
109         alert("An error occurred while loading the trial data.");
110       }
111   });
113     jQuery("#cross_tree_search").keyup(function() {
114         var v = jQuery("#cross_tree_search").val();
115         jQuery("#crosses_list").jstree(true).search(v);
116     });
118     jQuery('#crosses_list').on("changed.jstree", function (e, data) {
119         //console.log(data);
120         if ($('#trial_list').jstree('is_leaf', data.node) && data.node.data.jstree.type == 'folder') {
121             jQuery("#folder_edit_options").show();
122         }
123         else {
124             jQuery("#folder_edit_options").hide();
125         }
126     });
128     jQuery("#crosses_list").delegate("li", "dblclick", function(event){
129         var node = $("#crosses_list").jstree("get_node", this);
130         //console.log(node);
131         if (node.id.substr(0,1) !== 'j') {
132             if (node.type == 'folder') {
133                 window.open('/folder/'+node.id);
134                 event.stopPropagation();
135             } else if (node.type == 'cross') {
136                 window.open('/breeders_toolbox/trial/'+node.id);
137                 event.stopPropagation();
138             }
139         }
140     });
144 </script>