check file name
[sgn.git] / mason / breeders_toolbox / upload_seedlots_dialogs.mas
blob83b4a9f581bab643d26ded922ce36f77c0f5e8d6
1 <%args>
2 </%args>
4 <div class="modal fade" id="upload_seedlot_dialog" name="upload_seedlot_dialog" tabindex="-1" role="dialog" aria-labelledby="seedlot_upload_dialog">
5     <div class="modal-dialog modal-xl" role="document">
6         <div class="modal-content">
7             <div class="modal-header">
8                 <button type="button" class="close" name="close_seedlots_upload" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
9                 <h4 class="modal-title" id="seedlot_upload_dialog">Upload Seedlots</h4>
10             </div>
11             <div class="modal-body">
12                 <div class="container-fluid">
14                     <&| /util/workflow.mas, id=> "upload_seedlot_main_workflow" &>
15                         <&| /util/workflow.mas:step, title=> "Intro" &>
16                             <& /page/page_title.mas, title=>"What are seedlots?" &>
17                             <ul>
18                             <li>Seedlots represent physical seed in packets.</li>
19                             <li>This seed can be from crosses or for named accessions.</li>
20                             <li>Seedlots can have a specific location, box, weight_gram, and count.</li>
21                             <li>Seedlots can belong to breeding programs and organizations.</li>
22                             <li>Seedlots can be used in trials (e.g. they were planted in a plot) and they can be harvested from a plot or plant (e.g. a cross was performed and seeds were collected.)</li>
23                             </ul>
25                             <br/><br/>
26                             <center>
27                                 <button class="btn btn-primary" onclick="Workflow.complete(this);">Go to Next Step</button>
28                             </center>
29                         </&>
31                         <&| /util/workflow.mas:step, title=> "What seedlots do you have?" &>
32                             <& /page/page_title.mas, title=>"Seedlots fall into two categories" &>
34                             <div class="form-group">
35                                 <label class="col-sm-3 control-label">Select One: </label>
36                                 <div class="col-sm-9">
37                                     <select class="form-control" id="upload_seedlots_type_select" name="upload_seedlots_type_select">
38                                         <option value=""></option>
39                                         <option data-desc="If you have seed lots for named accessions, such as seed that was ordered from a vendor, use this option. Use this option if the seed was not harvested from a cross that is in the database." value="from_accession">I have seed lots for named accessions</option>
40                                         <option data-desc="If you have seed lots that were harvested from crosses that are in the database, use this option." value="from_cross">I have seed lots harvested from crosses</option>
41                                     </select>
42                                 </div>
43                             </div>
44                             <br/><br/>
45                             <div id="upload_seedlots_types_description">
46                             </div>
47                             <br/>
48                             <center>
49                                 <button disabled id="seedlot_upload_type_select_button" class="btn btn-primary" onclick="Workflow.complete(this);">Go to Next Step</button>
50                             </center>
51                         </&>
53                         <&| /util/workflow.mas:step, title=> "File format" &>
54                             <& /page/page_title.mas, title=>"Make sure your file matches the correct file format" &>
55                             <br/><br/>
56                             <center>
57                                 <div id="upload_seedlots_accessions_template_section" style="display:none">
58                                     <button class="btn btn-info" name="guided_help_seedlot_upload_format_button">Information about file format for uploading seedlots of named accessions</button><br/><br/>
59                                 </div>
60                                 <div id="upload_seedlots_crosses_template_section" style="display:none">
61                                     <button class="btn btn-info" name="guided_help_seedlot_crosses_upload_format_button">Information about file format for uploading seed lots harvested</button><br/><br/>
62                                 </div>
63                                 <button class="btn btn-primary" onclick="Workflow.complete(this);">Once you think your file matches, go to Next Step</button>
64                             </center>
65                         </&>
67                         <&| /util/workflow.mas:step, title=> "Upload seedlots" &>
68                             <& /page/page_title.mas, title=>"Provide basic information about the seedlots and upload your file" &>
70                             <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_seedlot_form" name="upload_seedlot_form">
72                                 <div class="form-group">
73                                     <label class="col-sm-3 control-label">Breeding Program: </label>
74                                     <div class="col-sm-9" >
75                                         <div id="upload_seedlot_breeding_program_div"></div>
76                                     </div>
77                                 </div>
78                                 <div class="form-group">
79                                     <label class="col-sm-3 control-label">Location of seedlot storage: </label>
80                                     <div class="col-sm-9" >
81                                         <input class="form-control" name="upload_seedlot_location" id="upload_seedlot_location" placeholder="Required">
82                                     </div>
83                                 </div>
84                                 <!--
85                                 <div class="form-group">
86                                     <label class="col-sm-3 control-label">Population Name: </label>
87                                     <div class="col-sm-9" >
88                                         <input class="form-control" name="upload_seedlot_population_name" id="upload_seedlot_population_name" placeholder="Optional">
89                                     </div>
90                                 </div>
91                                 -->
92                                 <div class="form-group">
93                                     <label class="col-sm-3 control-label">Organization Name: </label>
94                                     <div class="col-sm-9" >
95                                         <input class="form-control" name="upload_seedlot_organization_name" id="upload_seedlot_organization_name" placeholder="Optional">
96                                     </div>
97                                 </div>
99                                 <div id="upload_seedlots_accessions_section" style="display:none">
100                                     <div class="form-group">
101                                         <label class="col-sm-3 control-label">Upload File: </label>
102                                         <div class="col-sm-9" >
103                                             <input type="file" name="seedlot_uploaded_file" id="seedlot_uploaded_file" encoding="multipart/form-data" />
104                                         </div>
105                                     </div>
106                                 </div>
108                                 <div id="upload_seedlots_harvested_section" style="display:none">
109                                     <div class="form-group">
110                                         <label class="col-sm-3 control-label">Upload File: </label>
111                                         <div class="col-sm-9" >
112                                             <input type="file" name="seedlot_harvested_uploaded_file" id="seedlot_harvested_uploaded_file" encoding="multipart/form-data" />
113                                         </div>
114                                     </div>
115                                 </div>
117                             </form>
118                             <center>
119                             <button type="button" class="btn btn-lg btn-primary" onclick="Workflow.complete(this, false);" name="upload_seedlot_button" >Upload Seedlots</button><br/><br/>
120                             </center>
122                         </&>
123                         <&| /util/workflow.mas:step, title=> "Fix errors in file" &>
124                             <& /page/page_title.mas, title=>"Fix all errors in your file" &>
126                             <div id="upload_seedlots_missing_accessions_or_crosses_div" style="display:none">
127                                 <div id="upload_seedlots_missing_accessions_div" style="display:none">
128                                     <div class="well">
129                                         <ul>
130                                             <li>Accessions must exist in the database prior to adding seedlots of them. The reason for this is that an accession can be exist in many seedlots and therefore exists as a separate entity in the database. We also want to be careful about adding new accessions into the database because we do not want incorrectly duplicated data.</li>
131                                             <li>When adding accessions into the database, you can use either a list of accessions or an Excel file.</li>
132                                         </ul>
133                                     </div>
135                                     <div id="upload_seedlots_add_missing_accessions_html">
136                                     </div>
138                                     <button class="btn btn-info" name="add_accessions_link">Add your accessions to the database</button><br/><br/>
139                                     <button class="btn btn-primary" onclick="Workflow.complete(this);">Once all your accessions are in the database Click Here</button><br/><br/>
140                                 </div>
141                                 <div id="upload_seedlots_missing_crosses_div" style="display:none">
142                                     <div class="well">
143                                         <ul>
144                                             <li>Crosses must exist in the database before adding your seed lots. The reason for this is that a cross can produce many seed lots and so the cross must exists as a separate entity in the database. We also want to be careful about adding new crosses into the database because we do not want data to be incorrectly linked to duplicates.</li>
145                                         </ul>
146                                     </div>
147                                     <ul>
148                                     <li>When adding crosses into the database, you can upload an Excel file or you can add seedlots one at a time.<br/><br/>
149                                         <ul>
150                                         <li><button class="btn btn-info" name="upload_crosses_link">Upload Excel file</button><br/><br/></li>
151                                         <li><button class="btn btn-info" name="create_cross_link">Add One Cross</button></li>
152                                         </ul>
153                                     </li>
154                                     </ul><br/>
155                                     <center>
156                                     <button class="btn btn-primary" onclick="Workflow.complete(this);">Once all your crosses are in the database Click Here</button><br/><br/>
157                                     </center>
158                                 </div>
159                             </div>
160                             <div id="upload_seedlots_error_display" style="display:none">
162                                 <h3>Seedlot Upload Error Messages</h3>
163                                 <div class="panel panel-danger">
164                                     <div class="panel-body">
165                                         <table>
166                                             <tbody></tbody>
167                                         </table>
168                                     </div>
169                                 </div>
170                             </div>
171                             <center>
172                             <div id="upload_seedlots_no_error_messages_accessions_html">
173                             </div>
174                             <div name="upload_seedlots_completed_message">
175                             </div>
176                             </center>
177                         </&>
178                         <&| /util/workflow.mas:step, title=> "Try submitting seedlots again" &>
179                             <& /page/page_title.mas, title=>"Submit your seedlots again. You should have corrected all errors by now, but if not please take a look at the errors in the red box below. You can continue to modify your file and then click Upload until it works." &>
180                             <div id="seedlot_upload_show_repeat_upload_button">
181                                 <center>
182                                 <button type="button" class="btn btn-lg btn-primary" name="upload_seedlot_button" >Upload Seedlots</button><br/><br/>
183                                 </center>
184                             </div>
185                             <center>
186                             <div name="upload_seedlots_completed_message">
187                             </div>
188                             </center>
190                             <div id="upload_seedlots_error_display_second_try" style="display:none">
192                                 <h3>There exist these problems in your file:</h3>
193                                 <div class="panel panel-danger">
194                                     <div class="panel-body">
195                                         <table>
196                                             <tbody></tbody>
197                                         </table>
198                                     </div>
199                                 </div>
200                             </div>
201                         </&>
202                         <&| /util/workflow.mas:complete, title=> "Complete" &>
203                             <& /page/page_title.mas, title=>"Finished! Your seedlots are now in the database" &>
204                             <p>
205                                 <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
206                                 The seedlot file was uploaded successfully
207                             </p>
209                             <ul>
210                                 <li>You may want to proceed to the seedlot detail page(s) for the seedlot(s) you just created.</li>
211                                 <li>You can print barcodes for the seedlots.</li>
212                             </ul>
213                             <br/>
214                             <center>
215                             <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/>
216                             </center>
217                         </&>
218                     </&>
220                 </div>
221             </div>
222             <div class="modal-footer">
223                 <button id="close_seedlot_upload_dialog" name="close_seedlots_upload" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
224             </div>
225         </div>
226     </div>
227 </div>
229 <div class="modal fade" id="seedlot_upload_spreadsheet_info_dialog" name="seedlot_upload_spreadsheet_info_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadSeedlotInfoDialog">
230     <div class="modal-dialog modal-xl" role="document">
231         <div class="modal-content">
232             <div class="modal-header" style="text-align: center">
233                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
234                 <h4 class="modal-title" id="uploadSeedlotInfoDialog">Upload Template Information For Named Accessions</h4>
235             </div>
236             <div class="modal-body">
237                 <div class="container-fluid">
238                     <b>Header:</b>
239                     <br>
240                     The first row (header) should contain the following:
241                     <br />
243                     <table class="table table-hover table-bordered table-condensed" >
244                         <thead></thead>
245                         <tbody>
246                             <tr>
247                                 <td>seedlot_name</td>
248                                 <td>accession_name</td>
249                                 <td>operator_name</td>
250                                 <td>amount</td>
251                                 <td>weight_gram</td>
252                                 <td>description</td>
253                                 <td>box_name</td>
254                                 <td>quality</td>
255                                 <td>source</td>
256                             </tr>
257                         </tbody>
258                     </table>
260                     <b>Required fields:</b>
261                     <ul>
262                     <li>seedlot_name (must be unique)</li>
263                     <li>accession_name (must exist in the database. the accession_name is the unique identifier for the named genotype)</li>
264                     <li>operator_name (the name of the person who oversaw the inventory process. can be any name.)</li>
265                     <li>
266                     amount (number of seeds in seedlot. can be provided in conjunction with weight_gram. must provide a value for amount or weight_gram or both.)
267                     <br/><b>AND/OR</b><br/>
268                     weight_gram (weight in grams of seedlot. can be provided in conjunction with amount. must provide a value for amount or weight_gram or both.)
269                     </li>
270                     <li>box_name (the box name that the seed is located in. can be any name.)</li>
271                     </ul>
273                     <b>Optional fields:</b>
274                     <ul>
275                       <li>description (information about why this seedlot is being added)</li>
276                       <li>quality (status of the seedlot, for example "ok", "moldy", "insect damage" etc.</li>
277                       <li>source (an alternate source, such as a plot, subplot, or plant identifier from which the seed was collected)</li>
278                     </ul>
279                 </div>
280                 <& /help/file_upload_type.mas, type => "Seedlots", optional_column => 1 &>
281             </div>
282             <div class="modal-footer">
283                 <button id="close_seedlot_info_upload_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
284             </div>
285         </div>
286     </div>
287 </div>
289 <div class="modal fade" id="seedlot_upload_spreadsheet_harvested_info_dialog" name="seedlot_upload_spreadsheet_harvested_info_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadSeedlotHarvestedInfoDialog">
290     <div class="modal-dialog modal-xl" role="document">
291         <div class="modal-content">
292             <div class="modal-header" style="text-align: center">
293                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
294                 <h4 class="modal-title" id="uploadSeedlotHarvestedInfoDialog">Upload Template Information For Harvested Seedlots</h4>
295             </div>
296             <div class="modal-body">
297                 <div class="container-fluid">
298                     <b>Header:</b>
299                     <br>
300                     The first row (header) should contain the following:
301                     <br />
303                     <table class="table table-hover table-bordered table-condensed" >
304                         <thead></thead>
305                         <tbody>
306                             <tr>
307                                 <td>seedlot_name</td>
308                                 <td>cross_unique_id</td>
309                                 <td>operator_name</td>
310                                 <td>amount</td>
311                                 <td>weight_gram</td>
312                                 <td>description</td>
313                                 <td>box_name</td>
314                                 <td>quality</td>
315                             </tr>
316                         </tbody>
317                     </table>
319                     <b>Required fields:</b>
320                     <ul>
321                     <li>seedlot_name (must be unique)</li>
322                     <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>
323                     <li>operator_name (the name of the person who oversaw the inventory process. can be any name.)</li>
324                     <li>
325                     amount (number of seeds in seedlot. can be provided in conjunction with weight_gram. must provide a value for amount or weight_gram or both.)
326                     <br/><b>AND/OR</b><br/>
327                     weight_gram (weight in grams of seedlot. can be provided in conjunction with amount. must provide a value for amount or weight_gram or both.)
328                     </li>
329                     <li>box_name (the box name that the seed is located in. can be any name.)</li>
330                     </ul>
332                     <b>Optional fields:</b>
333                     <ul>
334                       <li>description (information about why this seedlot is being added)</li>
335                       <li>quality (brief description of quality, e.g.,  "ok", "moldy", "insect damage", etc)</li>
336                     </ul>
337                 </div>
338                 <& /help/file_upload_type.mas, type => "Seedlots", optional_column => 1 &>
339             </div>
340             <div class="modal-footer">
341                 <button id="close_seedlot_harvested_info_upload_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
342             </div>
343         </div>
344     </div>
345 </div>
349 <script>
350 jQuery(document).ready(function(){
352     jQuery("#upload_seedlot_location").autocomplete({
353        source: '/ajax/stock/geolocation_autocomplete',
354     });
356     jQuery('#upload_seedlots_type_select').change(function(){
357         if (jQuery(this).val() != ''){
358             jQuery('#seedlot_upload_type_select_button').attr('disabled', false);
359             jQuery('#upload_seedlots_types_description').html('<br/><div class="well"><p>'+jQuery(this).find("option:selected").data("desc")+'</p></div>');
360         } else {
361             jQuery('#seedlot_upload_type_select_button').attr('disabled', true);
362             jQuery('#upload_seedlots_types_description').html('');
363         }
365         if(jQuery(this).val() == 'from_accession'){
366             jQuery('#upload_seedlots_accessions_template_section').show();
367             jQuery('#upload_seedlots_crosses_template_section').hide();
368             jQuery('#upload_seedlots_accessions_section').show();
369             jQuery('#upload_seedlots_harvested_section').hide();
370         }
371         if(jQuery(this).val() == 'from_cross'){
372             jQuery('#upload_seedlots_crosses_template_section').show();
373             jQuery('#upload_seedlots_accessions_template_section').hide();
374             jQuery('#upload_seedlots_accessions_section').hide();
375             jQuery('#upload_seedlots_harvested_section').show();
376         }
377     });
379     jQuery('[name="seedlot_bulk_upload"]').click( function() {
380         jQuery('#upload_seedlot_dialog').modal('show');
381         get_select_box('breeding_programs', 'upload_seedlot_breeding_program_div', { 'name' : 'upload_seedlot_breeding_program_id', 'id' : 'upload_seedlot_breeding_program_id' });
382     });
384     jQuery("[name='guided_help_seedlot_upload_format_button']").click( function () {
385         jQuery("#seedlot_upload_spreadsheet_info_dialog" ).modal("show");
386     });
388     jQuery("[name='guided_help_seedlot_crosses_upload_format_button']").click( function () {
389         jQuery("#seedlot_upload_spreadsheet_harvested_info_dialog" ).modal("show");
390     });
392     jQuery('[name="upload_seedlot_button"]').click(function () {
393         upload_seedlot_button();
394     });
395     function upload_seedlot_button() {
396         var uploadSeedlotAccessionsFile = jQuery("#seedlot_uploaded_file").val();
397         var uploadSeedlotsHarvestedFile = jQuery("#seedlot_harvested_uploaded_file").val();
398         var location = jQuery("#upload_seedlot_location").val();
399         var breeding_program = jQuery("#upload_seedlot_breeding_program_id").val();
400         jQuery('#upload_seedlot_form').attr("action", "/ajax/breeders/seedlot-upload");
401         if (breeding_program === '') {
402             alert("Please choose a breeding program");
403             return;
404         }
405         if (location === '') {
406             alert("Please give a location");
407             return;
408         }
409         if (uploadSeedlotAccessionsFile === '' && uploadSeedlotsHarvestedFile == '') {
410             alert("Please select a file");
411             return;
412         }
413         jQuery("#upload_seedlot_form").submit();
414     }
416     jQuery('#upload_seedlot_form').iframePostForm({
417         json: true,
418         post: function () {
419         var uploadSeedlotAccessionsFile = jQuery("#seedlot_uploaded_file").val();
420         var uploadSeedlotsHarvestedFile = jQuery("#seedlot_harvested_uploaded_file").val();
421             jQuery('#working_modal').modal("show");
422             if (uploadSeedlotAccessionsFile === '' && uploadSeedlotsHarvestedFile == '') {
423                 jQuery('#working_modal').modal("hide");
424                 alert("No file selected");
425             }
426         },
427         complete: function (response) {
428             console.log(response);
429             jQuery('#working_modal').modal("hide");
431             if (response.error) {
432                 alert(response.error);
433                 return;
434             }
435             else if (response.error_string) {
437                 if (response.missing_accessions || response.missing_crosses) {
438                     jQuery('#upload_seedlots_missing_accessions_or_crosses_div').show();
439                     if (response.missing_accessions){
440                         jQuery('#upload_seedlots_missing_accessions_div').show();
441                         var missing_accessions_html = "<div class='well well-sm'><h3>Add the missing accessions to a list</h3><div id='upload_seedlots_missing_accessions' style='display:none'></div><div id='upload_seedlots_add_missing_accessions'></div></div><br/>";
442                         jQuery("#upload_seedlots_add_missing_accessions_html").html(missing_accessions_html);
444                         var missing_accessions_vals = '';
445                         for(var i=0; i<response.missing_accessions.length; i++) {
446                             missing_accessions_vals = missing_accessions_vals + response.missing_accessions[i] + '\n';
447                         }
448                         jQuery("#upload_seedlots_missing_accessions").html(missing_accessions_vals);
449                         addToListMenu('upload_seedlots_add_missing_accessions', 'upload_seedlots_missing_accessions', {
450                             selectText: true,
451                             listType: 'accessions'
452                         });
453                     } else if (response.missing_crosses){
454                         jQuery('#upload_seedlots_missing_crosses_div').show();
455                     }
456                 } else {
457                     jQuery('#upload_seedlots_missing_accessions_or_crosses_div').hide();
458                     var no_missing_accessions_html = '<button class="btn btn-primary" onclick="Workflow.skip(this);">There were no errors regarding missing accessions or crosses  Click Here</button><br/><br/>';
459                     jQuery('#upload_seedlots_no_error_messages_accessions_html').html(no_missing_accessions_html);
460                     Workflow.skip('#upload_seedlots_missing_accessions_or_crosses_div', false);
461                 }
463                 jQuery("#upload_seedlots_error_display").show();
464                 jQuery("#upload_seedlots_error_display tbody").html(response.error_string);
465                 jQuery("#upload_seedlots_error_display_second_try").show();
466                 jQuery("#upload_seedlots_error_display_second_try tbody").html(response.error_string);
467             }
468             if (response.missing_accessions || response.missing_crosses){
469                 Workflow.focus("#upload_seedlot_main_workflow", 4);
470             } else if(response.error_string){
471                 Workflow.focus("#upload_seedlot_main_workflow", 5);
472                 jQuery("#upload_seedlots_error_display_second_try").show();
473             }
474             if (response.success) {
475                 jQuery("#upload_seedlots_error_display").hide();
476                 jQuery("#upload_seedlots_error_display_second_try").hide();
477                 jQuery('#seedlot_upload_show_repeat_upload_button').hide();
478                 jQuery('[name="upload_seedlots_completed_message"]').html('<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/>');
479                 Workflow.skip('#upload_seedlots_missing_accessions_or_crosses_div', false);
480                 Workflow.skip('#upload_seedlots_error_display_second_try', false);
481                 Workflow.focus("#upload_seedlot_main_workflow", -1); //Go to success page
482                 Workflow.check_complete("#upload_seedlot_main_workflow");
483             }
485         }
486     });
488     jQuery(document).on('click', '[name="upload_seedlot_success_complete_button"]', function(){
489         alert('Seedlots were saved in the database');
490         jQuery('#upload_seedlot_dialog').modal('hide');
491         //location.reload();
492     });
494     jQuery('[name="close_seedlots_upload"]').click(function () {
495         jQuery('#upload_seedlots_type_select').val("");
496         jQuery('#upload_seedlot_location').val("");
497         jQuery('#upload_seedlot_organization_name').val("");
498         jQuery('#seedlot_uploaded_file').val("");
499         jQuery('#seedlot_harvested_uploaded_file').val("");
500         location.reload();
501     });
505 </script>