Merge pull request #5243 from solgenomics/topic/observations_upload_catch_error
[sgn.git] / mason / transformation / set_default_plant_material_dialog.mas
blob2a3e0f825b6ff08d8cd550514f1d2bd938c26b8e
1 <%args>
2 $project_id
3 $breeding_program_name
4 </%args>
6 <& /util/import_javascript.mas, classes => [ 'jquery', 'jquery.dataTables' ] &>
7 <& /util/import_css.mas, paths => ['/documents/inc/datatables/jquery.dataTables.css'] &>
9 <div class="modal fade" id="set_default_plant_material_dialog" tabindex="-1" role="dialog" aria-labelledby="setDefaultPlantMaterialDialog">
10     <div class="modal-dialog modal-lg" role="document">
11         <div class="modal-content ui-front">
12             <div class="modal-header text-center">
13                 <button type="reset" class="close" id="set_default_plant_material_dismiss_button_1" name="set_default_plant_material_dismiss_button" aria-label="Close"><span aria-hidden="true">&times;</span></button>
14                 <h4 class="modal-title" id="setDefaultPlantMaterialDialog">Set Default Plant Material for Transformation</h4>
15             </div>
16             <div class="modal-body" id="set_default_plant_material_body">
17                 <div class="container-fluid">
18                     <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data">
19                         <div class="form-group">
20                             <label class="col-sm-5 control-label" >Plant Material (accession name): </label>
21                             <div class="col-sm-7">
22                                 <input class="form-control" type="text" id="default_plant_material_input" name="default_plant_material_input"  />
23                             </div>
24                         </div>
25                     </form>
26                 </div>
27             </div>
28             <div class="modal-footer">
29                 <button id="set_default_plant_material_dismiss_button_2" name="set_default_plant_material_dismiss_button" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
30                 <button type="button" class="btn btn-primary" id="set_default_plant_material_submit">Submit</button>
31             </div>
32         </div>
33     </div>
34 </div>
36 <div class="modal fade" id="default_plant_material_saved_dialog_message" name="default_plant_material_saved_dialog_message" tabindex="-1" role="dialog" aria-labelledby="defaultPlantMaterialSavedDialog">
37     <div class="modal-dialog" role="document">
38         <div class="modal-content">
39             <div class="modal-header">
40                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
41                 <h4 class="modal-title" id="defaultPlantMaterialSavedDialog">Success</h4>
42             </div>
43             <div class="modal-body">
44                 <div class="container-fluid">
45                     <p>
46                         <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
47                         The default plant material was set successfully.
48                     </p>
49                 </div>
50             </div>
51             <div class="modal-footer">
52                 <button id="dismiss_default_plant_material_saved_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close & Reload</button>
53             </div>
54         </div>
55     </div>
56 </div>
59 <script>
61 jQuery(document).ready(function(){
63     jQuery('#set_plant_material_link').click(function() {
64         jQuery("#set_default_plant_material_dialog").modal("show");
65     });
67     var transformation_project_id = "<%$project_id%>";
68     var program_name = "<%$breeding_program_name%>";
70     jQuery("#default_plant_material_input").autocomplete({
71         source: '/ajax/stock/only_accession_autocomplete',
72     });
75     jQuery('#set_default_plant_material_submit').click(function() {
77         var default_plant_material = jQuery("#default_plant_material_input").val();
78         if (!default_plant_material) {
79             alert("Plant material is required");
80             return;
81         }
83         jQuery.ajax({
84             url: '/ajax/transformation/set_default_plant_material',
85             dataType: "json",
86             type: 'POST',
87             data:{
88                 'default_plant_material': default_plant_material,
89                 'transformation_project_id': transformation_project_id,
90                 'program_name': program_name
91             },
92             beforeSend: function(response){
93                 jQuery('#working_modal').modal('show');
94             },
95             success: function(response) {
96                 jQuery('#working_modal').modal('hide');
97                 if (response.success == 1) {
98                     jQuery('#set_default_plant_material_dialog').modal('hide');
99                     jQuery('#default_plant_material_saved_dialog_message').modal("show");
100                 }
101                 if (response.error) {
102                     alert(response.error);
103                 }
104             },
105             error: function(response){
106                 jQuery('#working_modal').modal('hide');
107                 alert('An error occurred saving default plant material');
108             }
109         });
111     });
113     jQuery("[name='set_default_plant_material_dismiss_button']").click(function() {
114         jQuery('#set_default_plant_material_dialog').modal('hide');
115         jQuery('#default_plant_material').val('');
116     });
118     jQuery("#dismiss_default_plant_material_saved_dialog").click(function(){
119         jQuery('#default_plant_material_input').val('');
120         location.reload();
121     });
126 </script>