This commit is contained in:
nasia 2017-08-25 00:43:28 +03:00
parent 4843021971
commit 93f7e07ebe
6 changed files with 56 additions and 15 deletions

View file

@ -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

View file

@ -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 }

View file

@ -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' }

View file

@ -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

View file

@ -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

View file

@ -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