Merge pull request #5205 from solgenomics/topic/generic_trial_upload
[sgn.git] / js / source / entries / sequenced_accessions.js
blob0493f39e3d998d3a7462eb5652e2de700c7f5aea
2 import '../legacy/jquery.js';
3 import '../legacy/jquery/dataTables.js';
4 import '../legacy/CXGN/Login.js';
6 export function init(main_div, stock_id, stockprop_id) {
8     if (!(main_div instanceof HTMLElement)) {
9         main_div = document.getElementById(
10             main_div.startsWith("#") ? main_div.slice(1) : main_div
11         );
12     }
14     jQuery(document).ready(function () {
15         var stock_param = "";
16         if (stock_id !== undefined && stock_id !== null) {
17             stock_param = "/" + stock_id;
18             jQuery('#sequenced_stocks_table').DataTable({
19                 "ajax": '/ajax/genomes/sequenced_stocks' + stock_param
20             });
21         }
22         else {
23             jQuery('#sequenced_stocks_table').DataTable({
24                 "ajax": '/ajax/genomes/sequenced_stocks'
25             });
26         }
27     });
29     jQuery('#sequencing_info_form').submit(function (event) {
31         event.preventDefault();
33         var formdata = jQuery("#sequencing_info_form").serialize();
34         //alert(formdata);
35         jQuery.ajax({
36             url: '/ajax/genomes/store_sequencing_info?' + formdata,
37             success: function (r) {
38                 if (r.error) { alert(r.error + r); }
39                 else {
40                     alert("The entry has been saved. Thank you!");
41                     jQuery('#edit_sequencing_info_dialog').modal('toggle');
42                     clear_dialog_entries();
43                     jQuery('#sequenced_stocks_table').DataTable().ajax.reload();
44                 }
45             },
46             error: function (r, e) {
47                 alert("An error occurred. (" + r.responseText + ")");
48                 var err = eval("(" + r.responseText + ")");
49             }
50         });
51     });
53     jQuery('#dismiss_sequencing_info_dialog').click(function () {
54         jQuery('#edit_sequencing_info_dialog').modal('toggle');
55         clear_dialog_entries();
56     });
60 function clear_dialog_entries() {
61     jQuery('#organization').val(undefined);
62     jQuery('#website').val(undefined);
63     jQuery('#genbank_accession').val(undefined);
64     jQuery('#funded_by').val(undefined);
65     jQuery('#funder_project_id').val(undefined);
66     jQuery('#contact_email').val(undefined);
67     jQuery('#sequencing_year').val(undefined);
68     jQuery('#publication').val(undefined);
69     jQuery('#jbrowse_link').val(undefined);
70     jQuery('#blast_db_id').val(undefined);
71     jQuery('#ftp_link').val(undefined);
72     jQuery('#ncbi_link').val(undefined);
73     jQuery('#stockprop_id').val(undefined);
74     jQuery('#website').val(undefined);
77 export function delete_sequencing_info(stockprop_id) {
78     var answer = confirm("Are you sure you want to delete this entry? (stockprop_id= " + stockprop_id + "). This action cannot be undone.");
79     if (answer) {
80         jQuery.ajax({
81             url: '/ajax/genomes/sequencing_info/delete/' + stockprop_id,
82             success: function (r) {
83                 if (r.error) { alert(r.error); }
84                 else {
85                     alert("The entry has been deleted.");
86                     jQuery('#sequenced_stocks_table').DataTable().ajax.reload();
87                 }
88             },
89             error: function (r) {
90                 alert("An error occurred. The entry was not deleted.");
91             }
92         });
93     }
96 export function edit_sequencing_info(stockprop_id) {
97     //alert(stockprop_id);
98     jQuery.ajax({
99         url: '/ajax/genomes/sequencing_info/' + stockprop_id,
100         success: function (r) {
101             if (r.error) { alert(r.error); }
102             else {
103                 //alert(JSON.stringify(r));
104                 jQuery('#organization').val(r.data.organization);
105                 jQuery('#website').val(r.data.website);
106                 jQuery('#genbank_accession').val(r.data.genbank_accession);
107                 jQuery('#funded_by').val(r.data.funded_by);
108                 jQuery('#funder_project_id').val(r.data.funder_project_id);
109                 jQuery('#contact_email').val(r.data.contact_email);
110                 jQuery('#sequencing_year').val(r.data.sequencing_year);
111                 jQuery('#publication').val(r.data.publication);
112                 jQuery('#jbrowse_link').val(r.data.jbrowse_link);
113                 jQuery('#blast_db_id').val(r.data.blast_db_id);
114                 jQuery('#ftp_link').val(r.data.ftp_link);
115                 jQuery('#ncbi_link').val(r.data.ncbi_link);
116                 jQuery('#stockprop_id').val(r.data.stockprop_id);
117                 jQuery('#sequencing_status_stock_id').val(r.data.stock_id);
118                 jQuery('#website').val(r.data.website);
119                 jQuery('#edit_sequencing_info_dialog').modal("show");
120             }
121         },
122         error: function (r) { alert("an error occurred"); }
123     });