Merge pull request #5243 from solgenomics/topic/observations_upload_catch_error
[sgn.git] / mason / breeders_toolbox / upload_seedlots_inventory_dialogs.mas
blob9403f576b323a5f9699ce5b6e39d0e26c81d3416
1 <%args>
2 </%args>
4 <div class="modal fade" id="upload_seedlot_inventory_dialog" name="upload_seedlot_inventory_dialog" tabindex="-1" role="dialog" aria-labelledby="seedlot_upload_inventory_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_inventory_dialog">Upload Seedlot Inventory</h4>
10             </div>
11             <div class="modal-body">
12                 <div class="container-fluid">
14                     <&| /util/workflow.mas, id=> "upload_seedlot_inventory_workflow" &>
15                         <&| /util/workflow.mas:step, title=> "Intro" &>
16                             <& /page/page_title.mas, title=>"What is a seedlot inventory?" &>
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                             <li>A seedlot inventory consists of giving a location and current weight(g) to your seedlots. The seedlot name is the unique identifier for each seedlot and so should be encoded in a barcode on each seedlot packet.</li>
24                             <li>You can use the "Inventory" Android Application to scan seedlot barcodes and record weight. If you prefer you can create your own CSV file and upload that, if you do not want to use the Inventory Application. For info about the format of the file to upload, go to the next tab.</li>
25                             <!-- li><b>For more info about the "Seed Inventory" Android Application go to <a href="https://play.google.com/store/apps/details?id=org.wheatgenetics.inventory/">Inventory</a>.</b></li --><!-- Note: inventory app is being revamped, until then link to Google app store doesn't work, re-instate as soon as new version is up -->
26                             <li>It is also possible to manually enter a transaction by going to the seedlot detail page and clicking "Add New Transaction".</li>
27                             </ul>
29                             <br/><br/>
30                             <center>
31                                 <button class="btn btn-primary" onclick="Workflow.complete(this);">Go to Next Step</button>
32                             </center>
33                         </&>
35                         <&| /util/workflow.mas:step, title=> "File format" &>
36                             <& /page/page_title.mas, title=>"Make sure you are collecting seedlot inventory in the following format" &>
38                             <p>The "Seed Inventory" Android Application will export this same exact format by default.</p>
40                             <br/><br/>
41                             <center>
42                                 <button class="btn btn-info" id="seedlot_upload_inventory_spreadsheet_format_info">Info about file format</button><br/><br/>
43                                 <button class="btn btn-primary" onclick="Workflow.complete(this);">Once you think your file matches, go to Next Step</button>
44                             </center>
45                         </&>
46                         <&| /util/workflow.mas:step, title=> "Upload inventory" &>
47                             <& /page/page_title.mas, title=>"Select your file and upload seedlot inventory" &>
49                             <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_seedlot_inventory_form" name="upload_seedlot_inventory_form">
50                                 <div class="form-group">
51                                     <label class="col-sm-3 control-label">Upload File (.csv): </label>
52                                     <div class="col-sm-9" >
53                                         <input type="file" name="seedlot_uploaded_inventory_file" id="seedlot_uploaded_inventory_file" encoding="multipart/form-data" />
54                                     </div>
55                                 </div>
56                             </form>
58                             <br/><br/>
59                             <center>
60                                 <button name="upload_seedlot_inventory_button" onclick="Workflow.complete(this, false);" type="button" class="btn btn-primary" >Submit</button>
61                             </center>
62                         </&>
63                         <&| /util/workflow.mas:step, title=> "Fix missing seedlots problem" &>
64                             <& /page/page_title.mas, title=>"Fixing the missing seedlot(s) problem" &>
66                             <div id="upload_seedlot_inventory_missing_seedlots_div" style="display:none">
67                                 <div class="well">
68                                     <ul>
69                                         <li>Seedlots must exist in the database prior to updating or adding inventory. The reason for this is that the inventory does not give information about the content (a named accession or a cross name) and this information is required for a seedlot to exist in the database. We also want to be careful about adding new seedlots into the database because we do not want data to be incorrectly linked to duplicates.</li>
70                                     </ul>
71                                 </div>
72                                 <ul>
73                                 <li>When adding seedlots into the database, you can upload an Excel file or you can add seedlots one at a time.<br/><br/>
74                                     <ul>
75                                     <li><button class="btn btn-info" name="seedlot_bulk_upload">Upload Excel file</button><br/><br/></li>
76                                     <li><button class="btn btn-info" name="add_seedlot_button">Add One Seedlot</button></li>
77                                     </ul>
78                                 </li>
79                                 </ul><br/>
80                                 <button class="btn btn-primary" onclick="Workflow.complete(this);">Once all your seedlots are in the database Click Here</button><br/><br/>
81                             </div>
82                             <div id="upload_seedlot_inventory_error_display">
84                                 <h3>Seedlot Inventory Upload Error Messages</h3>
85                                 <div class="panel panel-danger">
86                                     <div class="panel-body">
87                                         <table>
88                                             <tbody></tbody>
89                                         </table>
90                                     </div>
91                                 </div>
92                             </div>
93                             <center>
94                             <div id="upload_seedlot_inventory_no_error_messages_html">
95                             </div>
96                             <div name="upload_seedlot_inventory_completed_message">
97                             </div>
98                             </center>
99                         </&>
100                         <&| /util/workflow.mas:step, title=> "Try submitting inventory again" &>
101                             <& /page/page_title.mas, title=>"Submit your inventory 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." &>
102                             <div id="seedlot_inventory_upload_show_repeat_upload_button">
103                                 <center>
104                                 <button type="button" class="btn btn-lg btn-primary" name="upload_seedlot_inventory_button" >Upload Seedlot Inventory</button><br/><br/>
105                                 </center>
106                             </div>
107                             <center>
108                             <div name="upload_seedlot_inventory_completed_message">
109                             </div>
110                             </center>
112                             <div id="upload_seedlot_inventory_error_display_second_try" style="display:none">
114                                 <h3>There exist these problems in your file:</h3>
115                                 <div class="panel panel-danger">
116                                     <div class="panel-body">
117                                         <table>
118                                             <tbody></tbody>
119                                         </table>
120                                     </div>
121                                 </div>
122                             </div>
123                         </&>
124                         <&| /util/workflow.mas:complete, title=> "Complete" &>
125                             <& /page/page_title.mas, title=>"Finished! Your seedlot inventory is in the database" &>
126                             <p>
127                                 <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
128                                 The seedlot inventory file was uploaded successfully
129                             </p>
131                             <ul>
132                                 <li>You may want to proceed to the seedlot detail page(s) for the seedlot(s) you just updated.</li>
133                                 <li>You can print barcodes for the seedlots.</li>
134                             </ul>
135                             <br/>
136                         </&>
137                     </&><!-- End of workflow -->
139                 </div>
140             </div>
141             <div class="modal-footer">
142                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
143             </div>
144         </div>
145     </div>
146 </div>
148 <div class="modal fade" id="seedlot_upload_inventory_spreadsheet_info_dialog" name="seedlot_upload_inventory_spreadsheet_info_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadSeedlotInventoryInfoDialog">
149     <div class="modal-dialog modal-lg" role="document">
150         <div class="modal-content">
151             <div class="modal-header" style="text-align: center">
152                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
153                 <h4 class="modal-title" id="uploadSeedlotInventoryInfoDialog">Upload Template Information</h4>
154             </div>
155             <div class="modal-body">
156                 <div class="container-fluid">
157                     <b>Seedlots may be uploaded in a CSV file (.csv)</b>
158                     <br />
159                     (Excel .xls and .xlsx format not supported)
160                     <br /><br />
161                     <b>Header:</b>
162                     <br>
163                     The first row (header) should contain the following:
164                     <br />
166                     <table class="table table-hover table-bordered table-condensed" >
167                         <thead></thead>
168                         <tbody>
169                             <tr>
170                                 <td>box_id</td>
171                                 <td>seed_id</td>
172                                 <td>inventory_date</td>
173                                 <td>inventory_person</td>
174                                 <td>weight_gram</td>
175                             </tr>
176                         </tbody>
177                     </table>
179                     <b>Required fields:</b>
180                     <ul>
181                     <li>box_id (the name of the box that the seedlot is in. also called box_name.)</li>
182                     <li>seed_id (unique identifier for the seedlot. must exist in the database. also called seedlot_name)</li>
183                     <li>inventory_date (a timestamp for when the seedlot was inventoried)</li>
184                     <li>inventory_person (the name of the person doing the inventory. can be any name. also called operator_name)</li>
185                     <li>weight_gram (the weight in grams of the seedlot)</li>
186                     </ul>
188                 </div>
189             </div>
190             <div class="modal-footer">
191                 <button id="close_seedlot_info_upload_inventory_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
192             </div>
193         </div>
194     </div>
195 </div>
198 <script>
199 jQuery(document).ready(function(){
201     jQuery('[name="seedlot_upload_inventory"]').click( function() {
202         jQuery('#upload_seedlot_inventory_dialog').modal('show');
203     });
205     jQuery("#seedlot_upload_inventory_spreadsheet_format_info").click( function () {
206         jQuery("#seedlot_upload_inventory_spreadsheet_info_dialog" ).modal("show");
207     });
209     jQuery('[name="upload_seedlot_inventory_button"]').click(function () {
210         upload_seedlot_inventory_button();
211     });
212     function upload_seedlot_inventory_button() {
213         jQuery('#upload_seedlot_inventory_form').attr("action", "/ajax/breeders/seedlot-inventory-upload");
214         jQuery("#upload_seedlot_inventory_form").submit();
215     }
217     jQuery('#upload_seedlot_inventory_form').iframePostForm({
218         json: true,
219         post: function () {
220             var uploadedSeedlotInventoryFile = jQuery("#seedlot_uploaded_inventory_file").val();
221             jQuery('#working_modal').modal("show");
222             if (uploadedSeedlotInventoryFile === '') {
223                 jQuery('#working_modal').modal("hide");
224                 alert("No file selected");
225             }
226         },
227         complete: function (response) {
228             console.log(response);
229             jQuery('#working_modal').modal("hide");
231             if (response.error){
232                 alert(response.error);
233             }
235             if (response.error_string) {
236                 if (response.missing_seedlots) {
237                     jQuery('#upload_seedlot_inventory_missing_seedlots_div').show();
238                 } else {
239                     jQuery('#upload_seedlot_inventory_missing_seedlots_div').hide();
240                     var no_missing_seedlot_html = '<button class="btn btn-primary" onclick="Workflow.skip(this);">There were no errors regarding missing seedlots Click Here</button><br/><br/>';
241                     jQuery('#upload_seedlot_inventory_no_error_messages_html').html(no_missing_seedlot_html);
242                     Workflow.skip('#upload_seedlot_inventory_missing_seedlots_div', false);
243                 }
244                 jQuery("#upload_seedlot_inventory_error_display tbody").html(response.error_string);
245                 jQuery("#upload_seedlot_inventory_error_display_second_try").show();
246                 jQuery("#upload_seedlot_inventory_error_display_second_try tbody").html(response.error_string);
247             }
249             if(response.missing_seedlots){
250                 Workflow.focus("#upload_seedlot_inventory_workflow", 3);
251             } else if(response.error_string){
252                 Workflow.focus("#upload_seedlot_inventory_workflow", 4);
253                 jQuery("#upload_seedlot_inventory_error_display_second_try").show();
254             }
256             if (response.success) {
257                 jQuery("#upload_seedlot_inventory_error_display_second_try").hide();
258                 jQuery('#seedlot_inventory_upload_show_repeat_upload_button').hide();
259                 jQuery('[name="upload_seedlot_inventory_completed_message"]').html('<h3>The trial was saved to the database with no errors!</h3><br/><br/>');
260                 Workflow.skip('#upload_seedlot_inventory_missing_seedlots_div', false);
261                 Workflow.skip('#upload_seedlot_inventory_error_display_second_try', false);
262                 Workflow.focus("#upload_seedlot_inventory_workflow", -1); //Go to success page
263                 Workflow.check_complete("#upload_seedlot_inventory_workflow");
264             }
265         }
266     });
268 </script>