refactoring
[sgn.git] / mason / transformation / transformants_section.mas
blobf82039e8033b3aebc1a694de886e096849b1896f
1 <%args>
2 $transformation_id
3 $transformation_name
4 </%args>
6 <&| /page/info_section.mas, title => 'Transformants (Accessions) Derived from this Transformation ', collapsible=>1, collapsed=>0 &>
7     <div class = "well well-sm">
8         <div class = "panel panel-default">
9             <div class = "panel-body">
10                 <div style="overflow:scroll">
11                     <table class="table table-hover table-bordered" id="transformants_table">
12                     </table>
13                 </div>
14                 <div class="panel panel-default">
15                     <div class="panel-body">
16                         <&| /page/info_section.mas, title => 'Add transformants (accessions) to a List', collapsible=>1, collapsed=>1, subtitle=>'<i>Adding transformants (accessions) to a new or exisiting list</i>'&>
17                             <br>
18                             <div id="transformant_to_new_list" style="display:none"></div>
19                             <div id="transformant_add_to_list"></div>
20                         </&>
21                     </div>
22                 </div>
23             </div>
24         </div>
25     </div>
26 </&>
28 <script>
30 jQuery(document).ready(function(){
32     const transformation_stock_id = "<%$transformation_id%>";
33     const transformants_table = jQuery('#transformants_table').DataTable({
34         'ajax': '/ajax/transformation/transformants/'+transformation_stock_id,
35         'autoWidth': false,
36         'columns': [
37             { title: "Accession", "data": null, "render": function ( data, type, row ) { return "<a href='/stock/"+row.transformant_id+"/view'>"+row.transformant_name+"</a>"; } },
38             { title: "Obsolete Accession", "data": "null", "render": function ( data, type, row ) { return "<a onclick='obsoleteTransformant("+row.transformant_id+",\""+row.transformant_name+"\")'>X</a>"; } },
39         ],
41         "fnInitComplete": function(oSettings, json) {
42             //console.log(json);
43             if (!isLoggedIn()) {
44                 jQuery('#transformant_add_to_list').html("<div class='well well-sm'><h3>Please login to use lists!</h3></div>");
45             } else {
46                 let html = "";
47                 for(let i=0; i<json.data.length; i++){
48                     html += json.data[i].transformant_name+"\n";
49                 }
51                 jQuery("#transformant_to_new_list").html(html);
52                 addToListMenu("transformant_add_to_list", "transformant_to_new_list", {
53                     selectText: true,
54                     listType: 'accessions',
55                 });
56             }
57         }
58     });
60 });
63 function obsoleteTransformant(transformant_id, transformant_name){
64     const confirmation = confirm('Are you sure you want to obsolete this transformant?' + "  " + transformant_name);
66     if (confirmation) {
67         jQuery.ajax ({
68             url : '/stock/obsolete?stock_id='+transformant_id+'&is_obsolete=1',
69             beforeSend : function() {
70                 jQuery('#working_modal').modal('show');
71             },
72             success: function(response){
73                 console.log(response);
74                 jQuery('#working_modal').modal('hide');
75                 alert('Successfully obsoleted!');
76                 location.reload();
77             },
78             error: function(response){
79                 jQuery('#working_modal').modal('hide');
80                 alert("Error obsoleting transformants.");
81             }
82         });
83     }
86 </script>