fix test with new description field.
[sgn.git] / mason / breeders_toolbox / create_tissue_samples_dialogs.mas
blob6d1d12d44c67f82bad638230c160c702b7b42ce5
1 <%args>
2 </%args>
4 <& /util/import_javascript.mas, classes => [ 'CXGN.BreedersToolbox.GenotypingTrial' ] &>
6 <div class="modal fade" id="field_trial_tissue_sample_dialog" name="field_trial_tissue_sample_dialog" tabindex="-1" role="dialog" aria-labelledby="addFieldTrialTissueSampleDialog">
7     <div class="modal-dialog modal-xl" role="document">
8         <div class="modal-content">
9             <div class="modal-header">
10                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
11                 <h4 class="modal-title" id="addFieldTrialTissueSampleDialog">Create Tissue Samples for a Field Trial</h4>
12             </div>
13             <div class="modal-body">
15                 <div class="container-fluid">
17                     <&| /util/workflow.mas, id=> "field_tissue_samples_create_workflow" &>
18                         <&| /util/workflow.mas:step, title=> "Intro" &>
19                             <& /page/page_title.mas, title=>"This workflow will guide you through creating tissue samples for your field trial" &>
20                             <p>Tissue samples are linked to a single plant, which is in turn linked to a single plot.</p>
21                             <p>Many tissue samples can be created for each plant.</p>
22                             <p>Each tissue sample needs a globally unique name.</p>
23                             <p>Tissue samples can then be transferred into genotyping plates (96 or 384 well plates).</p>
25                             <br/><br/>
26                             <center>
27                             <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
28                             </center>
29                         </&>
31                         <&| /util/workflow.mas:step, title=> "Select a field trial" &>
32                             <& /page/page_title.mas, title=>"Select a field trial" &>
34                             <div class="well well-sm">
35                                 <div class="panel panel-default">
36                                     <div class="panel-body">
37                                         <table id="manage_tissue_samples_field_search_results" class="table table-hover table-striped">
38                                             <thead>
39                                                 <tr>
40                                                     <th>Select</th>
41                                                     <th>Trial name</th>
42                                                     <th>Description</th>
43                                                     <th>Breeding program</th>
44                                                     <th>Folder</th>
45                                                     <th>Year</th>
46                                                     <th>Location</th>
47                                                     <th>Trial type</th>
48                                                     <th>Design</th>
49                                                     <th>Planting Date</th>
50                                                     <th>Harvest Date</th>
51                                                     <th>Download</th>
52                                                 </tr>
53                                             </thead>
54                                         </table>
55                                     </div>
56                                 </div>
57                             </div>
59                             <br/><br/>
60                             <center>
61                                 <button class="btn btn-primary" id="create_tissue_samples_select_trial">Go to Next Step</button>
62                             </center>
64                         </&>
65                         <&| /util/workflow.mas:step, title=> "Plant Entries" &>
66                             <& /page/page_title.mas, title=>"Plant entries in your field trial" &>
68                             <div id="create_tissue_samples_plant_entries_exist_section" style="display:none">
69                                 <h4>Plant entries exist for this trial. Go to next step.</h4>
70                                 <center>
71                                 <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
72                                 </center>
73                             </div>
74                             <div id="create_tissue_samples_plant_entries_dont_exist_section" style="display:none">
75                                 <h4>Please create plant entries for this trial.</h4>
76                                 <form class="form-horizontal">
77                                     <div class="form-group">
78                                         <label class="col-sm-3 control-label">Number of plants per plot: </label>
79                                         <div class="col-sm-9" >
80                                             <input name="create_tissue_samples_plants_per_plot_num" id="create_tissue_samples_plants_per_plot_num" class="form-control" type="number" autofocus/>
81                                         </div>
82                                     </div>
83                                     <div class="form-group">
84                                         <label class="col-sm-3 control-label">Inherits Management Factor(s) From Plots: </label>
85                                         <div class="col-sm-9" >
86                                             <input name="create_tissue_samples_plants_per_plot_inherit_treatments" id="create_tissue_samples_plants_per_plot_inherit_treatments" type="checkbox" checked disabled/>
87                                         </div>
88                                     </div>
89                                 </form><br/>
90                                 <center>
91                                     <button type="button" class="btn btn-primary" id="create_tissue_samples_plants_per_plot_submit">Submit</button>
92                                 </center>
93                             </div>
95                         </&>
96                         <&| /util/workflow.mas:step, title=> "Create Tissue Sample Entries" &>
97                             <& /page/page_title.mas, title=>"Create tissue sample entries for this trial" &>
99                             <form class="form-horizontal" >
100                                 <div class="form-group">
101                                     <label class="col-sm-3 control-label"><span title="You can use the same tissue name, e.g. root and root, more than once below. The tissue name will still be unique because of a tissue index e.g. 1 and 2 added to the end." </span><span class="glyphicon glyphicon-info-sign"></span>&nbsp;&nbsp;Number of tissue samples per plant: </span></label>
102                                     <div class="col-sm-9" >
103                                         <input name="create_tissue_samples_per_plant_num" id="create_tissue_samples_per_plant_num" class="form-control" type="text" autofocus/>
104                                     </div>
105                                 </div>
107                                 <div id="create_tissue_samples_names_div">
108                                 </div>
111                                 <div class="form-group">
112                                     <label class="col-sm-3 control-label">Inherits Management Factor(s) From Plots: </label>
113                                     <div class="col-sm-9" >
114                                         <input name="create_tissue_samples_per_plant_inherit_treatments" id="create_tissue_samples_per_plant_inherit_treatments" type="checkbox"/>
115                                     </div>
116                                 </div>
117                                 <div class="form-group">
118                                     <label class="col-sm-3 control-label">Use Tissue Numbers: </label>
119                                     <div class="col-sm-9" >
120                                         <input name="create_tissue_samples_per_plant_use_tissue_numbers" id="create_tissue_samples_per_plant_use_tissue_numbers" type="checkbox"/>
121                                     </div>
122                                 </div>
123                             </form><br/>
124                             <center>
125                             <button type="button" class="btn btn-primary" name="create_tissue_samples_plants_per_plant_submit" id="create_tissue_samples_plants_per_plant_submit">Submit</button>
126                             </center>
127                         </&>
128                         <&| /util/workflow.mas:complete, title=> "Complete" &>
129                             <& /page/page_title.mas, title=>"Complete! Your field trial's tissue samples were saved." &>
131                             <p>
132                                 <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
133                                 Tissue samples saved successfully
134                             </p>
136                             <ul>
137                                 <li>You may want to go to the trial detail page for the trial now that it has plants.</li>
138                                 <li>You can print barcodes for the new tissue samples.</li>
139                                 <li>You can use these tissue samples as source material for a genotyping plates (96 or 384 well plate)</li>
140                             </ul>
141                             <br/>
142                         </&>
143                     </&>
145                 </div>
146             </div>
147             <div class="modal-footer">
148                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
149             </div>
150         </div>
151     </div>
152 </div>
154 <script>
155 jQuery(document).ready(function(){
157     var create_tissue_sample_trial_table = jQuery('#manage_tissue_samples_field_search_results').DataTable( {
158         'ajax': {
159             'url':'/ajax/search/trials',
160             'data': function(d) {
161                 d.select_checkbox_name = 'create_tissue_sample_select_trial';
162             }
163         },
164         "scrollX": true
165     });
167     var selected;
168     jQuery('#create_tissue_samples_select_trial').click(function(){
169         selected = [];
170         jQuery('input[name="create_tissue_sample_select_trial"]:checked').each(function() {
171             selected.push(jQuery(this).val());
172         });
173         if (selected.length !== 1){
174             alert('Only select one trial!');
175         } else {
176             new jQuery.ajax({
177                 type: 'POST',
178                 url: '/ajax/breeders/trial/'+selected[0]+'/has_plants',
179                 dataType: "json",
180                 beforeSend: function() {
181                     jQuery("#working_modal").modal("show");
182                 },
183                 success: function (response) {
184                     jQuery("#working_modal").modal("hide");
185                     if (response.has_plants){
186                         jQuery('#create_tissue_samples_plant_entries_exist_section').show();
187                         jQuery('#create_tissue_samples_plant_entries_dont_exist_section').hide();
188                         Workflow.complete('#create_tissue_samples_select_trial');
189                         Workflow.skip('#create_tissue_samples_plant_entries_exist_section');
190                         Workflow.focus("#field_tissue_samples_create_workflow", 3);
191                     } else {
192                         jQuery('#create_tissue_samples_plant_entries_dont_exist_section').show();
193                         jQuery('#create_tissue_samples_plant_entries_exist_section').hide();
194                         Workflow.complete('#create_tissue_samples_select_trial');
195                         Workflow.focus("#field_tissue_samples_create_workflow", 2);
196                     }
197                 },
198                 error: function () {
199                     jQuery("#working_modal").modal("hide");
200                     alert('An error occurred checking trial for plants.');
201                 }
202             });
203         }
204     });
206     jQuery('#create_tissue_samples_plants_per_plot_submit').click(function(){
207         var is_checked;
208         if(jQuery('#create_tissue_samples_plants_per_plot_inherit_treatments').is(":checked")){
209             is_checked = 1;
210         }
212         jQuery.ajax({
213             url: '/ajax/breeders/trial/'+selected[0]+'/create_plant_entries/',
214             type: 'POST',
215             beforeSend: function() {
216                 jQuery("#working_modal").modal("show");
217             },
218             data: {
219                 'plants_per_plot' : jQuery('#create_tissue_samples_plants_per_plot_num').val(),
220                 'inherits_plot_treatments' : is_checked
221             },
222             success: function(response) {
223                 jQuery("#working_modal").modal("hide");
224                 if (response.error) {
225                     alert(response.error);
226                 }
227                 else {
228                     alert("Successfully created plant entries.");
229                     Workflow.complete('#create_tissue_samples_plants_per_plot_submit');
230                     Workflow.focus("#field_tissue_samples_create_workflow", 3);
231                 }
232             },
233             error: function(response) {
234                 jQuery("#working_modal").modal("hide");
235                 alert("An error occurred saving plant entries");
236             },
237         });
238     });
240     jQuery('#create_tissue_samples_per_plant_num').keyup(function(){
241         var num_tissues = jQuery(this).val();
242         var html = '';
243         for (var i=1; i<=num_tissues; i++){
244             html = html + '<div class="form-group"><label class="col-sm-3 control-label"><span title="The sample names will be a combination of the plant name, the tissue name you give here, and the tissue number."><span class="glyphicon glyphicon-info-sign"></span>&nbsp;&nbsp;Tissue Name '+i+': </span></label><div class="col-sm-9" ><input name="create_tissue_samples_tissue_name" id="create_tissue_samples_tissue_name_'+i+'" class="form-control" type="text" placeholder="examples: leaf or root or stem or seed or fruit" /></div></div>';
245         }
246         jQuery('#create_tissue_samples_names_div').html(html);
247     });
249     jQuery('#create_tissue_samples_plants_per_plant_submit').click(function(){
250         var is_checked;
251         if(jQuery('#create_tissue_samples_per_plant_inherit_treatments').is(":checked")){
252             is_checked = 1;
253         }
255         var use_tissue_numbers;
256         if(jQuery('#create_tissue_samples_per_plant_use_tissue_numbers').is(":checked")){
257             use_tissue_numbers = 1;
258         }
260         var tissue_names = [];
261         jQuery('input[name="create_tissue_samples_tissue_name"]').each(function() {
262             tissue_names.push(this.value);
263        
264         });
266         jQuery.ajax({
267             url: '/ajax/breeders/trial/'+selected[0]+'/create_tissue_samples/',
268             type: 'POST',
269             beforeSend: function() {
270                 jQuery("#working_modal").modal("show");
271             },
272             data: {
273                 'tissue_samples_per_plant' : jQuery('#create_tissue_samples_per_plant_num').val(),
274                 'inherits_plot_treatments' : is_checked,
275                 'use_tissue_numbers' : use_tissue_numbers,
276                 'tissue_samples_names' : JSON.stringify(tissue_names)
277             },
278             success: function(response) {
279                 jQuery("#working_modal").modal("hide");
280                 if (response.error) {
281                     alert(response.error);
282                 }
283                 else {
284                     alert("Successfully created tissue sample entries.");
285                     Workflow.complete('#create_tissue_samples_plants_per_plant_submit');
286                     Workflow.focus("#field_tissue_samples_create_workflow", -1); //go to success
287                 }
288             },
289             error: function(response) {
290                 jQuery("#working_modal").modal("hide");
291                 alert("An error occurred creating tissue sample entries");
292             },
293         });
294     });
297 </script>