Merge pull request #5243 from solgenomics/topic/observations_upload_catch_error
[sgn.git] / mason / transformation / set_transformant_names_dialog.mas
blob7f2c6505dd9885b9808d6504a47da34297f3a0fd
1 <%args>
2 $trial_id
3 $autogenerated_name_formats => ()
4 $breeding_program_name
5 </%args>
7 <& /util/import_javascript.mas, classes => [] &>
10 <div class="modal fade" id="set_autogenerated_names_dialog" name="set_autogenerated_names_dialog" tabindex="-1" role="dialog" aria-labelledby="setAutogeneratedNamesDialog">
11     <div class="modal-dialog modal-lg" role="document">
12         <div class="modal-content">
13             <div class="modal-header" style="text-align: center">
14                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
15                 <h4 class="modal-title" id="setAutogeneratedNamesDialog">Set Autogenerated Names for Transformants in this Project</h4>
16             </div>
17             <div class="modal-body">
18                 <div class="container-fluid">
19                     <form class="form-horizontal" id="set_autogenerated_names_form" name="set_autogenerated_names_form">
20                         <div class="form-group">
21                             <label class="col-sm-5 control-label">Select a format: </label>
22                             <div class="col-sm-7">
23 % if ($autogenerated_name_formats) {
24                                 <select id="name_format_select">
25                                     <option value="">Please select a naming format</option>
26 % foreach my $name_format(@$autogenerated_name_formats){
27                                     <option value="<%$name_format%>"><%$name_format%></option>
28 % }
29                                 </select>
30 % }
31                             </div>
32                         </div>
33                     </form>
35                 </div>
36             </div>
37             <div class="modal-footer">
38                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
39                 <button type="button" class="btn btn-primary" id="set_autogenerated_names_button">Submit</button>
40             </div>
41         </div>
42     </div>
43 </div>
45 <div class="modal fade" id="set_name_saved_dialog_message" name="set_name_saved_dialog_message" tabindex="-1" role="dialog" aria-labelledby="setNameSavedDialog">
46     <div class="modal-dialog" model-lg role="document">
47         <div class="modal-content">
48             <div class="modal-header">
49                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
50                 <h4 class="modal-title" id="setNameSavedDialog">Success</h4>
51             </div>
52             <div class="modal-body">
53                 <div class="container-fluid">
54                     <p>
55                         <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
56                         Naming format has been set for this project.
57                     </p>
58                 </div>
59             </div>
60             <div class="modal-footer">
61                 <button id="dismiss_set_name_saved_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
62             </div>
63         </div>
64     </div>
65 </div>
68 <script>
70 jQuery(document).ready(function(){
72     let project_id = "<%$trial_id%>";
73     let autogenerated_name_formats = "<%$autogenerated_name_formats%>";
74     let program_name = "<%$breeding_program_name%>";
76     jQuery('#set_autogenerated_names_link').click(function() {
77         if (autogenerated_name_formats !== "") {
78             jQuery("#set_autogenerated_names_dialog").modal("show");
79         } else {
80             alert('Please set up autogenerated name format for your breeding program first')
81         }
82     });
84     jQuery('#set_autogenerated_names_button').click(function(){
86         let name_format = jQuery('#name_format_select').val();
87         if (!name_format) {
88             alert("Please select a name format");
89             return;
90         }
92         jQuery.ajax({
93             url : '/ajax/transformation/set_autogenerated_name_format',
94             type: 'POST',
95             dataType: "json",
96             data : {
97                 'project_id': project_id,
98                 'name_format': name_format,
99                 'program_name': program_name,
100             },
101             success: function(response){
102                 console.log(response);
103                 if(response.error){
104                     alert(response.error);
105                 }
106                 if (response.success == 1) {
107                     jQuery('#set_autogenerated_names_dialog').modal('hide');
108                     jQuery('#set_name_saved_dialog_message').modal("show");
109                 }
110             },
111             error: function(response){
112                 alert('Error storing autogenerated name format!');
113             }
114         });
115     });
117     jQuery("#dismiss_set_name_saved_dialog").click(function(){
118         jQuery('#name_format_select').val('');
119         location.reload();
120     });
125 </script>