fix test with new description field.
[sgn.git] / mason / breeders_toolbox / sampling_trials / create_sampling_trials_dialogs.mas
blob5a0d9097303311f2af266bd6cf373b1729147e0b
1 <%args>
2 $sampling_facilities => ();
3 </%args>
5 <& /util/import_javascript.mas, classes => [ 'CXGN.BreedersToolbox.GenotypingTrial' ] &>
8 <div class="modal fade" id="sampling_trial_dialog" name="sampling_trial_dialog" tabindex="-1" role="dialog" aria-labelledby="addSamplingTrialDialog">
9     <div class="modal-dialog modal-xl" role="document">
10         <div class="modal-content">
11             <div class="modal-header">
12                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
13                 <h4 class="modal-title" id="addSamplingTrialDialog">Add Sampling Trial</h4>
14             </div>
15             <div class="modal-body">
16                 <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_sampling_trials_form" name="upload_sampling_trials_form" >
18                     <div class="container-fluid">
20                         <&| /util/workflow.mas, id=> "sampling_trial_create_workflow" &>
21                             <&| /util/workflow.mas:step, title=> "Intro" &>
22                                 <& /page/page_title.mas, title=>"This workflow will guide you through adding a sampling trial in the database" &>
23                                 <p>Sampling trials can represent 96 or 384 well plates, or more generically any sampling scheme.</p>
24                                 <p>Each sample has a globally unique tissue sample ID.</p>
25                                 <p>The "contents" of each sample can be either a tissue sample, plant name, plot name, or accession name. This "source" name must be in the database already. This is useful if you provide a field trial entity (such as a plot or plant or tissue sample name), so that phenotypes and genotypes can be directly compared.</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=> "Basic Info" &>
34                                 <& /page/page_title.mas, title=>"Provide info about your sampling trial" &>
36                                 <div class="form-group">
37                                     <label class="col-sm-5 control-label">Sampling Facility: </label>
38                                     <div class="col-sm-7">
39                                         <select class="form-control" id="sampling_trial_facility_select">
40 % foreach my $facility(@$sampling_facilities){
41     <option value="<%$facility%>"><%$facility%></option>
42 % }
43                                         </select>
44                                     </div>
45                                 </div>
46                                 <div class="form-group">
47                                     <label class="col-sm-5 control-label">Sampling Trial Name: </label>
48                                     <div class="col-sm-7">
49                                         <input class="form-control" id="sampling_trial_name" name="sampling_trial_name" type="text" placeholder=" e.g. 18DNA00001"/>
50                                     </div>
51                                 </div>
52                                 <div class="form-group">
53                                     <label class="col-sm-5 control-label">Sample Type: </label>
54                                     <div class="col-sm-7">
55                                         <select class="form-control" id="sampling_trial_plate_sample_type">
56                                             <option value="Tissue">Tissue</option>
57                                             <option value="DNA">DNA</option>
58                                             <option value="RNA">RNA</option>
59                                         </select>
60                                     </div>
61                                 </div>
62                                 <div class="form-group">
63                                     <label class="col-sm-5 control-label">Sampling Trial's Breeding Program: </label>
64                                     <div class="col-sm-7">
65                                         <span id="sampling_trial_breeding_program_select_div"></span>
66                                     </div>
67                                 </div>
68                                 <div class="form-group">
69                                     <label class="col-sm-5 control-label">Sampling Trial's Location: </label>
70                                     <div class="col-sm-7">
71                                         <span id="sampling_trial_location_select_div"></span>
72                                     </div>
73                                 </div>
74                                 <div class="form-group">
75                                     <label class="col-sm-5 control-label">Sampling Trial's Year: </label>
76                                     <div class="col-sm-7">
77                                         <span id="sampling_trial_year_select_div"></span>
78                                     </div>
79                                 </div>
80                                 <div class="form-group">
81                                     <label class="col-sm-5 control-label">Sampling Trials's Description: </label>
82                                     <div class="col-sm-7">
83                                         <textarea class="form-control" id="sampling_trial_description" name="sampling_trial_description" maxlength="250"></textarea>
84                                     </div>
85                                 </div>
87                                 <br/>
88                                 <center>
89                                 <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
90                                 </center>
91                             </&>
92                             <&| /util/workflow.mas:step, title=> "Samples Info" &>
93                                 <& /page/page_title.mas, title=>"Provide information about the samples" &>
94                                 <br/><br/>
96                                 <div class="form-group">
97                                     <label class="col-sm-3 control-label">Select One: </label>
98                                     <div class="col-sm-9">
99                                         <select class="form-control" id="sampling_trial_well_input_option">
100                                             <option value="xls">I am uploading a sampling design I made in Excel</option>
101                                             <option value="design">I need to design a completely new sampling trial</option>
102                                         </select>
103                                     </div>
104                                 </div>
106                                 <div id="sampling_trial_well_upload_section">
107                                     <h3>You want to upload an existing samples layout</h3>
109                                     <div class="well well-sm">
110                                         <div class="row">
111                                             <div class="col-sm-4">
112                                                 <&| /page/explanation.mas, title=>'Template information' &>
113                                                     <p>
114                                                         <b>File format information</b>
115                                                         <br>
116                                                         <a id="sampling_trial_layout_upload_spreadsheet_info_format">Spreadsheet format</a>
117                                                     </p>
118                                                 </&>
119                                             </div>
120                                             <div class="col-sm-8">
121                                                 <br/>
122                                                 <div class="panel panel-default">
123                                                     <div class="panel-body">
124                                                         <div class="form-group">
125                                                             <label class="col-sm-6 control-label">Select Samples Layout XLSX (or XLS) File: </label>
126                                                             <div class="col-sm-6">
127                                                                 <input type="file" name="sampling_trial_layout_upload" id="sampling_trial_layout_upload" encoding="multipart/form-data" />
128                                                             </div>
129                                                         </div>
130                                                     </div>
131                                                 </div>
133                                             </div>
134                                         </div>
135                                     </div>
136                                 </div>
138                                 <div id="sampling_trial_well_design_section" style="display:none">
139                                     <h3>You want to design a completely new sampling trial.</h3>
141                                     <div class="well well-sm">
142                                         <ul>
143                                             <li>Select a list for the source material of each tissue sample. Then indicate how many replicates are required.</li>
144                                             <li>Note: From the most desirable to least desirable source observation unit you can choose: tissue samples, plants, plots, or accessions</li>
145                                         </ul>
146                                     </div>
147                                     <div class="form-group">
148                                         <label class="col-sm-7 control-label">Source Observation Unit List: </label>
149                                         <div class="col-sm-5">
150                                             <span id="sampling_trial_accession_select_box_span">[loading...]</span>
151                                         </div>
152                                     </div>
153                                     <div class="form-group">
154                                         <label class="col-sm-7 control-label">Replicates: </label>
155                                         <div class="col-sm-5">
156                                             <input class="form-control" id="sampling_trial_replicates" name="sampling_trial_replicates" type="number" placeholder="1"/>
157                                         </div>
158                                     </div>
159                                     <div class="form-group form-group-sm">
160                                         <label class="col-sm-7 control-label"><i>Optional</i> Sample Concentration (ng/ul): <small>(If you used the same conc for all samples)</small></label>
161                                         <div class="col-sm-5">
162                                             <input class="form-control" id="sampling_trial_concentration" name="sampling_trial_concentration" type="text" />
163                                         </div>
164                                     </div>
165                                     <div class="form-group form-group-sm">
166                                         <label class="col-sm-7 control-label"><i>Optional</i> Sampling Volume (ul): <small>(If you used the same vol for all samples)</small></label>
167                                         <div class="col-sm-5">
168                                             <input class="form-control" id="sampling_trial_volume" name="sampling_well_volume" type="text" />
169                                         </div>
170                                     </div>
171                                     <div class="form-group form-group-sm">
172                                         <label class="col-sm-7 control-label"><i>Optional</i> Tissue: <small>(If used the same tissue for all samples)</small> </label>
173                                         <div class="col-sm-5">
174                                             <select class="form-control" id="sampling_trial_tissue">
175                                                 <option value="leaf">Leaf</option>
176                                                 <option value="root">Root</option>
177                                                 <option value="stem">Stem</option>
178                                                 <option value="seed">Seed</option>
179                                                 <option value="fruit">Fruit</option>
180                                                 <option value="tuber">Tuber</option>
181                                             </select>
182                                         </div>
183                                     </div>
184                                     <div class="form-group form-group-sm">
185                                         <label class="col-sm-7 control-label"><i>Optional</i> NCBI Taxonomy ID: <small>(Official NCBI ID.)</small> </label>
186                                         <div class="col-sm-5">
187                                             <input class="form-control" id="sampling_trial_ncbi_taxonomy_id" name="sampling_trial_ncbi_taxonomy_id" type="text" />
188                                         </div>
189                                     </div>
190                                     <div class="form-group form-group-sm">
191                                         <label class="col-sm-7 control-label"><i>Optional</i> Extraction: <small>(If used the same extraction for all samples)</small> </label>
192                                         <div class="col-sm-5">
193                                             <input class="form-control" id="sampling_trial_extraction" name="sampling_trial_extraction" type="text" />
194                                         </div>
195                                     </div>
196                                     <div class="form-group form-group-sm">
197                                         <label class="col-sm-7 control-label"><i>Optional</i> Person: <small>(If same person prepared all samples.)</small> </label>
198                                         <div class="col-sm-5">
199                                             <input class="form-control" id="sampling_trial_person" name="sampling_trial_person" type="text" />
200                                         </div>
201                                     </div>
202                                     <div class="form-group form-group-sm">
203                                         <label class="col-sm-7 control-label"><i>Optional</i> Date: <small>(If sampled on same date. YYYY/MM/DD)</small> </label>
204                                         <div class="col-sm-5">
205                                             <input class="form-control" id="sampling_trial_date" name="sampling_trial_date" type="text" placeholder="YYYY/MM/DD"/>
206                                         </div>
207                                     </div>
208                                     <div class="form-group form-group-sm">
209                                         <label class="col-sm-7 control-label"><i>Optional</i> Notes: <small>(Additional notes for these samples.)</small> </label>
210                                         <div class="col-sm-5">
211                                             <input class="form-control" id="sampling_trial_notes" name="sampling_trial_notes" type="text" />
212                                         </div>
213                                     </div>
214                                 </div>
216                                 <br/><br/>
217                                 <center>
218                                 <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
219                                 </center>
220                             </&>
221                             <&| /util/workflow.mas:step, title=> "Linkage" &>
222                                 <& /page/page_title.mas, title=>"Is your sampling trial linked with field trials in the database? This information can also be added from the sampling trial detail page once the trial is saved in the database." &>
224                                 <p>If you provided us with information about where the sample originated (e.g. it came from a plot name or plant name or tissue sample name in a field trial), we will automatically create linkage between the field trial(s) and this sampling trial.</p>
226                                 <br/>
227                                 <center>
228                                 <button class="btn btn-lg btn-primary" onclick="Workflow.complete(this); return false;" >Continue to Next Step</button>
229                                 <center>
230                             </&>
231                             <&| /util/workflow.mas:step, title=> "Confirm" &>
232                                 <& /page/page_title.mas, title=>"Finalize and submit your sampling trial" &>
234                                 <hr>
235                                 <center>
236                                 <button type="button" class="btn btn-primary" name="add_sampling_trial_submit" id="add_sampling_trial_submit">Submit</button>
237                                 </center>
238                             </&>
239                             <&| /util/workflow.mas:complete, title=> "Complete" &>
240                                 <& /page/page_title.mas, title=>"Complete! Your sampling trial was saved in the database." &>
242                                 <p>
243                                     <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
244                                     The sampling trial was saved successfully
245                                 </p>
247                             </&>
248                         </&>
250                     </div>
251                 </form>
252             </div>
253             <div class="modal-footer">
254                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
255             </div>
256         </div>
257     </div>
258 </div>
260 <div class="modal fade" id="sampling_trial_layout_upload_spreadsheet_info_format_dialog" name="sampling_trial_layout_upload_spreadsheet_info_format_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadSamplingTrialInfoDialog">
261     <div class="modal-dialog modal-xl" role="document">
262         <div class="modal-content">
263             <div class="modal-header" style="text-align: center">
264                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
265                 <h4 class="modal-title" id="uploadSamplingTrialInfoDialog">Upload Template Information</h4>
266             </div>
267             <div class="modal-body">
268                 <div class="container-fluid">
269                     <b>This is for uploading a pre-existing sampling trial layout.</b>
270                     <br/>
271                     <b>File must be Excel file (.xls or .xlsx)</b>
272                     <br />
273                     <b>Header:</b>
274                     <br>
275                     The first row (header) must contain the following:
277                     <table class="table table-hover table-bordered table-condensed" >
278                         <thead></thead>
279                         <tbody>
280                             <tr>
281                                 <td>date</td>
282                                 <td>sample_name</td>
283                                 <td>source_observation_unit_name</td>
284                                 <td>sample_number</td>
285                                 <td>replicate</td>
286                                 <td>tissue_type</td>
287                                 <td>ncbi_taxonomy_id</td>
288                                 <td>person</td>
289                                 <td>notes</td>
290                                 <td>extraction</td>
291                                 <td>concentration</td>
292                                 <td>volume</td>
293                             </tr>
294                         </tbody>
295                     </table>
297                     <b>Required fields:</b>
298                     <ul>
299                     <li>date (should be YYYY-MM-DD)</li>
300                     <li>sample_name (the globally unique identifier for the sample)</li>
301                     <li>source_observation_unit_name (must exist in the database. the identifier of the origin material. in order of most desirable identifier to least desirable identifier that can be used here: tissue sample name, plant name, plot name, accession name. For blank wells, you can write BLANK here and place a 1 in the is_blank column also.)</li>
302                     <li>sample_number (the sample number for the sample. Must be unique within this sampling trial)</li>
303                     <li>replicate (the replicate number for the sample)</li>
304                     <li>tissue_type (must be either leaf, root, stem, seed, fruit or tuber)</li>
305                     </ul>
307                     <b>Optional fields:</b>
308                     <ul>
309                     <li>ncbi_taxonomy_id (NCBI taxonomy identifier)</li>
310                     <li>person (the name of the person who prepared the sample)</li>
311                     <li>notes (any additional notes on the sample)</li>
312                     <li>extraction (free-text for the extraction method e.g. CTAB)</li>
313                     <li>concentration (concentration in ng/ul)</li>
314                     <li>volume (volume in ul)</li>
315                     </ul>
317                 </div>
318             </div>
319             <div class="modal-footer">
320                 <button id="close_upload_sampling_spreadsheet_info_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
321             </div>
322         </div>
323     </div>
324 </div>
326 <script>
327 jQuery(document).ready(function(){
329     jQuery('button[name="create_sampling_trial_button"]').click(function(){
330         jQuery('#sampling_trial_dialog').modal('show');
331     });
333     jQuery('#sampling_trial_dialog').on('show.bs.modal', function (e) {
334         get_select_box("locations", "sampling_trial_location_select_div", {'id':'sampling_trial_location_select', 'name':'sampling_trial_location_select'});
335         get_select_box("breeding_programs", "sampling_trial_breeding_program_select_div", {'id':'sampling_trial_breeding_program_select', 'name':'sampling_trial_breeding_program_select'});
336         get_select_box("years", "sampling_trial_year_select_div", {'auto_generate': 1, 'id':'sampling_trial_year_select', 'name':'sampling_trial_year_select'});
338         var l = new CXGN.List();
339         var html = l.listSelect('sampling_trial_accession_select_box', [ 'accessions', 'plots', 'plants', 'tissue_samples' ], undefined, undefined, undefined);
340         jQuery('#sampling_trial_accession_select_box_span').html(html);
341     });
343     jQuery('#sampling_trial_layout_upload_spreadsheet_info_format').click(function(){
344         jQuery('#sampling_trial_layout_upload_spreadsheet_info_format_dialog').modal('show');
345     });
347     jQuery('#sampling_trial_well_input_option').change(function(){
348         if (jQuery(this).val() == 'xls'){
349             jQuery("#sampling_trial_well_upload_section").show();
350             jQuery("#sampling_trial_well_design_section").hide();
351         }
352         if (jQuery(this).val() == 'design' ){
353             jQuery("#sampling_trial_well_design_section").show();
354             jQuery("#sampling_trial_well_upload_section").hide();
355             jQuery('#sampling_trial_layout_upload').val('');
356         }
357     });
359     var sampling_data = new Object();
360     jQuery('#add_sampling_trial_submit').click(function () {
361         sampling_data = new Object();
362         sampling_data.breeding_program = jQuery('#sampling_trial_breeding_program_select').val();
363         sampling_data.year = jQuery('#sampling_trial_year_select').val();
364         sampling_data.sampling_facility = jQuery('#sampling_trial_facility_select').val();
365         sampling_data.location = jQuery('#sampling_trial_location_select').val();
366         sampling_data.description = jQuery('#sampling_trial_description').val();
367         sampling_data.replicates = jQuery('#sampling_trial_replicates').val();
368         sampling_data.name = jQuery('#sampling_trial_name').val();
369         sampling_data.sample_type = jQuery('#sampling_trial_plate_sample_type').val();
370         sampling_data.sample_concentration = jQuery('#sampling_trial_concentration').val();
371         sampling_data.ncbi_taxonomy_id = jQuery('#sampling_trial_ncbi_taxonomy_id').val();
372         sampling_data.sample_extraction = jQuery('#sampling_trial_extraction').val();
373         sampling_data.sample_date = jQuery('#sampling_trial_date').val();
374         sampling_data.sample_person = jQuery('#sampling_trial_person').val();
375         sampling_data.sample_volume = jQuery('#sampling_trial_volume').val();
376         sampling_data.sample_tissue = jQuery('#sampling_trial_tissue').val();
377         sampling_data.sample_notes = jQuery('#sampling_trial_notes').val();
379         if (sampling_data.breeding_program == '') {
380             alert("A breeding program is required. Please try again.");
381             return;
382         }
383         if (sampling_data.year == '') {
384             alert("A year is required. Please try again.");
385             return;
386         }
387         if (sampling_data.location == '') {
388             alert("A location is required. Please try again.");
389             return;
390         }
391         if (sampling_data.name == '') {
392             alert("A sampling trial name is required and it should be unique in the database. Please try again.");
393             return;
394         }
395         if (sampling_data.description == '') {
396             alert("A sampling trial description is required. Please try again.");
397             return;
398         }
399         if (sampling_data.sample_type == '') {
400             alert("A sampling trial type is required. Please try again.");
401             return;
402         }
403         if (sampling_data.replicates == '') {
404             sampling_data.replicates = 1;
405         }
407         var uploadFileXLS = jQuery("#sampling_trial_layout_upload").val();
408         if (uploadFileXLS === ''){
409             sampling_data.list_id = jQuery('#sampling_trial_accession_select_box_list_select').val();
410             var l = new CXGN.List();
411             if (! l.validate(sampling_data.list_id, 'accessions', true) && ! l.validate(sampling_data.list_id, 'plots', true) && ! l.validate(sampling_data.list_id, 'plants', true) && ! l.validate(sampling_data.list_id, 'tissue_samples', true)) {
412                 alert('The list contains elements that are not accessions or plots or plants or tissue_samples.');
413                 return;
414             }
415             var elements = l.getList(sampling_data.list_id);
416             if (typeof elements == 'undefined' ) {
417                 alert("There are no elements in the list provided.");
418                 return;
419             }
420             sampling_data.elements = elements;
422             jQuery.ajax({
423                 url: '/ajax/breeders/generatesamplingtrial',
424                 method: 'POST',
425                 beforeSend: function(){
426                     jQuery("working_modal").modal('show');
427                 },
428                 data: {
429                     'sampling_data': JSON.stringify(sampling_data)
430                 },
431                 success : function(response) {
432                     console.log(response);
433                     jQuery("working_modal").modal('hide');
434                     if (response.error) {
435                         alert(response.error);
436                     }
437                     else {
438                         sampling_data.design = response.design;
439                         store_sampling_trial(sampling_data);
440                     }
441                 },
442                 error: function(response) {
443                     alert('An error occurred trying the create the sampling trial layout.');
444                     jQuery("working_modal").modal('hide');
445                 }
446             });
447         }
448         else {
449             jQuery('#upload_sampling_trials_form').attr("action", "/ajax/breeders/parsesamplingtrial");
450             jQuery("#upload_sampling_trials_form").submit();
451         }
452     });
454     jQuery('#upload_sampling_trials_form').iframePostForm({
455         json: true,
456         post: function () {
457         },
458         complete: function (response) {
459             console.log(response);
460             if (response.error) {
461                 alert(response.error);
462                 return;
463             }
464             if (response.error_string) {
465                 alert(response.error_string);
466                 return;
467             }
468             if (response.success) {
469                 sampling_data.design = response.design;
470                 store_sampling_trial(sampling_data);
471             }
472         }
473     });
475     function store_sampling_trial(sampling_data) {
476         jQuery.ajax({
477             url: '/ajax/breeders/storesamplingtrial',
478             method: 'POST',
479             beforeSend: function(){
480                 jQuery("#working_modal").modal('show');
481             },
482             data: {
483                 'sampling_data': JSON.stringify(sampling_data)
484             },
485             success : function(response) {
486                 jQuery("#working_modal").modal('hide');
487                 if (response.error) {
488                     alert(response.error);
489                 }
490                 else {
491                     alert(response.message);
492                     Workflow.complete('#add_sampling_trial_submit');
493                     Workflow.focus("#sampling_trial_create_workflow", -1); //Go to success page
494                     Workflow.check_complete("#sampling_trial_create_workflow");
495                 }
496             },
497             error: function(response) {
498                 alert('An error occurred trying the create the layout.');
499                 jQuery("#working_modal").modal('hide');
500             }
501         });
502     }
505 </script>