check file name
[sgn.git] / mason / breeders_toolbox / seedlot_details.mas
bloba9f6260ce6241b19f742925fd3c119a23b3f525b
2 <%args>
3 $seedlot_id
4 $uniquename
5 $current_count => 0
6 $current_weight => 0
7 $content_html
8 $content_accession_name
9 $content_cross_name
10 $organization_name
11 $population_name
12 $timestamp
13 $description => undef
14 $box_name=>undef
15 $quality => undef
16 $owners_string => undef
17 $maintenance_enabled => undef
18 $discard_info => undef
19 $status => undef
20 $user_role => undef
21 </%args>
23 <& /util/import_javascript.mas, classes => [ 'bootstrap_min.js', 'jquery.iframe-post-form','CXGN.List','CXGN.BreedersToolbox.Accessions', 'CXGN.BreedersToolbox.UploadPedigrees', 'jquery', 'jquery.dataTables' ] &>
25 <style>
26 .ui-autocomplete {
27     z-index: 5000;
29 </style>
31 % my $edit_seedlot_link;
32 % my $new_transaction_link;
33 % if (!$discard_info) {
34 %    $edit_seedlot_link = "[<a id='edit_seedlot_details_link' >Edit Seedlot Details</a>]";
35 %    $new_transaction_link = "[<a id='add_seedlot_transaction_button' >Add New Transaction</a>]";
36 % }
38 <& /page/page_title.mas, title => 'Seedlot '.$uniquename &>
40 <&| /page/info_section.mas, title=>"Details",  collapsible => 1, collapsed=>0, subtitle=> $edit_seedlot_link &>
42 <table class="table table-bordered table-hover">
43 % if ($discard_info) {
44     <tr><td><b>Discard Info</b></td><td><% $discard_info %></td></tr>
45 % }
46 <tr><td><b>Breeding Program</b></td><td><div id="seedlot_breeding_program_div">[LOADING...]</div></td></tr>
47 <tr><td><b>Seedlot Name</b></td><td><a href="/stock/<% $seedlot_id %>/view"><% $uniquename %></a></td></tr>
48 <tr><td><b>Seedlot Description</b></td><td><% $description %></td></tr>
49 <tr><td><b>Organization</b></td><td><% $organization_name %></td></tr>
50 <tr><td><b>Location Code</b><td><div id="seedlot_location_code_div">[LOADING...]</div></td></tr>
51 <tr><td><b>Box Name</b></td><td><% $box_name %></td></tr>
52 <tr><td><b>Quality issues</b></td><td><% $quality %></td></tr>
53 <tr><td><b>Contents</b></td><td><% $content_html %></td></tr>
54 <!--<tr><td><b>Population</b></td><td><% $population_name %></td></tr>-->
55 <tr><td><b>Current count</b></td><td><% $current_count %></td></tr>
56 <tr><td><b>Current weight (g)</b></td><td><% $current_weight %></td></tr>
57 <tr><td><b>Submitters</b></td><td><% $owners_string %></td></tr>
58 </table>
60 </&>
62 <center>
63 <h3>Transactions</h3>
64 </center>
66 <&| /page/info_section.mas, title=>"Transactions Table",  collapsible => 1, collapsed=>0, subtitle=>$new_transaction_link &>
68 <div style="overflow:scroll">
69     <table id="available_seedlot_transactions_table" class="table table-hover table-bordered">
70     </table>
71 </div>
73 </&>
75 <&| /page/info_section.mas, title=>"Mark this seedlot as DISCARDED",  collapsible => 1, collapsed=>1 &>
76 % if ($user_role eq "curator" ) {
77     <div class="well well-sm">
78         <div class="panel panel-default">
79             <div class="panel-body">
80 % if ($discard_info) {
81     <button class="btn btn-sm btn-default" style="margin:3px" id ="discard_seedlot_usage_info" name = "discard_seedlot_usage_info">Usage Help <span class="glyphicon glyphicon-question-sign"></span></button><button class="btn btn-sm btn-primary" style="margin:3px" id="undo_discarding_seedlot_link">Undo Discarding this Seedlot</button>
82 % } else {
83     <button class="btn btn-sm btn-default" style="margin:3px" id ="discard_seedlot_usage_info" name = "discard_seedlot_usage_info">Usage Help <span class="glyphicon glyphicon-question-sign"></span></button><button class="btn btn-sm btn-primary" style="margin:3px" id="discard_seedlot_details_page_link">Mark this Seedlot as DISCARDED</button>
84 % }
85             </div>
86         </div>
87     </div>
88 % } else {
89     You need to be logged in or you do not have sufficient privileges to mark this seedlot as DISCARDED.
90 % }
91 </&>
93 <& /breeders_toolbox/discard_single_seedlot.mas, seedlot_id => $seedlot_id, uniquename => $uniquename &>
94 <& /breeders_toolbox/discard_undo_seedlot_usage.mas &>
96 % if ( $maintenance_enabled ) {
97     <& /page/page_title.mas, title => 'Maintenance Events' &>
99     <&| /page/info_section.mas, title=>"Events Table",  collapsible=>1, collapsed=>0, subtitle=>"[<a href='/breeders/seedlot/maintenance/record?seedlot_name=$uniquename' id='add_seedlot_maintenance_button' >Record Maintenance</a>]" &>
100         <& /breeders_toolbox/seedlot_maintenance/table.mas, seedlot_id => $seedlot_id, seedlot_name => $uniquename &>
101     </&>
102 % }
104 <div class="modal fade" id="add_seedlot_transaction_dialog" name="add_seedlot_transaction_dialog" tabindex="-1" role="dialog" aria-labelledby="seedlot_transaction_dialog">
105   <div class="modal-dialog modal-xl" role="document">
106     <div class="modal-content">
107       <div class="modal-header">
108         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
109         <h4 class="modal-title" id="seedlot_transaction_dialog">Add New Seedlot Transaction</h4>
110       </div>
111       <div class="modal-body">
112         <div class="container-fluid">
113             <form class="form-horizontal" role="form" method="post" id="create_new_seedlot_transaction_form" name="create_new_seedlot_transaction_form">
115                 <div class="form-group">
116                     <label class="col-sm-3 control-label">Transaction Type: </label>
117                     <div class="col-sm-9" >
118                         <select class="form-control" id="seedlot_transaction_factor">
119                             <option value="1">Added to this Seedlot (<% $uniquename %>)</option>
120                             <option value="-1">Taken from this Seedlot (<% $uniquename %>)</option>
121                         </select>
122                     </div>
123                 </div>
125                 <div id="seedlot_transaction_from_seedlot">
126                     <div class="form-group">
127                         <label class="col-sm-3 control-label">Taken From Existing Seedlot:<br/><small>Only showing seedlots with matching content</small></label>
128                         <div class="col-sm-9" >
129                             <div id="seedlot_transaction_seedlot_div"></div>
130                         </div>
131                     </div>
132                 </div>
134                 <div id="seedlot_transaction_to_seedlot" style="display: none">
135                     <div class="form-group">
136                         <label class="col-sm-3 control-label">Transferring to a new seed lot?: </label>
137                         <div class="col-sm-9" >
138                             <select class="form-control" id="seedlot_transaction_to_seedlot_new">
139                                 <option value="no">No</option>
140                                 <option value="yes">Yes</option>
141                             </select>
142                         </div>
143                     </div>
144                     <div id="seedlot_transaction_to_seedlot_new_no">
145                         <div class="form-group">
146                             <label class="col-sm-3 control-label">To Existing Seedlot:<br/><small>Only showing seedlots with matching content</small> </label>
147                             <div class="col-sm-9" >
148                                 <div id="seedlot_transaction_to_seedlot_existing"></div>
149                             </div>
150                         </div>
151                     </div>
152                     <div id="seedlot_transaction_to_seedlot_new_yes" style="display: none">
153                         <div class="well well-sm">
154                             <div class="panel panel-default">
155                                 <div class="panel-body">
156                                     <div class="form-group">
157                                         <label class="col-sm-3 control-label">To New Seedlot: </label>
158                                         <div class="col-sm-9" >
160                                             <div class="form-group">
161                                                 <label class="col-sm-3 control-label">Name: </label>
162                                                 <div class="col-sm-9" >
163                                                     <input class="form-control" id="transaction_new_seedlot_name" placeholder="Required">
164                                                 </div>
165                                             </div>
166                                             <div class="form-group">
167                                                 <label class="col-sm-3 control-label">Seedlot Description: </label>
168                                                 <div class="col-sm-9" >
169                                                     <input class="form-control" id="transaction_new_seedlot_description" placeholder="Optional">
170                                                 </div>
171                                             </div>
172                                             <div class="form-group">
173                                                 <label class="col-sm-3 control-label">Breeding Program: </label>
174                                                 <div class="col-sm-9" >
175                                                     <div id="transaction_new_seedlot_breeding_program_div"></div>
176                                                 </div>
177                                             </div>
178                                             <div class="form-group">
179                                                 <label class="col-sm-3 control-label">Location: </label>
180                                                 <div class="col-sm-9" >
181                                                     <input class="form-control" id="transaction_new_seedlot_location" placeholder="Required">
182                                                 </div>
183                                             </div>
184                                             <div class="form-group">
185                                                 <label class="col-sm-3 control-label">Box Name: </label>
186                                                 <div class="col-sm-9" >
187                                                     <input class="form-control" id="transaction_new_seedlot_box_name" placeholder="Required">
188                                                 </div>
189                                             </div>
191                                                                     <div class="form-group">
192                                               <label class="col-sm-3 control-label">Quality issues: </label>
193                                               <div class="col-sm-9" >
194                                                 <input class="form-control" id="transaction_new_seedlot_quality" placeholder="Leave blank for no issues">
195                                               </div>
196                                             </div>
198                                             <div class="well well-sm">
199                                                 <div class="row">
200                                                     <div class="col-sm-3">
201                                                        <div class="form-group">
202                                                             <label class="col-sm-12 control-label">Contents:<br/><small>Contents must match between seedlots</small> </label>
203                                                         </div>
204                                                     </div>
205                                                     <div class="col-sm-9">
206                                                         <div class="panel panel-default">
207                                                             <div class="panel-body">
208                                                                 <div class="form-group">
209 % if ($content_accession_name){
210                                                                     <label class="col-sm-3 control-label">Accession name: </label>
211                                                                     <div class="col-sm-9" >
212                                                                         <input class="form-control" id="transaction_new_seedlot_accession_uniquename" disabled value="<% $content_accession_name %>">
213                                                                     </div>
214 % }
215 % if ($content_cross_name){
216                                                                     <label class="col-sm-3 control-label">Cross Unique ID: </label>
217                                                                     <div class="col-sm-9" >
218                                                                         <input class="form-control" id="transaction_new_seedlot_cross_uniquename" disabled value="<% $content_cross_name %>">
219                                                                     </div>
220 % }
221                                                                 </div>
222                                                             </div>
223                                                         </div>
224                                                     </div>
225                                                 </div>
226                                             </div>
228                                             <div class="form-group">
229                                                 <label class="col-sm-3 control-label">Starting Amount (number of seeds): </label>
230                                                 <div class="col-sm-9" >
231                                                     <input class="form-control" id="transaction_new_seedlot_amount" placeholder="Amount OR Weight Required" disabled value="0">
232                                                 </div>
233                                             </div>
234                                             <div class="form-group">
235                                                 <label class="col-sm-3 control-label">Starting Weight (g): </label>
236                                                 <div class="col-sm-9" >
237                                                     <input class="form-control" id="transaction_new_seedlot_weight" placeholder="Amount OR Weight Required" disabled value="0">
238                                                 </div>
239                                             </div>
240                                             <!--
241                                             <div class="form-group">
242                                                 <label class="col-sm-3 control-label">Population: </label>
243                                                 <div class="col-sm-9" >
244                                                     <input class="form-control" id="transaction_new_seedlot_population_name" placeholder="Optional">
245                                                 </div>
246                                             </div>
247                                             -->
248                                             <div class="form-group">
249                                                 <label class="col-sm-3 control-label">Organization: </label>
250                                                 <div class="col-sm-9" >
251                                                     <input class="form-control" id="transaction_new_seedlot_organization" placeholder="Optional">
252                                                 </div>
253                                             </div>
254                                             <div class="form-group">
255                                                 <label class="col-sm-3 control-label">Timestamp: </label>
256                                                 <div class="col-sm-9" >
257                                                     <input class="form-control" id="transaction_new_seedlot_timestamp" value="<% $timestamp %>" placeholder="<% $timestamp %>">
258                                                 </div>
259                                             </div>
260                                             <div class="form-group">
261                                                 <label class="col-sm-3 control-label">Transaction Description: </label>
262                                                 <div class="col-sm-9" >
263                                                     <input class="form-control" id="transaction_new_seedlot_transaction_description" placeholder="Optional">
264                                                 </div>
265                                             </div>
266                                         </div>
267                                     </div>
268                                 </div>
269                             </div>
270                         </div>
271                     </div>
272                 </div>
274                 <div class="form-group">
275                     <label class="col-sm-3 control-label">Transaction Amount (number of seeds): </label>
276                     <div class="col-sm-9" >
277                         <input class="form-control" id="seedlot_transaction_amount" placeholder="Amount OR Weight Required">
278                     </div>
279                 </div>
280                 <div class="form-group">
281                     <label class="col-sm-3 control-label">Transaction Weight (g): </label>
282                     <div class="col-sm-9" >
283                         <input class="form-control" id="seedlot_transaction_weight" placeholder="Amount OR Weight Required">
284                     </div>
285                 </div>
286                 <div class="form-group">
287                     <label class="col-sm-3 control-label">Timestamp: </label>
288                     <div class="col-sm-9" >
289                         <input class="form-control" id="seedlot_transaction_timestamp" value="<% $timestamp %>" placeholder="<% $timestamp %>">
290                     </div>
291                 </div>
292                 <div class="form-group">
293                     <label class="col-sm-3 control-label">Transaction Description: </label>
294                     <div class="col-sm-9" >
295                         <input class="form-control" id="seedlot_transaction_description" placeholder="Optional">
296                     </div>
297                 </div>
298             </form>
299         </div>
300       </div>
301       <div class="modal-footer">
302         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
303         <button id="create_new_seedlot_transaction_button" type="button" class="btn btn-primary" >Submit</button>
304       </div>
305     </div>
306   </div>
307 </div>
309 <div class="modal fade" id="edit_seedlot_transaction_dialog" name="edit_seedlot_transaction_dialog" tabindex="-1" role="dialog" aria-labelledby="seedlot_edit_transaction_dialog">
310   <div class="modal-dialog modal-lg" role="document">
311     <div class="modal-content">
312       <div class="modal-header">
313         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
314         <h4 class="modal-title" id="seedlot_edit_transaction_dialog">Edit Seedlot Transaction</h4>
315       </div>
316       <div class="modal-body">
317         <div class="container-fluid">
318             <div id="edit_seedlot_transaction_div">
319             </div>
320         </div>
321       </div>
322       <div class="modal-footer">
323         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
324         <button id="edit_seedlot_transaction_button" type="button" class="btn btn-primary" >Save</button>
325       </div>
326     </div>
327   </div>
328 </div>
330 <div class="modal fade" id="edit_seedlot_details_dialog" name="edit_seedlot_details_dialog" tabindex="-1" role="dialog" aria-labelledby="seedlot_edit_details_dialog">
331   <div class="modal-dialog modal-lg" role="document">
332     <div class="modal-content">
333       <div class="modal-header">
334         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
335         <h4 class="modal-title" id="seedlot_edit_details_dialog">Edit Seedlot Details</h4>
336       </div>
337       <div class="modal-body">
338         <div class="container-fluid">
339             <form class="form-horizontal">
340                 <div class="form-group">
341                     <label class="col-sm-3 control-label">Seedlot Name: </label>
342                     <div class="col-sm-9" >
343                         <input class="form-control" type="text" id="edit_seedlot_details_uniquename" value="LOADING..."/>
344                     </div>
345                 </div>
346                 <div class="form-group">
347                     <label class="col-sm-3 control-label">Seedlot Description: </label>
348                     <div class="col-sm-9" >
349                         <input class="form-control" type="text" id="edit_seedlot_details_description" placeholder="Optional"/>
350                     </div>
351                 </div>
352                 <div class="form-group">
353                     <label class="col-sm-3 control-label">Breeding Program: </label>
354                     <div class="col-sm-9" >
355                         <input class="form-control" type="text" id="edit_seedlot_details_breeding_program" value="LOADING..."/>
356                     </div>
357                 </div>
358                 <div class="form-group">
359                     <label class="col-sm-3 control-label">Organization: </label>
360                     <div class="col-sm-9" >
361                         <input class="form-control" type="text" id="edit_seedlot_details_organization" value="LOADING..."/>
362                     </div>
363                 </div>
364                 <div class="form-group">
365                     <label class="col-sm-3 control-label">Location Code: </label>
366                     <div class="col-sm-9" >
367                         <input class="form-control" type="text" id="edit_seedlot_details_location" value="LOADING..."/>
368                     </div>
369                 </div>
370                 <div class="form-group">
371                     <label class="col-sm-3 control-label">Box Name: </label>
372                     <div class="col-sm-9" >
373                         <input class="form-control" type="text" id="edit_seedlot_details_box_name" value="LOADING..."/>
374                     </div>
375                 </div>
377                 <div class="form-group">
378                   <label class="col-sm-3 control-label">Quality issues: </label>
379                   <div class="col-sm-9" >
380                     <input class="form-control" id="edit_seedlot_details_quality" placeholder="Leave blank for no issues">
381                   </div>
382                 </div>
384                 <div class="well well-sm">
385                     <div class="row">
386                         <div class="col-sm-3">
387                             <div class="form-group">
388                                 <label class="col-sm-12 control-label">Contents: </label>
389                             </div>
390                         </div>
391                         <div class="col-sm-9">
392                             <div class="panel panel-default">
393                                 <div class="panel-body">
394                                     <div class="form-group">
395                                         <label class="col-sm-3 control-label">Accession name: </label>
396                                         <div class="col-sm-9" >
397                                             <input class="form-control" id="edit_seedlot_details_accession" placeholder="One Content Required">
398                                         </div>
399                                     </div>
400                                 </div>
401                             </div>
402                             <center><h4>OR</h4></center>
403                             <div class="panel panel-default">
404                                 <div class="panel-body">
405                                     <div class="form-group">
406                                         <label class="col-sm-3 control-label">Cross Unique ID: </label>
407                                         <div class="col-sm-9" >
408                                             <input class="form-control" id="edit_seedlot_details_cross" placeholder="One Content Required">
409                                         </div>
410                                     </div>
411                                 </div>
412                             </div>
413                         </div>
414                     </div>
415                 </div>
417                 <!--
418                 <div class="form-group">
419                     <label class="col-sm-3 control-label">Population: </label>
420                     <div class="col-sm-9" >
421                         <input class="form-control" type="text" id="edit_seedlot_details_population" value="LOADING..."/>
422                     </div>
423                 </div>
424                 -->
425             </form>
426         </div>
427       </div>
428       <div class="modal-footer">
429         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
430         <button id="edit_seedlot_details_button" type="button" class="btn btn-primary" >Save</button>
431       </div>
432     </div>
433   </div>
434 </div>
436 <div class="modal fade" id="transaction_saved_dialog_message" name="transaction_saved_dialog_message" tabindex="-1" role="dialog" aria-labelledby="transactionSavedDialog">
437     <div class="modal-dialog" role="document">
438         <div class="modal-content">
439             <div class="modal-header">
440                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
441                 <h4 class="modal-title" id="transactionSavedDialog">Success</h4>
442             </div>
443             <div class="modal-body">
444                 <div class="container-fluid">
445                     <p>
446                         <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
447                         The transaction was saved successfully.
448                     </p>
449                 </div>
450             </div>
451             <div class="modal-footer">
452                 <button id="dismiss_transaction_saved_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close & Reload</button>
453             </div>
454         </div>
455     </div>
456 </div>
458 <script>
459   jQuery(document).ready(function () {
461     jQuery('#add_seedlot_transaction_button').click( function() {
462         get_select_box('seedlots', 'seedlot_transaction_seedlot_div', { 'name' : 'seedlot_transaction_seedlot_id', 'id' : 'seedlot_transaction_seedlot_id', 'multiple':'0', 'seedlot_content_accession_name':'<% $content_accession_name %>', 'seedlot_content_cross_name':'<% $content_cross_name %>', 'exclude_discarded': '1', 'seedlot_id':'<% $seedlot_id %>', 'exclude_self': '1' });
463         get_select_box('seedlots', 'seedlot_transaction_to_seedlot_existing', { 'name' : 'seedlot_transaction_to_seedlot_existing_id', 'id' : 'seedlot_transaction_to_seedlot_existing_id', 'multiple':'0', 'seedlot_content_accession_name':'<% $content_accession_name %>', 'seedlot_content_cross_name':'<% $content_cross_name %>', 'exclude_discarded': '1', 'seedlot_id':'<% $seedlot_id %>' });
464         get_select_box('breeding_programs', 'transaction_new_seedlot_breeding_program_div', { 'name' : 'transaction_new_seedlot_breeding_program_id', 'id' : 'transaction_new_seedlot_breeding_program_id' });
465         jQuery('#add_seedlot_transaction_dialog').modal('show')
466     });
468     jQuery("#transaction_new_seedlot_location").autocomplete({
469        source: '/ajax/stock/geolocation_autocomplete',
470     });
471     jQuery("#edit_seedlot_details_accession").autocomplete({
472        source: '/ajax/stock/accession_autocomplete',
473     });
474     jQuery("#edit_seedlot_details_cross").autocomplete({
475        source: '/ajax/stock/cross_autocomplete',
476     });
478     var status = "<% $status %>";
479     var seedlot_transactions_table = jQuery('#available_seedlot_transactions_table').DataTable( {
480         'ajax': '/ajax/breeders/seedlot/<% $seedlot_id %>/transactions',
481         columns: [
482             { title: "Transaction Id", "data": "transaction_id" },
483             { title: "Transaction Date", "data": "timestamp" },
484             { title: "From", "data": "from" },
485             { title: "To", "data": "to" },
486             { title: "Transaction Num Seeds", "data": "value" },
487             { title: "Transaction Weight (g)", "data": "weight" },
488             { title: "Operator", "data": "operator" },
489             { title: "Transaction Description", "data": "description" },
490             { title: "Options", "data": "null", "render" : function ( data, type, row ) {
491                 if (status == 'discarded') {
492                     return "";
493                 } else {return "<a onclick='editSeedlotTransaction("+row.transaction_id+")' >[Edit]</a>";}
494             }},
495         ],
496     });
498     jQuery.ajax({
499         url: '/ajax/breeders/seedlot/<% $seedlot_id %>',
500         success: function(response) {
501             //console.log(response);
502             if (response.success == 1) {
503                 jQuery('#seedlot_location_code_div').html(response.location_code);
504                 jQuery('#seedlot_breeding_program_div').html(response.breeding_program);
505                 jQuery('#edit_seedlot_details_uniquename').val(response.uniquename);
506                 jQuery('#edit_seedlot_details_description').val(response.description);
507                 jQuery('#edit_seedlot_details_breeding_program').val(response.breeding_program);
508                 jQuery('#edit_seedlot_details_organization').val(response.organization_name);
509                 jQuery('#edit_seedlot_details_population').val(response.population_name);
510                 jQuery('#edit_seedlot_details_location').val(response.location_code);
511                 jQuery('#edit_seedlot_details_box_name').val(response.box_name);
512                 jQuery('#edit_seedlot_details_quality').val(response.quality);
513                 var accession_name = '';
514                 if (response.accession){
515                     accession_name = response.accession[1];
516                 }
517                 var cross_name = '';
518                 if (response.cross){
519                     cross_name = response.cross[1];
520                 }
521                 jQuery('#edit_seedlot_details_accession').val(accession_name);
522                 jQuery('#edit_seedlot_details_cross').val(cross_name);
523             }
524             if (response.error) {
525                 alert(response.error);
526             }
527         },
528         error: function(response) {
529             alert('An error occurred retrieving seedlot details');
530         }
531     });
533     jQuery('#create_new_seedlot_transaction_button').click( function() {
534         var factor = jQuery('#seedlot_transaction_factor').val();
535         var to_new = jQuery('#seedlot_transaction_to_seedlot_new').val();
536         var from_existing_seedlot_id_array;
537         var from_existing_seedlot_id;
538         var to_existing_seedlot_id_array;
539         var to_existing_seedlot_id;
540         var to_new_seedlot_name;
541         var to_new_seedlot_description;
542         var to_new_seedlot_breeding_program_id;
543         var to_new_seedlot_location_name;
544         var to_new_seedlot_box_name;
545         var to_new_seedlot_quality;
546         var to_new_seedlot_accession_name;
547         var to_new_seedlot_cross_name;
548         var to_new_seedlot_amount;
549         var to_new_seedlot_weight;
550         var to_new_seedlot_population_name;
551         var to_new_seedlot_organization;
552         var to_new_seedlot_timestamp;
554         if (factor == 1){
555             from_existing_seedlot_id_array = jQuery('#seedlot_transaction_seedlot_id').val();
556             if (from_existing_seedlot_id_array.length > 1) {
557                 alert("Please select only one seedlot.");
558                 return;
559             } else {
560                 from_existing_seedlot_id = from_existing_seedlot_id_array[0];
561             }
562         }
563         if (factor == -1){
564             if (to_new == 'no'){
565                 to_existing_seedlot_id_array = jQuery('#seedlot_transaction_to_seedlot_existing_id').val();
566                 if (to_existing_seedlot_id_array.length > 1) {
567                     alert("Please select only one seedlot.");
568                     return;
569                 } else {
570                     to_existing_seedlot_id = to_existing_seedlot_id_array[0];
571                 }
572             }
573             if (to_new == 'yes'){
574                 to_new_seedlot_name = jQuery('#transaction_new_seedlot_name').val();
575                 to_new_seedlot_breeding_program_id = jQuery('#transaction_new_seedlot_breeding_program_id').val();
576                 to_new_seedlot_location_name = jQuery('#transaction_new_seedlot_location').val();
577                 to_new_seedlot_box_name = jQuery('#transaction_new_seedlot_box_name').val();
578                 to_new_seedlot_accession_name = "<% $content_accession_name %>";
579                 to_new_seedlot_cross_name = "<% $content_cross_name %>";
580                 to_new_seedlot_amount = jQuery('#transaction_new_seedlot_amount').val();
581                 to_new_seedlot_weight = jQuery('#transaction_new_seedlot_weight').val();
582                 to_new_seedlot_population_name = jQuery('#transaction_new_seedlot_population_name').val();
583                 to_new_seedlot_organization = jQuery('#transaction_new_seedlot_organization').val();
584                 to_new_seedlot_timestamp = jQuery('#transaction_new_seedlot_timestamp').val();
585                 to_new_seedlot_description = jQuery('#transaction_new_seedlot_description').val();
586                 to_new_seedlot_quality = jQuery('#transaction_new_seedlot_quality').val();
588                 if (to_new_seedlot_accession_name == '' && to_new_seedlot_cross_name == '') {
589                     alert("Please provide an accession name or a cross unique id as the content of the seedlot."); return;
590                 }
591                 if (to_new_seedlot_accession_name != '' && to_new_seedlot_cross_name != '') {
592                     alert("Please provide an accession name OR a cross unique id as the content of the seedlot. Not both."); return;
593                 }
594                 if (to_new_seedlot_location_name == ''){
595                     alert("Please provide a location for new seedlot."); return;
596                 }
597                 if (to_new_seedlot_box_name == ''){
598                     alert("Please provide a box name for new seedlot."); return;
599                 }
600                 if (to_new_seedlot_amount == '' && to_new_seedlot_weight == ''){
601                     alert("Please provide a starting amount OR weight in grams for new seedlot."); return;
602                 }
603                 if (to_new_seedlot_timestamp == ''){
604                     alert("Please provide a timestamp for new seedlot created."); return;
605                 }
606             }
607         }
608         var amount = jQuery('#seedlot_transaction_amount').val();
609         var weight = jQuery('#seedlot_transaction_weight').val();
610         var timestamp = jQuery('#seedlot_transaction_timestamp').val();
611         var transaction_description = jQuery('#seedlot_transaction_description').val();
613         if (factor == '') { alert("Please provide a factor"); }
614         else if (amount == '' && weight == '') { alert("Please provide an amount OR a weight in grams"); }
615         else if (timestamp == '') { alert("Please provide a timestamp"); }
616         else if (from_existing_seedlot_id == '' && to_existing_seedlot_id == '' && to_new_seedlot_name == '') { alert("Please provide seed lot"); }
617         else {
619             jQuery.ajax( {
620                 url: '/ajax/breeders/seedlot/<% $seedlot_id %>/transaction/add',
621                 data : {
622                     'factor' : factor,
623                     'seedlot_id': <% $seedlot_id %>,
624                     'amount': amount,
625                     'weight': weight,
626                     'timestamp': timestamp,
627                     'transaction_description': transaction_description,
628                     'from_existing_seedlot_id': from_existing_seedlot_id,
629                     'to_existing_seedlot_id': to_existing_seedlot_id,
630                     'to_new_seedlot_name' : to_new_seedlot_name,
631                     'to_new_seedlot_breeding_program_id': to_new_seedlot_breeding_program_id,
632                     'to_new_seedlot_location_name': to_new_seedlot_location_name,
633                     'to_new_seedlot_box_name': to_new_seedlot_box_name,
634                     'to_new_seedlot_accession_name': to_new_seedlot_accession_name,
635                     'to_new_seedlot_cross_name': to_new_seedlot_cross_name,
636                     'to_new_seedlot_amount': to_new_seedlot_amount,
637                     'to_new_seedlot_weight': to_new_seedlot_weight,
638                     'to_new_seedlot_population_name': to_new_seedlot_population_name,
639                     'to_new_seedlot_organization': to_new_seedlot_organization,
640                     'to_new_seedlot_timestamp': to_new_seedlot_timestamp,
641                     'to_new_seedlot_description': to_new_seedlot_description,
642                     'to_new_seedlot_quality': to_new_seedlot_quality
643                 },
644                 beforeSend: function(){
645                     jQuery('#working_modal').modal('show');
646                 },
647                 success: function(response) {
648                     jQuery('#working_modal').modal('hide');
649                     if (response.success == 1) {
650                         jQuery('#add_seedlot_transaction_dialog').modal('hide');
651                         jQuery('#transaction_saved_dialog_message').modal('show');
652                         seedlot_transactions_table.ajax.reload();
653                     }
654                     if (response.error) {
655                         alert(response.error);
656                     }
657                 },
658                 error: function(response) {
659                     jQuery('#working_modal').modal('hide');
660                     alert('An error occurred creating seedlot transaction');
661                 }
662             });
663         }
664     });
666     jQuery('#seedlot_transaction_factor').change(function(){
667         var transaction_factor = jQuery('#seedlot_transaction_factor').val();
668         if (transaction_factor == 1){
669             jQuery('#seedlot_transaction_to_seedlot').hide();
670             jQuery('#seedlot_transaction_from_seedlot').show();
671         }
672         if (transaction_factor == -1){
673             jQuery('#seedlot_transaction_from_seedlot').hide();
674             jQuery('#seedlot_transaction_to_seedlot').show();
675         }
676     });
678     jQuery('#seedlot_transaction_to_seedlot_new').change(function(){
679         var option = jQuery('#seedlot_transaction_to_seedlot_new').val();
680         if (option == 'yes'){
681             jQuery('#seedlot_transaction_to_seedlot_new_no').hide();
682             jQuery('#seedlot_transaction_to_seedlot_new_yes').show();
683         }
684         if (option == 'no'){
685             jQuery('#seedlot_transaction_to_seedlot_new_no').show();
686             jQuery('#seedlot_transaction_to_seedlot_new_yes').hide();
687         }
688     });
690     jQuery('#edit_seedlot_transaction_button').click(function(){
691         var transaction_id = jQuery('#edit_seedlot_transaction_id').val();
692         var operator = jQuery('#edit_seedlot_transaction_operator').val();
693         var amount = jQuery('#edit_seedlot_transaction_amount').val();
694         var weight = jQuery('#edit_seedlot_transaction_weight').val();
695         var transaction_description =  jQuery('#edit_seedlot_transaction_description').val();
696         var timestamp = jQuery('#edit_seedlot_transaction_timestamp').val();
697         if (transaction_id == ''){
698             alert('Transaction ID must not be blank');
699         } else if (operator == ''){
700             alert('Operator must not be blank');
701         } else if (amount == '' && weight == ''){
702             alert('Amount OR weight must not be blank');
703         } else if (timestamp == ''){
704             alert('Timestamp must not be blank');
705         } else {
706             jQuery.ajax({
707                 url: '/ajax/breeders/seedlot/<% $seedlot_id %>/transaction/'+transaction_id+'/edit',
708                 data: {
709                     'operator':operator,
710                     'amount':amount,
711                     'weight_gram':weight,
712                     'description':transaction_description,
713                     'timestamp':timestamp
714                 },
715                 beforeSend: function(){
716                     jQuery('#working_modal').modal('show');
717                 },
718                 success: function(response) {
719                     jQuery('#working_modal').modal('hide');
720                     if (response.success == 1) {
721                         jQuery('#edit_seedlot_transaction_dialog').modal('hide');
722                         jQuery('#transaction_saved_dialog_message').modal('show');
723                         seedlot_transactions_table.ajax.reload();
724                     }
725                     if (response.error) {
726                         alert(response.error);
727                     }
728                 },
729                 error: function(response) {
730                     jQuery('#working_modal').modal('hide');
731                     alert('An error occurred editing seedlot transaction details');
732                 }
733             });
734         }
735     });
737     jQuery('#edit_seedlot_details_link').click(function(){
738         jQuery('#edit_seedlot_details_dialog').modal('show');
739     });
741     jQuery('#edit_seedlot_details_button').click(function(){
742         var uniquename = jQuery('#edit_seedlot_details_uniquename').val();
743         var description = jQuery('#edit_seedlot_details_description').val();
744         var breeding_program = jQuery('#edit_seedlot_details_breeding_program').val();
745         var organization = jQuery('#edit_seedlot_details_organization').val();
746         var population = jQuery('#edit_seedlot_details_population').val();
747         var location = jQuery('#edit_seedlot_details_location').val();
748         var box_name = jQuery('#edit_seedlot_details_box_name').val();
749         var quality = jQuery('#edit_seedlot_details_quality').val();
750         var accession = jQuery('#edit_seedlot_details_accession').val();
751         var cross = jQuery('#edit_seedlot_details_cross').val();
752         if (uniquename == ''){
753             alert('Seedlot name must not be blank');
754         } else if (breeding_program == ''){
755             alert('Breeding program must not be blank');
756         } else if (location == ''){
757             alert('Location must not be blank');
758         } else if (accession == '' && cross == '') {
759             alert("Please provide an accession name or a cross unique id as the content of the seedlot."); return;
760         }
761         else if (accession != '' && cross != '') {
762             alert("Please provide an accession name OR a cross unique id as the content of the seedlot. Not both."); return;
763         }
764         else {
765             jQuery.ajax({
766                 url: '/ajax/breeders/seedlot/<% $seedlot_id %>/edit',
767                 data: {
768                     'uniquename':uniquename,
769                     'description':description,
770                     'breeding_program':breeding_program,
771                     'organization':organization,
772                     'population':population,
773                     'location':location,
774                     'box_name':box_name,
775                     'quality' : quality,
776                     'accession':accession,
777                     'cross':cross
778                 },
779                 beforeSend: function(){
780                     jQuery('#working_modal').modal('show');
781                 },
782                 success: function(response) {
783                     jQuery('#working_modal').modal('hide');
784                     if (response.success == 1) {
785                         alert('Seedlot updated!');
786                         document.location.reload();
787                     }
788                     if (response.error) {
789                         alert(response.error);
790                     }
791                 },
792                 error: function(response) {
793                     jQuery('#working_modal').modal('hide');
794                     alert('An error occurred editing seedlot details');
795                 }
796             });
797         }
798     });
800     jQuery('#dismiss_transaction_saved_dialog').click(function(){
801         location.reload();
802     });
806 function editSeedlotTransaction(transaction_id){
807     jQuery.ajax({
808         url: '/ajax/breeders/seedlot/<% $seedlot_id %>/transaction/'+transaction_id,
809         beforeSend: function(){
810             jQuery('#working_modal').modal('show');
811         },
812         success: function(response) {
813             jQuery('#working_modal').modal('hide');
814             if (response.success == 1) {
815                 html = '<form class="form-horizontal"><div class="form-group"><label class="col-sm-3 control-label">Transaction ID: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_id" value="'+response.transaction_id+'" disabled /></div></div><div class="form-group"><label class="col-sm-3 control-label">Operator: </label><div class="col-sm-9" ><input type="text" id="edit_seedlot_transaction_operator" class="form-control" value="'+response.operator+'" /></div></div><div class="form-group"><label class="col-sm-3 control-label">Transaction Type: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_type" value="'+response.transaction_type+'" disabled/></div></div><div class="form-group"><label class="col-sm-3 control-label">Amount (Number of seeds): </label><div class="col-sm-9" ><input type="number" class="form-control" id="edit_seedlot_transaction_amount" value="'+response.amount+'" /></div></div><div class="form-group"><label class="col-sm-3 control-label">Weight (g): </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_weight" value="'+response.weight_gram+'" /></div></div><div class="form-group"><label class="col-sm-3 control-label">Timestamp: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_timestamp" value="'+response.timestamp+'" disabled /></div></div><div class="form-group"><label class="col-sm-3 control-label">Transaction Description: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_description" value="'+response.description+'" /></div></div></form>';
816                 jQuery('#edit_seedlot_transaction_div').html(html);
817                 jQuery('#edit_seedlot_transaction_dialog').modal('show');
818             }
819             if (response.error) {
820                 alert(response.error);
821             }
822         },
823         error: function(response){
824             jQuery('#working_modal').modal('hide');
825             alert('An error occurred getting seedlot transaction');
826         }
827     });
830 </script>