Merge pull request #2864 from solgenomics/topic/fixing_h2_detail_page
[sgn.git] / mason / breeders_toolbox / create_tissue_samples_dialogs.mas
blob91efe186abd7e453f8d952176926551064f8ce6f
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>
110                                 <div class="form-group">
111                                     <label class="col-sm-3 control-label">Inherits Management Factor(s) From Plots: </label>
112                                     <div class="col-sm-9" >
113                                         <input name="create_tissue_samples_per_plant_inherit_treatments" id="create_tissue_samples_per_plant_inherit_treatments" type="checkbox" checked disabled/>
114                                     </div>
115                                 </div>
116                             </form><br/>
117                             <center>
118                             <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>
119                             </center>
120                         </&>
121                         <&| /util/workflow.mas:complete, title=> "Complete" &>
122                             <& /page/page_title.mas, title=>"Complete! Your field trial's tissue samples were saved." &>
124                             <p>
125                                 <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
126                                 Tissue samples saved successfully
127                             </p>
129                             <ul>
130                                 <li>You may want to go to the trial detail page for the trial now that it has plants.</li>
131                                 <li>You can print barcodes for the new tissue samples.</li>
132                                 <li>You can use these tissue samples as source material for a genotyping plates (96 or 384 well plate)</li>
133                             </ul>
134                             <br/>
135                         </&>
136                     </&>
138                 </div>
139             </div>
140             <div class="modal-footer">
141                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
142             </div>
143         </div>
144     </div>
145 </div>
147 <script>
148 jQuery(document).ready(function(){
150     var create_tissue_sample_trial_table = jQuery('#manage_tissue_samples_field_search_results').DataTable( {
151         'ajax': {
152             'url':'/ajax/search/trials',
153             'data': function(d) {
154                 d.select_checkbox_name = 'create_tissue_sample_select_trial';
155             }
156         },
157         "scrollX": true
158     });
160     var selected;
161     jQuery('#create_tissue_samples_select_trial').click(function(){
162         selected = [];
163         jQuery('input[name="create_tissue_sample_select_trial"]:checked').each(function() {
164             selected.push(jQuery(this).val());
165         });
166         if (selected.length !== 1){
167             alert('Only select one trial!');
168         } else {
169             new jQuery.ajax({
170                 type: 'POST',
171                 url: '/ajax/breeders/trial/'+selected[0]+'/has_plants',
172                 dataType: "json",
173                 beforeSend: function() {
174                     jQuery("#working_modal").modal("show");
175                 },
176                 success: function (response) {
177                     jQuery("#working_modal").modal("hide");
178                     if (response.has_plants){
179                         jQuery('#create_tissue_samples_plant_entries_exist_section').show();
180                         jQuery('#create_tissue_samples_plant_entries_dont_exist_section').hide();
181                         Workflow.complete('#create_tissue_samples_select_trial');
182                         Workflow.skip('#create_tissue_samples_plant_entries_exist_section');
183                         Workflow.focus("#field_tissue_samples_create_workflow", 3);
184                     } else {
185                         jQuery('#create_tissue_samples_plant_entries_dont_exist_section').show();
186                         jQuery('#create_tissue_samples_plant_entries_exist_section').hide();
187                         Workflow.complete('#create_tissue_samples_select_trial');
188                         Workflow.focus("#field_tissue_samples_create_workflow", 2);
189                     }
190                 },
191                 error: function () {
192                     jQuery("#working_modal").modal("hide");
193                     alert('An error occurred checking trial for plants.');
194                 }
195             });
196         }
197     });
199     jQuery('#create_tissue_samples_plants_per_plot_submit').click(function(){
200         var is_checked;
201         if(jQuery('#create_tissue_samples_plants_per_plot_inherit_treatments').is(":checked")){
202             is_checked = 1;
203         }
205         jQuery.ajax({
206             url: '/ajax/breeders/trial/'+selected[0]+'/create_plant_entries/',
207             type: 'POST',
208             beforeSend: function() {
209                 jQuery("#working_modal").modal("show");
210             },
211             data: {
212                 'plants_per_plot' : jQuery('#create_tissue_samples_plants_per_plot_num').val(),
213                 'inherits_plot_treatments' : is_checked
214             },
215             success: function(response) {
216                 jQuery("#working_modal").modal("hide");
217                 if (response.error) {
218                     alert(response.error);
219                 }
220                 else {
221                     alert("Successfully created plant entries.");
222                     Workflow.complete('#create_tissue_samples_plants_per_plot_submit');
223                     Workflow.focus("#field_tissue_samples_create_workflow", 3);
224                 }
225             },
226             error: function(response) {
227                 jQuery("#working_modal").modal("hide");
228                 alert("An error occurred saving plant entries");
229             },
230         });
231     });
233     jQuery('#create_tissue_samples_per_plant_num').keyup(function(){
234         var num_tissues = jQuery(this).val();
235         var html = '';
236         for (var i=1; i<=num_tissues; i++){
237             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" /></div></div>';
238         }
239         jQuery('#create_tissue_samples_names_div').html(html);
240     });
242     jQuery('#create_tissue_samples_plants_per_plant_submit').click(function(){
243         var is_checked;
244         if(jQuery('#create_tissue_samples_per_plant_inherit_treatments').is(":checked")){
245             is_checked = 1;
246         }
248         var tissue_names = [];
249         jQuery('input[name="create_tissue_samples_tissue_name"]').each(function() {
250             tissue_names.push(this.value);
251         });
253         jQuery.ajax({
254             url: '/ajax/breeders/trial/'+selected[0]+'/create_tissue_samples/',
255             type: 'POST',
256             beforeSend: function() {
257                 jQuery("#working_modal").modal("show");
258             },
259             data: {
260                 'tissue_samples_per_plant' : jQuery('#create_tissue_samples_per_plant_num').val(),
261                 'inherits_plot_treatments' : is_checked,
262                 'tissue_samples_names' : JSON.stringify(tissue_names)
263             },
264             success: function(response) {
265                 jQuery("#working_modal").modal("hide");
266                 if (response.error) {
267                     alert(response.error);
268                 }
269                 else {
270                     alert("Successfully created tissue sample entries.");
271                     Workflow.complete('#create_tissue_samples_plants_per_plant_submit');
272                     Workflow.focus("#field_tissue_samples_create_workflow", -1); //go to success
273                 }
274             },
275             error: function(response) {
276                 jQuery("#working_modal").modal("hide");
277                 alert("An error occurred creating tissue sample entries");
278             },
279         });
280     });
283 </script>