fix to comments in patch
[sgn.git] / mason / breeders_toolbox / breeding_programs.mas
blob3726af57f161a767f26c3c8ef37e331fd7201f46
2 <%args>
3 $breeding_programs
4 $user => undef
5 </%args>
7 <%perl>
8 my $delete_flag = 0;
9 if ($user && $user->check_roles("curator")) {
10     $delete_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 ($delete_flag) { print "<th>Name</th><th>Info</th><th>Delete</th>"; }
25         else { print "<th>Name</th><th>Info</th>"; }
26     </%perl>
27           
28     </tr>
29   </thead>
30   <tbody>
32     <%perl>
33       foreach my $bp (@$breeding_programs) { 
35         print "<tr><td><b>$bp->[1]</b></td><td>$bp->[2]</td>";
37         if ($delete_flag) { 
38           print "<td><a title=\"delete this breeding program\" id=\"delete_breeding_program_link\_".$bp->[1]."\" href=\"javascript:delete_breeding_program($bp->[0])\" ><font color=\"red\">X</font></a></td></tr>";
39         } else { 
40           print "</tr>"; 
41         }
42       }
43     </%perl>    
44         
45   </tbody>
46 </table>
48 <br/>
49 <button type="button" class="btn btn-primary" name="new_breeding_program_link" id="new_breeding_program_link">Add New Program</button>
51 </div>
53 <!-- Modal Dialogs Below Here -->
55 <div class="modal fade" id="new_breeding_program_dialog" name="new_breeding_program_dialog" tabindex="-1" role="dialog" aria-labelledby="addBreedingProgramDialog">
56   <div class="modal-dialog" role="document">
57     <div class="modal-content">
58       <div class="modal-header">
59         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
60         <h4 class="modal-title" id="addBreedingProgramDialog">Add New Breeding Program</h4>
61       </div>
62       <div class="modal-body">
63         <div class="container-fluid">
64           <form class="form-horizontal" role="form" name="new_breeding_program_form" id="new_breeding_program_form">
65             <div class="form-group">
66               <label class="col-sm-2 control-label">Name: </label>
67               <div class="col-sm-10">
68                 <input class="form-control" name="new_breeding_program_name" id="new_breeding_program_name" type="text" />
69               </div>
70             </div>
71             <div class="form-group">
72               <label class="col-sm-2 control-label">Description: </label>
73               <div class="col-sm-10">
74                 <input class="form-control" name="new_breeding_program_desc" id="new_breeding_program_desc" type="text" />
75               </div>
76             </div>
77           </form>      
78         </div>
79       </div>
80       <div class="modal-footer">
81         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
82         <button type="button" class="btn btn-primary" name="new_breeding_program_submit" id="new_breeding_program_submit">Add Breeding Program</button>
83       </div>
84     </div>
85   </div>
86 </div>
88 <!--
89 <div id="new_breeding_program_dialog">
90 <table>
91 <tr><td>Name</td><td><input type="text" id="new_breeding_program_name" size="15" /></td></tr>
92 <tr><td>Description</td><td><input type="text" id="new_breeding_program_desc" size="30" /></td></tr>
93 </table>
94 </div>
95 -->
98 <script>
100 jQuery(document).ready(function() { 
101   
102   $("button#new_breeding_program_link").click( function(event) { 
103       event.preventDefault();
104       $("#new_breeding_program_dialog").modal("show");
105   });
107   $('button#new_breeding_program_submit').click( function(event) {
108       event.preventDefault();
109       var name = jQuery('#new_breeding_program_name').val();
110       var desc = jQuery('#new_breeding_program_desc').val();
111       if ( (name === '') || (desc === '')) { 
112           alert("Please enter a name and a description.");
113           return;
114       }
115       $.ajax({
116           url: '/breeders/program/new',
117           data: { 'name': name, 'desc': desc },
118           beforeSend: function()  { jQuery('#working').dialog("open") },
119           error: function(response) { 
120               alert("An error occurred."+ response.responseText);
121               jQuery('#working').dialog("close");
122           },
123           success: function(response) { 
124               if (response.error) { 
125                   alert(response.error);
126        
127               }
128               else { 
129                   alert("The new breeding program "+name+" was created");
130               }
131               jQuery('#working').dialog("close");
132               location.reload();
133           }
134       });
135       $("#new_breeding_program_dialog").modal("hide");
136    });
139 //jQuery('#new_breeding_program_dialog').dialog( { 
140 //  title: "Add new breeding program",
141 //  width: 400,
142 //  height: 200,
143 //  buttons: { 
144 //    'OK':     { id: 'new_breeding_program_dialog_ok_button',
145 //                text: 'OK',
146 //                click: function() { store_new_breeding_program(); }
147 //              },
148 //    'Cancel': { id: 'new_breeding_program_dialog_cancel_button',
149 //                text: 'Cancel',
150 //                click: function() {  
151 //                  jQuery('#new_breeding_program_dialog').dialog("close"); }
152 //              }
153 //  },
154 //  autoOpen: false
155 //});
157 //function store_new_breeding_program() { 
158 //   var name = jQuery('#new_breeding_program_name').val();
159 //   var desc = jQuery('#new_breeding_program_desc').val();
160 //   if ( (name === '') || (desc === '')) { 
161 //     alert("Please enter a name and a description.");
162 //     return;
163 //   }
164 //   jQuery.ajax( { 
165 //     url: '/breeders/program/new',
166 //     data: { 'name': name, 'desc': desc },
167 //async: false,
168 //     beforeSend: function()  { jQuery('#working').dialog("open") },
169 //     error: function(response) { 
170 //        alert("An error occurred."+ response.responseText);
171 //       jQuery('#working').dialog("close");
172 //     },
174 //     success: function(response) { 
175 //       if (response.error) { 
176 //         alert(response.error);
177 //       
178 //       }
179 //       else { 
180 //         alert("The new breeding program "+name+" was created");
181 //       }
182 //       jQuery('#working').dialog("close");
183 //       location.reload();
184 //     }
186 //   });
187 //   jQuery('#new_breeding_program_dialog').dialog("close");
191 function delete_breeding_program(program_id) { 
192    if (confirm("Delete breeding program? The associated trials will not be deleted, but be listed under 'Other'")) { 
193       jQuery.ajax( { 
194         url: '/breeders/program/delete/'+program_id, 
195         error: function(response) { 
196         alert("An error occurred.");
197       },
198       success: function(response) { 
199         if (response.error) { 
200           alert(response.error);
201         }
202         else { 
203           location.reload();
204         }
205       }
206     });
207   }
210 </script>