Merge pull request #5243 from solgenomics/topic/observations_upload_catch_error
[sgn.git] / mason / breeders_toolbox / discard_single_seedlot.mas
blob0b2b8ebefa1172c2f0feab473df12a2b06305dcc
1 <%args>
2 $seedlot_id
3 $uniquename
4 </%args>
6 <div class="modal fade" id="discard_seedlot_dialog" name="discard_seedlot_dialog" tabindex="-1" role="dialog" aria-labelledby="discardSeedlotDialog">
7     <div class="modal-dialog modal-lg" role="document">
8         <div class="modal-content">
9             <div class="modal-header">
10                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
11                 <h4 class="modal-title" id="discardSeedlotDialog">Mark this Seedlot as DISCARDED </h4>
12             </div>
13             <div class="modal-body">
14                 <div class="container-fluid">
15                     <form class="form-horizontal" role="form" method="post" id="discard_seedlot_form" name="discard_seedlot_form">
16                         <div class="form-group">
17                             <label class="col-sm-4 control-label">Seedlot Name: </label>
18                             <div class="col-sm-8" >
19                                 <input class="form-control" name="discard_seedlot_name" id="discard_seedlot_name" disabled value="<% $uniquename %>">
20                             </div>
21                         </div>
22                         <div class="form-group">
23                             <label class="col-sm-4 control-label">Reason for Discarding: </label>
24                             <div class="col-sm-8" >
25                                 <textarea class="form-control" id="reason_for_discarding_details_page" name="reason_for_discarding_details_page" placeholder="Required"></textarea>
26                             </div>
27                         </div>
28                     </form>
29                 </div>
30             </div>
31             <div class="modal-footer">
32                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
33                 <button type="button" class="btn btn-primary" name="discard_single_seedlot_submit" id="discard_single_seedlot_submit">Submit</button>
34             </div>
35         </div>
36     </div>
37 </div>
39 <div class="modal fade" id="saved_dialog_message" name="saved_dialog_message" tabindex="-1" role="dialog" aria-labelledby="savedDialog">
40     <div class="modal-dialog" role="document">
41         <div class="modal-content">
42             <div class="modal-header">
43                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
44                 <h4 class="modal-title" id="savedDialog">Success</h4>
45             </div>
46             <div class="modal-body">
47                 <div class="container-fluid">
48                     <p>
49                         <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
50                         This seedlot was marked as DISCARDED.
51                     </p>
52                 </div>
53             </div>
54             <div class="modal-footer">
55                 <button id="dismiss_saved_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close & Reload</button>
56             </div>
57         </div>
58     </div>
59 </div>
61 <div class="modal fade" id="undo_dialog_message" name="undo_dialog_message" tabindex="-1" role="dialog" aria-labelledby="undoDialog">
62     <div class="modal-dialog" role="document">
63         <div class="modal-content">
64             <div class="modal-header">
65                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
66                 <h4 class="modal-title" id="undoDialog">Success</h4>
67             </div>
68             <div class="modal-body">
69                 <div class="container-fluid">
70                     <p>
71                         <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
72                         This seedlot was restored.
73                     </p>
74                 </div>
75             </div>
76             <div class="modal-footer">
77                 <button id="dismiss_undo_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close & Reload</button>
78             </div>
79         </div>
80     </div>
81 </div>
84 <script>
85 jQuery(document).ready(function(){
87     var seedlot_name = "<% $uniquename %>";
89     jQuery("#discard_seedlot_details_page_link").click( function() {
90         jQuery('#discard_seedlot_dialog').modal('show');
91     });
93     jQuery('#discard_single_seedlot_submit').click(function(){
95         var discard_reason = jQuery('#reason_for_discarding_details_page').val();
97         if (seedlot_name === '') {
98             alert("Error retrieving seedlot info");
99             return;
100         }
102         if (discard_reason === '') {
103             alert("Please provide reason for discarding this seedlot");
104             return;
105         }
107         jQuery.ajax({
108             url: '/ajax/breeders/seedlot/discard',
109             dataType: "json",
110             data : {
111                 'seedlot_name' : seedlot_name,
112                 'discard_reason': discard_reason,
113             },
114             beforeSend: function(response){
115                 jQuery('#working_modal').modal('show');
116             },
117             success: function(response) {
118                 jQuery('#working_modal').modal('hide');
119                 if (response.success == 1) {
120                     jQuery('#discard_seedlot_dialog').modal('hide');
121                     jQuery('#saved_dialog_message').modal("show");
122                 }
123                 if (response.error_string) {
124                     alert(response.error_string);
125                 }
126             },
127             error: function(response){
128                 jQuery('#working_modal').modal('hide');
129                 alert('An error occurred discarding seedlot');
130             }
131         });
132     });
134     jQuery("#dismiss_saved_dialog").click( function() {
135         jQuery('#saved_dialog_message').modal('hide');
136         location.reload();
137     });
139     jQuery('#undo_discarding_seedlot_link').click(function() {
140         var seedlot_id = "<% $seedlot_id %>";
141         var confirmation = confirm("Are you sure you want to UNDO marking this seedlot as DISCARDED ?");
142         if (confirmation) {
143             jQuery.ajax({
144                 url: '/ajax/breeders/seedlot/undo_discard',
145                 dataType: "json",
146                 data : {
147                     'seedlot_id' : seedlot_id,
148                 },
149                 beforeSend: function(response){
150                     jQuery('#working_modal').modal('show');
151                 },
152                 success: function(response) {
153                     jQuery('#working_modal').modal('hide');
154                     if (response.success == 1) {
155                         jQuery('#undo_dialog_message').modal("show");
156                     }
157                     if (response.error_string) {
158                         alert(response.error_string);
159                     }
160                 },
161                 error: function(response){
162                     jQuery('#working_modal').modal('hide');
163                     alert('An error occurred processing your request');
164                 }
165             });
166         }
167     });
169     jQuery("#dismiss_undo_dialog").click( function() {
170         jQuery('#undo_dialog_message').modal('hide');
171         location.reload();
172     });
177 </script>