Merge pull request #2754 from solgenomics/topic/fix_homepage_add_accessions_dialog
[sgn.git] / mason / help / workflow_guided / tissue_sample_help.mas
blob6fcef36ff34f34255e2b1605b4569b5eb41fae7e
1 <%args>
2 </%args>
4 <& /util/import_javascript.mas, classes => [ 'CXGN.BreedersToolbox.GenotypingTrial' ] &>
6 <div class="modal fade" id="tissue_sample_help_dialog" name="tissue_sample_help_dialog" tabindex="-1" role="dialog" aria-labelledby="tissueSampleHelpDialog">
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="tissueSampleHelpDialog">Tissue Sampling</h4>
12             </div>
13             <div class="modal-body">
15                 <div class="container-fluid">
17                     <&| /util/workflow.mas, id=> "tissue_sample_help_workflow" &>
18                         <&| /util/workflow.mas:step, title=> "Intro" &>
19                             <& /page/page_title.mas, title=>"This workflow will guide you through tissue sampling an experiment" &>
20                             <p>Tissue samples collected from the field 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 has a globally unique name.</p>
23                             <br/>
24                             <p>A unique tissue sample is present in each well of a genotyping plate (96 or 384 well plates).</p>
25                             <p>The tissue sample in a 96 well plate can originate from another tissue sample name, plant name, plot name, or accession name.</p>
27                             <br/><br/>
28                             <center>
29                             <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
30                             </center>
31                         </&>
33                         <&| /util/workflow.mas:step, title=> "Sampling Level" &>
34                             <& /page/page_title.mas, title=>"At which level do you plan to keep track of your sampling?" &>
35                             
36                             <input type="radio" name="tissue_sample_help_select_level" value="accession">&nbsp;&nbsp;&nbsp;Accession Level: The sample is not from a field trial entity and only the accession name is known.<br/>
37                             <input type="radio" name="tissue_sample_help_select_level" value="plot">&nbsp;&nbsp;&nbsp;Plot Level: Each plot in the field has a unique identifier, ideally with a barcode label.<br/>
38                             <input type="radio" name="tissue_sample_help_select_level" value="plant">&nbsp;&nbsp;&nbsp;Plant Level: Each plant in the field has a unique identifier, ideally with a barcode label.<br/>
39                             <input type="radio" name="tissue_sample_help_select_level" value="tissue_sample">&nbsp;&nbsp;&nbsp;Tissue Sample Level: Each tissue sample collected from the field has a unique identifier, ideally with a barcode label.
41                             <br/><br/>
42                             <center>
43                                 <button class="btn btn-primary" id="tissue_sample_help_select_level_submit">Go to Next Step</button>
44                             </center>
45                         </&>
46                         <&| /util/workflow.mas:step, title=> "Select a field trial" &>
47                             <& /page/page_title.mas, title=>"Select a field trial" &>
49                             <div id="tissue_sample_help_trial_select_not_relevant" style="display:none">
50                                 <h4>Field trial is not relevant for the type of tissue sampling you selected. Go to next step.</h4>
51                                 <center>
52                                 <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
53                                 </center>
54                             </div>
55                             <div id="tissue_sample_help_trial_select_relevant" style="display:none">
56                                 <div class="well well-sm">
57                                     <div class="panel panel-default">
58                                         <div class="panel-body">
59                                             <table id="tissue_sample_help_field_search_results" class="table table-hover table-striped">
60                                                 <thead>
61                                                     <tr>
62                                                         <th>Select</th>
63                                                         <th>Trial name</th>
64                                                         <th>Description</th>
65                                                         <th>Breeding program</th>
66                                                         <th>Folder</th>
67                                                         <th>Year</th>
68                                                         <th>Location</th>
69                                                         <th>Trial type</th>
70                                                         <th>Design</th>
71                                                         <th>Planting Date</th>
72                                                         <th>Harvest Date</th>
73                                                         <th>Download</th>
74                                                     </tr>
75                                                 </thead>
76                                             </table>
77                                         </div>
78                                     </div>
79                                 </div>
81                                 <br/><br/>
82                                 <center>
83                                     <button class="btn btn-primary" id="tissue_sample_help_select_trial_submit">Go to Next Step</button>
84                                 </center>
85                             </div>
87                         </&>
88                         <&| /util/workflow.mas:step, title=> "Plant Entries" &>
89                             <& /page/page_title.mas, title=>"Plant entries in your field trial" &>
91                             <div id="tissue_sample_help_plant_entries_not_relevant" style="display:none">
92                                 <h4>Plant entries not relevant for the type of tissue sampling you selected. Go to next step.</h4>
93                                 <center>
94                                 <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
95                                 </center>
96                             </div>
97                             <div id="tissue_sample_help_plant_entries_exist_section" style="display:none">
98                                 <h4>Plant entries exist for this trial. Go to next step.</h4>
99                                 <center>
100                                 <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
101                                 </center>
102                             </div>
103                             <div id="tissue_sample_help_plant_entries_dont_exist_section" style="display:none">
104                                 <h4>Please create plant entries for this trial.</h4>
105                                 <form class="form-horizontal">
106                                     <div class="form-group">
107                                         <label class="col-sm-3 control-label">Number of plants per plot: </label>
108                                         <div class="col-sm-9" >
109                                             <input name="tissue_sample_help_plants_per_plot_num" id="tissue_sample_help_plants_per_plot_num" class="form-control" type="number" autofocus/>
110                                         </div>
111                                     </div>
112                                     <div class="form-group">
113                                         <label class="col-sm-3 control-label">Inherits Management Factor(s) From Plots: </label>
114                                         <div class="col-sm-9" >
115                                             <input name="tissue_sample_help_plants_per_plot_inherit_treatments" id="tissue_sample_help_plants_per_plot_inherit_treatments" type="checkbox" checked disabled/>
116                                         </div>
117                                     </div>
118                                 </form><br/>
119                                 <center>
120                                     <button type="button" class="btn btn-primary" id="tissue_sample_help_plants_per_plot_submit">Submit</button>
121                                 </center>
122                             </div>
124                         </&>
125                         <&| /util/workflow.mas:step, title=> "Create Tissue Sample Entries" &>
126                             <& /page/page_title.mas, title=>"Create tissue sample entries for this trial" &>
128                             <div id="tissue_sample_help_tissue_samples_not_relevant" style="display:none">
129                                 <h4>Field trial tissue sample entries not relevant for the type of tissue sampling you selected. Go to next step.</h4>
130                                 <center>
131                                 <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
132                                 </center>
133                             </div>
134                             <div id="tissue_sample_help_tissue_samples_exist_section" style="display:none">
135                                 <h4>Tissue sample entries exist for this trial. Go to next step.</h4>
136                                 <center>
137                                 <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
138                                 </center>
139                             </div>
140                             <div id="tissue_sample_help_tissue_samples_relevant" style="display:none">
141                                 <form class="form-horizontal" >
142                                     <div class="form-group">
143                                         <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>
144                                         <div class="col-sm-9" >
145                                             <input name="tissue_sample_help_tissue_samples_per_plant_num" id="tissue_sample_help_tissue_samples_per_plant_num" class="form-control" type="number" autofocus/>
146                                         </div>
147                                     </div>
149                                     <div id="tissue_sample_help_tissue_samples_names_div">
150                                     </div>
152                                     <div class="form-group">
153                                         <label class="col-sm-3 control-label">Inherits Management Factor(s) From Plots: </label>
154                                         <div class="col-sm-9" >
155                                             <input name="tissue_sample_help_per_plant_inherit_treatments" id="tissue_sample_help_per_plant_inherit_treatments" type="checkbox" checked disabled/>
156                                         </div>
157                                     </div>
158                                 </form><br/>
160                                 <center>
161                                 <button type="button" class="btn btn-primary" name="tissue_sample_help_per_plant_submit" id="tissue_sample_help_per_plant_submit">Submit</button>
162                                 </center>
163                             </div>
164                         </&>
165                         <&| /util/workflow.mas:complete, title=> "Complete" &>
166                             <& /page/page_title.mas, title=>"Complete! You have all the entities you need to conduct your sampling." &>
167                             <ul>
168                                 <li>All of the entities that you want to sample are saved in the database and available to use!</li>
169                                 <li>You can print barcodes for the entities you intend to sample on. These barcodes can be attached to your collection vials/containers to assist during sampling.</li>
170                             </ul>
171                             <center>
172                                 <button class="btn btn-primary" onclick="final_download_layout_button_click()">Download Field Trial Layout!</button>
173                             </center>
174                             <br/>
176                             <ul>
177                                 <li>After you have finished sampling, you can use these entities as source material for a genotyping plate (96 or 384 well plate). Click the button below to create a genotyping plate now, if you will create a 96 or 384 well plate.</li>
178                                 <li>The Android Coordinate application can help you create 96 or 384 well plates. Alternatively you can create your plate layout in Excel and upload it.</li>
179                             </ul>
180                             <center>
181                                 <button class="btn btn-primary" name="create_genotyping_trial_link">Create Genotyping Plate Now!</button>
182                             </center>
183                         </&>
184                     </&>
186                 </div>
187             </div>
188             <div class="modal-footer">
189                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
190             </div>
191         </div>
192     </div>
193 </div>
195 <script>
197 var selected_level;
198 var selected;
200 jQuery(document).ready(function(){
202     jQuery('button[name="tissue_sample_guided_help"]').click(function(){
203         jQuery('#tissue_sample_help_dialog').modal('show');
204     });
206     var tissue_sample_help_trial_table = jQuery('#tissue_sample_help_field_search_results').DataTable( {
207         'ajax': {
208             'url':'/ajax/search/trials',
209             'data': function(d) {
210                 d.select_checkbox_name = 'tissue_sample_help_select_trial_checkbox';
211             }
212         },
213         "scrollX": true
214     });
216     jQuery('#tissue_sample_help_select_level_submit').click(function(){
217         selected_level = jQuery('input[name="tissue_sample_help_select_level"]:checked').val();
218         if (selected_level == '' || !selected_level){
219             alert('Please select one');
220         } else {
221             Workflow.complete('#tissue_sample_help_select_level_submit');
222             if (selected_level == 'accession'){
223                 jQuery('#tissue_sample_help_plant_entries_not_relevant').show();
224                 jQuery('#tissue_sample_help_plant_entries_exist_section').hide();
225                 jQuery('#tissue_sample_help_plant_entries_dont_exist_section').hide();
226                 jQuery('#tissue_sample_help_trial_select_not_relevant').show();
227                 jQuery('#tissue_sample_help_trial_select_relevant').hide();
228                 jQuery('#tissue_sample_help_tissue_samples_not_relevant').show();
229                 jQuery('#tissue_sample_help_tissue_samples_relevant').hide();
230                 Workflow.skip('#tissue_sample_help_select_trial_submit');
231                 Workflow.skip('#tissue_sample_help_plants_per_plot_submit');
232                 Workflow.skip('#tissue_sample_help_per_plant_submit');
233                 Workflow.focus("#tissue_sample_help_workflow", -1);
234             } else {
235                 jQuery('#tissue_sample_help_plant_entries_not_relevant').hide();
236                 jQuery('#tissue_sample_help_plant_entries_exist_section').hide();
237                 jQuery('#tissue_sample_help_plant_entries_dont_exist_section').hide();
238                 jQuery('#tissue_sample_help_trial_select_not_relevant').hide();
239                 jQuery('#tissue_sample_help_trial_select_relevant').show();
240                 jQuery('#tissue_sample_help_tissue_samples_not_relevant').hide();
241                 jQuery('#tissue_sample_help_tissue_samples_relevant').hide();
242                 jQuery('#tissue_sample_help_tissue_samples_exist_section').hide();
243                 Workflow.focus("#tissue_sample_help_workflow", 2);
244             }
245         }
246     });
248     jQuery('#tissue_sample_help_select_trial_submit').click(function(){
249         selected = [];
250         jQuery('input[name="tissue_sample_help_select_trial_checkbox"]:checked').each(function() {
251             selected.push(jQuery(this).val());
252         });
253         selected_level = jQuery('input[name="tissue_sample_help_select_level"]:checked').val();
254         if (selected.length !== 1){
255             alert('Only select one trial!');
256         } else {
257             Workflow.complete('#tissue_sample_help_select_trial_submit');
258             if (selected_level == 'plot'){
259                 jQuery('#tissue_sample_help_plant_entries_not_relevant').show();
260                 jQuery('#tissue_sample_help_plant_entries_exist_section').hide();
261                 jQuery('#tissue_sample_help_plant_entries_dont_exist_section').hide();
262                 jQuery('#tissue_sample_help_tissue_samples_not_relevant').show();
263                 jQuery('#tissue_sample_help_tissue_samples_relevant').hide();
264                 Workflow.skip('#tissue_sample_help_plants_per_plot_submit');
265                 Workflow.skip('#tissue_sample_help_per_plant_submit');
266                 Workflow.focus("#tissue_sample_help_workflow", -1);
267             } else {
268                 new jQuery.ajax({
269                     type: 'POST',
270                     url: '/ajax/breeders/trial/'+selected[0]+'/has_plants',
271                     dataType: "json",
272                     beforeSend: function() {
273                         jQuery("#working_modal").modal("show");
274                     },
275                     success: function (response) {
276                         jQuery("#working_modal").modal("hide");
277                         if (response.has_plants){
278                             jQuery('#tissue_sample_help_plant_entries_exist_section').show();
279                             jQuery('#tissue_sample_help_plant_entries_dont_exist_section').hide();
280                             Workflow.complete('#tissue_sample_help_select_trial_submit');
281                             Workflow.skip('#tissue_sample_help_plant_entries_exist_section');
282                             if (selected_level == 'plant'){
283                                 jQuery('#tissue_sample_help_tissue_samples_not_relevant').show();
284                                 jQuery('#tissue_sample_help_tissue_samples_relevant').hide();
285                                 Workflow.skip('#tissue_sample_help_per_plant_submit');
286                                 Workflow.focus("#tissue_sample_help_workflow", -1);
287                             } else {
288                                 new jQuery.ajax({
289                                     type: 'POST',
290                                     url: '/ajax/breeders/trial/'+selected[0]+'/has_tissue_samples',
291                                     dataType: "json",
292                                     beforeSend: function() {
293                                         jQuery("#working_modal").modal("show");
294                                     },
295                                     success: function (response) {
296                                         jQuery("#working_modal").modal("hide");
297                                         if (response.has_tissue_samples){
298                                             jQuery('#tissue_sample_help_tissue_samples_not_relevant').hide();
299                                             jQuery('#tissue_sample_help_tissue_samples_relevant').hide();
300                                             jQuery('#tissue_sample_help_tissue_samples_exist_section').show();
301                                             Workflow.skip('#tissue_sample_help_per_plant_submit');
302                                             Workflow.focus("#tissue_sample_help_workflow", -1);
303                                         } else {
304                                             jQuery('#tissue_sample_help_tissue_samples_not_relevant').hide();
305                                             jQuery('#tissue_sample_help_tissue_samples_relevant').show();
306                                             jQuery('#tissue_sample_help_tissue_samples_exist_section').hide();
307                                             Workflow.focus("#tissue_sample_help_workflow", 4);
308                                         }
309                                     },
310                                     error: function () {
311                                         jQuery("#working_modal").modal("hide");
312                                         alert('An error occurred checking trial for tissue samples.');
313                                     }
314                                 });
315                             }
316                         } else {
317                             jQuery('#tissue_sample_help_plant_entries_dont_exist_section').show();
318                             jQuery('#tissue_sample_help_plant_entries_exist_section').hide();
319                             Workflow.complete('#tissue_sample_help_select_trial_submit');
320                             Workflow.focus("#tissue_sample_help_workflow", 3);
321                         }
322                     },
323                     error: function () {
324                         jQuery("#working_modal").modal("hide");
325                         alert('An error occurred checking trial for plants.');
326                     }
327                 });
328             }
329         }
330     });
333     jQuery('#tissue_sample_help_plants_per_plot_submit').click(function(){
334         var is_checked;
335         if(jQuery('#tissue_sample_help_plants_per_plot_inherit_treatments').is(":checked")){
336             is_checked = 1;
337         }
339         jQuery.ajax({
340             url: '/ajax/breeders/trial/'+selected[0]+'/create_plant_entries/',
341             type: 'POST',
342             beforeSend: function() {
343                 jQuery("#working_modal").modal("show");
344             },
345             data: {
346                 'plants_per_plot' : jQuery('#tissue_sample_help_plants_per_plot_num').val(),
347                 'inherits_plot_treatments' : is_checked
348             },
349             success: function(response) {
350                 jQuery("#working_modal").modal("hide");
351                 if (response.error) {
352                     alert(response.error);
353                 }
354                 else {
355                     alert("Successfully created plant entries.");
356                     Workflow.complete('#tissue_sample_help_plants_per_plot_submit');
357                     if (selected_level == 'plant'){
358                         jQuery('#tissue_sample_help_tissue_samples_not_relevant').show();
359                         jQuery('#tissue_sample_help_tissue_samples_relevant').hide();
360                         Workflow.skip('#tissue_sample_help_per_plant_submit');
361                         Workflow.focus("#tissue_sample_help_workflow", -1);
362                     } else {
363                         new jQuery.ajax({
364                             type: 'POST',
365                             url: '/ajax/breeders/trial/'+selected[0]+'/has_tissue_samples',
366                             dataType: "json",
367                             beforeSend: function() {
368                                 jQuery("#working_modal").modal("show");
369                             },
370                             success: function (response) {
371                                 jQuery("#working_modal").modal("hide");
372                                 if (response.has_tissue_samples){
373                                     jQuery('#tissue_sample_help_tissue_samples_not_relevant').hide();
374                                     jQuery('#tissue_sample_help_tissue_samples_relevant').hide();
375                                     jQuery('#tissue_sample_help_tissue_samples_exist_section').show();
376                                     Workflow.skip('#tissue_sample_help_per_plant_submit');
377                                     Workflow.focus("#tissue_sample_help_workflow", -1);
378                                 } else {
379                                     jQuery('#tissue_sample_help_tissue_samples_not_relevant').hide();
380                                     jQuery('#tissue_sample_help_tissue_samples_relevant').show();
381                                     jQuery('#tissue_sample_help_tissue_samples_exist_section').hide();
382                                     Workflow.focus("#tissue_sample_help_workflow", 4);
383                                 }
384                             },
385                             error: function () {
386                                 jQuery("#working_modal").modal("hide");
387                                 alert('An error occurred checking trial for tissue samples.');
388                             }
389                         });
390                     }
391                 }
392             },
393             error: function(response) {
394                 jQuery("#working_modal").modal("hide");
395                 alert("An error occurred saving plant entries");
396             },
397         });
398     });
400     jQuery('#tissue_sample_help_tissue_samples_per_plant_num').keyup(function(){
401         var num_tissues = jQuery(this).val();
402         var html = '';
403         for (var i=1; i<=num_tissues; i++){
404             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="tissue_sample_help_tissue_name" id="tissue_samples_help_tissue_name_'+i+'" class="form-control" type="text" placeholder="examples: leaf or root or stem" /></div></div>';
405         }
406         jQuery('#tissue_sample_help_tissue_samples_names_div').html(html);
407     });
409     jQuery('#tissue_sample_help_per_plant_submit').click(function(){
410         var is_checked;
411         if(jQuery('#tissue_sample_help_per_plant_inherit_treatments').is(":checked")){
412             is_checked = 1;
413         }
415         var tissue_names = [];
416         jQuery('input[name="tissue_sample_help_tissue_name"]').each(function() {
417             tissue_names.push(this.value);
418         });
420         jQuery.ajax({
421             url: '/ajax/breeders/trial/'+selected[0]+'/create_tissue_samples/',
422             type: 'POST',
423             beforeSend: function() {
424                 jQuery("#working_modal").modal("show");
425             },
426             data: {
427                 'tissue_samples_per_plant' : jQuery('#tissue_sample_help_tissue_samples_per_plant_num').val(),
428                 'inherits_plot_treatments' : is_checked,
429                 'tissue_samples_names' : JSON.stringify(tissue_names)
430             },
431             success: function(response) {
432                 jQuery("#working_modal").modal("hide");
433                 if (response.error) {
434                     alert(response.error);
435                 }
436                 else {
437                     alert("Successfully created tissue sample entries.");
438                     Workflow.complete('#tissue_sample_help_per_plant_submit');
439                     Workflow.focus("#tissue_sample_help_workflow", -1); //go to success
440                 }
441             },
442             error: function(response) {
443                 jQuery("#working_modal").modal("hide");
444                 alert("An error occurred creating tissue sample entries");
445             },
446         });
447     });
451 function final_download_layout_button_click(){
452     if (selected_level == 'accession'){
453         alert('You selected to sample on the accession level, meaning that you wil not sample from a field trial. In this case there is no field layout to download!');
454     }
455     if (selected_level == 'plot'){
456         var selected_columns = {'plot_name':1,'plot_id':1,'block_number':1,'plot_number':1,'rep_number':1,'row_number':1,'col_number':1,'accession_name':1,'is_a_control':1};
457         var selected_columns_json = JSON.stringify(selected_columns);
458         window.open("/breeders/trial/"+selected[0]+"/download/layout?format=csv&dataLevel=plots&selected_columns="+selected_columns_json);
459     }
460     if (selected_level == 'plant'){
461         var selected_columns = {'plant_name':1,'plant_id':1,'plot_name':1,'block_number':1,'plant_number':1,'plot_number':1,'rep_number':1,'row_number':1,'col_number':1,'accession_name':1,'is_a_control':1};
462         var selected_columns_json = JSON.stringify(selected_columns);
463         window.open("/breeders/trial/"+selected[0]+"/download/layout?format=csv&dataLevel=plants&selected_columns="+selected_columns_json);
464     }
465     if (selected_level == 'tissue_sample'){
466         var selected_columns = {'tissue_sample_name':1,'tissue_sample_id':1,'plant_name':1,'plot_name':1,'block_number':1,'plant_number':1,'plot_number':1,'rep_number':1,'row_number':1,'col_number':1,'accession_name':1,'is_a_control':1};
467         var selected_columns_json = JSON.stringify(selected_columns);
468         window.open("/breeders/trial/"+selected[0]+"/download/layout?format=csv&dataLevel=field_trial_tissue_samples&selected_columns="+selected_columns_json);
469     }
472 </script>