wip
This commit is contained in:
parent
4843021971
commit
93f7e07ebe
6 changed files with 56 additions and 15 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
||||
|
|
|
|||
|
|
@ -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' }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue