Skip to content

Commit

Permalink
Merge branch 'master' into 0_7_x
Browse files Browse the repository at this point in the history
  • Loading branch information
schof committed Mar 10, 2009
2 parents 09a448f + 7136a4e commit e012d4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
13 changes: 0 additions & 13 deletions app/controllers/checkout_controller.rb
Expand Up @@ -60,22 +60,9 @@ def require_user_account

private

# switch state info into name if the id isn't a valid state
def fix_address_states(params)
unless State.find_by_id(params[:bill_address_state_id])
params[:bill_address_state_name] = params[:bill_address_state_id]
params.delete :bill_address_state_id
end
unless State.find_by_id(params[:ship_address_state_id])
params[:ship_address_state_name] = params[:ship_address_state_id]
params.delete :ship_address_state_id
end
end

def build_object
@order = Order.find_by_number(params[:order_number])
if params[:checkout_presenter]
fix_address_states params[:checkout_presenter]
@object ||= end_of_association_chain.send parent? ? :build : :new, params[:checkout_presenter]
else
# user has not yet submitted checkout parameters, we can use defaults of current_user and order objects
Expand Down
14 changes: 12 additions & 2 deletions public/javascripts/checkout.js
Expand Up @@ -67,9 +67,19 @@ var get_states = function() {
// {name,id} attributes over, returning the new child
var chg_state_input_element = function (parent, html) {
var child = parent.find(':only-child');
var name = child.attr('name');
var id = child.attr('id');
//Toggle back and forth between id and name
if(html.attr('type') == 'text' && child.attr('type') != 'text') {
name = name.replace('_id', '_name');
id = id.replace('_id', '_name');
} else if(html.attr('type') != 'text' && child.attr('type') == 'text') {
name = name.replace('_name', '_id');
id = id.replace('_name', '_id');
}
html.addClass('required')
.attr('name', child.attr('name'))
.attr('id', child.attr('id'));
.attr('name', name)
.attr('id', id);
child.remove(); // better as parent-relative?
parent.append(html);
return html;
Expand Down

0 comments on commit e012d4c

Please sign in to comment.