diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 1c2147dc..080b0b99 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -10,9 +10,14 @@ module Admin authorize! :index, Sponsor.new(conference_id: @conference.id) end - def show; end + def show + @sponsor.swag_index = @sponsor.swag_hash.length + end - def edit; end + def edit + @sponsor.swag_index = @sponsor.swag_hash.length + @sponsor.swag_hash = @sponsor.swag_hash + end def new @sponsor = @conference.sponsors.new @@ -30,6 +35,7 @@ module Admin end def update + if @sponsor.update_attributes(sponsor_params) redirect_to admin_conference_sponsor_path( conference_id: @conference.short_title, id: @sponsor.id), @@ -56,8 +62,12 @@ module Admin end def generate_swags_hash(type, quantity) - swags_hash = {} - swags_hash[type.to_s] = quantity.to_i + unless @sponsor.swag_hash + @sponsor.swag_hash = {} + end + + @sponsor.swag_hash[type.to_s] = quantity.to_i + @sponsor.update_attribute(:swag_hash, @sponsor.swag_hash) end def get_swag_hash; end @@ -93,7 +103,7 @@ module Admin def sponsor_params params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id, - :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :type, :quantity) + :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :swag_hash, :type, :quantity, :swag_index) end def sponsorship_level_required diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index c54b1f5c..133d8dd2 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -2,7 +2,8 @@ class Sponsor < ActiveRecord::Base belongs_to :sponsorship_level belongs_to :conference - attr_accessor :type, :quantity + serialize :swag_hash, Hash + attr_accessor :type, :quantity, :swag_index has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml index d55fe311..9ceb326f 100644 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ b/app/views/admin/sponsors/_edit_form.html.haml @@ -4,25 +4,35 @@ %h1 Edit = @sponsor.name + = @sponsor.swag_index .row .col-md-8 = semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f| = f.input :name - = f.input :description + = f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } } = f.input :picture = f.input :website_url = f.input :sponsorship_level, collection: @conference.sponsorship_levels = f.input :address, label: 'Company\'s address' = f.input :vat, label: 'VAT Registration Number' + %b Has Swags? = check_box_tag @conference.short_title, @sponsor.id, @sponsor.has_swag, method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[has_swag]=", class: 'switch-checkbox', data: { size: 'small', off_color: 'warning', on_text: 'Yes', off_text: 'No' } - - - = image_tag f.object.picture.thumb.url if f.object.picture? - = f.input :picture - %p.text-right - = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } + - @sponsor.swag_hash.each do |type, quantity| + .row + .col-md-6 + = f.input :type, label: 'Swag type' + .col-md-6 + = f.input :quantity, as: :number, in: 0..9999 + - generate_swags_hash(@type, @quantity) + = f.submit 'Add Swag', :type + .row + .col-md-8 + = image_tag f.object.picture.thumb.url if f.object.picture? + = f.input :picture + %p.text-right + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index 5dd4defa..abd47b3e 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -63,6 +63,20 @@ off_color: 'warning', on_text: 'Yes', off_text: 'No' } + - if @sponsor.swag_index > 0 + %tr + %td.col-md-2 + %b Swag's Type + %td + %b Quantity + %tr + - @sponsor.swag_hash.each do |key, value| + %td.col-md-2 + = key + %td + = value + + - if @sponsor.address? %tr diff --git a/db/migrate/20170822173332_add_swags_to_sponsors.rb b/db/migrate/20170822173332_add_swags_to_sponsors.rb index 32adf654..41811351 100644 --- a/db/migrate/20170822173332_add_swags_to_sponsors.rb +++ b/db/migrate/20170822173332_add_swags_to_sponsors.rb @@ -6,5 +6,6 @@ class AddSwagsToSponsors < ActiveRecord::Migration add_column :sponsors, :address, :string add_column :sponsors, :vat, :string add_column :sponsors, :has_banner, :boolean, default: false + add_column :sponsors, :swag_hash, :text end end diff --git a/db/schema.rb b/db/schema.rb index 790527bb..dad230b7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -127,8 +127,8 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.integer "end_hour", default: 20 t.integer "organization_id" t.integer "ticket_layout", default: 0 - t.string "custom_domain" t.integer "booth_limit", default: 0 + t.string "custom_domain" end add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id" @@ -468,12 +468,18 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.datetime "created_at" t.datetime "updated_at" t.string "picture" + t.boolean "payed", default: false + t.boolean "swags", default: false + t.boolean "swags_received" + t.string "company_address" + t.string "vat_registration" t.boolean "paid", default: false t.boolean "has_swag", default: false t.boolean "swag_received" t.string "address" t.string "vat" t.boolean "has_banner", default: false + t.text "swag_hash" end create_table "sponsorship_levels", force: :cascade do |t| @@ -583,7 +589,6 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.boolean "is_admin", default: false t.string "username" t.boolean "is_disabled", default: false - t.string "token" end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true