trial treatments
[sgn.git] / js / CXGN / BreedersToolbox / UploadPhenotype.js
blobd4925050b1cee61260f6f5866c17269a565f44a3
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");
7     });
9     jQuery("#upload_spreadsheet_phenotype_file_form").iframePostForm({
10         json: true,
11         post: function () { },
12         timeout: 7200000,
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");
19             });
21             jQuery("#upload_spreadsheet_phenotype_file_form").iframePostForm({
22                 json: true,
23                 post: function () { },
24                 timeout: 7200000,
25                 complete: function (response) {
26                     hidePhenotypeUploadWorkingModal();
27                     displayPhenotypeUploadStoreResponse(response, "spreadsheet");
28                 },
29             });
30         }
31     });
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");
36     });
38     jQuery("#upload_datacollector_phenotype_file_form").iframePostForm({
39         json: true,
40         post: function () { },
41         timeout: 7200000,
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");
48             });
50             jQuery("#upload_datacollector_phenotype_file_form").iframePostForm({
51                 json: true,
52                 post: function () { },
53                 timeout: 7200000,
54                 complete: function (response) {
55                     hidePhenotypeUploadWorkingModal();
56                     displayPhenotypeUploadStoreResponse(response, "datacollector");
57                 },
58             });
59         }
60     });
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");
65     });
67     jQuery("#upload_fieldbook_phenotype_file_form").iframePostForm({
68         json: true,
69         post: function () { },
70         timeout: 7200000,
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");
77             });
79             jQuery("#upload_fieldbook_phenotype_file_form").iframePostForm({
80                 json: true,
81                 post: function () { },
82                 timeout: 7200000,
83                 complete: function (response) {
84                     hidePhenotypeUploadWorkingModal();
85                     displayPhenotypeUploadStoreResponse(response, "fieldbook");
86                 },
87             });
88         }
89     });
91 //      jQuery('#upload_phenotype_spreadsheet_dialog').on('hidden.bs.modal', function () {
92 //              location.reload();
93 //      })
94 //      jQuery('#upload_datacollector_phenotypes_dialog').on('hidden.bs.modal', function () {
95 //              location.reload();
96 //      })
97 //      jQuery('#upload_fieldbook_phenotypes_dialog').on('hidden.bs.modal', function () {
98 //              location.reload();
99 //      })
101         jQuery('#delete_pheno_file_link').click( function() { 
102                 alert('Deleted successfully.');
103         });  
107 function initializeUploadPhenotype(uploadFile, message, file_form, url) {
108     if (uploadFile === '') {
109         alert("Please select a file");
110     } else {
111         showPhenotypeUploadWorkingModal(message);
112         jQuery(file_form).attr("action", url);
113         jQuery(file_form).submit();
114     }
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";
132     }
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";
137     }
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";
142     }
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>";
153         }
154         jQuery(submit_store_button).attr('disabled', false);
155     }
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>";
163         }
164         if (errorarrayLength > 0) {
165            jQuery(submit_store_button).attr('disabled', true);
166         }
167     }
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>";
180             }
181         }
182     }
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";
191     }
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";
195     }
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";
199     }
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>";
211         }
212     }
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>";
220         }
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>";
223         }
224     } else {
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>";
226     }
227     message_text += "</ul>";
228     jQuery(upload_phenotype_status).html(message_text);
229     matviews_update_options();