Merge pull request #5248 from solgenomics/topic/batch_update_trials
[sgn.git] / mason / breeders_toolbox / add_new_trait_dialogs.mas
blob23de1fc997947065d71f2bea79871a27b50092aa
1 <%args>
2 </%args>
4 <div class="modal fade" id="add_new_observation_variable_dialog" name="add_new_observation_variable_dialog" tabindex="-1" role="dialog" aria-labelledby="addNewObservationVariableDialog">
5     <div class="modal-dialog modal-xl" role="document">
6         <div class="modal-content">
7             <div class="modal-header">
8                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
9                 <h4 class="modal-title" id="addNewObservationVariableDialog">Add New Observation Variable</h4>
10             </div>
11             <div class="modal-body">
12                 <div class="container-fluid">
14                     <&| /util/workflow.mas, id=> "add_new_trait_workflow" &>
15                         <&| /util/workflow.mas:step, title=> "Intro" &>
16                             <& /page/page_title.mas, title=>"Need a new observation variable?" &>
17                             <ul>
18                                 <li>Please be sure the observation variable does not currently exist in the database using the trait search.</li>
19                                 <li>Having many observation variables that are in fact recording the same thing is dangerous and can cause the database data to become fragmented.</li>
20                                 <li>An observation variable is composed of a trait for the attribute being observed, a method describing how the attribute was measured, and a scale indicating the units of the observation.</li>
21                                 <li>Having descriptive observation variables is critical for downstream analysis.</li>
22                             </ul>
24                             <br/><br/>
25                             <center>
26                                 <button class="btn btn-primary" name="add_new_observation_variable_ontology_add_button">Need a new ontology? Click here first.</button>
27                             </center>
29                             <br/><br/>
30                             <center>
31                                 <button class="btn btn-primary" onclick="Workflow.complete(this);">Go to Next Step</button>
32                             </center>
33                         </&>
35                         <&| /util/workflow.mas:step, title=> "Observation Variable" &>
36                             <& /page/page_title.mas, title=>"Define your observation variable" &>
38                             <p>An observation variable is composed of a trait for the attribute being observed, a method describing how the attribute was measured, and a scale indicating the units of the observation.</p>
39                             <hr>
41                             <center>
42                                 <button class="btn btn-primary" name="add_new_observation_variable_ontology_add_button">Need a new ontology? Click here first.</button>
43                             </center>
44                             <br/><br/>
46                             <form class="form-horizontal">
47                                 <div class="form-group">
48                                     <label class="col-sm-3 control-label">Observation Variable Ontology Name: </label>
49                                     <div class="col-sm-9">
50                                         <div id="add_new_observation_variable_ontology_select_div">
51                                         </div>
52                                     </div>
53                                 </div>
54                                 <div class="form-group">
55                                     <label class="col-sm-3 control-label">New Observation Variable Name: </label>
56                                     <div class="col-sm-9">
57                                         <input class="form-control" id="add_new_observation_variable_name" name="add_new_observation_variable_name" type="text" placeholder="e.g. total mass of fruit harvest from a plant using MachineX in kilograms"/>
58                                     </div>
59                                 </div>
60                                 <div class="form-group">
61                                     <label class="col-sm-3 control-label">New Observation Variable Definition: </label>
62                                     <div class="col-sm-9">
63                                         <input class="form-control" id="add_new_observation_variable_definition" name="add_new_observation_variable_definition" type="text" placeholder="e.g. total mass of fruit harvest from a plant using MachineX in kilograms"/>
64                                     </div>
65                                 </div>
66                             </form>
67                             <br/>
69                             <center>
70                                 <button class="btn btn-primary" id="add_new_trait_observation_variable_step">Go to Next Step</button>
71                             </center>
73                         </&>
74                         <&| /util/workflow.mas:step, title=> "Trait" &>
75                             <& /page/page_title.mas, title=>"Define your trait" &>
77                             <ul>
78                                 <li>A trait defines the attribute being measured. It is one component of an observation variable; the others are a method and a scale.</li>
79                                 <li>Here you can select a trait that already exists in an ontology in the database or you can add a new trait into an ontology.</li>
80                             </ul>
81                             <hr>
83                             <center>
84                                 <button class="btn btn-primary" name="add_new_observation_variable_ontology_add_button">Need a new ontology? Click here first.</button>
85                             </center>
86                             <br/><br/>
88                             <form class="form-horizontal">
89                                 <div class="form-group">
90                                     <label class="col-sm-3 control-label">Trait Ontology Name: </label>
91                                     <div class="col-sm-9">
92                                         <div id="add_new_trait_ontology_select_div">
93                                         </div>
94                                     </div>
95                                 </div>
96                                 <div class="form-group">
97                                     <label class="col-sm-3 control-label">Existing Traits in Selected Ontology: </label>
98                                     <div class="col-sm-9">
99                                         <div id="add_new_trait_existing_trait_select_div">
100                                         </div>
101                                     </div>
102                                 </div>
103                                 <hr>
105                                 <div class="well">
106                                     <h3>If the trait does not exist in the ontology you selected above, you can add a new trait into the ontology here.</h3>
107                                 </div>
109                                 <div class="form-group">
110                                     <label class="col-sm-3 control-label">New Trait Name: </label>
111                                     <div class="col-sm-9">
112                                         <input class="form-control" id="add_new_trait_name" name="add_new_trait_name" type="text" placeholder="e.g. harvested fruit mass per plant"/>
113                                     </div>
114                                 </div>
115                                 <div class="form-group">
116                                     <label class="col-sm-3 control-label">New Trait Definition: </label>
117                                     <div class="col-sm-9">
118                                         <input class="form-control" id="add_new_trait_definition" name="add_new_trait_definition" type="text" placeholder="e.g. the total mass of fruit harvested from a plant"/>
119                                     </div>
120                                 </div>
121                             </form>
123                             <center>
124                                 <button class="btn btn-primary" id="add_new_trait_trait_step">Go to Next Step</button>
125                             </center>
127                         </&>
128                         <&| /util/workflow.mas:step, title=> "Method" &>
129                             <p>A method defines the how it was measured measured. It is one component of an observation variable; the others are a trait and a scale.</p>
130                             <hr>
132                             <center>
133                                 <button class="btn btn-primary" name="add_new_observation_variable_ontology_add_button">Need a new ontology? Click here first.</button>
134                             </center>
135                             <br/><br/>
137                             <form class="form-horizontal">
138                                 <div class="form-group">
139                                     <label class="col-sm-3 control-label">Method Ontology Name: </label>
140                                     <div class="col-sm-9">
141                                         <div id="add_new_trait_method_ontology_select_div">
142                                         </div>
143                                     </div>
144                                 </div>
145                                 <div class="form-group">
146                                     <label class="col-sm-3 control-label">Existing Methods in Selected Ontology: </label>
147                                     <div class="col-sm-9">
148                                         <div id="add_new_trait_existing_method_select_div">
149                                         </div>
150                                     </div>
151                                 </div>
152                                 <hr>
154                                 <div class="well">
155                                     <h3>If the method does not exist in the ontology you selected above, you can add a new method into the ontology here.</h3>
156                                 </div>
158                                 <div class="form-group">
159                                     <label class="col-sm-3 control-label">New Method Name: </label>
160                                     <div class="col-sm-9">
161                                         <input class="form-control" id="add_new_trait_method_name" name="add_new_trait_method_name" type="text" placeholder="e.g. BrandA Mass Balance 0.001g Accuracy"/>
162                                     </div>
163                                 </div>
164                                 <div class="form-group">
165                                     <label class="col-sm-3 control-label">New Method Definition: </label>
166                                     <div class="col-sm-9">
167                                         <input class="form-control" id="add_new_trait_method_definition" name="add_new_trait_method_definition" type="text" placeholder="e.g. BrandA MachineX Mass Balance 0.001g Accuracy"/>
168                                     </div>
169                                 </div>
170                             </form>
172                             <center>
173                                 <button type="button" class="btn btn-primary" id="add_new_trait_method_step">Go to Next Step</button>
174                             </center>
176                         </&>
177                         <&| /util/workflow.mas:step, title=> "Scale" &>
178                             <& /page/page_title.mas, title=>"Define your scale" &>
180                             <center>
181                                 <button class="btn btn-primary" name="add_new_observation_variable_ontology_add_button">Need a new ontology? Click here first.</button>
182                             </center>
183                             <br/><br/>
185                             <form class="form-horizontal">
186                                 <div class="form-group">
187                                     <label class="col-sm-3 control-label">Scale Ontology Name: </label>
188                                     <div class="col-sm-9">
189                                         <div id="add_new_trait_scale_ontology_select_div">
190                                         </div>
191                                     </div>
192                                 </div>
193                                 <div class="form-group">
194                                     <label class="col-sm-3 control-label">Existing Scales in Selected Ontology: </label>
195                                     <div class="col-sm-9">
196                                         <div id="add_new_trait_existing_scale_select_div">
197                                         </div>
198                                     </div>
199                                 </div>
200                                 <hr>
202                                 <div class="well">
203                                     <h3>If the scale does not exist in the ontology you selected above, you can add a new scale into the ontology here.</h3>
204                                 </div>
206                                 <div class="form-group">
207                                     <label class="col-sm-3 control-label">New Scale Name: </label>
208                                     <div class="col-sm-9">
209                                         <input class="form-control" id="add_new_trait_scale_name" name="add_new_trait_scale_name" type="text" placeholder="e.g. mass in kilograms"/>
210                                     </div>
211                                 </div>
212                                 <div class="form-group">
213                                     <label class="col-sm-3 control-label">New Scale Definition: </label>
214                                     <div class="col-sm-9">
215                                         <input class="form-control" id="add_new_trait_scale_definition" name="add_new_trait_scale_definition" type="text" placeholder="e.g. the mass in kilograms"/>
216                                     </div>
217                                 </div>
218                                 <div class="form-group">
219                                     <label class="col-sm-3 control-label">New Scale Format: </label>
220                                     <div class="col-sm-9">
221                                         <select class="form-control" id="add_new_trait_scale_format" name="add_new_trait_scale_format" >
222                                             <option value="">Select One</option>
223                                             <option value="qualitative">qualitative</option>
224                                             <option value="quantitative">quantitative</option>
225                                         </select>
226                                     </div>
227                                 </div>
228                                 <div class="form-group">
229                                     <label class="col-sm-3 control-label">New Scale Minimum: </label>
230                                     <div class="col-sm-9">
231                                         <input class="form-control" id="add_new_trait_scale_minimum" name="add_new_trait_scale_minimum" type="text" placeholder="e.g. 1"/>
232                                     </div>
233                                 </div>
234                                 <div class="form-group">
235                                     <label class="col-sm-3 control-label">New Scale Maximum: </label>
236                                     <div class="col-sm-9">
237                                         <input class="form-control" id="add_new_trait_scale_maximum" name="add_new_trait_scale_maximum" type="text" placeholder="e.g. 10000"/>
238                                     </div>
239                                 </div>
240                                 <div class="form-group">
241                                     <label class="col-sm-3 control-label">New Scale Categories ('/' separated): </label>
242                                     <div class="col-sm-9">
243                                         <input class="form-control" id="add_new_trait_scale_categories" name="add_new_trait_scale_categories" type="text" placeholder="e.g. 1/3/5/7"/>
244                                     </div>
245                                 </div>
246                                 <div class="form-group">
247                                     <label class="col-sm-3 control-label">New Scale Default Value: </label>
248                                     <div class="col-sm-9">
249                                         <input class="form-control" id="add_new_trait_scale_default" name="add_new_trait_scale_default" type="text" placeholder="e.g. 5"/>
250                                     </div>
251                                 </div>
252                             </form>
254                             <center>
255                                 <button type="button" class="btn btn-primary" id="add_new_trait_scale_step">Go to Next Step</button>
256                             </center>
258                         </&>
259                         <&| /util/workflow.mas:step, title=> "Confirm" &>
260                             <& /page/page_title.mas, title=>"Confirm you are creating this observation variable in the database" &>
262                             <center>
263                                 <button class="btn btn-primary" id="add_new_trait_submit_button">Submit</button>
264                             </center>
265                         </&>
266                         <&| /util/workflow.mas:complete, title=> "Complete" &>
267                             <& /page/page_title.mas, title=>"Finished! Your observation variable is now in the database" &>
269                             <div id="add_new_trait_added_observation_variable_div">
270                             </div>
271                         </&>
273                     </&><!-- End of workflow -->
275                 </div>
276             </div>
277             <div class="modal-footer">
278                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
279             </div>
280         </div>
281     </div>
282 </div>
284 <div class="modal fade" id="add_new_observation_variable_ontology_dialog" name="add_new_observation_variable_ontology_dialog" tabindex="-1" role="dialog" aria-labelledby="addNewObservationVariableOntologyDialog">
285     <div class="modal-dialog modal-xl" role="document">
286         <div class="modal-content">
287             <div class="modal-header">
288                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
289                 <h4 class="modal-title" id="addNewObservationVariableOntologyDialog">Add New Ontology</h4>
290             </div>
291             <div class="modal-body">
292                 <div class="container-fluid">
294                     <&| /util/workflow.mas, id=> "add_new_ontology_workflow" &>
295                         <&| /util/workflow.mas:step, title=> "Intro" &>
296                             <& /page/page_title.mas, title=>"Start a new ontology" &>
297                             <ul>
298                                 <li>In this workflow you can add a new ontology to the database. Once an ontology is added, you can add terms into it from the add observation variables workflow.</li>
299                                 <li>Ontologies are tagged as being either for traits, methods, or scales</li>
300                             </ul>
302                             <br/><br/>
303                             <center>
304                                 <button class="btn btn-primary" onclick="Workflow.complete(this);">Go to Next Step</button>
305                             </center>
306                         </&>
308                         <&| /util/workflow.mas:step, title=> "Ontology" &>
309                             <& /page/page_title.mas, title=>"Define your ontology" &>
311                             <form class="form-horizontal">
312                                 <div class="form-group">
313                                     <label class="col-sm-3 control-label">New Ontology Name: </label>
314                                     <div class="col-sm-9">
315                                         <input class="form-control" id="add_new_observation_variable_ontology_name" name="add_new_observation_variable_ontology_name" type="text" placeholder="e.g. MyBreedingProgram Grape Ontology"/>
316                                     </div>
317                                 </div>
318                                 <div class="form-group">
319                                     <label class="col-sm-3 control-label">New Ontology Definition: </label>
320                                     <div class="col-sm-9">
321                                         <input class="form-control" id="add_new_observation_variable_ontology_definition" name="add_new_observation_variable_ontology_definition" type="text" placeholder="e.g. description of the ontology"/>
322                                     </div>
323                                 </div>
324                                 <div class="form-group">
325                                     <label class="col-sm-3 control-label">New Ontology Database Identifier: </label>
326                                     <div class="col-sm-9">
327                                         <input class="form-control" id="add_new_observation_variable_ontology_db_name" name="add_new_observation_variable_ontology_db_name" type="text" placeholder="a unique identifier for the terms in the ontology e.g. CO322"/>
328                                     </div>
329                                 </div>
330                                 <div class="form-group">
331                                     <label class="col-sm-3 control-label">Ontology Type: </label>
332                                     <div class="col-sm-9">
333                                         <select class="form-control" id="add_new_observation_variable_ontology_type" name="add_new_observation_variable_ontology_type"/>
334                                             <option value="trait_ontology">Trait or Observation Variable</option>
335                                             <option value="method_ontology">Method</option>
336                                             <option value="unit_ontology">Scale</option>
337                                         </select>
338                                     </div>
339                                 </div>
340                             </form>
341                             <br/>
343                             <center>
344                                 <button class="btn btn-primary" id="add_new_trait_observation_variable_ontology_step">Store Ontology</button>
345                             </center>
347                         </&>
348                         <&| /util/workflow.mas:complete, title=> "Complete" &>
349                             <& /page/page_title.mas, title=>"Finished! Your ontology is now in the database. Add new terms into it from the add observation variable workflow." &>
350                         </&>
352                     </&><!-- End of workflow -->
354                 </div>
355             </div>
356             <div class="modal-footer">
357                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
358             </div>
359         </div>
360     </div>
361 </div>
363 <script>
364 jQuery(document).ready(function() {
366     jQuery('button[name="add_new_observation_variable_ontology_add_button"]').click(function(){
367         jQuery('#add_new_observation_variable_ontology_dialog').modal('show');
368     });
370     jQuery('button[name="add_new_observation_variable_button"]').click(function(){
371         jQuery('#add_new_observation_variable_dialog').modal('show');
373         get_select_box('trait_variable_ontologies', 'add_new_observation_variable_ontology_select_div', { 'name':'add_new_observation_variable_ontology_select',    'id':'add_new_observation_variable_ontology_select', 'empty':1, 'cvprop_type_name':JSON.stringify(['trait_ontology','composed_trait_ontology','attribute_ontology']) });
374         get_select_box('trait_variable_ontologies', 'add_new_trait_ontology_select_div', { 'name':'add_new_trait_ontology_select', 'id':'add_new_trait_ontology_select', 'empty':1, 'cvprop_type_name':JSON.stringify(['trait_ontology','composed_trait_ontology','attribute_ontology']) });
375         get_select_box('trait_variable_ontologies', 'add_new_trait_method_ontology_select_div', { 'name':'add_new_trait_method_ontology_select', 'id':'add_new_trait_method_ontology_select', 'empty':1, 'cvprop_type_name':JSON.stringify(['method_ontology']) });
376         get_select_box('trait_variable_ontologies', 'add_new_trait_scale_ontology_select_div', { 'name':'add_new_trait_scale_ontology_select', 'id':'add_new_trait_scale_ontology_select', 'empty':1, 'cvprop_type_name':JSON.stringify(['unit_ontology']) });
377         
378     });
380     var add_new_trait_new_observation_variable_db_id;
381     var add_new_trait_new_observation_variable_name;
382     var add_new_trait_new_observation_variable_definition;
383     jQuery('#add_new_trait_observation_variable_step').click(function() {
384         if (jQuery('#add_new_observation_variable_name').val() == '') {
385             alert('Please give a new observation variable name!');
386             return false;
387         }
388         if (jQuery('#add_new_observation_variable_definition').val() == '') {
389             alert('Please give a new observation variable definition!');
390             return false;
391         }
392         var selected = [];
393         jQuery('input[name="add_new_observation_variable_ontology_select"]:checked').each(function(){
394             selected.push(jQuery(this).val());
395         });
396         if (selected.length < 1) {
397             alert('Please select one observation variable ontology!');
398         } else if (selected.length > 1) {
399             alert('Only select one observation variable ontology!');
400         } else {
401             add_new_trait_new_observation_variable_name = jQuery('#add_new_observation_variable_name').val();
402             add_new_trait_new_observation_variable_definition = jQuery('#add_new_observation_variable_definition').val();
403             add_new_trait_new_observation_variable_db_id = selected[0];
404             Workflow.complete('#add_new_trait_observation_variable_step');
405             Workflow.focus('#add_new_trait_workflow', 2);
406         }
407         return false;
408     });
410     var add_new_trait_new_trait_db_id;
411     jQuery(document).on('change', 'input[name="add_new_trait_ontology_select"]', function(){
412         var selected = [];
413         jQuery('input[name="add_new_trait_ontology_select"]:checked').each(function(){
414             selected.push(jQuery(this).val());
415         });
416         if (selected.length > 1) {
417             alert('Only select one trait ontology!');
418         } else {
419             add_new_trait_new_trait_db_id = selected[0];
420             get_select_box('all_ontology_terms', 'add_new_trait_existing_trait_select_div', { 'selectbox_name':'add_new_trait_existing_trait_select',    'selectbox_id':'add_new_trait_existing_trait_select', 'empty':1, 'db_id':selected[0], 'exclude_top_term':1 });
421         }
422     });
424     var add_new_trait_new_method_db_id;
425     jQuery(document).on('change', 'input[name="add_new_trait_method_ontology_select"]', function(){
426         var selected = [];
427         jQuery('input[name="add_new_trait_method_ontology_select"]:checked').each(function(){
428             selected.push(jQuery(this).val());
429         });
430         if (selected.length > 1) {
431             alert('Only select one method ontology!');
432         } else {
433             add_new_trait_new_method_db_id = selected[0];
434             get_select_box('all_ontology_terms', 'add_new_trait_existing_method_select_div', { 'selectbox_name':'add_new_trait_existing_method_select',    'selectbox_id':'add_new_trait_existing_method_select', 'empty':1, 'db_id':selected[0], 'exclude_top_term':1 });
435         }
436     });
438     var add_new_trait_new_scale_db_id;
439     jQuery(document).on('change', 'input[name="add_new_trait_scale_ontology_select"]', function(){
440         var selected = [];
441         jQuery('input[name="add_new_trait_scale_ontology_select"]:checked').each(function(){
442             selected.push(jQuery(this).val());
443         });
444         if (selected.length > 1) {
445             alert('Only select one scale ontology!');
446         } else {
447             add_new_trait_new_scale_db_id = selected[0];
448             get_select_box('all_ontology_terms', 'add_new_trait_existing_scale_select_div', { 'selectbox_name':'add_new_trait_existing_scale_select',    'selectbox_id':'add_new_trait_existing_scale_select', 'empty':1, 'db_id':selected[0], 'exclude_top_term':1 });
449         }
450     });
452     var add_new_trait_selected_trait_cvterm_id;
453     var add_new_trait_new_trait_name;
454     var add_new_trait_new_trait_definition;
455     jQuery('#add_new_trait_trait_step').click(function() {
456         var add_new_trait_selected_trait_val = jQuery('#add_new_trait_existing_trait_select').val();
457         if (add_new_trait_selected_trait_val == '0') {
458             add_new_trait_selected_trait_val = '';
459         }
460         if (add_new_trait_selected_trait_val == '' && jQuery('#add_new_trait_name').val() == '') {
461             alert('Please select an existing trait or give a new trait name!');
462             return false;
463         }
464         if (add_new_trait_selected_trait_val != '' && jQuery('#add_new_trait_name').val() != '') {
465             alert('Please select an existing trait or give a new trait name, and not both!');
466             return false;
467         }
468         var selected = [];
469         jQuery('input[name="add_new_trait_ontology_select"]:checked').each(function(){
470             selected.push(jQuery(this).val());
471         });
472         if (selected.length < 1) {
473             alert('Please select one trait ontology!');
474         } else if (selected.length > 1) {
475             alert('Only select one trait ontology!');
476         } else {
477             if (add_new_trait_selected_trait_val == '') {
478                 if (jQuery('#add_new_trait_name').val() == ''){
479                     alert('Please give a new trait name!');
480                 }
481                 else if (jQuery('#add_new_trait_definition').val() == ''){
482                     alert('Please give a new trait definition!');
483                 }
484                 else {
485                     add_new_trait_new_trait_name = jQuery('#add_new_trait_name').val();
486                     add_new_trait_new_trait_definition = jQuery('#add_new_trait_definition').val();
487                     Workflow.complete('#add_new_trait_trait_step');
488                     Workflow.focus('#add_new_trait_workflow', 3);
489                 }
490             } else {
491                 add_new_trait_selected_trait_cvterm_id = add_new_trait_selected_trait_val;
492                 Workflow.complete('#add_new_trait_trait_step');
493                 Workflow.focus('#add_new_trait_workflow', 3);
494             }
495         }
496         return false;
497     });
499     var add_new_trait_selected_method_cvterm_id;
500     var add_new_trait_new_method_name;
501     var add_new_trait_new_method_definition;
502     jQuery('#add_new_trait_method_step').click(function(){
503         var add_new_trait_selected_method_val = jQuery('#add_new_trait_existing_method_select').val();
504         if (add_new_trait_selected_method_val == '0') {
505             add_new_trait_selected_method_val = '';
506         }
507         if (add_new_trait_selected_method_val == '' && jQuery('#add_new_trait_method_name').val() == '') {
508             alert('Please select an existing method or give a new method name!');
509             return false;
510         }
511         if (add_new_trait_selected_method_val != '' && jQuery('#add_new_trait_method_name').val() != '') {
512             alert('Please select an existing method or give a new method name, and not both!');
513             return false;
514         }
515         var selected = [];
516         jQuery('input[name="add_new_trait_method_ontology_select"]:checked').each(function(){
517             selected.push(jQuery(this).val());
518         });
519         if (selected.length < 1) {
520             alert('Please select one method ontology!');
521         } else if (selected.length > 1) {
522             alert('Only select one method ontology!');
523         } else {
524             if (add_new_trait_selected_method_val == '') {
525                 if (jQuery('#add_new_trait_method_name').val() == ''){
526                     alert('Please give a new method name!');
527                 }
528                 else if (jQuery('#add_new_trait_method_definition').val() == ''){
529                     alert('Please give a new method definition!');
530                 }
531                 else {
532                     add_new_trait_new_method_name = jQuery('#add_new_trait_method_name').val();
533                     add_new_trait_new_method_definition = jQuery('#add_new_trait_method_definition').val();
534                     Workflow.complete('#add_new_trait_method_step');
535                     Workflow.focus('#add_new_trait_workflow', 4);
536                 }
537             } else {
538                 add_new_trait_selected_method_cvterm_id = add_new_trait_selected_method_val;
539                 Workflow.complete('#add_new_trait_method_step');
540                 Workflow.focus('#add_new_trait_workflow', 4);
541             }
542         }
543         return false;
544     });
546     var add_new_trait_selected_scale_cvterm_id;
547     var add_new_trait_new_scale_name;
548     var add_new_trait_new_scale_definition;
549     var add_new_trait_new_scale_format;
550     var add_new_trait_new_scale_minimum;
551     var add_new_trait_new_scale_maximum;
552     var add_new_trait_new_scale_default;
553     var add_new_trait_new_scale_categories;
554     jQuery('#add_new_trait_scale_step').click(function(){
555         var add_new_trait_selected_scale_val = jQuery('#add_new_trait_existing_scale_select').val();
556         if (add_new_trait_selected_scale_val == '0') {
557             add_new_trait_selected_scale_val = '';
558         }
559         if (add_new_trait_selected_scale_val == '' && jQuery('#add_new_trait_scale_name').val() == '') {
560             alert('Please select an existing scale or give a new scale name!');
561             return false;
562         }
563         if (add_new_trait_selected_scale_val != '' && jQuery('#add_new_trait_scale_name').val() != '') {
564             alert('Please select an existing scale or give a new scale name, and not both!');
565             return false;
566         }
567         var selected = [];
568         jQuery('input[name="add_new_trait_scale_ontology_select"]:checked').each(function(){
569             selected.push(jQuery(this).val());
570         });
571         if (selected.length < 1) {
572             alert('Please select one scale ontology!');
573         } else if (selected.length > 1) {
574             alert('Only select one scale ontology!');
575         } else {
576             if (add_new_trait_selected_scale_val == '') {
577                 if (jQuery('#add_new_trait_scale_name').val() == ''){
578                     alert('Please give a new scale name!');
579                 }
580                 else if (jQuery('#add_new_trait_scale_definition').val() == ''){
581                     alert('Please give a new scale definition!');
582                 }
583                 else if (jQuery('#add_new_trait_scale_format').val() == ''){
584                     alert('Please give a new scale format!');
585                 }
586                 else if (jQuery('#add_new_trait_scale_minimum').val() == ''){
587                     alert('Please give a new scale minimum!');
588                 }
589                 else if (jQuery('#add_new_trait_scale_maximum').val() == ''){
590                     alert('Please give a new scale maximum!');
591                 }
592                 else {
593                     add_new_trait_new_scale_name = jQuery('#add_new_trait_scale_name').val();
594                     add_new_trait_new_scale_definition = jQuery('#add_new_trait_scale_definition').val();
595                     add_new_trait_new_scale_format = jQuery('#add_new_trait_scale_format').val();
596                     add_new_trait_new_scale_minimum = jQuery('#add_new_trait_scale_minimum').val();
597                     add_new_trait_new_scale_maximum = jQuery('#add_new_trait_scale_maximum').val();
598                     add_new_trait_new_scale_default = jQuery('#add_new_trait_scale_default').val();
599                     add_new_trait_new_scale_categories = jQuery('#add_new_trait_scale_categories').val();
600                     Workflow.complete('#add_new_trait_scale_step');
601                     Workflow.focus('#add_new_trait_workflow', 5);
602                 }
603             } else {
604                 add_new_trait_selected_scale_cvterm_id = add_new_trait_selected_scale_val;
605                 Workflow.complete('#add_new_trait_scale_step');
606                 Workflow.focus('#add_new_trait_workflow', 5);
607             }
608         }
609         return false;
610     });
612     jQuery('#add_new_trait_submit_button').click(function(){
613         jQuery.ajax ({
614             url: '/ajax/onto/store_trait_method_scale_observation_variable',
615             type: 'POST',
616             data: {
617                 'selected_observation_variable_db_id':add_new_trait_new_observation_variable_db_id,
618                 'new_observation_variable_name':add_new_trait_new_observation_variable_name,
619                 'new_observation_variable_definition':add_new_trait_new_observation_variable_definition,
620                 'selected_trait_db_id':add_new_trait_new_trait_db_id,
621                 'selected_trait_cvterm_id':add_new_trait_selected_trait_cvterm_id,
622                 'new_trait_name':add_new_trait_new_trait_name,
623                 'new_trait_definition':add_new_trait_new_trait_definition,
624                 'selected_method_db_id':add_new_trait_new_method_db_id,
625                 'selected_method_cvterm_id':add_new_trait_selected_method_cvterm_id,
626                 'new_method_name':add_new_trait_new_method_name,
627                 'new_method_definition':add_new_trait_new_method_definition,
628                 'selected_scale_db_id':add_new_trait_new_scale_db_id,
629                 'selected_scale_cvterm_id':add_new_trait_selected_scale_cvterm_id,
630                 'new_scale_name':add_new_trait_new_scale_name,
631                 'new_scale_definition':add_new_trait_new_scale_definition,
632                 'new_scale_format':add_new_trait_new_scale_format,
633                 'new_scale_minimum':add_new_trait_new_scale_minimum,
634                 'new_scale_maximum':add_new_trait_new_scale_maximum,
635                 'new_scale_default':add_new_trait_new_scale_default,
636                 'new_scale_categories':add_new_trait_new_scale_categories,
637             },
638             beforeSend: function() {
639                 jQuery("#working_modal").modal("show");
640             },
641             success: function(response){
642                 console.log(response);
643                 jQuery("#working_modal").modal("hide");
644                 //if (response.message){
645                 //    jQuery('#add_new_trait_added_observation_variable_div').html(response.message);
646                 //    Workflow.complete('#add_new_trait_submit_button');
647                 //    Workflow.focus("#add_new_trait_workflow", -1); //go to success page
648                 //}
649                 if (response.success) {
650                     alert(response.success);
651                 }
652                 if (response.error) {
653                     alert(response.error);
654                 }
655                 location.reload();
656             },
657             error: function(response){
658                 jQuery("#working_modal").modal("hide");
659                 alert("Error saving observation variable.");
660             }
661         });
662     });
664     jQuery('#add_new_trait_observation_variable_ontology_step').click(function(){
665         jQuery.ajax ({
666             url: '/ajax/onto/store_ontology_identifier',
667             type: 'POST',
668             data: {
669                 'ontology_name':jQuery('#add_new_observation_variable_ontology_name').val(),
670                 'ontology_description':jQuery('#add_new_observation_variable_ontology_definition').val(),
671                 'ontology_identifier':jQuery('#add_new_observation_variable_ontology_db_name').val(),
672                 'ontology_type':jQuery('#add_new_observation_variable_ontology_type').val()
673             },
674             beforeSend: function() {
675                 jQuery("#working_modal").modal("show");
676             },
677             success: function(response){
678                 console.log(response);
679                 jQuery("#working_modal").modal("hide");
680                 //if (response.message){
681                 //    Workflow.complete('#add_new_trait_observation_variable_ontology_step');
682                 //    Workflow.focus("#add_new_ontology_workflow", -1); //go to success page
683                 //}
684                 if (response.success) {
685                     alert(response.success);
686                 }
687                 if (response.error) {
688                     alert(response.error);
689                 }
690                 location.reload();
691             },
692             error: function(response){
693                 jQuery("#working_modal").modal("hide");
694                 alert("Error saving ontology.");
695             }
696         });
697     });
699 </script>