add pdf download test
[sgn.git] / mason / breeders_toolbox / upload_seedlots_dialogs.mas
blob5dddb2099ce68474707747b1093f1de9342b0021
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-lg" 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                     <&| /page/explanation.mas, title=>'Template information' &>
15                         <p>
16                             <b>File format information</b>
17                             <br>
18                             <a id="seedlot_upload_spreadsheet_format_info">Spreadsheet format</a>
19                         </p>
20                     </&>
22                     <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_seedlot_form" name="upload_seedlot_form">
24                         <div class="form-group">
25                             <label class="col-sm-3 control-label">Breeding Program: </label>
26                             <div class="col-sm-9" >
27                                 <div id="upload_seedlot_breeding_program_div"></div>
28                             </div>
29                         </div>
30                         <div class="form-group">
31                             <label class="col-sm-3 control-label">Location: </label>
32                             <div class="col-sm-9" >
33                                 <input class="form-control" name="upload_seedlot_location" id="upload_seedlot_location" placeholder="Required">
34                             </div>
35                         </div>
36                         <div class="form-group">
37                             <label class="col-sm-3 control-label">Population Name: </label>
38                             <div class="col-sm-9" >
39                                 <input class="form-control" name="upload_seedlot_population_name" id="upload_seedlot_population_name" placeholder="Optional">
40                             </div>
41                         </div>
42                         <div class="form-group">
43                             <label class="col-sm-3 control-label">Organization Name: </label>
44                             <div class="col-sm-9" >
45                                 <input class="form-control" name="upload_seedlot_organization_name" id="upload_seedlot_organization_name" placeholder="Optional">
46                             </div>
47                         </div>
48                         <div class="form-group">
49                             <label class="col-sm-3 control-label">Upload File (.xls): </label>
50                             <div class="col-sm-9" >
51                                 <input type="file" name="seedlot_uploaded_file" id="seedlot_uploaded_file" encoding="multipart/form-data" />
52                             </div>
53                         </div>
55                     </form>
56                 </div>
57             </div>
58             <div class="modal-footer">
59                 <button id="upload_seedlot_button" type="button" class="btn btn-default" >Submit</button>
60             </div>
61         </div>
62     </div>
63 </div>
65 <div class="modal fade" id="seedlot_upload_spreadsheet_info_dialog" name="seedlot_upload_spreadsheet_info_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadSeedlotInfoDialog">
66     <div class="modal-dialog modal-lg" role="document">
67         <div class="modal-content">
68             <div class="modal-header" style="text-align: center">
69                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
70                 <h4 class="modal-title" id="uploadSeedlotInfoDialog">Upload Template Information</h4>
71             </div>
72             <div class="modal-body">
73                 <div class="container-fluid">
74                     <b>Seedlots may be uploaded in an Excel file (.xls)</b>
75                     <br />
76                     (.xlsx format not supported)
77                     <br /><br />
78                     <b>Header:</b>
79                     <br>
80                     The first row (header) should contain the following:
81                     <br />
83                     <table class="table table-hover table-bordered table-condensed" >
84                         <thead></thead>
85                         <tbody>
86                             <tr>
87                                 <td>seedlot_name</td>
88                                 <td>accession_name</td>
89                                 <td>amount</td>
90                                 <td>description</td>
91                             </tr>
92                         </tbody>
93                     </table>
95                     <b>Required fields:</b>
96                     <br/>
97                     seedlot_name (must be unique)
98                     <br />
99                     accession_name (must exist in the database)
100                     <br />
101                     <b>Optional fields:</b>
102                     <br />
103                     amount (number of seeds in seedlot. if not given will default to 0)
104                     <br />
105                     description
106                 </div>
107             </div>
108             <div class="modal-footer">
109                 <button id="close_seedlot_info_upload_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
110             </div>
111         </div>
112     </div>
113 </div>
115 <script>
116 jQuery(document).ready(function(){
118     jQuery("#upload_seedlot_location").autocomplete({
119        source: '/ajax/stock/geolocation_autocomplete',
120     });
122     jQuery('#seedlot_bulk_upload').click( function() {
123         jQuery('#upload_seedlot_dialog').modal('show');
124         get_select_box('breeding_programs', 'upload_seedlot_breeding_program_div', { 'name' : 'upload_seedlot_breeding_program_id', 'id' : 'upload_seedlot_breeding_program_id' });
125     });
127     jQuery("#seedlot_upload_spreadsheet_format_info").click( function () {
128         jQuery("#seedlot_upload_spreadsheet_info_dialog" ).modal("show");
129     });
131     jQuery('#upload_seedlot_button').click(function () {
132         upload_seedlot_button();
133     });
134     function upload_seedlot_button() {
135         var uploadFile = jQuery("#seedlot_uploaded_file").val();
136         var location = jQuery("#upload_seedlot_location").val();
137         var breeding_program = jQuery("#upload_seedlot_breeding_program_id").val();
138         jQuery('#upload_seedlot_form').attr("action", "/ajax/breeders/seedlot-upload");
139         if (breeding_program === '') {
140             alert("Please choose a breeding program");
141             return;
142         }
143         if (location === '') {
144             alert("Please give a location");
145             return;
146         }
147         if (uploadFile === '') {
148             alert("Please select a file");
149             return;
150         }
151         jQuery("#upload_seedlot_form").submit();
152     }
154     jQuery('#upload_seedlot_form').iframePostForm({
155         json: true,
156         post: function () {
157             var uploadedSeedlotFile = jQuery("#seedlot_uploaded_file").val();
158             jQuery('#working_modal').modal("show");
159             if (uploadedSeedlotFile === '') {
160                 jQuery('#working_modal').modal("hide");
161                 alert("No file selected");
162             }
163         },
164         complete: function (response) {
165             console.log(response);
166             jQuery('#working_modal').modal("hide");
168             if (response.error_string) {
169                 alert(response.error_string);
170                 return;
171             }
172             if (response.success) {
173                 alert("File uploaded successfully");
174                 jQuery('#upload_seedlot_dialog').modal('hide');
175                 seedlots_table.ajax.reload();
176             }
177         }
178     });
180 </script>