message dialog and js
[sgn.git] / mason / brapiclient / studies_table.mas
blobc2d15c9f9033cf33220594dd274fd49d1d805d8d
1 <%args>
2 </%args>
4 <div id="brapi_home_study_table_div">
6     <h4>Study Observation Units Table</h4>
7     <input name="brapi_home_studytabledbid" id="brapi_home_studytabledbid" class="form-control" type="text" placeholder="StudyDbId e.g. 139" value="139"/>
8     <select name="brapi_home_studytable_datalevel" id="brapi_home_studytable_datalevel" class="form-control" />
9         <option value="plot">Plot</option>
10         <option value="plant">Plant</option>
11         <option value="all">All</option>
12     </select>
13     <select name="brapi_home_studytable_format" id="brapi_home_studytable_format" class="form-control" />
14         <option value="json">JSON (transformed to HTML table)</option>
15         <option value="csv">CSV</option>
16         <option value="xls">Excel (xls)</option>
17     </select>
18     <button class="btn btn-primary" name="brapi_home_studytabledbid_submit" id="brapi_home_studytabledbid_submit">Get Phenotypes</button>
19     <br/><br/>
20     <div id="brapi_studytable_detail_result_div">
21     </div>
22     <div id="brapi_studytable_data_result_div">
23     </div>
25 </div>
27 <script>
29 jQuery(document).ready(function() {
30     jQuery("#brapi_home_studytabledbid_submit").click(function() {
31     
32         if (jQuery('#brapi_home_studytable_format').val() == 'json') {
33             jQuery.ajax( {
34               'url': jQuery('#brapi_home_url_select').val()+'/brapi/v1/studies/'+jQuery('#brapi_home_studytabledbid').val()+'/table?format='+jQuery('#brapi_home_studytable_format').val()+'&observationLevel='+jQuery("#brapi_home_studytable_datalevel").val(),
35               'method': 'GET',
36               'success': function(response) {
37                 console.log(response);
38                 var html = '<table class="table table-bordered"><thead><tr><th>StudyDbId</th><th>HeaderRow</th><th>ObservationVariableDbIds</th><th>ObservationVariableNames</th></tr></thead><tbody><tr><td>'+response.result.studyDbId+'</td><td>'+response.result.headerRow+'</td><td>'+response.result.observationVariableDbIds+'</td><td>'+response.result.observationVariableNames+'</td></tr></tbody></table>';
39                 jQuery('#brapi_studytable_detail_result_div').empty().html(html);
40                 brapi_create_paginated_table(response.result.data, response.metadata.pagination, 'brapi_studytable_data_result_div', jQuery('#brapi_home_url_select').val()+'/brapi/v1/studies/'+jQuery('#brapi_home_studytabledbid').val()+'/table?format='+jQuery('#brapi_home_studytable_format').val()+'&observationLevel='+jQuery("#brapi_home_studytable_datalevel").val(),  undefined);
42               },
43               error: function(response) {
44                 alert('An error occurred');
45               }
46             });
47         } else {
48             window.open(jQuery('#brapi_home_url_select').val()+'/brapi/v1/studies/'+jQuery('#brapi_home_studytabledbid').val()+'/table?format='+jQuery('#brapi_home_studytable_format').val());
49         }
50     });
51 });
53 </script>