Merge pull request #2864 from solgenomics/topic/fixing_h2_detail_page
[sgn.git] / mason / breeders_toolbox / add_data_agreement_dialogs.mas
blobf0747f543948e4fdaf89cdcf5f507b1c8337d915
1 <%args>
2 $trial_id
3 </%args>
5 <div class="modal fade" id="add_data_agreement_dialog" name="add_data_agreement_dialog" tabindex="-1" role="dialog" aria-labelledby="addDataAgreementDialog" data-backdrop="static" data-keyboard="false">
6     <div class="modal-dialog modal-lg" role="document">
7         <div class="modal-content">
8             <div class="modal-header">
9                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
10                 <h4 class="modal-title" id="addDataAgreementDialog">Modify Data Agreement</h4>
11             </div>
12             <div class="modal-body">
13                 <div class="container-fluid">
15                     <textarea class="form-control" rows="10" id="data_agreement_text">
16                     </textarea>
18                 </div>
19             </div>
20             <div class="modal-footer">
21                 <button type="button" class="btn btn-default" data-dismiss="modal" id="data_agreement_cancel_button">Close</button>
22                 <button type="button" class="btn btn-primary" name="data_agreement_ok_button" id="data_agreement_ok_button">Submit</button>
23             </div>
24         </div>
25     </div>
26 </div>
28 <script>
30 jQuery(document).ready(function () {
32     jQuery('#data_agreement_ok_button').click(function(){
33         add_data_agreement();
34     });
36     jQuery('#add_data_agreement').click( function() {
37         get_data_agreement(<% $trial_id %>, 'data_agreement_text');
38         jQuery('#add_data_agreement_dialog').modal('show');
39     });
41    function add_data_agreement() { 
42      var data_agreement_text = jQuery('#data_agreement_text').val();
43      jQuery.ajax( { 
44         url: '/breeders/trial/add/data_agreement',
45         data: { 'text': data_agreement_text, 'project_id': <% $trial_id %> },
46         success: function(response) { 
47           if (response.error) { alert(response.error); }
48           else 
49           if (response.message) { alert(response.message); }
50           else { 
51             alert("Successfully added a data agreement to this trial.");
52           }
53           get_data_agreement(<% $trial_id %>, 'data_agreement_div');
54         },
55         error: function(response) { 
56           alert("An error occurred storing the data agreement.");
57         }
58       });
59     }
61     function get_data_agreement(project_id, div) { 
62       jQuery.ajax( { 
63         async: true,
64         url: '/breeders/trial/data_agreement/get',
65         data: { 'project_id': project_id },
66         success: function(response) { 
67            if (response.text) { 
68              jQuery('#'+div).html(response.text);
69            }
70            else { 
71              jQuery('#'+div).html('By default, trial data is provided under the Toronto agreement, as explained in the <a href="/usage_policy">data usage policy</a>.');
72            }
73            if (response.message) { alert(response.message); }
74         },
75         error: function(response) { 
76            alert('An error occurred fetching the data agreement data.');
77         }
78       });
79     }
82 });
85 </script>