1
0
Fork 0
forked from OpenNeo/impress

i18n for closet_hangers#create, closet_hangers#destroy, closet_hangers#update, closet_hangers#update_quantities (flashes, largely intertwined)

This commit is contained in:
Emi Matchu 2013-01-02 22:03:45 -05:00
parent c5e92ec53c
commit 75031c142b
3 changed files with 105 additions and 55 deletions

View file

@ -7,10 +7,7 @@ class ClosetHangersController < ApplicationController
@closet_hanger = current_user.closet_hangers.find params[:id] @closet_hanger = current_user.closet_hangers.find params[:id]
@closet_hanger.destroy @closet_hanger.destroy
@item = @closet_hanger.item @item = @closet_hanger.item
respond_to do |format| closet_hanger_destroyed
format.html { redirect_after_destroy! }
format.json { render :json => true }
end
end end
def index def index
@ -85,26 +82,9 @@ class ClosetHangersController < ApplicationController
@closet_hanger.item = @item @closet_hanger.item = @item
if @closet_hanger.save if @closet_hanger.save
respond_to do |format| closet_hanger_saved
format.html {
message = "Success! You #{@closet_hanger.verb(:you)} #{@closet_hanger.quantity} "
message << ((@closet_hanger.quantity > 1) ? @item.name.pluralize : @item.name)
message << " in the \"#{@closet_hanger.list.name}\" list" if @closet_hanger.list
flash[:success] = "#{message}."
redirect_back!(@item)
}
format.json { render :json => true }
end
else else
respond_to do |format| closet_hanger_invalid
format.html {
flash[:alert] = "We couldn't save how many of this item you #{@closet_hanger.verb(:you)}: #{@closet_hanger.errors.full_messages.to_sentence}"
redirect_back!(@item)
}
format.json { render :json => {:errors => @closet_hanger.errors.full_messages}, :status => :unprocessable_entity }
end
end end
end end
@ -115,34 +95,13 @@ class ClosetHangersController < ApplicationController
unless @closet_hanger.quantity == 0 # save the hanger, new record or not unless @closet_hanger.quantity == 0 # save the hanger, new record or not
if @closet_hanger.save if @closet_hanger.save
respond_to do |format| closet_hanger_saved
format.html {
message = "Success! You #{@closet_hanger.verb(:you)} #{@closet_hanger.quantity} "
message << ((@closet_hanger.quantity > 1) ? @item.name.pluralize : @item.name)
message << " in the \"#{@closet_hanger.list.name}\" list" if @closet_hanger.list
flash[:success] = "#{message}."
redirect_back!(@item)
}
format.json { render :json => true }
end
else else
respond_to do |format| closet_hanger_invalid
format.html {
flash[:alert] = "We couldn't save how many of this item you #{@closet_hanger.verb(:you)}: #{@closet_hanger.errors.full_messages.to_sentence}"
redirect_back!(@item)
}
format.json { render :json => {:errors => @closet_hanger.errors.full_messages}, :status => :unprocessable_entity }
end
end end
else # delete the hanger since the user doesn't want it else # delete the hanger since the user doesn't want it
@closet_hanger.destroy @closet_hanger.destroy
respond_to do |format| closet_hanger_destroyed
format.html { redirect_after_destroy! }
format.json { render :json => true }
end
end end
end end
@ -153,15 +112,65 @@ class ClosetHangersController < ApplicationController
ClosetHanger.set_quantity!(quantity, :user_id => @user.id, ClosetHanger.set_quantity!(quantity, :user_id => @user.id,
:item_id => @item.id, :key => key) :item_id => @item.id, :key => key)
end end
flash[:success] = "Successfully saved how many #{@item.name} you own and want." flash[:success] = t('closet_hangers.update_quantities.success',
:item_name => @item.name)
end end
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
flash[:alert] = "We couldn't save those quantities. #{e.message}" flash[:alert] = t('closet_hangers.update_quantities.invalid',
:errors => e.message)
end end
redirect_to @item redirect_to @item
end end
protected private
def closet_hanger_destroyed
respond_to do |format|
format.html {
ownership_key = @closet_hanger.owned? ? 'owned' : 'wanted'
flash[:success] = t("closet_hangers.destroy.success.#{ownership_key}",
:item_name => @item.name)
redirect_back!(@item)
}
format.json { render :json => true }
end
end
def closet_hanger_invalid
respond_to do |format|
format.html {
ownership_key = @closet_hanger.owned? ? 'owned' : 'wanted'
flash[:alert] = t("closet_hangers.create.invalid.#{ownership_key}",
:item_name => @item.name,
:errors => @closet_hanger.errors.full_messages.to_sentence)
redirect_back!(@item)
}
format.json { render :json => {:errors => @closet_hanger.errors.full_messages}, :status => :unprocessable_entity }
end
end
def closet_hanger_saved
respond_to do |format|
format.html {
ownership_key = @closet_hanger.owned? ? 'owned' : 'wanted'
if @closet_hanger.list
flash[:success] = t("closet_hangers.create.success.#{ownership_key}.in_list",
:item_name => @item.name,
:list_name => @closet_hanger.list.name,
:count => @closet_hanger.quantity)
else
flash[:success] = t("closet_hangers.create.success.#{ownership_key}.unlisted",
:item_name => @item.name,
:count => @closet_hanger.quantity)
end
redirect_back!(@item)
}
format.json { render :json => true }
end
end
def find_item def find_item
@item = Item.find params[:item_id] @item = Item.find params[:item_id]
@ -202,10 +211,5 @@ class ClosetHangersController < ApplicationController
end end
end end
end end
def redirect_after_destroy!
flash[:success] = "Success! You do not #{@closet_hanger.verb(:you)} #{@item.name}."
redirect_back!(@item)
end
end end

