Skip to content

Commit

Permalink
Unify alert CSS and update/prune existing alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhenry committed Jan 29, 2014
1 parent 20b0fde commit 798b717
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 69 deletions.
18 changes: 0 additions & 18 deletions app/assets/stylesheets/admin.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,6 @@
}
}

.admin-alert {
margin-top: 30px!important;
}

.admin-alert.alert.alert-success {
background: rgba(115, 211, 107, 1)!important;
text-shadow: none;
}

.admin-alert.alert.alert-notice {
background: rgba(211, 211, 136, 1)!important;
text-shadow: none;
}
.inline-alert{
text-shadow: none;
font-size: 12px;
Expand All @@ -258,8 +245,3 @@
.text-area-border{
border: 1px solid red;
}
.admin-alert.alert.alert-error {
background: rgba(219, 94, 94, 1)!important;
color: white;
text-shadow: none;
}
39 changes: 28 additions & 11 deletions app/assets/stylesheets/flash.css.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
.alert {
padding: 10px;
color: black;
text-align: center;
margin-bottom: 0px;
}

.alert.alert-success {
background: rgba(0, 128, 0, 0.25);
}
&.alert-admin {
margin-top: 30px;
}

.alert.alert-notice {
background: rgba(255, 255, 0, 0.25);
}
&.alert-success {
color: #3c763d;
background-color: #dff0d8;
border-color: darken(adjust-hue(#dff0d8, -10), 5%);
}

&.alert-info, &.alert-notice {
color: #31708f;
background-color: #d9edf7;
border-color: darken(adjust-hue(#d9edf7, -10), 7%);
}

.alert.alert-error {
background: rgba(255, 0, 0, 0.25);
}
&.alert-warning {
background: rgba(255, 255, 0, 0.25);
color: #8a6d3b;
background: #fcf8e3;
border-color: darken(adjust-hue(#fcf8e3, -10), 5%);
}

&.alert-danger, &.alert-error, &.alert-alert {
color: #a94442;
background: #f2dede;
border-color: darken(adjust-hue(#f2dede, -10), 5%);
}

}
7 changes: 0 additions & 7 deletions app/assets/stylesheets/primitives.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ $primary_font: "Helvetica Neue";
$secondary_font: "Helvetica";
$tertiary_font: "Arial";

.alert {
padding: 10px;
color: black;
text-align: center;
margin-bottom: 40px;
}

#main {
min-height: 400px;
}
Expand Down
10 changes: 4 additions & 6 deletions app/controllers/admin/campaigns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def copy
Crowdtilt.sandbox
response = Crowdtilt.post('/campaigns', {campaign: campaign})
rescue => exception
redirect_to admin_campaigns, :flash => { :error => "An error occurred" }
redirect_to admin_campaigns, :flash => { :error => "Could not copy campaign" }
else
@campaign.update_api_data(response['campaign'])
@campaign.save
Expand Down Expand Up @@ -59,7 +59,6 @@ def create
is_default = params[:campaign].delete :is_default
@campaign = Campaign.new(params[:campaign])

# Check if the new settings pass validations...if not, re-render form and display errors in flash msg
if !@campaign.valid?
flash.now[:error] = @campaign.errors.full_messages.join(', ')
render action: "new"
Expand Down Expand Up @@ -133,7 +132,7 @@ def create
end
@settings.save

redirect_to campaign_home_url(@campaign), :flash => { :notice => "Campaign updated!" }
redirect_to campaign_home_url(@campaign), :flash => { :success => "Campaign created!" }
return
end
end
Expand Down Expand Up @@ -187,7 +186,7 @@ def update
r.collect_shipping_flag = reward['collect_shipping_flag']
r.include_claimed = reward['include_claimed']
unless r.save
flash.now[:error] = "Invalid rewards"
flash.now[:error] = "A reward field is missing or invalid"
render action: "edit"
return
end
Expand All @@ -205,7 +204,6 @@ def update
end
end

# Check if the new settings pass validations...if not, re-render form and display errors in flash msg
if !@campaign.valid?
flash.now[:error] = @campaign.errors.full_messages.join(', ')
render action: "edit"
Expand Down Expand Up @@ -248,7 +246,7 @@ def update
else
@campaign.update_api_data(response['campaign'])
@campaign.save
redirect_to campaign_home_url(@campaign), :flash => { :notice => "Campaign updated!" } and return
redirect_to campaign_home_url(@campaign), :flash => { :success => "Campaign updated!" } and return
end
end

Expand Down
14 changes: 7 additions & 7 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ def admin_website

def admin_processor_setup
if request.post?
flash.now[:error] = "Invalid credentials" and return if params[:ct_prod_api_key].blank? || params[:ct_prod_api_secret].blank?
flash.now[:error] = "Missing API credentials" and return if params[:ct_prod_api_key].blank? || params[:ct_prod_api_secret].blank?
if @settings.activate_payments(params[:ct_prod_api_key], params[:ct_prod_api_secret])
flash.now[:success] = "Your payment processor is all set up!"
else
flash.now[:error] = "Invalid credentials"
flash.now[:error] = "Could not activate payment processing. Please double-check your API credentials."
end
end
end

def create_admin_bank_account
if params[:ct_bank_id].blank?
flash = { :error => "Looks like you have JavaScript disabled. JavaScript is required for bank account setup." }
flash = { :warning => "Looks like you have JavaScript disabled. JavaScript is required for bank account setup." }
else
begin
bank = {
Expand All @@ -46,7 +46,7 @@ def create_admin_bank_account

def admin_bank_account
unless @settings.payments_activated?
redirect_to admin_processor_setup_url, flash: { error: "Please set up your payment processor before providing your bank details" } and return
redirect_to admin_processor_setup_url, flash: { info: "Please set up your payment processor before providing your bank details" } and return
end
@bank = {}
begin
Expand All @@ -66,14 +66,14 @@ def delete_admin_bank_account
begin
response = Crowdtilt.get('/users/' + @ct_admin_id + '/banks/default')
rescue => exception
flash = { :error => "No default bank account" }
flash = { :warning => "No default bank account" }
else
begin
Crowdtilt.delete('/users/' + @ct_admin_id + '/banks/' + response['bank']['id'])
rescue => exception
flash = { :error => "An error occurred, please contact [email protected]: #{exception.message}" }
else
flash = { :info => "Bank account deleted successfully" }
flash = { :success => "Bank account deleted successfully" }
end
end
redirect_to admin_bank_account_url, :status => 303, :flash => flash
Expand Down Expand Up @@ -114,7 +114,7 @@ def admin_notification_setup
if current_user.update_attributes(params[:user])
flash.now[:success] = "Notification settings saved!"
else
flash.now[:error] = "There was an error saving your notification settings. Please try again!"
flash.now[:error] = "Could not save notification settings. Please try again!"
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def after_sign_in_path_for(resource)

def verify_admin
if !current_user.admin?
redirect_to root_url, :flash => { :notice => "You must be an admin to access that page" }
end
redirect_to root_url, :flash => { :error => "You must be an admin to access that page" }
end
end

def check_init
Expand Down Expand Up @@ -74,10 +74,10 @@ def check_init
redirect_to admin_website_url, :flash => { :success => "Nice! Your app is now initialized." }
else
if (User.count == 0)
redirect_to new_user_registration_url, :flash => { :error => "Please create an account below to initialize the app." }
else
redirect_to user_session_url , :flash => { :error => "Please sign in below." }
end
redirect_to new_user_registration_url, :flash => { :info => "Please create an account below to initialize the app." }
else
redirect_to user_session_url , :flash => { :info => "Please sign in below." }
end
end
end
end
Expand Down
33 changes: 21 additions & 12 deletions app/controllers/campaigns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def checkout_amount
@reward = Reward.find_by_id(params[:reward])
unless @reward && @reward.campaign_id == @campaign.id && !@reward.sold_out?
@reward = false
flash.now[:notice] = "Please select a different reward"
flash.now[:info] = "This reward is unavailable. Please select a different reward!"
end
end
end
Expand All @@ -30,7 +30,7 @@ def checkout_payment
@quantity = params[:quantity].to_i
@amount = ((@quantity * @campaign.fixed_payment_amount.to_f)*100).ceil/100.0
else
redirect_to checkout_amount_url(@campaign), flash: { error: "Invalid quantity!" }
redirect_to checkout_amount_url(@campaign), flash: { warning: "Invalid quantity!" }
return
end
elsif params.has_key?(:amount) && params[:amount].to_f >= @campaign.min_payment_amount
Expand All @@ -41,17 +41,21 @@ def checkout_payment
begin
@reward = Reward.find(params[:reward])
rescue => exception
redirect_to checkout_amount_url(@campaign), flash: { error: "Please select a different reward" }
redirect_to checkout_amount_url(@campaign), flash: { info: "This reward is unavailable. Please select a different reward!" }
return
end
unless @reward && @reward.campaign_id == @campaign.id && !@reward.sold_out? && @reward.price <= @amount
redirect_to checkout_amount_url(@campaign), flash: { error: "Invalid reward!" }
return
unless @reward && @reward.campaign_id == @campaign.id && @amount >= @reward.price && !@reward.sold_out?
if @reward.sold_out?
flash = { info: "This reward is unavailable. Please select a different reward!" }
else
flash = { warning: "Please enter a higher amount to redeem this reward!" }
end
redirect_to checkout_amount_url(@campaign), flash: flash and return
end
end

else
redirect_to checkout_amount_url(@campaign), flash: { error: "Invalid amount!" }
redirect_to checkout_amount_url(@campaign), flash: { info: "Please enter a higher amount!" }
return
end

Expand Down Expand Up @@ -88,8 +92,13 @@ def checkout_process
@reward = false
if params[:reward].to_i != 0
@reward = Reward.find_by_id(params[:reward])
unless @reward && @reward.campaign_id == @campaign.id && !@reward.sold_out? && @reward.price <= amount
redirect_to checkout_amount_url(@campaign), flash: { error: "Please select a different reward" } and return
unless @reward && @reward.campaign_id == @campaign.id && amount >= @reward.price && !@reward.sold_out?
if @reward.sold_out?
flash = { info: "This reward is unavailable. Please select a different reward!" }
else
flash = { warning: "Please enter a higher amount to redeem this reward!" }
end
redirect_to checkout_amount_url(@campaign), flash: flash and return
end
end

Expand Down Expand Up @@ -203,7 +212,7 @@ def checkout_confirmation
end
end

private
private

def load_campaign
@campaign = Campaign.find(params[:id])
Expand All @@ -214,14 +223,14 @@ def load_campaign
def check_published
if !@campaign.published_flag
unless user_signed_in? && current_user.admin?
redirect_to root_url, :flash => { :error => "Campaign is no longer available" }
redirect_to root_url, :flash => { :info => "Campaign is no longer available" }
end
end
end

def check_exp
if @campaign.expired?
redirect_to campaign_home_url(@campaign), :flash => { :error => "Campaign is expired!" }
redirect_to campaign_home_url(@campaign), :info => { :error => "Campaign is expired!" }
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/views/layouts/_flash.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<% admin = false if local_assigns[:admin].nil? %>
<% flash.to_hash().slice(:success, :info, :notice, :warning, :error, :alert).each do |key, value| %>
<% if !value.blank? %><div class="alert <%= 'alert-admin' if admin %> alert-<%= key %>"><%= value %></div><% end %>
<% end %>
3 changes: 3 additions & 0 deletions app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<% content_for :header do %>
<%= render 'layouts/navbar' %>
<% end %>
<% content_for :flash do %>
<%= render 'layouts/flash', flash: flash, admin: true %>
<% end %>
<% content_for :footer do %>
<%= render 'admin/footer' %>
<% end %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/layouts/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

<%= yield :header %>

<% flash.to_hash().slice(:success, :info, :notice, :error, :alert).each do |key, value| %>
<% if !value.blank? %><div class="alert alert-<%= key %>"><%= value %></div><% end %>
<% if content_for?(:flash) %>
<%= yield :flash %>
<% else %>
<%= render 'layouts/flash', flash: flash %>
<% end %>

<div id="main">
Expand Down

0 comments on commit 798b717

Please sign in to comment.