working on tests
[sgn.git] / mason / breeders_toolbox / trialtreefolders.mas
blobcabdd1c7d6cf2950c87f740c00904be325aacc03
2 <%args>
3 @locations => ()
4 $breeding_programs
5 </%args>
7 <& /util/import_javascript.mas, classes => [ 'jquery.iframe-post-form','CXGN.BreedersToolbox.AddTrial','CXGN.BreedersToolbox.UploadTrial','CXGN.BreedersToolbox.Trial', 'jstree.dist.jstree', 'CXGN.Trial', 'CXGN.BreedersToolbox.HTMLSelect', 'CXGN.TrialTreeFolders' ] &>
9 <link rel="stylesheet" href="/static/documents/inc/jstree_theme/jstree-bstheme-min.css" />
11 <& /breeders_toolbox/folder/folder_set.mas &>
12 <& /breeders_toolbox/folder/folder_new.mas &>
13 <& /breeders_toolbox/folder/folder_move.mas &>
15 <& /breeders_toolbox/trial/trial_create_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs &>
16 <& /breeders_toolbox/trial/trial_upload_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs &>
18 <& /breeders_toolbox/trial/download_trials_phenotypes_dialog.mas &>
20 <table class="table table-bordered">
21   <thead>
22     <tr>
23       <th>Information</th>
24       <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>
25     </tr>
26   </thead>
27   <tbody>
28   <tr>
29     <td>
30         <h4>Search</h4>
31         <input type="text" class="form-control input-sm" id="trial_tree_search" placeholder="Search" />
32         <hr>
33       <h4>Download Trial Phenotypes</h4>
34       <h5><i>Select multiple trials by holding 'Ctrl'.</i></h5>
35       <button class="btn btn-primary" id="trials_download_phenotypes_button" disabled="disabled" title="First Select Trial(s) to Download">Download Phenotypes</button>
36       <hr>
37       <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>
38       <h5><i>Breeding programs (&nbsp;<span class="glyphicon glyphicon-briefcase text-info"></span>&nbsp;)</i></h5>
39       <hr>
40       <h4>Folders</h4>
41       <button class="btn btn-sm btn-default" id="new_folder_dialog_link">Create new folder</button><br/><br/>
42       <button class="btn btn-sm btn-default" id="open_folder_dialog_link">Move trial to folder</button><br/><br/>
43       <button class="btn btn-sm btn-default" id="move_folder_dialog_link">Move folder</button>
44       <br/>
46       <!--<button id="delete" disabled="disabled" >Delete</button -->
47       <br />
48     </td>
49     <td>
50         <div id="trial_list" >[loading...]</div>
51     </td>
52   </tr>
53   </tbody>
54 </table>
55 <script>
57   jQuery.noConflict();
59   jQuery(document).ready(function($) {
60   
61     jQuery.ajax( {
62       url: '/ajax/breeders/get_trials_with_folders_cached',
63       success: function(response) {
64         var html = '<ul>'+response.html+'</ul>';
66         jQuery('#trial_list').html(html);
67         //console.log(html);
68         jQuery('#trial_list').jstree( {
69             "core": { 'themes': { 'name': 'proton', 'responsive': true}},
70             "valid_children" : [ "folder", "trial", "breeding_program" ],
71             "types" : {
72                 "breeding_program" : {
73                     "icon": 'glyphicon glyphicon-briefcase text-info',
74                 },
75                 "folder" : {
76                     "icon": 'glyphicon glyphicon-folder-open text-danger',
77                 },
78                 "trial" : {
79                     "icon": 'glyphicon glyphicon-leaf text-success',
80                 }
81             },
82             "search" : {  
83                  "case_insensitive" : true,    
84              },
85           "plugins" : ["html_data","types","search"],
87         });
89       },
90       error: function(response) {
91         alert("An error occurred while loading the trial data.");
92       }
93   });
94   
95     jQuery("#trial_tree_search").keyup(function() {
96         var v = jQuery("#trial_tree_search").val();
97         jQuery("#trial_list").jstree(true).search(v);
98     });
102   $('#trial_list').on("changed.jstree", function (e, data) {
103     //console.log(data);
104        if ($('#trial_list').jstree('is_leaf', data.node) && data.node.data.jstree.type == 'trial') {
105          $('#trials_download_phenotypes_button').removeAttr('disabled');
106        }
107        else {
108          $('#trials_download_phenotypes_button').attr('disabled', 'disabled');
109        }
110     });
113     $("#trial_list").delegate("li", "dblclick", function(event){
114       var node = $("#trial_list").jstree("get_node", this);
115       //console.log(node);
116       if (node.id.substr(0,1) !== 'j') {
117         if (node.type == 'folder') {
118             window.open('/folder/'+node.id);
119             event.stopPropagation();
120         } else if (node.type == 'trial') {
121             window.open('/breeders_toolbox/trial/'+node.id);
122             event.stopPropagation();
123         }
124       }
125     });
126   });
128 </script>