Add flash messages

This commit is contained in:
Erik Michaels-Ober 2011-08-29 14:51:44 -07:00
parent 668b127f58
commit 34f9b75e79
4 changed files with 62 additions and 7 deletions

View File

@ -273,7 +273,10 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
'hydrant_id': activeHydrantId,
'flash': {
'notice': "Thanks for signing up!"
}
},
success: function(data) {
activeInfoWindow.setContent(data);
@ -325,7 +328,10 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
'hydrant_id': activeHydrantId,
'flash': {
'notice': "Signed in!"
}
},
success: function(data) {
activeInfoWindow.setContent(data);
@ -402,7 +408,10 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
'hydrant_id': activeHydrantId,
'flash': {
'notice': "You just adopted " + $('#hydrant_name').val() + "!"
}
},
success: function(data) {
activeInfoWindow.setContent(data);
@ -453,7 +462,10 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
'hydrant_id': activeHydrantId,
'flash': {
'notice': "Hydrant abandoned!"
}
},
success: function(data) {
activeInfoWindow.setContent(data);
@ -504,7 +516,10 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
'hydrant_id': activeHydrantId,
'flash': {
'notice': "Hydrant stolen!"
}
},
success: function(data) {
activeInfoWindow.setContent(data);
@ -687,7 +702,10 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
'hydrant_id': activeHydrantId,
'flash': {
'notice': "Signed out."
}
},
success: function(data) {
activeInfoWindow.setContent(data);
@ -780,7 +798,10 @@ $(function() {
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
'hydrant_id': activeHydrantId,
'flash': {
'notice': "Reminder sent!"
}
},
success: function(data) {
activeInfoWindow.setContent(data);
@ -790,4 +811,10 @@ $(function() {
});
return false;
});
$('#notice').live('click', function() {
$(this).fadeOut('slow');
});
$('#error').live('click', function() {
$(this).fadeOut('slow');
});
});

View File

@ -51,6 +51,26 @@ form {
width: 100%;
}
#error, #notice, #warning {
margin: auto;
padding: 5px 10px;
}
#error {
background-color: #ff7373;
border: 1px solid #c07373;
}
#notice {
background-color: #8fe38f;
border: 1px solid #82b082;
}
#warning {
background-color: #fff773;
border: 1px solid #c0bb73;
}
label, input {
white-space: nowrap;
text-align: left;

View File

@ -1,6 +1,11 @@
class InfoWindowController < ApplicationController
def index
@hydrant = Hydrant.find_by_id(params[:hydrant_id])
if params[:flash]
params[:flash].each do |key, message|
flash.now[key.to_sym] = message
end
end
if @hydrant.adopted?
if user_signed_in? && current_user.id == @hydrant.user_id
render("users/thank_you")

View File

@ -1,4 +1,7 @@
#loader{:style => "display: none;"}
= image_tag "ajax-loader.gif"
#info_window
- flash.each do |key, message|
%div{:id => key}
= message
= yield