Merge pull request #2754 from solgenomics/topic/fix_homepage_add_accessions_dialog
[sgn.git] / mason / breeders_toolbox / add_seedlot_dialogs.mas
blobb618c2185a378d374997e427b9ecdba6850ae1b6
1 <%args>
2 $timestamp => localtime()
3 $accession_uniquename => ''
4 $cross_uniquename => ''
5 </%args>
7 <div class="modal fade" id="add_seedlot_dialog" name="add_seedlot_dialog" tabindex="-1" role="dialog" aria-labelledby="seedlot_dialog">
8   <div class="modal-dialog modal-lg" role="document">
9     <div class="modal-content">
10       <div class="modal-header">
11         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
12         <h4 class="modal-title" id="seedlot_dialog">Create New Seedlot</h4>
13       </div>
14       <div class="modal-body">
15         <div class="container-fluid">
16             <form class="form-horizontal" role="form" method="post" id="create_new_seedlot_form" name="create_new_seedlot_form">
18                 <div class="form-group">
19                     <label class="col-sm-3 control-label">Name: </label>
20                     <div class="col-sm-9" >
21                         <input class="form-control" id="seedlot_name" placeholder="Required">
22                     </div>
23                 </div>
24                 <div class="form-group">
25                     <label class="col-sm-3 control-label">Breeding Program: </label>
26                     <div class="col-sm-9" >
27                         <div id="seedlot_breeding_program_div"></div>
28                     </div>
29                 </div>
30                 <div class="form-group">
31                     <label class="col-sm-3 control-label">Location: </label>
32                     <div class="col-sm-9" >
33                         <input class="form-control" id="seedlot_location" placeholder="Required">
34                     </div>
35                 </div>
36                 <div class="form-group">
37                     <label class="col-sm-3 control-label">Box Name: </label>
38                     <div class="col-sm-9" >
39                         <input class="form-control" id="seedlot_box_name" placeholder="Required">
40                     </div>
41                 </div>
43                 <div class="well well-sm">
44                     <div class="row">
45                         <div class="col-sm-3">
46                             <div class="form-group">
47                                 <label class="col-sm-12 control-label">Contents: </label>
48                             </div>
49                         </div>
50                         <div class="col-sm-9">
51 % if ($accession_uniquename || $cross_uniquename){
52                             <div class="panel panel-default">
53                                 <div class="panel-body">
54                                     <div class="form-group">
55                                         <label class="col-sm-3 control-label">Accession name: </label>
56                                         <div class="col-sm-9" >
57                                             <input class="form-control" id="seedlot_accession_uniquename" placeholder="One Content Required" disabled value="<% $accession_uniquename %>">
58                                         </div>
59                                     </div>
60                                 </div>
61                             </div>
62                             <center><h4>OR</h4></center>
63                             <div class="panel panel-default">
64                                 <div class="panel-body">
65                                     <div class="form-group">
66                                         <label class="col-sm-3 control-label">Cross Unique ID: </label>
67                                         <div class="col-sm-9" >
68                                             <input class="form-control" id="seedlot_cross_uniquename" placeholder="One Content Required" disabled value="<% $cross_uniquename %>">
69                                         </div>
70                                     </div>
71                                 </div>
72                             </div>
73 % } else {
74                             <div class="panel panel-default">
75                                 <div class="panel-body">
76                                     <div class="form-group">
77                                         <label class="col-sm-3 control-label">Accession name: </label>
78                                         <div class="col-sm-9" >
79                                             <input class="form-control" id="seedlot_accession_uniquename" placeholder="One Content Required">
80                                         </div>
81                                     </div>
82                                 </div>
83                             </div>
84                             <center><h4>OR</h4></center>
85                             <div class="panel panel-default">
86                                 <div class="panel-body">
87                                     <div class="form-group">
88                                         <label class="col-sm-3 control-label">Cross Unique ID: </label>
89                                         <div class="col-sm-9" >
90                                             <input class="form-control" id="seedlot_cross_uniquename" placeholder="One Content Required">
91                                         </div>
92                                     </div>
93                                 </div>
94                             </div>
95 % }
96                         </div>
97                     </div>
98                 </div>
100                 <div class="form-group">
101                     <label class="col-sm-3 control-label">Amount (number of seeds): </label>
102                     <div class="col-sm-9" >
103                         <input class="form-control" id="seedlot_amount" placeholder="Amount OR Weight(g) Required">
104                     </div>
105                 </div>
106                 <div class="form-group">
107                     <label class="col-sm-3 control-label">Weight (g): </label>
108                     <div class="col-sm-9" >
109                         <input class="form-control" id="seedlot_weight" placeholder="Amount OR Weight(g) Required">
110                     </div>
111                 </div>
112                 <!--
113                 <div class="form-group">
114                     <label class="col-sm-3 control-label">Population: </label>
115                     <div class="col-sm-9" >
116                         <input class="form-control" id="seedlot_population_name" placeholder="Optional">
117                     </div>
118                 </div>
119                 -->
120                 <div class="form-group">
121                     <label class="col-sm-3 control-label">Organization: </label>
122                     <div class="col-sm-9" >
123                         <input class="form-control" id="seedlot_organization" placeholder="Optional">
124                     </div>
125                 </div>
126                 <div class="form-group">
127                     <label class="col-sm-3 control-label">Timestamp: </label>
128                     <div class="col-sm-9" >
129                         <input class="form-control" id="seedlot_timestamp" value="<% $timestamp %>" placeholder="<% $timestamp %>">
130                     </div>
131                 </div>
132                 <div class="form-group">
133                     <label class="col-sm-3 control-label">Description: </label>
134                     <div class="col-sm-9" >
135                         <input class="form-control" id="seedlot_description" placeholder="Optional">
136                     </div>
137                 </div>
138             </form>
139         </div>
140       </div>
141       <div class="modal-footer">
142         <button id="create_new_seedlot_button" type="button" class="btn btn-primary" >OK</button>
143       </div>
144     </div>
145   </div>
146 </div>
148 <script>
149 jQuery(document).ready(function(){
151     jQuery("#seedlot_location").autocomplete({
152        source: '/ajax/stock/geolocation_autocomplete',
153     });
154     jQuery("#seedlot_accession_uniquename").autocomplete({
155        source: '/ajax/stock/accession_autocomplete',
156     });
157     jQuery("#seedlot_cross_uniquename").autocomplete({
158        source: '/ajax/stock/cross_autocomplete',
159     });
161     jQuery('[name="add_seedlot_button"]').click( function() {
162         jQuery('#add_seedlot_dialog').modal('show');
163         get_select_box('breeding_programs', 'seedlot_breeding_program_div', { 'name' : 'seedlot_breeding_program_id', 'id' : 'seedlot_breeding_program_id' });
164     });
166     jQuery('#create_new_seedlot_button').click( function() {
167         var name = jQuery('#seedlot_name').val();
168         var location = jQuery('#seedlot_location').val();
169         var box_name = jQuery('#seedlot_box_name').val();
170         var accession_uniquename = jQuery('#seedlot_accession_uniquename').val();
171         var cross_uniquename = jQuery('#seedlot_cross_uniquename').val();
172         var population_name = jQuery('#seedlot_population_name').val();
173         var organization = jQuery('#seedlot_organization').val();
174         var amount = jQuery('#seedlot_amount').val();
175         var weight = jQuery('#seedlot_weight').val();
176         var timestamp = jQuery('#seedlot_timestamp').val();
177         var description = jQuery('#seedlot_description').val();
178         var breeding_program_id = jQuery('#seedlot_breeding_program_id').val();
180         if (name == '') { alert("Please provide a name"); return; }
181         else if (location == '') { alert("Please provide a location"); return; }
182         else if (box_name == '') { alert("Please provide a box name"); return; }
183         else if (amount == '' && weight == '') { alert("Please provide an seed count amount or a weight in grams!"); return; }
184         else if (breeding_program_id == '') { alert("Please select a breeding program"); return; }
185         else if (accession_uniquename == '' && cross_uniquename == '') {
186             alert("Please provide an accession name or a cross unique id as the content of the seedlot."); return;
187         }
188         else if (accession_uniquename != '' && cross_uniquename != '') {
189             alert("Please provide an accession name OR a cross unique id as the content of the seedlot. Not both."); return;
190         }
191         else {
193             jQuery.ajax({
194                 url: '/ajax/breeders/seedlot-create',
195                 data : {
196                     'seedlot_name' : name,
197                     'seedlot_location': location,
198                     'seedlot_box_name':box_name,
199                     'seedlot_accession_uniquename': accession_uniquename,
200                     'seedlot_cross_uniquename': cross_uniquename,
201                     'seedlot_organization': organization,
202                     'seedlot_population_name': population_name,
203                     'seedlot_amount':amount,
204                     'seedlot_weight':weight,
205                     'seedlot_timestamp':timestamp,
206                     'seedlot_description':description,
207                     'seedlot_breeding_program_id':breeding_program_id
208                 },
209                 beforeSend: function(response){
210                     jQuery('#working_modal').modal('show');
211                 },
212                 success: function(response) {
213                     jQuery('#working_modal').modal('hide');
214                     if (response.success == 1) {
215                         alert("The seedlot has been created.");
216                         jQuery('#add_seedlot_dialog').modal('hide');
217                         //seedlots_table.ajax.reload();
218                         //document.location.reload();
219                     }
220                     if (response.error) {
221                         alert(response.error);
222                     }
223                 },
224                 error: function(response){
225                     jQuery('#working_modal').modal('hide');
226                     alert('An error occurred creating seed lot');
227                 }
228             });
229         }
231     });
234 </script>