4 <& /util/import_javascript.mas, classes => [ 'jquery', 'jqueryui' ] &>
6 <div class="modal fade" id="upload_maintenance_event_upload_modal" name="upload_maintenance_event_upload_modal" tabindex="-1" role="dialog">
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">×</span></button>
11 <h4 class="modal-title">Upload Seedlot Maintenance Events</h4>
13 <div class="modal-body">
14 <div class="container-fluid">
15 <p><strong>Select an Excel (.xls) file with the Seedlot Maintenance Events to upload</strong></p>
16 <p><strong>Requirements:</strong></p>
19 The Maintenance Events are associated with Seedlots, so the name of the Seedlot in the file must match an existing Seedlot in the database.
20 If a Seedlot is not yet in the database, go to the <a href='/breeders/seedlots/'>Manage Seedlots</a> page to create it first.
23 The name of the Maintenance Event must be a valid event type. Valid event types include:
24 <table class="table table-striped">
27 <th>Event Type Name</th>
28 <th>Event Type Values</th>
31 <tbody id="maintenece_event_terms"></tbody>
35 <&| /page/explanation.mas, title=>'Template Information' &>
37 <b>File format information</b>
39 <a id="maintenance_event_upload_spreadsheet_format_info">Spreadsheet Format</a>
43 <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_maintenance_events_form" name="upload_maintenance_events_form">
44 <div class="form-group">
45 <label class="col-sm-4 control-label">Upload File: </label>
46 <div class="col-sm-8" >
47 <input class="form-control" type="file" name="maintenance_events_upload_file" id="maintenance_events_upload_file" encoding="multipart/form-data" />
52 <div id="maintenance_events_upload_messages">
53 <ul id="maintenance_events_upload_messages_list" class='list-group'></ul>
57 <div class="modal-footer">
58 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
59 <button type="button" class="btn btn-primary" name="maintenance_events_submit" id="maintenance_events_submit">Upload</button>
65 <!-- Template Info Modal -->
66 <div class="modal fade" id="maintenance_event_upload_spreadsheet_format_modal" name="maintenance_event_upload_spreadsheet_format_modal" tabindex="-1" role="dialog" aria-labelledby="uploadMaintenanceInfoDialog">
67 <div class="modal-dialog modal-xl" role="document">
68 <div class="modal-content">
69 <div class="modal-header" style="text-align: center">
70 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
71 <h4 class="modal-title" id="uploadMaintenanceInfoDialog">Upload Seedlot Maintenance Event Template Information</h4>
73 <div class="modal-body">
74 <div class="container-fluid">
75 <strong>Seedlot Maintenance Events may be uploaded in an Excel file (.xls or .xlsx)</strong>
77 <strong>Header:</strong>
79 The first row (header) should contain the following:
82 <table class="table table-hover table-bordered table-condensed" >
98 <li>seedlot (name of the seedlot, must match an existing seedlot))</li>
99 <li>type (name of the maintenance event type, must match an existing term)</li>
100 <li>value (value of the event)</li>
101 <li>notes (optional, additional comments about the event)</li>
102 <li>operator (username of the person recording the event)</li>
103 <li>timestamp (date/time of when the event is recorded in 'YYYY-MM-DD HH:MM:SS' format)</li>
107 <div class="modal-footer">
108 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
120 <script type="text/javascript">
122 jQuery(document).ready(function() {
125 getValidEventTypes();
128 jQuery('#maintenance_event_upload_spreadsheet_format_info').click(function() {
129 jQuery('#maintenance_event_upload_spreadsheet_format_modal').modal('show');
131 jQuery('#maintenance_events_submit').click(uploadMaintenanceEvents);
137 * Get the maintenance event ontology and populate the table of valid names and values
139 function getValidEventTypes() {
144 url: '/ajax/breeders/seedlot/maintenance/ontology',
145 success: function(data) {
146 if ( data && data.ontology ) {
147 for ( let i = 0; i < data.ontology.length; i++ ) {
148 for ( let j = 0; j < data.ontology[i].children.length; j++ ) {
149 let name = data.ontology[i].children[j].name;
151 if ( data.ontology[i].children[j].children ) {
152 for ( let k = 0; k < data.ontology[i].children[j].children.length; k++ ) {
153 values.push(data.ontology[i].children[j].children[k].name);
156 if ( values.length === 0 ) values.push('<em>Any Value</em>');
157 html += "<tr><td>" + name + "</td><td>" + values.join(', ') + "</td></tr>";
162 complete: function() {
163 jQuery("#maintenece_event_terms").html(html);
169 * Upload the Excel file and process the results
171 function uploadMaintenanceEvents() {
172 let file = jQuery('#maintenance_events_upload_file').val();
173 if ( !file || file === '' ) {
174 alert("Please select your upload file");
178 // Setup working modal
179 jQuery('#working_msg').html("Uploading Seedlot Maintenance Events File");
180 jQuery('#working_modal_progress').css('width', 0).attr('aria-valuenow', 0);
181 jQuery('#working_modal_progress_div').css('display', 'block');
182 jQuery('#working_modal').modal("show");
183 jQuery('#maintenance_events_upload_messages_list').empty();
185 // Build the FormData to pass as POST arguments
186 let formData = new FormData();
187 formData.append('file', jQuery('#maintenance_events_upload_file').prop('files')[0]);
189 // Make the POST request
191 url: '/ajax/breeders/seedlot/maitenance/upload',
198 var myXhr = jQuery.ajaxSettings.xhr();
200 myXhr.upload.addEventListener('progress', function (e) {
201 if (e.lengthComputable) {
202 let prog = (e.loaded / e.total)*100;
203 jQuery('#working_modal_progress').css('width', prog + "%").attr('aria-valuenow', prog);
205 jQuery('#working_msg').html("Uploading Seedlot Maintenance Events File");
212 success: function(response) {
213 handleUploadResponse(response);
217 alert("ERROR: Could not upload file!");
219 complete: function() {
220 jQuery('#working_msg').html("");
221 jQuery('#working_modal_progress').css('width', 0).attr('aria-valuenow', 0);
222 jQuery('#working_modal_progress_div').css('display', 'none');
223 jQuery('#working_modal').modal("hide");
230 * Handle the Upload Response
231 * - display success message, if no errors
232 * - display error messages, if errors encountered
234 function handleUploadResponse(response) {
235 if ( response && response.success && response.success === 1 ) {
236 add_message("success", "Seedlot Maintenace Events successfully stored!");
237 if ( getEvents ) getEvents();
239 else if ( response && response.error ) {
240 let html = "<strong>The Seedlot Maintenance Events could not be stored due to the following error(s):</strong><br />" + response.error;
241 add_message("error", html);
244 add_message("error", "The Seedlot Maintenance Events were not stored due to an unknown error!");
250 * Add Message to Upload step
251 * @param {string} type Message Type (success, error)
252 * @param {string} message Message Text
254 function add_message(type, message) {
256 let class_name = "danger";
257 let icon_name = "remove";
259 if ( type === "success" ) {
260 class_name = "success";
263 else if ( type === "warning" ) {
264 class_name = "warning";
265 icon_name = "asterisk";
267 else if ( type === "info" ) {
269 icon_name = "info-sign";
272 html += "<li class='list-group-item list-group-item-" + class_name + "'>";
273 html += "<span class='badge'><span class='glyphicon glyphicon-" + icon_name + "'></span></span>";
277 jQuery('#maintenance_events_upload_messages_list').append(html);