Merge pull request #5205 from solgenomics/topic/generic_trial_upload
[sgn.git] / mason / breeders_toolbox / add_seedlot_dialogs.mas
blob28cc2fa5eaa5f3a11f6e69db8a07c37d89fd14b7
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">Seedlot Description: </label>
26                     <div class="col-sm-9" >
27                         <input class="form-control" id="seedlot_description" placeholder="Optional">
28                     </div>
29                 </div>
30                 <div class="form-group">
31                     <label class="col-sm-3 control-label">Breeding Program: </label>
32                     <div class="col-sm-9" >
33                         <div id="seedlot_breeding_program_div"></div>
34                     </div>
35                 </div>
36                 <div class="form-group">
37                     <label class="col-sm-3 control-label">Location: </label>
38                     <div class="col-sm-9" >
39                         <input class="form-control" id="seedlot_location" placeholder="Required">
40                     </div>
41                 </div>
42                 <div class="form-group">
43                     <label class="col-sm-3 control-label">Box Name: </label>
44                     <div class="col-sm-9" >
45                         <input class="form-control" id="seedlot_box_name" placeholder="Required">
46                     </div>
47                 </div>
49                 <div class="form-group">
50                     <label class="col-sm-3 control-label">Quality issues:</label>
51                     <div class="col-sm-9" >
52                         <input class="form-control" id="seedlot_quality" placeholder="list quality issues here, or 'ok' for good quality seed" >
53                     </div>
54                 </div>
56                 <div class="well well-sm">
57                     <div class="row">
58                         <div class="col-sm-3">
59                             <div class="form-group">
60                                 <label class="col-sm-12 control-label">Contents: </label>
61                             </div>
62                         </div>
63                         <div class="col-sm-9">
64 % if ($accession_uniquename || $cross_uniquename){
65                             <div class="panel panel-default">
66                                 <div class="panel-body">
67                                     <div class="form-group">
68                                         <label class="col-sm-3 control-label">Accession name: </label>
69                                         <div class="col-sm-9" >
70                                             <input class="form-control" id="seedlot_accession_uniquename" placeholder="One Content Required" disabled value="<% $accession_uniquename %>">
71                                         </div>
72                                     </div>
73                                 </div>
74                             </div>
75                             <center><h4>OR</h4></center>
76                             <div class="panel panel-default">
77                                 <div class="panel-body">
78                                     <div class="form-group">
79                                         <label class="col-sm-3 control-label">Cross Unique ID: </label>
80                                         <div class="col-sm-9" >
81                                             <input class="form-control" id="seedlot_cross_uniquename" placeholder="One Content Required" disabled value="<% $cross_uniquename %>">
82                                         </div>
83                                     </div>
84                                 </div>
85                             </div>
86 % } else {
87                             <div class="panel panel-default">
88                                 <div class="panel-body">
89                                     <div class="form-group">
90                                         <label class="col-sm-3 control-label">Accession name: </label>
91                                         <div class="col-sm-9" >
92                                             <input class="form-control" id="seedlot_accession_uniquename" placeholder="One Content Required">
93                                         </div>
94                                     </div>
95                                 </div>
96                             </div>
97                             <center><h4>OR</h4></center>
98                             <div class="panel panel-default">
99                                 <div class="panel-body">
100                                     <div class="form-group">
101                                         <label class="col-sm-3 control-label">Cross Unique ID: </label>
102                                         <div class="col-sm-9" >
103                                             <input class="form-control" id="seedlot_cross_uniquename" placeholder="One Content Required">
104                                         </div>
105                                     </div>
106                                 </div>
107                             </div>
108 % }
109                         </div>
110                     </div>
111                 </div>
113                 <div class="form-group">
114                     <label class="col-sm-3 control-label">Source: </label>
115                     <div class="col-sm-9">
116                         <input class="form-control" id="seedlot_source" placeholder="Optional">
117                         <span style="font-size: 80; color: #666">Seedlot/Plot/Subplot/Plant name to be used as the source for the first transaction</span>
118                     </div>
119                 </div>
121                 <div class="form-group">
122                     <label class="col-sm-3 control-label">Amount (number of seeds): </label>
123                     <div class="col-sm-9" >
124                         <input class="form-control" id="seedlot_amount" placeholder="Amount OR Weight(g) Required">
125                     </div>
126                 </div>
127                 <div class="form-group">
128                     <label class="col-sm-3 control-label">Weight (g): </label>
129                     <div class="col-sm-9" >
130                         <input class="form-control" id="seedlot_weight" placeholder="Amount OR Weight(g) Required">
131                     </div>
132                 </div>
133                 <!--
134                 <div class="form-group">
135                     <label class="col-sm-3 control-label">Population: </label>
136                     <div class="col-sm-9" >
137                         <input class="form-control" id="seedlot_population_name" placeholder="Optional">
138                     </div>
139                 </div>
140                 -->
141                 <div class="form-group">
142                     <label class="col-sm-3 control-label">Organization: </label>
143                     <div class="col-sm-9" >
144                         <input class="form-control" id="seedlot_organization" placeholder="Optional">
145                     </div>
146                 </div>
147                 <div class="form-group">
148                     <label class="col-sm-3 control-label">Timestamp: </label>
149                     <div class="col-sm-9" >
150                         <input class="form-control" id="seedlot_timestamp" value="<% $timestamp %>" placeholder="<% $timestamp %>">
151                     </div>
152                 </div>
153                 <div class="form-group">
154                     <label class="col-sm-3 control-label">Transaction Description: </label>
155                     <div class="col-sm-9" >
156                         <input class="form-control" id="seedlot_transaction_description" placeholder="Optional">
157                     </div>
158                 </div>
159             </form>
160         </div>
161       </div>
162       <div class="modal-footer">
163         <button id="create_new_seedlot_button" type="button" class="btn btn-primary" >OK</button>
164       </div>
165     </div>
166   </div>
167 </div>
169 <script>
170 jQuery(document).ready(function(){
172     jQuery("#seedlot_location").autocomplete({
173        source: '/ajax/stock/geolocation_autocomplete',
174     });
175     jQuery("#seedlot_accession_uniquename").autocomplete({
176        source: '/ajax/stock/accession_autocomplete',
177     });
178     jQuery("#seedlot_cross_uniquename").autocomplete({
179        source: '/ajax/stock/cross_autocomplete',
180     });
181     jQuery("#seedlot_source").autocomplete({
182         source: '/ajax/stock/seedlot_source_autocomplete'
183     });
185     jQuery('[name="add_seedlot_button"]').click( function() {
186         jQuery('#add_seedlot_dialog').modal('show');
187         get_select_box('breeding_programs', 'seedlot_breeding_program_div', { 'name' : 'seedlot_breeding_program_id', 'id' : 'seedlot_breeding_program_id' });
188     });
190     jQuery('#create_new_seedlot_button').click( function() {
191         var name = jQuery('#seedlot_name').val();
192         var seedlot_description = jQuery('#seedlot_description').val();
193         var location = jQuery('#seedlot_location').val();
194         var box_name = jQuery('#seedlot_box_name').val();
195         var accession_uniquename = jQuery('#seedlot_accession_uniquename').val();
196         var cross_uniquename = jQuery('#seedlot_cross_uniquename').val();
197         var population_name = jQuery('#seedlot_population_name').val();
198         var organization = jQuery('#seedlot_organization').val();
199         var source = jQuery("#seedlot_source").val();
200         var amount = jQuery('#seedlot_amount').val();
201         var weight = jQuery('#seedlot_weight').val();
202         var timestamp = jQuery('#seedlot_timestamp').val();
203         var transaction_description = jQuery('#seedlot_transaction_description').val();
204         var breeding_program_id = jQuery('#seedlot_breeding_program_id').val();
205         var seedlot_quality = jQuery('#seedlot_quality').val();
207         if (name == '') { alert("Please provide a name"); return; }
208         else if (location == '') { alert("Please provide a location"); return; }
209         else if (box_name == '') { alert("Please provide a box name"); return; }
210         else if (amount == '' && weight == '') { alert("Please provide a seed count amount or a weight in grams!"); return; }
211         else if (isNaN(amount)) { alert("If inputting a seed count amount, it must be a numeric value."); return; }
212         else if (isNaN(weight)) { alert("If inputting a weight, it must be a numeric value."); return; }
213         else if (breeding_program_id == '') { alert("Please select a breeding program"); return; }
214         else if (accession_uniquename == '' && cross_uniquename == '') {
215             alert("Please provide an accession name or a cross unique id as the content of the seedlot."); return;
216         }
217         else if (accession_uniquename != '' && cross_uniquename != '') {
218             alert("Please provide an accession name OR a cross unique id as the content of the seedlot. Not both."); return;
219         }
220         else {
222             jQuery.ajax({
223                 url: '/ajax/breeders/seedlot-create',
224                 data : {
225                     'seedlot_name' : name,
226                     'seedlot_description': seedlot_description,
227                     'seedlot_location': location,
228                     'seedlot_box_name':box_name,
229                     'seedlot_accession_uniquename': accession_uniquename,
230                     'seedlot_cross_uniquename': cross_uniquename,
231                     'seedlot_organization': organization,
232                     'seedlot_population_name': population_name,
233                     'seedlot_source': source,
234                     'seedlot_amount':amount,
235                     'seedlot_weight':weight,
236                     'seedlot_timestamp':timestamp,
237                     'seedlot_transaction_description':transaction_description,
238                     'seedlot_breeding_program_id':breeding_program_id,
239                     'seedlot_quality' : seedlot_quality
241                 },
242                 beforeSend: function(response){
243                     jQuery('#working_modal').modal('show');
244                 },
245                 success: function(response) {
246                     jQuery('#working_modal').modal('hide');
247                     if (response.success == 1) {
248                         alert("The seedlot has been created.");
249                         jQuery('#add_seedlot_dialog').modal('hide');
250                         //seedlots_table.ajax.reload();
251                         //document.location.reload();
252                     }
253                     if (response.error) {
254                         alert(response.error);
255                     }
256                 },
257                 error: function(response){
258                     jQuery('#working_modal').modal('hide');
259                     alert('An error occurred creating seed lot');
260                 }
261             });
262         }
264     });
267 </script>