Merge pull request #5248 from solgenomics/topic/batch_update_trials
[sgn.git] / mason / breeders_toolbox / drone_imagery / drone_imagery_export_imaging_events.mas
blob29263dd16f366b289c3ede6337fff5b63534fcc8
1 <%args>
2 </%args>
4 <& /util/import_javascript.mas, classes => [ ] &>
6 <!--button class='btn btn-default' style='margin:3px' id='export_drone_imagery_events'>Export Imaging Events</button-->
8 <div class="modal fade" id="export_drone_imagery_dialog" name="export_drone_imagery_dialog" tabindex="-1" role="dialog" aria-labelledby="exportDroneImageryDialog">
9   <div class="modal-dialog modal-xl" role="document">
10     <div class="modal-content">
11       <div class="modal-header">
12         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
13         <h4 class="modal-title" id="exportDroneImageryDialog">Export Aerial Imaging Event(s)</h4>
14       </div>
15       <div class="modal-body">
16         <div class="container-fluid">
18             <&| /util/workflow.mas, id=> "drone_imagery_export_workflow" &>
19                 <&| /util/workflow.mas:step, title=> "Intro" &>
20                     <& /page/page_title.mas, title=>"This workflow will guide you through exporting aerial imaging event(s) from the database" &>
21                     <ul>
22                         <li>Exporting imaging events is important for transferring data across ImageBreed instances.</li>
23                         <li>Exporting imaging events will return a spreadsheet file defining the imaging events, a zipfile containing the orthophoto imges, and a zipfile containing the GeoJSON plot-polygon definitions.</li>
24                         <li>Phenotypic values will not be exported in this workflow, please use the Wizard of the "Download Image-Phenotype File" to retrieve phenotypic values.</li>
25                     </ul>
26                     <br/>
27                     <center>
28                     <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to export imaging event(s)</button>
29                     </center>
30                 </&>
31                 <&| /util/workflow.mas:step, title=> "Field Trial" &>
32                     <& /page/page_title.mas, title=>"Select your field trial" &>
34                     <div class="form-horizontal">
35                         <div class="form-group">
36                             <label class="col-sm-3 control-label">Field Trial: </label>
37                             <div class="col-sm-9" >
38                                 <div id="export_drone_image_trial_select_div"></div>
39                             </div>
40                         </div>
41                     </div>
43                     <br/>
44                     <center>
45                     <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
46                     </center>
47                 </&>
48                 <&| /util/workflow.mas:step, title=> "Drone Run" &>
49                     <& /page/page_title.mas, title=>"Create a new drone run" &>
51                     <table class="table table-bordered table-hover" id="drone_image_export_drone_runs_table">
52                         <thead>
53                             <tr>
54                                 <th>Select</th>
55                                 <th>Imaging Event Name</th>
56                                 <th>Imaging Event Type</th>
57                                 <th>Imaging Event Description</th>
58                                 <th>Imaging Event Date</th>
59                                 <th>Drone Run GDD</th>
60                                 <th>Sensor</th>
61                                 <th>Field Trial Name</th>
62                                 <th>Field Trial Description</th>
63                             </tr>
64                         </thead>
65                     </table>
67                     <center>
68                     <button class="btn btn-primary" id="drone_image_export_drone_run_continue">Go to Next Step</button>
69                     </center>
70                 </&>
71                 <&| /util/workflow.mas:step, title=> "Submit" &>
72                     <& /page/page_title.mas, title=>"Export Imaging Event(s)" &>
74                     <div id="export_drone_imagery_submit_div">
75                     </div>
77                     <center>
78                     <button type="button" class="btn btn-info" name="export_drone_imagery_submit" id="export_drone_imagery_submit">Submit</button>
79                     </center>
80                 </&>
82             </&>
84             <div id="upload_drone_imagery_verify_status"></div>
85         </div>
86       </div>
87       <div class="modal-footer">
88         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
89       </div>
90     </div>
91   </div>
92 </div>
94 <script defer="defer">
96 jQuery(document).ready(function() {
98     jQuery('#export_drone_imagery_events').on('click', function(){
99         jQuery('#export_drone_imagery_dialog').modal('show');
100     });
102     get_select_box('trials', 'export_drone_image_trial_select_div', { 'name' : 'export_drone_run_field_trial_id', 'id' : 'export_drone_run_field_trial_id', 'empty':1, 'multiple':0 });
104     var export_imaging_events_field_trial_id;
105     jQuery(document).on('change', '#export_drone_run_field_trial_id', function() {
106         export_imaging_events_field_trial_id = jQuery(this).val();
107         jQuery('#drone_image_export_drone_runs_table').DataTable({
108             destroy : true,
109             ajax : '/api/drone_imagery/drone_runs?select_checkbox_name=export_drone_imagery_drone_run_select&field_trial_ids='+export_imaging_events_field_trial_id
110         });
111     });
113     var export_imaging_events_drone_run_ids = [];
114     jQuery('#drone_image_export_drone_run_continue').click(function(){
115         export_imaging_events_drone_run_ids = [];
116         jQuery('input[name="export_drone_imagery_drone_run_select"]:checked').each(function() {
117             export_imaging_events_drone_run_ids.push(jQuery(this).val());
118         });
119         if (export_imaging_events_drone_run_ids.length < 1) {
120             alert('Please select at least one imaging event.');
121             return false;
122         }
123         else {
124             Workflow.complete('#drone_image_export_drone_run_continue');
125             Workflow.focus('#drone_imagery_export_workflow', 3);
126         }
127         return false;
128     });
131     jQuery('#export_drone_imagery_submit').click(function(){
132         jQuery.ajax({
133             url : '/api/drone_imagery/export_drone_runs?drone_run_project_ids='+JSON.stringify(export_imaging_events_drone_run_ids)+'&field_trial_id='+export_imaging_events_field_trial_id,
134             success: function(response){
135                 console.log(response);
137                 if (response.error) {
138                     alert(response.error);
139                     return false;
140                 }
141                 else {
142                     var html = '<a href="'+response.imaging_events_spreadsheet+'">Download Imaging Event Spreadsheet</a><hr><a href="'+response.orthoimage_zipfile+'">Download Orthoimage Zipfile</a><hr><a href="'+response.geojson_zipfile+'">Download GeoJSON Zipfile</a>';
143                     jQuery('#export_drone_imagery_submit_div').html(html);
144                     return false;
145                 }
146             },
147             error: function(response){
148                 alert('Error exporting imaging events!');
149             }
150         });
151     });
154 </script>