Changed trials-in-common page to use a single database query to get analyses. Changed...
[sgn.git] / mason / breeders_toolbox / cross / upload_crossingtrial_seedlots_dialog.mas
blobf8f7cd40e744b827996f0a8b9f7c5f9d5152885d
1 <%args>
3 $breeding_program_name
4 $breeding_program_id
5 $locations_by_program_json
7 </%args>
9 <div class="modal fade" id="upload_cross_seedlot_dialog" name="upload_cross_seedlot_dialog" tabindex="-1" role="dialog" aria-labelledby="seedlot_upload_dialog">
10     <div class="modal-dialog modal-xl" role="document">
11         <div class="modal-content">
12             <div class="modal-header">
13                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
14                 <h4 class="modal-title" id="seedlot_upload_dialog">Upload Seedlots</h4>
15             </div>
16             <div class="modal-body">
17                 <div class="container-fluid">
18                     <&| /util/workflow.mas, id=> "upload_seedlot_main_workflow" &>
19                         <&| /util/workflow.mas:step, title=> "Intro" &>
20                             <& /page/page_title.mas, title=>"What are seedlots?" &>
21                             <ul>
22                                 <li>A seedlot is a collection of seeds harvested from a cross, accession, plot or plant.</li>
23                                 <li>Seedlots can have a specific location, box, weight(g), and count.</li>
24                                 <li>Seedlots can belong to breeding programs and organizations.</li>
25                             </ul>
26                             <br/><br/>
27                             <center>
28                                 <button class="btn btn-primary" onclick="Workflow.complete(this);">Go to Next Step</button>
29                             </center>
30                     </&>
31                     <&| /util/workflow.mas:step, title=> "File format" &>
32                         <& /page/page_title.mas, title=>"Make sure your file matches the correct file format" &>
33                             <br/><br/>
34                             <center>
35                                 <div id="upload_crosses_seedlots_template_section" style="display:none">
36                                     <button class="btn btn-info" id ="guided_help_crosses_seedlots_upload_format_button" name ="guided_help_crosses_seedlots_upload_format_button">Information about file format for uploading seed lots harvested</button><br/><br/>
37                                 </div>
38                                     <button class="btn btn-primary" onclick="Workflow.complete(this);">Once you think your file matches, go to Next Step</button>
39                             </center>
40                     </&>
41                     <&| /util/workflow.mas:step, title=> "Upload seedlots" &>
42                         <& /page/page_title.mas, title=>"Provide basic information about the seedlots and upload your file" &>
43                         <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_cross_seedlot_form" name="upload_cross_seedlot_form">
44                             <div class="form-group">
45                                 <label class="col-sm-3 control-label">Breeding Program: </label>
46                                 <div class="col-sm-9" >
47                                     <input class="form-control" name="upload_seedlot_breeding_program_name" id="upload_seedlot_breeding_program_name" disabled value="<% $breeding_program_name %>">
48                                     <input name="upload_seedlot_breeding_program_id" id="upload_seedlot_breeding_program_id" type="hidden" value="<% $breeding_program_id %>">
49                                 </div>
50                             </div>
51                             <div class="form-group">
52                                 <label class="col-sm-3 control-label">Location of seedlot storage: </label>
53                                 <div class="col-sm-9" >
54                                     <select class="form-control" name="upload_seedlot_location" id="upload_seedlot_location"></select>
55                                 </div>
56                             </div>
57                             <div class="form-group">
58                                 <label class="col-sm-3 control-label">Organization Name: </label>
59                                 <div class="col-sm-9" >
60                                     <input class="form-control" name="upload_seedlot_organization_name" id="upload_seedlot_organization_name" placeholder="Optional">
61                                 </div>
62                             </div>
63                             <div id="upload_seedlots_harvested_section" style="display:none">
64                                 <div class="form-group">
65                                     <label class="col-sm-3 control-label">Upload File (.xls or .xlsx): </label>
66                                     <div class="col-sm-9" >
67                                         <input type="file" name="seedlot_harvested_uploaded_file" id="seedlot_harvested_uploaded_file" encoding="multipart/form-data" />
68                                     </div>
69                                 </div>
70                             </div>
71                             <div id="upload_seedlot_breeding_program_id" style="visibility:hidden">
72                                 <% $breeding_program_id %>
73                             </div>
74                         </form>
75                         <center>
76                             <button type="button" class="btn btn-lg btn-primary" onclick="Workflow.complete(this, false);" id ="upload_cross_seedlot_button" name="upload_cross_seedlot_button" >Upload Seedlots</button><br/><br/>
77                         </center>
78                     </&>
79                     <&| /util/workflow.mas:complete, title=> "Complete" &>
80                         <& /page/page_title.mas, title=>"Finished! Your seedlots are now in the database" &>
81                             <p>
82                                 <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
83                                 The seedlot file was uploaded successfully
84                             </p>
85                             <ul>
86                                 <li>You may want to proceed to the seedlot detail page(s) for the seedlot(s) you just created.</li>
87                                 <li>You can print barcodes for the seedlots.</li>
88                             </ul>
89                             <br/>
90                             <center>
91                                 <button class="btn btn-primary" name="upload_seedlot_success_complete_button">The seedlots were saved to the database with no errors! Congrats Click Here</button><br/><br/>
92                             </center>
93                         </&>
94                     </&>
95                 </div>
96             </div>
97             <div class="modal-footer">
98                 <button id="close_seedlot_upload_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
99             </div>
100         </div>
101     </div>
102 </div>
104 <div class="modal fade" id="crosses_seedlots_upload_spreadsheet_info_dialog" name="crosses_seedlots_upload_spreadsheet_info_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadSeedlotHarvestedInfoDialog">
105     <div class="modal-dialog modal-xl" role="document">
106         <div class="modal-content">
107             <div class="modal-header" style="text-align: center">
108                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
109                 <h4 class="modal-title" id="uploadSeedlotHarvestedInfoDialog">Upload Template Information For Seedlots From Crosses</h4>
110             </div>
111             <div class="modal-body">
112                 <div class="container-fluid">
113                     <b>Seedlots may be uploaded in an Excel file (.xls or .xlsx)</b>
114                     <br />
115                     <b>Header:</b>
116                     <br>
117                         The first row (header) must contain the following:
118                     <br />
120                     <table class="table table-hover table-bordered table-condensed" >
121                         <thead></thead>
122                         <tbody>
123                             <tr>
124                                 <td>seedlot_name</td>
125                                 <td>cross_unique_id</td>
126                                 <td>operator_name</td>
127                                 <td>amount</td>
128                                 <td>weight(g)</td>
129                                 <td>description</td>
130                                 <td>box_name</td>
131                             </tr>
132                         </tbody>
133                     </table>
134                     <b>Required fields:</b>
135                     <ul>
136                         <li>seedlot_name (must be unique)</li>
137                         <li>cross_unique_id (must exist in the database. a cross_unique_id can represent a cross between accessions e.g. AxB, but a cross can also represent a cross between specific plots in the field if you have this information)</li>
138                         <li>operator_name (the name of the person who oversaw the inventory process. can be any name.)</li>
139                         <li>amount (number of seeds in seedlot. can be provided in conjunction with weight(g). must provide a value for amount or weight(g) or both.)
140                             <br/><b>AND/OR</b><br/>
141                             weight(g) (weight in grams of seedlot. can be provided in conjunction with amount. must provide a value for amount or weight(g) or both.)
142                         </li>
143                         <li>box_name (the box name that the seed is located in. can be any name.)</li>
144                     </ul>
146                     <b>Optional fields:</b>
147                     <ul>
148                         <li>description (additional information about each seedlot)</li>
149                     </ul>
150                 </div>
151             </div>
152             <div class="modal-footer">
153                 <button id="close_seedlot_harvested_info_upload_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
154             </div>
155         </div>
156     </div>
157 </div>
159 <div class="modal fade" id="upload_cross_seedlot_error_display" name="upload_cross_seedlot_error_display" tabindex="-1" role="dialog" aria-labelledby="uploadCrossSeedlotErrorDialog">
160   <div class="modal-dialog modal-lg" role="document">
161     <div class="modal-content">
162       <div class="modal-header">
163         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
164         <h4 class="modal-title" id="uploadCrossSeedlotErrorDialog">Upload Seedlot File Error</h4>
165       </div>
166       <div class="modal-body">
167         <div class="container-fluid">
168           <table>
169           <tbody></tbody>
170           </table>
171         </div>
172       </div>
173       <div class="modal-footer">
174         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
175       </div>
176     </div>
177   </div>
178 </div>
181 <script>
182 jQuery(document).ready(function(){
184     var locations_by_program_json = <% $locations_by_program_json %>;
185     var locations_string = locations_by_program_json.toString();
186     var locations_array = locations_string.split(",");
188     jQuery('#upload_seedlots_from_crosses').click( function() {
189         jQuery('#upload_cross_seedlot_dialog').modal('show');
191         var html = '<select id = "upload_seedlot_location" >';
192         for (var i=0; i<locations_array.length; i++) {
193             html = html + '<option value='+locations_array[i]+'>'+locations_array[i]+'</option>';
194         }
195         html = html + "</select>";
197         jQuery('#upload_seedlot_location').html(html);
199     });
201     jQuery('#upload_crosses_seedlots_template_section').show();
203     jQuery('#upload_seedlots_harvested_section').show();
205     jQuery('#guided_help_crosses_seedlots_upload_format_button').click( function () {
206         jQuery('#crosses_seedlots_upload_spreadsheet_info_dialog').modal("show");
207     });
209     jQuery('#upload_cross_seedlot_button').click(function () {
210         upload_crosses_seedlots();
211     });
213     function upload_crosses_seedlots() {
214         var uploadSeedlotsHarvestedFile = jQuery("#seedlot_harvested_uploaded_file").val();
215         var location = jQuery("#upload_seedlot_location").val();
216         var breeding_program = jQuery("#upload_seedlot_breeding_program_id").val();
217         jQuery('#upload_cross_seedlot_form').attr("action", "/ajax/breeders/seedlot-upload");
218         if (breeding_program === '') {
219             alert("Please choose a breeding program");
220             return;
221         }
222         if (location === '') {
223             alert("Please give a location");
224             return;
225         }
226         if (uploadSeedlotsHarvestedFile == '') {
227             alert("Please select a file");
228             return;
229         }
230         jQuery("#upload_cross_seedlot_form").submit();
231     }
233     jQuery('#upload_cross_seedlot_form').iframePostForm({
234         json: true,
235         post: function () {
236         var uploadSeedlotsHarvestedFile = jQuery("#seedlot_harvested_uploaded_file").val();
237             jQuery('#working_modal').modal("show");
238             if (uploadSeedlotsHarvestedFile == '') {
239                 jQuery('#working_modal').modal("hide");
240                 alert("No file selected");
241             }
242         },
243         complete: function(response) {
244             jQuery("#working_modal").modal("hide");
245             if (response.error_string) {
246                 jQuery('#upload_cross_seedlot_error_display').modal("show");
247                 jQuery('#upload_cross_seedlot_error_display tbody').html('');
248                 jQuery('#upload_cross_seedlot_error_display tbody').append(response.error_string);
249                 return;
250             }
251             if (response.error) {
252                 alert(response.error);
253                 return;
254             }
255             if (response.success) {
256                 Workflow.focus("#upload_seedlot_main_workflow", -1); //Go to success page
257                 Workflow.check_complete("#upload_seedlot_main_workflow");
259             }
260         }
261     });
263     jQuery(document).on('click', '[name="upload_seedlot_success_complete_button"]', function(){
264         alert('Seedlots were saved in the database');
265         jQuery('#upload_seedlot_dialog').modal('hide');
266         //location.reload();
267     });
272 </script>