Add ability to abandon an adopted hydrant

This commit is contained in:
Erik Michaels-Ober 2011-03-22 01:45:44 -07:00
parent 77c8df874d
commit dedb04ed60
4 changed files with 43 additions and 8 deletions

View File

@ -0,0 +1,6 @@
<%= form_for @hydrant, :html => {:id => "abandon_form"} do |f| %>
<%= f.hidden_field "id" %>
<%= f.hidden_field "user_id", :value => "" %>
<%= f.hidden_field "name", :value => "" %>
<%= f.submit "Abandon this hydrant", :id => "abandon_form_submit" %>
<% end %>

View File

@ -1,12 +1,10 @@
<%= form_for @hydrant, :html => {:id => "adoption_form"} do |f| %>
<h2>Adopt this Hydrant</h2>
<div id="adoption_fields">
<%= f.hidden_field "id" %>
<%= f.hidden_field "user_id", :value => current_user.id %>
<%= f.label "name", "Give your hydrant a name", :id => "hydrant_name_label" %>
<%= f.text_field "name", :tabindex => 1 %>
<%= f.submit "Adopt!", :tabindex => 2, :id => "adoption_form_submit" %>
<p>By adopting this hydrant, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 3 %>.</p>
</div>
<%= f.hidden_field "id" %>
<%= f.hidden_field "user_id", :value => current_user.id %>
<%= f.label "name", "Give your hydrant a name", :id => "hydrant_name_label" %>
<%= f.text_field "name", :tabindex => 1 %>
<%= f.submit "Adopt!", :tabindex => 2, :id => "adoption_form_submit" %>
<p>By adopting this hydrant, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 3 %>.</p>
<% end %>
<%= render :partial => 'sign_out_form' %>

View File

@ -1,2 +1,3 @@
<h2>Thank you for adopting this hydrant!</h2>
<%= render :partial => 'abandon_form' %>
<%= render :partial => 'sign_out_form' %>

View File

@ -340,6 +340,36 @@ $(function() {
});
return false;
});
$('#abandon_form').live('submit', function() {
var answer = window.confirm("Are you sure you want to abandon this hydrant?")
if(answer) {
$.post('<%= hydrant_path :format => "json" %>', {
'id': $('#hydrant_id').val(),
'commit': $('#abandon_form_submit').val(),
'utf8': '✓',
'authenticity_token': $('#abandon_form input[name="authenticity_token"]').val(),
'_method': 'put',
'hydrant': {
'user_id': $('#hydrant_user_id').val(),
'name': $('#hydrant_name').val()
}
}, function(data) {
$.get('<%= contents_path %>', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
image = new google.maps.MarkerImage('/images/markers/red.png',
new google.maps.Size(27.0, 37.0),
new google.maps.Point(0, 0),
new google.maps.Point(13.0, 18.0)
);
activeMarker.setIcon(image);
activeMarker.setAnimation(null);
});
});
return false;
}
});
$('#steal_form').live('submit', function() {
var answer = window.confirm("Are you sure you want to steal this hydrant?")
if(answer) {