Merge pull request #2754 from solgenomics/topic/fix_homepage_add_accessions_dialog
[sgn.git] / mason / breeders_toolbox / upload_seedlots_dialogs.mas
blobf05626e5510b27ff3b4dcd415c13c32d372c074b
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" 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(g), 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 (.xls): </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 (.xls): </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" 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>Seedlots may be uploaded in an Excel file (.xls)</b>
239                     <br />
240                     (.xlsx format not supported)
241                     <br /><br />
242                     <b>Header:</b>
243                     <br>
244                     The first row (header) must contain the following:
245                     <br />
247                     <table class="table table-hover table-bordered table-condensed" >
248                         <thead></thead>
249                         <tbody>
250                             <tr>
251                                 <td>seedlot_name</td>
252                                 <td>accession_name</td>
253                                 <td>operator_name</td>
254                                 <td>amount</td>
255                                 <td>weight(g)</td>
256                                 <td>description</td>
257                                 <td>box_name</td>
258                             </tr>
259                         </tbody>
260                     </table>
262                     <b>Required fields:</b>
263                     <ul>
264                     <li>seedlot_name (must be unique)</li>
265                     <li>accession_name (must exist in the database. the accession_name is the unique identifier for the named genotype)</li>
266                     <li>operator_name (the name of the person who oversaw the inventory process. can be any name.)</li>
267                     <li>
268                     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.)
269                     <br/><b>AND/OR</b><br/>
270                     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.)
271                     </li>
272                     <li>box_name (the box name that the seed is located in. can be any name.)</li>
273                     </ul>
275                     <b>Optional fields:</b>
276                     <ul>
277                     <li>description (information about why this seedlot is being added)</li>
278                     </ul>
280                 </div>
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>Seedlots may be uploaded in an Excel file (.xls)</b>
299                     <br />
300                     (.xlsx format not supported)
301                     <br /><br />
302                     <b>Header:</b>
303                     <br>
304                     The first row (header) must contain the following:
305                     <br />
307                     <table class="table table-hover table-bordered table-condensed" >
308                         <thead></thead>
309                         <tbody>
310                             <tr>
311                                 <td>seedlot_name</td>
312                                 <td>cross_unique_id</td>
313                                 <td>operator_name</td>
314                                 <td>amount</td>
315                                 <td>weight(g)</td>
316                                 <td>description</td>
317                                 <td>box_name</td>
318                             </tr>
319                         </tbody>
320                     </table>
322                     <b>Required fields:</b>
323                     <ul>
324                     <li>seedlot_name (must be unique)</li>
325                     <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>
326                     <li>operator_name (the name of the person who oversaw the inventory process. can be any name.)</li>
327                     <li>
328                     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.)
329                     <br/><b>AND/OR</b><br/>
330                     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.)
331                     </li>
332                     <li>box_name (the box name that the seed is located in. can be any name.)</li>
333                     </ul>
335                     <b>Optional fields:</b>
336                     <ul>
337                     <li>description (information about why this seedlot is being added)</li>
338                     </ul>
340                 </div>
341             </div>
342             <div class="modal-footer">
343                 <button id="close_seedlot_harvested_info_upload_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
344             </div>
345         </div>
346     </div>
347 </div>
351 <script>
352 jQuery(document).ready(function(){
354     jQuery("#upload_seedlot_location").autocomplete({
355        source: '/ajax/stock/geolocation_autocomplete',
356     });
358     jQuery('#upload_seedlots_type_select').change(function(){
359         if (jQuery(this).val() != ''){
360             jQuery('#seedlot_upload_type_select_button').attr('disabled', false);
361             jQuery('#upload_seedlots_types_description').html('<br/><div class="well"><p>'+jQuery(this).find("option:selected").data("desc")+'</p></div>');
362         } else {
363             jQuery('#seedlot_upload_type_select_button').attr('disabled', true);
364             jQuery('#upload_seedlots_types_description').html('');
365         }
367         if(jQuery(this).val() == 'from_accession'){
368             jQuery('#upload_seedlots_accessions_template_section').show();
369             jQuery('#upload_seedlots_crosses_template_section').hide();
370             jQuery('#upload_seedlots_accessions_section').show();
371             jQuery('#upload_seedlots_harvested_section').hide();
372         }
373         if(jQuery(this).val() == 'from_cross'){
374             jQuery('#upload_seedlots_crosses_template_section').show();
375             jQuery('#upload_seedlots_accessions_template_section').hide();
376             jQuery('#upload_seedlots_accessions_section').hide();
377             jQuery('#upload_seedlots_harvested_section').show();
378         }
379     });
381     jQuery('[name="seedlot_bulk_upload"]').click( function() {
382         jQuery('#upload_seedlot_dialog').modal('show');
383         get_select_box('breeding_programs', 'upload_seedlot_breeding_program_div', { 'name' : 'upload_seedlot_breeding_program_id', 'id' : 'upload_seedlot_breeding_program_id' });
384     });
386     jQuery("[name='guided_help_seedlot_upload_format_button']").click( function () {
387         jQuery("#seedlot_upload_spreadsheet_info_dialog" ).modal("show");
388     });
390     jQuery("[name='guided_help_seedlot_crosses_upload_format_button']").click( function () {
391         jQuery("#seedlot_upload_spreadsheet_harvested_info_dialog" ).modal("show");
392     });
394     jQuery('[name="upload_seedlot_button"]').click(function () {
395         upload_seedlot_button();
396     });
397     function upload_seedlot_button() {
398         var uploadSeedlotAccessionsFile = jQuery("#seedlot_uploaded_file").val();
399         var uploadSeedlotsHarvestedFile = jQuery("#seedlot_harvested_uploaded_file").val();
400         var location = jQuery("#upload_seedlot_location").val();
401         var breeding_program = jQuery("#upload_seedlot_breeding_program_id").val();
402         jQuery('#upload_seedlot_form').attr("action", "/ajax/breeders/seedlot-upload");
403         if (breeding_program === '') {
404             alert("Please choose a breeding program");
405             return;
406         }
407         if (location === '') {
408             alert("Please give a location");
409             return;
410         }
411         if (uploadSeedlotAccessionsFile === '' && uploadSeedlotsHarvestedFile == '') {
412             alert("Please select a file");
413             return;
414         }
415         jQuery("#upload_seedlot_form").submit();
416     }
418     jQuery('#upload_seedlot_form').iframePostForm({
419         json: true,
420         post: function () {
421         var uploadSeedlotAccessionsFile = jQuery("#seedlot_uploaded_file").val();
422         var uploadSeedlotsHarvestedFile = jQuery("#seedlot_harvested_uploaded_file").val();
423             jQuery('#working_modal').modal("show");
424             if (uploadSeedlotAccessionsFile === '' && uploadSeedlotsHarvestedFile == '') {
425                 jQuery('#working_modal').modal("hide");
426                 alert("No file selected");
427             }
428         },
429         complete: function (response) {
430             console.log(response);
431             jQuery('#working_modal').modal("hide");
433             if (response.error) {
434                 alert(response.error);
435                 return;
436             }
437             else if (response.error_string) {
439                 if (response.missing_accessions || response.missing_crosses) {
440                     jQuery('#upload_seedlots_missing_accessions_or_crosses_div').show();
441                     if (response.missing_accessions){
442                         jQuery('#upload_seedlots_missing_accessions_div').show();
443                         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/>";
444                         jQuery("#upload_seedlots_add_missing_accessions_html").html(missing_accessions_html);
446                         var missing_accessions_vals = '';
447                         for(var i=0; i<response.missing_accessions.length; i++) {
448                             missing_accessions_vals = missing_accessions_vals + response.missing_accessions[i] + '\n';
449                         }
450                         jQuery("#upload_seedlots_missing_accessions").html(missing_accessions_vals);
451                         addToListMenu('upload_seedlots_add_missing_accessions', 'upload_seedlots_missing_accessions', {
452                             selectText: true,
453                             listType: 'accessions'
454                         });
455                     } else if (response.missing_crosses){
456                         jQuery('#upload_seedlots_missing_crosses_div').show();
457                     }
458                 } else {
459                     jQuery('#upload_seedlots_missing_accessions_or_crosses_div').hide();
460                     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/>';
461                     jQuery('#upload_seedlots_no_error_messages_accessions_html').html(no_missing_accessions_html);
462                     Workflow.skip('#upload_seedlots_missing_accessions_or_crosses_div', false);
463                 }
465                 jQuery("#upload_seedlots_error_display").show();
466                 jQuery("#upload_seedlots_error_display tbody").html(response.error_string);
467                 jQuery("#upload_seedlots_error_display_second_try").show();
468                 jQuery("#upload_seedlots_error_display_second_try tbody").html(response.error_string);
469             }
470             if (response.missing_accessions || response.missing_crosses){
471                 Workflow.focus("#upload_seedlot_main_workflow", 4);
472             } else if(response.error_string){
473                 Workflow.focus("#upload_seedlot_main_workflow", 5);
474                 jQuery("#upload_seedlots_error_display_second_try").show();
475             }
476             if (response.success) {
477                 jQuery("#upload_seedlots_error_display").hide();
478                 jQuery("#upload_seedlots_error_display_second_try").hide();
479                 jQuery('#seedlot_upload_show_repeat_upload_button').hide();
480                 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/>');
481                 Workflow.skip('#upload_seedlots_missing_accessions_or_crosses_div', false);
482                 Workflow.skip('#upload_seedlots_error_display_second_try', false);
483                 Workflow.focus("#upload_seedlot_main_workflow", -1); //Go to success page
484                 Workflow.check_complete("#upload_seedlot_main_workflow");
485             }
487         }
488     });
490     jQuery(document).on('click', '[name="upload_seedlot_success_complete_button"]', function(){
491         alert('Seedlots were saved in the database');
492         jQuery('#upload_seedlot_dialog').modal('hide');
493         //location.reload();
494     });
496 </script>