comment out large section of breeding program details - this info should be on the...
[sgn.git] / mason / breeders_toolbox / breeding_programs.mas
blob2663b4f9565a0770ad5786006757d73279887534
2 <%args>
3 $breeding_programs
4 $user => undef
5 </%args>
7 <%perl>
8 my $curator_flag = 0;
9 if ($user && $user->check_roles("curator")) {
10     $curator_flag = 1;
12 </%perl>
14 <& /page/page_title.mas, title=>"Manage Breeding Programs" &>
16 <div class="container-fluid">
17 <hr>
19 <table class="table table-condensed table-striped table-hover">
20   <thead>
21     <tr>
23     <%perl>
24       if ($curator_flag) { print "<th>Name</th><th>Info</th><th>Edit</th><th>Delete</th>"; }
25         else { print "<th>Name</th><th>Info</th>"; }
26     </%perl>
28     </tr>
29   </thead>
30   <tbody>
32     <%perl>
33       foreach my $bp (@$breeding_programs) {
35         print "<tr><td><b><a href=\"/breeders/program/$bp->[0]\" >$bp->[1]</a></b></td><td>$bp->[2]</td>";
37         if ($curator_flag) {
38       print "<td><a title=\"edit this breeding program\" id=\"edit_breeding_program_link\_".$bp->[1]."\" href=\"javascript:edit_breeding_program($bp->[0],'$bp->[1]','$bp->[2]')\" ><span class=\"glyphicon glyphicon-pencil\"></span></a></td>";
39           print "<td><a title=\"delete this breeding program\" id=\"delete_breeding_program_link\_".$bp->[1]."\" href=\"javascript:delete_breeding_program($bp->[0],'$bp->[1]')\" ><font color=\"red\">X</font></a></td></tr>";
40         } else {
41           print "</tr>";
42         }
43       }
44     </%perl>
46   </tbody>
47 </table>
49 <br/>
50 <button type="button" class="btn btn-primary" name="new_breeding_program_link" id="new_breeding_program_link">Add New Program</button>
52 </div>
54 <!-- Modal Dialogs Below Here -->
56 <div class="modal fade" id="store_breeding_program_dialog" name="store_breeding_program_dialog" tabindex="-1" role="dialog" aria-labelledby="storeBreedingProgramDialog">
57   <div class="modal-dialog" role="document">
58     <div class="modal-content">
59       <div class="modal-header">
60         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
61         <h4 class="modal-title" id="addBreedingProgramDialog">Store Breeding Program Details</h4>
62       </div>
63       <div class="modal-body">
64         <div class="container-fluid">
65           <form class="form-horizontal" role="form" name="store_breeding_program_form" id="store_breeding_program_form">
66         <div class="form-group" id="store_breeding_program_id" style="display: none"></div>
67             <div class="form-group">
68               <label class="col-sm-2 control-label">Name: </label>
69               <div class="col-sm-10">
70                 <input class="form-control" name="store_breeding_program_name" id="store_breeding_program_name" type="text" />
71               </div>
72             </div>
73             <div class="form-group">
74               <label class="col-sm-2 control-label">Description: </label>
75               <div class="col-sm-10">
76                 <input class="form-control" name="store_breeding_program_desc" id="store_breeding_program_desc" type="text" />
77               </div>
78             </div>
79           </form>
80         </div>
81       </div>
82       <div class="modal-footer">
83         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
84         <button type="button" class="btn btn-primary" name="store_breeding_program_submit" id="store_breeding_program_submit">Store Breeding Program Details</button>
85       </div>
86     </div>
87   </div>
88 </div>
91 <script>
93 jQuery(document).ready(function() {
95   $("button#new_breeding_program_link").click( function(event) {
96       event.preventDefault();
97       $("#store_breeding_program_dialog").modal("show");
98   });
100   $('#store_breeding_program_submit').click( function(event) {
101       event.preventDefault();
102       var id= jQuery('#store_breeding_program_id').val();
103       var name = jQuery('#store_breeding_program_name').val();
104       var desc = jQuery('#store_breeding_program_desc').val();
105       name = name.trim();
106       if ( (name === '') || (desc === '')) {
107           alert("Please enter a name and a description.");
108           return;
109       }
110       // console.log("Name is "+name+" and desc is: "+desc);
111       $.ajax({
112           type: 'POST',
113           url: '/breeders/program/store',
114           data: { 'id': id, 'name': name, 'desc': desc },
115           beforeSend: function()  { jQuery('#working').dialog("open") },
116           success: function(response) {
117               if (response.error) { alert(response.error); }
118               else {
119                   alert(response.success);
120               }
121               jQuery('#working').dialog("close");
122               location.reload();
123           },
124           error: function(response) {
125               alert("An error occurred."+ response.responseText);
126               jQuery('#working').dialog("close");
127           }
128       });
129       $("#store_breeding_program_dialog").modal("hide");
130   });
135 function edit_breeding_program(program_id, program_name, program_description) {
136     jQuery('#store_breeding_program_id').val(program_id);
137     jQuery('#store_breeding_program_name').val(program_name);
138     jQuery('#store_breeding_program_desc').val(program_description);
139     $("#store_breeding_program_dialog").modal("show");
143 function delete_breeding_program(program_id, program_name) {
144    if (confirm("Delete breeding program "+program_name+"? The associated trials will not be deleted, but be listed under 'Other'")) {
145       jQuery.ajax( {
146         url: '/breeders/program/delete/'+program_id,
147         error: function(response) {
148         alert("An error occurred.");
149       },
150       success: function(response) {
151         if (response.error) {
152           alert(response.error);
153         }
154         else {
155           location.reload();
156         }
157       }
158     });
159   }
162 </script>