This commit is contained in:
Seth Call 2015-11-12 21:44:08 -06:00
parent fcb9db3d06
commit 3fa93a26af
4 changed files with 70 additions and 34 deletions

View File

@ -0,0 +1,41 @@
ActiveAdmin.register_page "Giftcarduploads" do
menu :label => 'Gift Cards Upload', :parent => 'JamTracks'
page_action :upload_giftcards, :method => :post do
GiftCard.transaction do
puts params
file = params[:jam_ruby_gift_card][:csv]
array_of_arrays = CSV.read(file.tempfile.path)
array_of_arrays.each do |row|
if row.length != 1
raise "UKNONWN CSV FORMAT! Must be 1 column"
end
code = row[0]
gift_card = GiftCard.new
gift_card.code = code
gift_card.card_type = params[:jam_ruby_gift_card][:card_type]
gift_card.origin = file .original_filename
gift_card.save!
end
redirect_to admin_giftcards_path, :notice => "Created #{array_of_arrays.length} gift cards!"
end
end
content do
semantic_form_for GiftCard.new, :url => admin_giftcarduploads_upload_giftcards_path, :builder => ActiveAdmin::FormBuilder do |f|
f.inputs "Upload Gift Cards" do
f.input :csv, as: :file, required: true, :label => "A single column CSV that contains ONE type of gift card (5 JamTrack, 10 JamTrack, etc)"
f.input :card_type, required:true, as: :select, :collection => JamRuby::GiftCard::CARD_TYPES
end
f.actions
end
end
end

View File

@ -1,41 +1,24 @@
ActiveAdmin.register_page "Giftcards" do
ActiveAdmin.register JamRuby::GiftCard, :as => 'GiftCards' do
menu :label => 'Gift Cards', :parent => 'JamTracks'
page_action :upload_giftcards, :method => :post do
GiftCard.transaction do
config.batch_actions = false
config.filters = true
config.per_page = 50
puts params
scope("Redeemed Most Recently", default: true) { |scope| scope.where('user_id IS NOT NULL').order('updated_at DESC') }
scope("Available") { |scope| scope.where('user_id is NULL') }
file = params[:jam_ruby_gift_card][:csv]
array_of_arrays = CSV.read(file.tempfile.path)
array_of_arrays.each do |row|
if row.length != 1
raise "UKNONWN CSV FORMAT! Must be 1 column"
end
filter :card_type
filter :origin
filter :code
code = row[0]
gift_card = GiftCard.new
gift_card.code = code
gift_card.card_type = params[:jam_ruby_gift_card][:card_type]
gift_card.origin = file .original_filename
gift_card.save!
end
redirect_to admin_giftcards_path, :notice => "Created #{array_of_arrays.length} gift cards!"
end
index do
column 'User' do |oo| oo.user ? link_to(oo.user.email, oo.user.admin_url, {:title => oo.user.email}) : '' end
column 'Code' do |oo| oo.code end
column 'Card Type' do |oo| oo.card_type end
column 'Origin' do |oo| oo.origin end
column 'Created' do |oo| oo.created_at end
end
content do
semantic_form_for GiftCard.new, :url => admin_giftcards_upload_giftcards_path, :builder => ActiveAdmin::FormBuilder do |f|
f.inputs "Upload Gift Cards" do
f.input :csv, as: :file, required: true, :label => "A single column CSV that contains ONE type of gift card (5 JamTrack, 10 JamTrack, etc)"
f.input :card_type, required:true, as: :select, :collection => JamRuby::GiftCard::CARD_TYPES
end
f.actions
end
end
end

View File

@ -241,7 +241,8 @@ module JamRuby
jam_track_carts = user.shopping_carts.where(cart_type:JamTrack::PRODUCT_TYPE)
if jam_track_carts.count > user.gifted_jamtracks
# can't do anything automatically
# just whack everything in their shopping cart
user.destroy_all_shopping_carts
return
end

View File

@ -455,7 +455,18 @@ MIX_MODES = context.JK.MIX_MODES
context.location = '/client#/shoppingCart'
).fail(() => @app.ajaxError)
).fail(((jqxhr) =>
handled = false
if jqxhr.status == 422
body = JSON.parse(jqxhr.responseText)
if body.errors && body.errors.base
handled = true
context.JK.Banner.showAlert("You can not have a mix of free and non-free items in your shopping cart.<br/><br/>If you want to add this new item to your shopping cart, then clear out all current items by clicking on the shopping cart icon and clicking 'delete' next to each item.")
if !handled
@app.ajaxError(arguments[0], arguments[1], arguments[2])
))
licenseUSWhy:(e) ->
e.preventDefault()