Merge pull request #2754 from solgenomics/topic/fix_homepage_add_accessions_dialog
[sgn.git] / mason / breeders_toolbox / upload_locations_dialogs.mas
blob948de0593cabb3606cefef9063d913f1403bc512
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>Locations may be uploaded in an Excel file (.xls)</b><br>
16                 (.xlsx format not supported)
17                 <br><br>
18                 <b>Header:</b><br>
19                 The first row (header) must contain the following:
20                 <br>
21                 <table class="table table-bordered table-hover">
22                   <tbody>
23                   <tr>
24                     <td>Name</td>
25                     <td>Abbreviation</td>
26                     <td>Country Code</td>
27                     <td>Country Name</td>
28                     <td>Program</td>
29                     <td>Type</td>
30                     <td>Latitude</td>
31                     <td>Longitude</td>
32                     <td>Altitude</td>
33                   </tr>
34                   </tbody>
35                 </table>
36                 <b>Required columns:</b><br><br>
37                 <b>Name:</b> must not conflict with an existing location name<br>
38                 <b>Abbreviation</b><br>
39                 <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>
40                 <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>
41                 <b>Program:</b> must be an exisiting Breeding Program in the database, or multiple breeding programs separated by '&'<br>
42                 <b>Type:</b> must be one of the following: Farm, Field, Greenhouse, Screenhouse, Lab, Storage, Other<br>
43                 <b>Latitude:</b> (in degrees) must be a number between 90 and -90.<br>
44                 <b>Longitude:</b> (in degrees) must be a number between 180 and -180.<br>
45                 <b>Altitude:</b> (in meters) must be a number between -418 (Dead Sea) and 8,848 (Mt. Everest).<br>
46                 <br>
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: true,
98         post: function () {
99             jQuery('#working_modal').modal("show");
100         },
101         complete: function (response) {
102             jQuery('#working_modal').modal("hide");
103             //console.log(response);
104             if (response.error) {
105                 var errors = [];
106                 for (i = 0; i < response.error.length; i++) {
107                     errors.push( '<p>'+response.error[i]+'</p>');
108                 }
109                 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>';
110                 html += errors.join('') + '<br>';
111                 document.getElementById('locations_result_body').innerHTML = html;
112                 jQuery('#locations_result_dialog').modal("show");
113             }
114             else {
115                 jQuery('#upload_locations_dialog').modal("hide");
116                 var saved_locations = [];
117                 for (var key in response) {
118                     saved_locations.push( '<p>'+key+': '+response[key]+'</p>');
119                 }
120                 var html = '<br><center>'+saved_locations.join('')+'</center>';
121                 document.getElementById('locations_result_body').innerHTML = html;
122                 jQuery('#locations_result_dialog').modal("show");
123                 jQuery('#locations_result_close_button').click( function() {
124                     location.reload();
125                 });
126             }
127         },
128         error: function(response) {
129             jQuery('#working_modal').modal("hide");
130             alert("An error occurred");
131         }
132     });
136 </script>