View file

@ -70,6 +70,25 @@ en-meep:
submit: Submeep submit: Submeep
delete: Deleep delete: Deleep
create:
success:
owned:
in_list:
Meep! You own %{count} of the %{item_name} in the %{list_name} list.
unlisted: eep! You own of the %{count} %{item_name}.
wanted:
in_list:
Meep! You want %{count} of the %{item_name} in the %{list_name} list.
unlisted: Meep! You want %{count} of the %{item_name}.
invalid:
owned: "We couldn't meep how many %{item_name} you own: %{errors}"
wanted: "We couldn't meep how many %{item_name} you want: %{errors}"
destroy:
success:
owned: Meep! You do not own the %{item_name}.
wanted: Meep! You do not want the %{item_name}.
index: index:
title_for: title_for:
you: Your Meeps you: Your Meeps
@ -133,6 +152,10 @@ en-meep:
description: description:
items: These items will be publicly meeped for trades items: These items will be publicly meeped for trades
list: Items in this list will be publicly meeped for trades list: Items in this list will be publicly meeped for trades
update_quantities:
success: Successfully meeped how many of the %{item_name} you own and want.
invalid: "We couldn't meep those quantities: %{errors}"
closet_lists: closet_lists:
closet_list: closet_list:

View file

@ -71,6 +71,25 @@ en:
submit: Save submit: Save
delete: Remove delete: Remove
create:
success:
owned:
in_list:
Success! You own %{count} of the %{item_name} in the %{list_name} list.
unlisted: Success! You own of the %{count} %{item_name}.
wanted:
in_list:
Success! You want %{count} of the %{item_name} in the %{list_name} list.
unlisted: Success! You want %{count} of the %{item_name}.
invalid:
owned: "We couldn't save how many %{item_name} you own: %{errors}"
wanted: "We couldn't save how many %{item_name} you want: %{errors}"
destroy:
success:
owned: Success! You do not own the %{item_name}.
wanted: Success! You do not want the %{item_name}.
index: index:
title_for: title_for:
you: Your Items you: Your Items
@ -134,6 +153,10 @@ en:
description: description:
items: These items will be publicly listed for trades items: These items will be publicly listed for trades
list: Items in this list will be publicly listed for trades list: Items in this list will be publicly listed for trades
update_quantities:
success: Successfully saved how many of the %{item_name} you own and want.
invalid: "We couldn't save those quantities: %{errors}"
closet_lists: closet_lists:
closet_list: closet_list: