fix test with new description field.
[sgn.git] / mason / breeders_toolbox / upload_locations_dialogs.mas
blob3952d353ab4497f2a9afb07cb88fd22980b6184c
1 <%args>
2 </%args>
4 <& /util/import_javascript.mas, classes => ['jquery.dataTables-buttons-min', 'jquery.iframe-post-form', 'jszip-min','buttons.bootstrap-min', 'buttons.html5-min', 'buttons.print-min'] &>
6 <div class="modal fade" id="upload_locations_dialog" name="upload_locations_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadLocationsDialog">
7   <div class="modal-dialog modal-lg" role="document">
8     <div class="modal-content">
9       <div class="modal-header">
10         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
11         <h4 class="modal-title" id="uploadLocationsDialog">Upload Locations</h4>
12       </div>
13       <div class="modal-body">
14         <div class="container-fluid">
15                 <b>Header:</b><br>
16                 The first row (header) must contain the following:
17                 <br>
18                 <table class="table table-bordered table-hover">
19                   <tbody>
20                   <tr>
21                     <td>Name</td>
22                     <td>Abbreviation</td>
23                     <td>Country Code</td>
24                     <td>Country Name</td>
25                     <td>Program</td>
26                     <td>Type</td>
27                     <td>Latitude</td>
28                     <td>Longitude</td>
29                     <td>Elevation</td>
30                     <td>NOAA Station ID</td>
31                   </tr>
32                   </tbody>
33                 </table>
34                 <b>Required values:</b><br>
35                 <b>Name:</b> must not conflict with an existing location name<br>
36                 <b>Abbreviation:</b> used in the map and in uploads, must not conflict with an existing abbreviation<br>
37                 <b>Country Code:</b> must be an <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3">ISO Alpha-3 country code</a><br>
38                 <b>Country Name:</b> must be an uppercase english short name from the <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3">ISO standard</a><br>
39                 <b>Program:</b> must be an exisiting Breeding Program in the database, or multiple breeding programs separated by '&'<br>
40                 <b>Type:</b> must be one of the following: Town, Farm, Field, Greenhouse, Screenhouse, Lab, Storage, Other<br>
41                 <b>Latitude:</b> (in degrees) must be a number between 90 and -90.<br>
42                 <b>Longitude:</b> (in degrees) must be a number between 180 and -180.<br>
43                 <b>Elevation:</b> (in meters) must be a number between -418 (Dead Sea) and 8,848 (Mt. Everest).<br>
44                 <br><b>Optional values:</b><br>
45                 <b>NOAA Station ID:</b> The NOAA Station ID that is nearest and most relevant to the location. <a href="https://www.ncdc.noaa.gov/cdo-web/search" target="_blank">Search Here</a><br>
47           <& /help/file_upload_type.mas, type => "Locations" , optional_column => 1 &>
48           <form method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_locations_form" name="upload_locations_form">
49     <label for="locations_upload_file" style="display: inline-block;">Location File:</label>
50     <input type="file" name="locations_upload_file" id="locations_upload_file" encoding="multipart/form-data" />
51   </form>
52         </div>
53       </div>
54       <div class="modal-footer">
55         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
56         <button type="button" class="btn btn-primary" name="upload_locations_dialog_submit" id="upload_locations_dialog_submit">Upload</button>
57       </div>
58     </div>
59   </div>
60 </div>
62 <div class="modal fade" id="locations_result_dialog" tabindex="-1" role="dialog" aria-labelledby="locationsResultDialog">
63     <div class="modal-dialog modal-lg" role="document">
64         <div class="modal-content ui-front">
65             <div class="modal-header text-center">
66                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
67                 <h4 class="modal-title" id="locationsResultDialog">Results</h4>
68             </div>
69             <div id="locations_result_body" class="container-fluid">
70             </div>
71             <div class="modal-footer">
72                 <button id="locations_result_close_button" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
73             </div>
74         </div>
75     </div>
76 </div>
78 <script defer="defer">
80 jQuery(document).ready(function() {
82     jQuery('#upload_locations_link').click( function() {
83         jQuery('#upload_locations_dialog').modal("show");
84     });
86     jQuery('#upload_locations_dialog_submit').click( function() {
87         var uploadFile = jQuery("#locations_upload_file").val();
88         jQuery('#upload_locations_form').attr("action", "/ajax/locations/upload");
89         if (uploadFile === '') {
90             alert("Please select a file");
91             return;
92         }
93         jQuery("#upload_locations_form").submit();
94     });
96     jQuery('#upload_locations_form').iframePostForm({
97         json: false,
98         post: function () {
99             jQuery('#working_modal').modal("show");
100         },
101         complete: function (r) {
102             r = r.replace('<pre>', '');
103             r = r.replace('</pre>', '');
104             var response = JSON.parse(r);
106             jQuery('#working_modal').modal("hide");
107             //console.log(response);
108             if (response.error) {
109                 var errors = [];
110                 for (i = 0; i < response.error.length; i++) {
111                     errors.push( '<p>'+response.error[i]+'</p>');
112                 }
113                 var html = '<br><center><b>Upload failed.</b><br><b>Please fix the following errors in </b>'+response.filename+'<b> and try again:</b></center><br>';
114                 html += errors.join('') + '<br>';
115                 document.getElementById('locations_result_body').innerHTML = html;
116                 jQuery('#locations_result_dialog').modal("show");
117             }
118             else {
119                 jQuery('#upload_locations_dialog').modal("hide");
120                 var saved_locations = [];
121                 for (var key in response) {
122                     saved_locations.push( '<p>'+key+': '+response[key]+'</p>');
123                 }
124                 var html = '<br><center>'+saved_locations.join('')+'</center>';
125                 document.getElementById('locations_result_body').innerHTML = html;
126                 jQuery('#locations_result_dialog').modal("show");
127                 jQuery('#locations_result_close_button').click( function() {
128                     location.reload();
129                 });
130             }
131         },
132         error: function(response) {
133             jQuery('#working_modal').modal("hide");
134             alert("An error occurred");
135         }
136     });
140 </script>