5 $timestamp => localtime()
6 $locations_by_program_json
9 <& /util/import_javascript.mas, classes => [ 'jquery', 'jquery.dataTables' ] &>
10 <& /util/import_css.mas, paths => ['/documents/inc/datatables/jquery.dataTables.css'] &>
12 <table class="table table-hover table-bordered" id="seedlots_from_crossingtrial_table">
15 <div class="modal fade" id="add_cross_seedlot_dialog" name="add_cross_seedlot_dialog" tabindex="-1" role="dialog" aria-labelledby="add_seedlot_dialog">
16 <div class="modal-dialog modal-lg" role="document">
17 <div class="modal-content">
18 <div class="modal-header">
19 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
20 <h4 class="modal-title" id="add_seedlot_dialog">Add New Seedlot</h4>
22 <div class="modal-body">
23 <div class="container-fluid">
24 <div id="add_cross_seedlot_div">
28 <div class="modal-footer">
29 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
30 <button id="add_cross_seedlot_button" type="button" class="btn btn-primary" >Add</button>
39 jQuery(document).ready(function(){
41 jQuery('#seedlots_from_crossingtrial_section_onswitch').click(function(){
43 var breeding_program_name = "<% $breeding_program_name %>";
44 var breeding_program_id = "<% $breeding_program_id %>";
45 var time = "<% $timestamp %>";
46 var locations_by_program_json = <% $locations_by_program_json %>;
48 var seedlots_crossingtrial_table = jQuery('#seedlots_from_crossingtrial_table').DataTable({
50 'ajax':'/ajax/breeders/trial/'+ <% $trial_id %> + '/seedlots_from_crossingtrial',
53 { title: "Cross Unique ID", "data": null, "render": function ( data, type, row ) { return "<a href='/cross/"+row.cross_id+"'>"+row.cross_name+"</a>"; } },
54 { title: "Seedlot Name", "data": null, "render": function ( data, type, row ) {
55 if (row.seedlot_id === null){
58 return "<a href='/breeders/seedlot/"+row.seedlot_id+"'>"+row.seedlot_name+"</a>"
61 { title: "Add New Seedlot", "data": "null", "render": function ( data, type, row ) { return "<a onclick='addSeedlot(\""+row.cross_name+"\", \""+breeding_program_name+"\", \""+breeding_program_id+"\", \""+locations_by_program_json+"\", \""+time+"\")' >Add</a>"; } },
66 jQuery('#add_cross_seedlot_button').click( function() {
68 var seedlot_name = jQuery('#new_seedlot_name').val();
70 alert ("Seedlot name is required");
74 var seedlot_program = jQuery('#new_seedlot_program').val();
75 if (!seedlot_program) {
76 alert ("Error retrieving breeding program name");
80 var seedlot_program_id = jQuery('#new_seedlot_breeding_program_id').val();
81 if (!seedlot_program_id) {
82 alert ("Error retrieving breeding program id");
86 var seedlot_location = jQuery('#new_seedlot_location').val();
87 if (!seedlot_location) {
88 alert ("Location is required");
92 var box_name = jQuery('#new_seedlot_box_name').val();
94 alert ("Box name is required");
98 var seedlot_content = jQuery('#new_seedlot_content').val();
99 if (!seedlot_content) {
100 alert ("Cross Unique ID is required");
104 var seedlot_amount = jQuery('#new_seedlot_amount').val();
105 var seedlot_weight = jQuery('#new_seedlot_weight').val();
106 if (!seedlot_amount && !seedlot_weight) {
107 alert ("Seedlot amount or weight is required");
111 var seedlot_organization = jQuery('#new_seedlot_organization').val();
113 var seedlot_timestamp = jQuery('#new_seedlot_timestamp').val();
114 if (!seedlot_timestamp) {
115 alert ("Timestamp is required");
119 var seedlot_description = jQuery('#new_seedlot_description').val();
122 url: '/ajax/breeders/seedlot-create',
124 'seedlot_name' : seedlot_name,
125 'seedlot_location': seedlot_location,
126 'seedlot_box_name':box_name,
127 'seedlot_cross_uniquename': seedlot_content,
128 'seedlot_organization': seedlot_organization,
129 'seedlot_amount':seedlot_amount,
130 'seedlot_weight':seedlot_weight,
131 'seedlot_timestamp':seedlot_timestamp,
132 'seedlot_description':seedlot_description,
133 'seedlot_breeding_program_id':seedlot_program_id
135 beforeSend: function(response){
136 jQuery('#working_modal').modal('show');
138 success: function(response) {
139 jQuery('#working_modal').modal('hide');
140 if (response.success == 1) {
141 alert("The seedlot has been added.");
142 jQuery('#add_cross_seedlot_dialog').modal('hide');
145 if (response.error) {
146 alert(response.error);
149 error: function(response){
150 jQuery('#working_modal').modal('hide');
151 alert('An error occurred adding seedlot');
158 function addSeedlot(cross_name, breeding_program_name, breeding_program_id,locations_by_program_json, time){
160 var locations = locations_by_program_json.split (",");
162 html = html + '<form class="form-horizontal"><div class="form-group"><label class="col-sm-4 control-label">Cross Unique ID: </label><div class="col-sm-8" ><input class="form-control" id="new_seedlot_content" name="new_seedlot_content" value="'+cross_name+'" disabled></div></div>';
163 html = html + '<div class="form-group"><label class="col-sm-4 control-label">Seedlot Name: </label><div class="col-sm-8" ><input class="form-control" id="new_seedlot_name" name="new_seedlot_name" placeholder="Required"></div></div>';
164 html = html + '<div class="form-group"><label class="col-sm-4 control-label">Breeding Program: </label><div class="col-sm-8" ><input class="form-control" id="new_seedlot_program" name="new_seedlot_program" value="'+breeding_program_name+'" disabled></div></div>';
165 html = html + '<div class="form-group"><label class="col-sm-4 control-label">Location: </label><div class="col-sm-8" ><select class="form-control" id="new_seedlot_location" name="new_seedlot_location"><option disabled value="" selected hidden>Select a location</option>';
167 for (var i=0; i<locations.length; i++) {
168 html = html + '<option value='+locations[i]+'>'+locations[i]+'</option>';
171 html = html + '</select></div></div>';
172 html = html + '<div class="form-group"><label class="col-sm-4 control-label">Box Name: </label><div class="col-sm-8" ><input class="form-control" id="new_seedlot_box_name" name="new_seedlot_box_name" placeholder="Required"></div></div>';
173 html = html + '<div class="form-group"><label class="col-sm-4 control-label">Amount: </label><div class="col-sm-8" ><input class="form-control" id="new_seedlot_amount" name="new_seedlot_amount" placeholder="Amount (number of seeds) OR Weight (g), required"></div></div>';
174 html = html + '<div class="form-group"><label class="col-sm-4 control-label">Weight (g): </label><div class="col-sm-8" ><input class="form-control" id="new_seedlot_weight" name="new_seedlot_weight" placeholder="Amount (number of seeds) OR Weight (g), required"></div></div>';
175 html = html + '<div class="form-group"><label class="col-sm-4 control-label">Organization: </label><div class="col-sm-8" ><input class="form-control" id="new_seedlot_organization" name="new_seedlot_organization" placeholder="Optional"></div></div>';
176 html = html + '<div class="form-group"><label class="col-sm-4 control-label">Timestamp: </label><div class="col-sm-8" ><input class="form-control" id="new_seedlot_timestamp" name="new_seedlot_timestamp" value="'+time+'"></div></div>';
177 html = html + '<div class="form-group"><label class="col-sm-4 control-label">Description: </label><div class="col-sm-8" ><input class="form-control" id="new_seedlot_description" name="new_seedlot_description" placeholder="Optional"></div></div></form>';
178 html = html + '<div class="form-group"><input id="new_seedlot_breeding_program_id" type="hidden" value="'+breeding_program_id+'"/>';
180 jQuery('#add_cross_seedlot_div').html(html);
181 jQuery('#add_cross_seedlot_dialog').modal('show');