modified keys
[sgn.git] / mason / breeders_toolbox / seedlots.mas
blobdec9ba3bb2c449d6d16b989a0693b7a72de4ed84
2 <%args>
3 $timestamp
4 $preferred_species
5 $editable_stock_props => {}
6 $editable_stock_props_definitions => {}
7 $programs
8 $locations
9 $crossing_trials
10 $maintenance_enabled => undef
11 $user_role => undef
12 </%args>
14 <& /page/page_title.mas, title=>"Available Seedlots" &>
16 <style>
17 .ui-autocomplete {
18     z-index: 5000;
20 </style>
22   <& /util/import_javascript.mas, classes => [ 'bootstrap_min.js', 'jquery.iframe-post-form','CXGN.List','CXGN.BreedersToolbox.Accessions', 'CXGN.BreedersToolbox.UploadPedigrees', 'jquery', 'jquery.dataTables', 'CXGN.BreedersToolbox.Crosses', 'jqueryui' ] &>
24 <&| /page/info_section.mas, title=>"About Seedlots",  collapsible => 1, collapsed=>1 &>
25     <div class="well well-sm">
26         <div class="panel panel-default">
27             <div class="panel-body">
28                 <b><p>What are seedlots?</p></b>
29                 <ul>
30                 <li>Seedlots represent physical seed in packets.</li>
31                 <li>This seed can be from crosses or for named accessions.</li>
32                 <li>Seedlots can have a specific location, box, weight(g), and count.</li>
33                 <li>Seed can be transferred into and out of a seedlot. Such as from a seedlot into a plot.</li>
34                 <li>Seedlots can belong to breeding programs and organizations.</li>
35                 </ul>
37                 <b><p>How do I inventory my seed?</p></b>
38                 <ul>
39                 <li>Make sure your seedlots are in the database. Use "Add New Seedlot" to add a single seedlot or "Upload New Seedlots" to add many.</li>
40                 <li>Make sure your seedlots are barcoded. You can print these barcodes from the database.</li>
41                 <li>The inventory app is currently not available but you can continue using it if it is installed on your tablet device.
42                 <!-- li>3) Use the "Inventory" Android Application to scan seedlot barcodes and record weight. Then click "Upload Inventory" on the Manage Seedlots page to upload this info into the database. If you do not want to use the Inventory Android Application you can create your own CSV file and upload that.</li --><!-- the app is currently not available - re-instate when it is available again -->
43                 <!-- li><b>For more info about the "Seed Inventory" Android Application go to <a href="https://play.google.com/store/apps/details?id=org.wheatgenetics.inventory/">Inventory</a>.</b></li -->
44                 It is also possible to manually enter a transaction by going to the seedlot detail page and clicking "Add New Transaction".</li>
45                 </ul>
46             </div>
47         </div>
48     </div>
49 </&>
51 <%perl>
52     my $maintenance_button = $maintenance_enabled ? ' <button onclick="location.href=\'/breeders/seedlot/maintenance\'" class="btn btn-sm btn-primary" style="margin:3px" name="seedlot_record_maintenance">Seedlot Maintenance</button>' : '';
53     my $seedlot_subtitle = !!$c->user()
54         ? '<div class="btn-group"><button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Create Seedlot(s)&nbsp;<span class="caret"></span></button><ul class="dropdown-menu"><li><a href="#" name="add_seedlot_button">Add New Seedlot</a></li><li><a href="#" name="seedlot_bulk_upload">Upload Seedlots</a></li><li><a href="#" name="create_seedlots_trial_button">Create Seedlots from Trial</a></li></ul></div>
55         <div class="btn-group"><button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Add/Upload Transactions&nbsp;<span class="caret"></span></button><ul class="dropdown-menu"><li><a href="#" name="transactions_upload_link">Upload a File</a></li><li><a href="#" id="add_transactions_using_list_link" name="add_transactions_using_list_link">Using a List</a></li><li></ul></div>
56         <button class="btn btn-sm btn-primary" style="margin:3px" name="seedlot_upload_inventory">Upload Inventory</button>' . $maintenance_button
57         : "Login to add or upload seedlots";
58 </%perl>
59 <&| /page/info_section.mas, title=>"Seedlots",  collapsible => 1, subtitle => $seedlot_subtitle &>
61 <br/>
63 <div class="well well-sm">
64     <div class="panel panel-default">
65         <div class="panel-body">
67 <&| /page/info_section.mas, title=>"Search Seedlots",  collapsible => 1, collapsed=>0 &>
69 <div class="well well-sm">
70     <form class="form-horizontal" id="search_seedlot_form" name="search_seedlot_form">
71         <div class="form-group form-group-sm">
72             <label class="col-sm-3 control-label">Seedlot Name: </label>
73             <div class="col-sm-9" >
74                 <input class="form-control" id="search_seedlot_form_seedlot_name" type="text" />
75             </div>
76         </div>
77         <div class="form-group form-group-sm">
78             <label class="col-sm-3 control-label">Breeding Program: </label>
79             <div class="col-sm-9" >
80                 <input class="form-control" id="search_seedlot_form_breeding_program" type="text" />
81             </div>
82         </div>
83         <div class="form-group form-group-sm">
84             <label class="col-sm-3 control-label">Contents (Accession Uniquename): </label>
85             <div class="col-sm-7" >
86                 <input class="form-control" id="search_seedlot_form_contents_accession" type="text" />
87             </div>
88             <div class="col-sm-2 form-check form-check-inline align-bottom">
89               <input class="form-check-input" type="checkbox" id="exact_accession" value="1">
90               <label class="form-check-label" for="exact_accession">exact match</label>
91             </div>
92         </div>
93         <div class="form-group form-group-sm">
94             <label class="col-sm-3 control-label">Contents (Cross Unique ID): </label>
95             <div class="col-sm-7" >
96                 <input class="form-control" id="search_seedlot_form_contents_cross" type="text" />
97             </div>
98             <div class="col-sm-2 form-check form-check-inline align-bottom">
99               <input class="form-check-input" type="checkbox" id="exact_cross" value="1">
100               <label class="form-check-label" for="exact_cross">exact match</label>
101             </div>
102         </div>
103         <div class="form-group form-group-sm">
104             <label class="col-sm-3 control-label">Location: </label>
105             <div class="col-sm-9" >
106                 <input class="form-control" id="search_seedlot_form_location" type="text" />
107             </div>
108         </div>
109         <div class="form-group form-group-sm">
110             <label class="col-sm-3 control-label">Box Name: </label>
111             <div class="col-sm-9" >
112                 <input class="form-control" id="search_seedlot_form_box_name" type="text" />
113             </div>
114         </div>
115         <div class="form-group form-group-sm">
116             <label class="col-sm-3 control-label">Minimum Count: </label>
117             <div class="col-sm-9" >
118                 <input class="form-control" id="search_seedlot_form_minimum_count" type="number" />
119             </div>
120         </div>
121         <div class="form-group form-group-sm">
122             <label class="col-sm-3 control-label">Minimum Weight (g): </label>
123             <div class="col-sm-9" >
124                 <input class="form-control" id="search_seedlot_form_minimum_weight" type="number" />
125             </div>
126         </div>
128         <!-- div class="form-group form-group-sm">
129           <label class="col-sm-3 control-label"></label>
130           <div class="col-sm-9" >
131             <input id="search_seedlot_form_only_good_quality_checkbox" type="checkbox" /> Only show seedlots without quality issues
132           </div>
133         </div  -->
135         <div class="form-group form-group-sm">
136             <label class="col-sm-3 control-label">Quality: </label>
137             <div class="col-sm-9" >
138                 <input class="form-control" id="search_seedlot_form_quality" type="text" />
139             </div>
140         </div>
142     </form>
143     <center>
144     <button class="btn btn-primary" id="submit_seedlot_search" />Search</button>
145     </center>
146 </div>
147 </&>
149 <center>
150   Enter search terms and click the "Search" button to view results.
151 </center>
153 <br />
154 <br />
155 <br />
156 <div style="overflow:scroll">
157     <table id="available_seedlots_table" class="table table-hover table-striped table-bordered">
158     </table>
159 </div>
161 <hr>
163 <div id="available_seedlots_to_list" style="display:none">
164 </div>
165 <div id="available_seedlots_add_to_list">
166 </div>
168         </div>
169     </div>
170 </div>
171 </&>
173 <&| /page/info_section.mas, title=>"Mark seedlots as DISCARDED using a list",  collapsible => 1, collapsed=>1 &>
174 % if ($user_role eq "curator" ) {
175     <div class="well well-sm">
176         <div class="panel panel-default">
177             <div class="panel-body">
178                 <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_link">Mark Seedlots as Discarded</button>
179             </div>
180         </div>
181     </div>
182 % } else {
183     You need to be logged in or you do not have sufficient privileges to mark seedlots as DISCARDED using lists.
184 % }
185 </&>
187 <&| /page/info_section.mas, title=>"Delete seedlots using a list",  collapsible => 1, collapsed=>1 &>
188 % if ($user_role eq "curator" ) {
189     <div class="well well-sm">
190         <div class="panel panel-default">
191             <div class="panel-body">
192                 <button class="btn btn-sm btn-primary" style="margin:3px" id="delete_seedlots_link">Delete seedlots using a list</button>
193             </div>
194         </div>
195     </div>
196 % } else {
197     You need to be logged in or you do not have sufficient privileges to delete seedlots.
198 % }
199 </&>
201 <& /breeders_toolbox/upload_seedlots_inventory_dialogs.mas &>
202 <& /breeders_toolbox/upload_seedlots_dialogs.mas &>
203 <& /breeders_toolbox/add_seedlot_dialogs.mas, timestamp=>$timestamp &>
204 <& /breeders_toolbox/add_accessions_dialogs.mas, preferred_species=>$preferred_species, editable_stock_props=>$editable_stock_props, editable_stock_props_definitions=>$editable_stock_props_definitions &>
205 <& /breeders_toolbox/cross/upload_crosses_dialogs.mas, programs=>$programs, locations=>$locations, crossing_trials=>$crossing_trials &>
206 <& /breeders_toolbox/cross/add_cross_dialogs.mas, programs=>$programs, locations=>$locations, crossing_trials=>$crossing_trials &>
207 <& /breeders_toolbox/cross/add_crossing_trial_dialogs.mas, programs=>$programs, locations=>$locations &>
208 <& /breeders_toolbox/create_seedlots_from_trial_dialogs.mas &>
209 <& /breeders_toolbox/delete_seedlots.mas, user_role => $user_role &>
210 <& /breeders_toolbox/discard_seedlots.mas, user_role => $user_role &>
211 <& /breeders_toolbox/discard_undo_seedlot_usage.mas &>
212 <& /breeders_toolbox/upload_transactions_dialogs.mas &>
213 <& /breeders_toolbox/add_transactions_using_list.mas &>
216 <script>
217 jQuery(document).ready(function(){
218     jQuery("#search_seedlot_form_seedlot_name").autocomplete({
219        source: '/ajax/stock/seedlot_name_autocomplete',
220     });
222     var seedlots_table;
224     //run the query only when the search button is clicked
225     jQuery('#submit_seedlot_search').click( function() {
226         if (seedlots_table) { seedlots_table.destroy() };
227         seedlots_table = jQuery('#available_seedlots_table').DataTable({
228             'searching' : false,
229             'ordering'  : false,
230             'processing': true,
231             'serverSide': true,
232             'lengthMenu': [10,20,50,100,1000],
234             columns: [
235                 { title: "Seedlot Name", "data": null, "render": function ( data, type, row ) { return "<a href='/breeders/seedlot/"+row.seedlot_stock_id+"'>"+row.seedlot_stock_uniquename+"</a>"; } },
236                 { title: "Breeding Program", "data": "breeding_program_name" },
237                 { title: "Contents", "data": "contents_html" },
238                 { title: "Location", "data": "location" },
239                 { title: "Count", "data": "count" },
240                 { title: "Weight (g)", "data": "weight_gram" },
241                 { title: "Submitters", "data": "owners_string" },
242                 { title: "Organization", "data": "organization" },
243                 { title: "Box", "data": "box" },
244                 { title: "Quality", "data": "seedlot_quality" },
245                 { title: "Delete", "data": "null", "render": function ( data, type, row ) { return "<a onclick='removeSeedlot("+row.seedlot_stock_id+")' >X</a>"; } },
246                 { title: "", "data": "seedlot_stock_uniquename"}
247             ],
248             'ajax': { 'url': '/ajax/breeders/seedlots',
249                 'data': function(d) {
250                     d.seedlot_name  = jQuery('#search_seedlot_form_seedlot_name').val();
251                     d.breeding_program = jQuery('#search_seedlot_form_breeding_program').val();
252                     d.minimum_count   = jQuery('#search_seedlot_form_minimum_count').val();
253                     d.minimum_weight   = jQuery('#search_seedlot_form_minimum_weight').val();
254                     d.location     = jQuery('#search_seedlot_form_location').val();
255                     d.box_name = jQuery('#search_seedlot_form_box_name').val();
256                     d.contents_accession = jQuery('#search_seedlot_form_contents_accession').val();
257                     d.contents_cross = jQuery('#search_seedlot_form_contents_cross').val();
258                     d.exact_accession = jQuery('#exact_accession').is(":checked") ? 1 : 0;
259                     d.exact_cross = jQuery('#exact_cross').is(":checked") ? 1 : 0;
260                     d.quality = jQuery('#search_seedlot_form_quality').val();
261                     d.only_good_quality = jQuery('#search_seedlot_form_only_good_quality_checkbox').is(":checked") ? 1 : 0;
262                 }
263             },
264         });
266         seedlots_table.draw();
267         seedlots_table.column(11).visible(false);
269     });
272     jQuery('#available_seedlots_table').on( 'draw.dt', function () {
273         var seedlot_names = seedlots_table.column(11).data();
274         var names = "";
276         for (var i = 0; i < seedlot_names.length; i++) {
277             names += seedlot_names[i]+'\n';
278         }
280         jQuery('#available_seedlots_to_list').html(names);
281         addToListMenu('available_seedlots_add_to_list', 'available_seedlots_to_list', {
282             listType: 'seedlots'
283         });
284     });
286     jQuery('#search_seedlot_form').keypress( function( e ) {
287         var code = e.keyCode || e.which;
288         if( code == 13 ) {
289             jQuery('#submit_seedlot_search').click();
290         }
291     });
294 function removeSeedlot(seedlot_stock_id){
295     if (confirm("Are you sure you want to delete this seedlot?")){
296         jQuery.ajax({
297             url: '/ajax/breeders/seedlot/'+seedlot_stock_id+'/delete',
298             beforeSend: function(){
299                 jQuery('#working_modal').modal('show');
300             },
301             success: function(response) {
302                 jQuery('#working_modal').modal('hide');
303                 if (response.success == 1) {
304                     alert("The seedlot has been deleted.");
305                     location.reload();
306                 }
307                 if (response.error) {
308                     alert(response.error);
309                 }
310             },
311             error: function(response){
312                 jQuery('#working_modal').modal('hide');
313                 alert('An error occurred deleting seed lot');
314             }
315         });
316     }
319 </script>