2 jQuery( document ).ready( function() {
4 //For Spreadsheet Upload
5 jQuery('#upload_spreadsheet_phenotype_submit_verify').click( function() {
6 initializeUploadPhenotype(jQuery("#upload_spreadsheet_phenotype_file_input").val(), "Verifying Spreadsheet File and Data", "#upload_spreadsheet_phenotype_file_form", "/ajax/phenotype/upload_verify/spreadsheet");
9 jQuery("#upload_spreadsheet_phenotype_file_form").iframePostForm({
11 post: function () { },
13 complete: function (response) {
14 hidePhenotypeUploadWorkingModal();
15 displayPhenotypeUploadVerifyResponse(response, "spreadsheet");
17 jQuery("#upload_spreadsheet_phenotype_submit_store").click( function() {
18 initializeUploadPhenotype(jQuery("#upload_spreadsheet_phenotype_file_input").val(), "Storing Spreadsheet File and Data", "#upload_spreadsheet_phenotype_file_form", "/ajax/phenotype/upload_store/spreadsheet");
21 jQuery("#upload_spreadsheet_phenotype_file_form").iframePostForm({
23 post: function () { },
25 complete: function (response) {
26 hidePhenotypeUploadWorkingModal();
27 displayPhenotypeUploadStoreResponse(response, "spreadsheet");
33 //For Datacollector Upload
34 jQuery('#upload_datacollector_phenotype_submit_verify').click( function() {
35 initializeUploadPhenotype(jQuery("#upload_datacollector_phenotype_file_input").val(), "Verifying Datacollector File and Phenotype Data", "#upload_datacollector_phenotype_file_form", "/ajax/phenotype/upload_verify/datacollector");
38 jQuery("#upload_datacollector_phenotype_file_form").iframePostForm({
40 post: function () { },
42 complete: function (response) {
43 hidePhenotypeUploadWorkingModal();
44 displayPhenotypeUploadVerifyResponse(response, "datacollector");
46 jQuery("#upload_datacollector_phenotype_submit_store").click( function() {
47 initializeUploadPhenotype(jQuery("#upload_datacollector_phenotype_file_input").val(), "Storing Datacollector File and Phenotype Data", "#upload_datacollector_phenotype_file_form", "/ajax/phenotype/upload_store/datacollector");
50 jQuery("#upload_datacollector_phenotype_file_form").iframePostForm({
52 post: function () { },
54 complete: function (response) {
55 hidePhenotypeUploadWorkingModal();
56 displayPhenotypeUploadStoreResponse(response, "datacollector");
62 //For Fieldbook Upload
63 jQuery('#upload_fieldbook_phenotype_submit_verify').click( function() {
64 initializeUploadPhenotype(jQuery("#upload_fieldbook_phenotype_file_input").val(), "Verifying Fieldbook File and Phenotype Data", "#upload_fieldbook_phenotype_file_form", "/ajax/phenotype/upload_verify/fieldbook");
67 jQuery("#upload_fieldbook_phenotype_file_form").iframePostForm({
69 post: function () { },
71 complete: function (response) {
72 hidePhenotypeUploadWorkingModal();
73 displayPhenotypeUploadVerifyResponse(response, "fieldbook");
75 jQuery("#upload_fieldbook_phenotype_submit_store").click( function() {
76 initializeUploadPhenotype(jQuery("#upload_fieldbook_phenotype_file_input").val(), "Storing Fieldbook File and Phenotype Data", "#upload_fieldbook_phenotype_file_form", "/ajax/phenotype/upload_store/fieldbook");
79 jQuery("#upload_fieldbook_phenotype_file_form").iframePostForm({
81 post: function () { },
83 complete: function (response) {
84 hidePhenotypeUploadWorkingModal();
85 displayPhenotypeUploadStoreResponse(response, "fieldbook");
91 // jQuery('#upload_phenotype_spreadsheet_dialog').on('hidden.bs.modal', function () {
94 // jQuery('#upload_datacollector_phenotypes_dialog').on('hidden.bs.modal', function () {
97 // jQuery('#upload_fieldbook_phenotypes_dialog').on('hidden.bs.modal', function () {
101 jQuery('#delete_pheno_file_link').click( function() {
102 alert('Deleted successfully.');
107 function initializeUploadPhenotype(uploadFile, message, file_form, url) {
108 if (uploadFile === '') {
109 alert("Please select a file");
111 showPhenotypeUploadWorkingModal(message);
112 jQuery(file_form).attr("action", url);
113 jQuery(file_form).submit();
117 function showPhenotypeUploadWorkingModal(message) {
118 jQuery('#working_msg').html(message);
119 jQuery('#working_modal').modal("show");
122 function hidePhenotypeUploadWorkingModal() {
123 jQuery('#working_modal').modal("hide");
127 function displayPhenotypeUploadVerifyResponse(response, upload_type) {
128 if (upload_type == "spreadsheet") {
129 var submit_verify_button = "#upload_spreadsheet_phenotype_submit_verify";
130 var submit_store_button = "#upload_spreadsheet_phenotype_submit_store";
131 var upload_phenotype_status = "#upload_phenotype_spreadsheet_verify_status";
133 else if (upload_type == "datacollector") {
134 var submit_verify_button = "#upload_datacollector_phenotype_submit_verify";
135 var submit_store_button = "#upload_datacollector_phenotype_submit_store";
136 var upload_phenotype_status = "#upload_phenotype_datacollector_verify_status";
138 else if (upload_type == "fieldbook") {
139 var submit_verify_button = "#upload_fieldbook_phenotype_submit_verify";
140 var submit_store_button = "#upload_fieldbook_phenotype_submit_store";
141 var upload_phenotype_status = "#upload_phenotype_fieldbook_verify_status";
144 jQuery(submit_verify_button).attr('disabled', true);
145 var message_text = "<hr><ul class='list-group'>";
146 if (response.success) {
147 var arrayLength = response.success.length;
148 for (var i = 0; i < arrayLength; i++) {
149 message_text += "<li class='list-group-item list-group-item-success'>";
150 message_text += "<span class='badge'><span class='glyphicon glyphicon-ok'></span></span>";
151 message_text += response.success[i];
152 message_text += "</li>";
154 jQuery(submit_store_button).attr('disabled', false);
156 if (response.error) {
157 var errorarrayLength = response.error.length;
158 for (var i = 0; i < errorarrayLength; i++) {
159 message_text += "<li class='list-group-item list-group-item-danger'>";
160 message_text += "<span class='badge'><span class='glyphicon glyphicon-remove'></span></span>";
161 message_text += response.error[i];
162 message_text += "</li>";
164 if (errorarrayLength > 0) {
165 jQuery(submit_store_button).attr('disabled', true);
168 if (response.warning) {
169 var warningarrayLength = response.warning.length;
170 if (warningarrayLength > 0) {
171 message_text += "<li class='list-group-item list-group-item-warning'>";
172 message_text += "<span class='badge'><span class='glyphicon glyphicon-asterisk'></span></span>";
173 message_text += "Warnings are shown in yellow. Either fix the file and try again or continue with storing the data.<hr>Warnings notifying you that values already exist in the database can be disregarded if your data is indeed new.<hr>To overwrite previously stored values: <input type='checkbox' id='phenotype_upload_overwrite_values' name='phenotype_upload_overwrite_values' /><br><br>";
174 message_text += "</li>";
175 for (var i = 0; i < warningarrayLength; i++) {
176 message_text += "<li class='list-group-item list-group-item-warning'>";
177 message_text += "<span class='badge'><span class='glyphicon glyphicon-asterisk'></span></span>";
178 message_text += response.warning[i];
179 message_text += "</li>";
183 message_text += "</ul>";
184 jQuery(upload_phenotype_status).html(message_text);
187 function displayPhenotypeUploadStoreResponse(response, upload_type) {
188 if (upload_type == "spreadsheet") {
189 var submit_store_button = "#upload_spreadsheet_phenotype_submit_store";
190 var upload_phenotype_status = "#upload_phenotype_spreadsheet_verify_status";
192 else if (upload_type == "datacollector") {
193 var submit_store_button = "#upload_datacollector_phenotype_submit_store";
194 var upload_phenotype_status = "#upload_phenotype_datacollector_verify_status";
196 else if (upload_type == "fieldbook") {
197 var submit_store_button = "#upload_fieldbook_phenotype_submit_store";
198 var upload_phenotype_status = "#upload_phenotype_fieldbook_verify_status";
201 jQuery(upload_phenotype_status).empty();
202 jQuery(submit_store_button).attr('disabled', true);
203 var message_text = "<hr><ul class='list-group'>";
204 if (response.success) {
205 var arrayLength = response.success.length;
206 for (var i = 0; i < arrayLength; i++) {
207 message_text += "<li class='list-group-item list-group-item-success'>";
208 message_text += "<span class='badge'><span class='glyphicon glyphicon-ok'></span></span>";
209 message_text += response.success[i];
210 message_text += "</li>";
213 if (response.error) {
214 var errorarrayLength = response.error.length;
215 for (var i = 0; i < errorarrayLength; i++) {
216 message_text += "<li class='list-group-item list-group-item-danger'>";
217 message_text += "<span class='badge'><span class='glyphicon glyphicon-remove'></span></span>";
218 message_text += response.error[i];
219 message_text += "</li>";
221 if (errorarrayLength == 0) {
222 message_text += "<li class='list-group-item list-group-item-success'><hr><h3>Upload Successfull!</h3><p id='update_wizard_error'> To make this data available right away in searches: </p><div id='update_wizard'></div></li>";
225 message_text += "<li class='list-group-item list-group-item-success'><hr><h3>Upload Successfull!</h3><p id='update_wizard_error'> To make this data available right away in searches: </p><div id='update_wizard'></div></li>";
227 message_text += "</ul>";
228 jQuery(upload_phenotype_status).html(message_text);
229 matviews_update_options();