Add responsible and fix how hashes are stored
This commit is contained in:
parent
88a6b2769b
commit
4810aa22f6
7 changed files with 43 additions and 14 deletions
|
|
@ -8,16 +8,9 @@ module Admin
|
||||||
authorize! :index, Sponsor.new(conference_id: @conference.id)
|
authorize! :index, Sponsor.new(conference_id: @conference.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show; end
|
||||||
@sponsor.swag.reject! { |_key, value| value[:type].blank? || value[:quantity].blank? }
|
|
||||||
@sponsor.swag_transportation.reject! { |_key, value| value[:carrier_name].blank? || value[:tracking_number].blank? || value[:boxes].blank? }
|
|
||||||
@sponsor.swag_index = @sponsor.swag.length
|
|
||||||
@sponsor.carrier_index = @sponsor.swag_transportation.length
|
|
||||||
end
|
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@sponsor.swag.reject! { |_key, value| value[:type].blank? || value[:quantity].blank? }
|
|
||||||
@sponsor.swag_transportation.reject! { |_key, value| value[:carrier_name].blank? || value[:tracking_number].blank? }
|
|
||||||
@sponsor.swag_index = @sponsor.swag.length
|
@sponsor.swag_index = @sponsor.swag.length
|
||||||
@sponsor.carrier_index = @sponsor.swag_transportation.length
|
@sponsor.carrier_index = @sponsor.swag_transportation.length
|
||||||
end
|
end
|
||||||
|
|
@ -39,6 +32,9 @@ module Admin
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @sponsor.update_attributes(sponsor_params)
|
if @sponsor.update_attributes(sponsor_params)
|
||||||
|
@sponsor.update_attribute(:swag, @sponsor.swag.reject! { |_key, value| value[:type].blank? || value[:quantity].blank? })
|
||||||
|
@sponsor.update_attribute(:swag_transportation, @sponsor.swag_transportation.reject! { |_key, value| value[:carrier_name].blank? || value[:tracking_number].blank? })
|
||||||
|
|
||||||
redirect_to admin_conference_sponsor_path(
|
redirect_to admin_conference_sponsor_path(
|
||||||
conference_id: @conference.short_title, id: @sponsor.id),
|
conference_id: @conference.short_title, id: @sponsor.id),
|
||||||
notice: 'Sponsor successfully updated.'
|
notice: 'Sponsor successfully updated.'
|
||||||
|
|
@ -124,7 +120,8 @@ module Admin
|
||||||
def sponsor_params
|
def sponsor_params
|
||||||
params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id,
|
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, :swag_index, :carrier_index, :amount,
|
:paid, :has_swag, :swag_received, :address, :vat, :has_banner, :swag_index, :carrier_index, :amount,
|
||||||
swag: [:type, :quantity], swag_transportation: [:carrier_name, :tracking_number, :boxes])
|
responsibe: [:responsible_name, :responsible_email], swag: [:type, :quantity],
|
||||||
|
swag_transportation: [:carrier_name, :tracking_number, :boxes])
|
||||||
end
|
end
|
||||||
|
|
||||||
def sponsorship_level_required
|
def sponsorship_level_required
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,11 @@ class Sponsor < ActiveRecord::Base
|
||||||
|
|
||||||
serialize :swag, Hash
|
serialize :swag, Hash
|
||||||
serialize :swag_transportation, Hash
|
serialize :swag_transportation, Hash
|
||||||
|
serialize :responsibe, Hash
|
||||||
|
|
||||||
attr_accessor :type, :quantity, :swag_index, :carrier_index,
|
attr_accessor :type, :quantity, :swag_index, :carrier_index,
|
||||||
:carrier_name, :tracking_number, :boxes
|
:carrier_name, :tracking_number, :boxes,
|
||||||
|
:responsible_name, :responsible_email
|
||||||
|
|
||||||
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||||
|
|
||||||
|
|
@ -18,7 +20,6 @@ class Sponsor < ActiveRecord::Base
|
||||||
|
|
||||||
scope :confirmed, -> { where(state: 'confirmed') }
|
scope :confirmed, -> { where(state: 'confirmed') }
|
||||||
scope :contacted, -> { where(state: 'contacted') }
|
scope :contacted, -> { where(state: 'contacted') }
|
||||||
scope :to_contact, -> { where(state: 'to_contact') }
|
|
||||||
|
|
||||||
state_machine initial: :to_contact do
|
state_machine initial: :to_contact do
|
||||||
state :to_contact
|
state :to_contact
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,15 @@
|
||||||
= semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f|
|
= semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f|
|
||||||
= f.input :name
|
= f.input :name
|
||||||
= f.input :amount, as: :number, label: 'Donation amount'
|
= f.input :amount, as: :number, label: 'Donation amount'
|
||||||
|
%b Sponsorship paid?
|
||||||
|
= check_box_tag @conference.short_title, @sponsor.id, @sponsor.paid,
|
||||||
|
method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[paid]=",
|
||||||
|
class: 'switch-checkbox', data: { size: 'small',
|
||||||
|
off_color: 'warning',
|
||||||
|
on_text: 'Yes',
|
||||||
|
off_text: 'No' }
|
||||||
|
= f.input :responsible_name, label: 'Responsible\'s name', hint: 'The person with whom you are in contact', input_html: { name: 'sponsor[responsibe][responsible_name]', value: @sponsor.responsibe[:responsible_name] }
|
||||||
|
= f.input :responsible_name, label: 'Responsible\'s email', input_html: { name: 'sponsor[responsibe][responsible_email]', value: @sponsor.responsibe[:responsible_email] }
|
||||||
= f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } }
|
= f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } }
|
||||||
= f.input :picture
|
= f.input :picture
|
||||||
= f.input :website_url
|
= f.input :website_url
|
||||||
|
|
@ -26,6 +35,14 @@
|
||||||
= render partial: 'swag_fields', locals: {f: f, index: index, type_value: value[:type].to_s, quantity_value: value[:quantity].to_i}
|
= render partial: 'swag_fields', locals: {f: f, index: index, type_value: value[:type].to_s, quantity_value: value[:quantity].to_i}
|
||||||
= render partial: 'swag_fields', locals: {f: f, index: @sponsor.swag_index, type_value: nil, quantity_value: nil}
|
= render partial: 'swag_fields', locals: {f: f, index: @sponsor.swag_index, type_value: nil, quantity_value: nil}
|
||||||
|
|
||||||
|
%b Swag received?
|
||||||
|
= check_box_tag @conference.short_title, @sponsor.id, @sponsor.swag_received,
|
||||||
|
method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[swag_received]=",
|
||||||
|
class: 'switch-checkbox', data: { size: 'small',
|
||||||
|
off_color: 'warning',
|
||||||
|
on_text: 'Yes',
|
||||||
|
off_text: 'No' }
|
||||||
|
|
||||||
- @sponsor.swag_transportation.each_with_index do |(key, value), index|
|
- @sponsor.swag_transportation.each_with_index do |(key, value), index|
|
||||||
= render partial: 'carrier_fields', locals: {f: f, index: index, name_value: value[:carrier_name].to_s, tracking_value: value[:tracking_number].to_s, boxes_value: value[:boxes]}
|
= render partial: 'carrier_fields', locals: {f: f, index: index, name_value: value[:carrier_name].to_s, tracking_value: value[:tracking_number].to_s, boxes_value: value[:boxes]}
|
||||||
= render partial: 'carrier_fields', locals: {f: f, index: @sponsor.carrier_index, name_value: nil, tracking_value: nil, boxes_value: nil}
|
= render partial: 'carrier_fields', locals: {f: f, index: @sponsor.carrier_index, name_value: nil, tracking_value: nil, boxes_value: nil}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
%td
|
%td
|
||||||
= sponsor.amount
|
= sponsor.amount
|
||||||
%td
|
%td
|
||||||
- if sponsor.payed
|
- if sponsor.paid
|
||||||
%span.fa.fa-check.text-success
|
%span.fa.fa-check.text-success
|
||||||
- else
|
- else
|
||||||
%span.fa.fa-times.text-danger
|
%span.fa.fa-times.text-danger
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,18 @@
|
||||||
off_color: 'warning',
|
off_color: 'warning',
|
||||||
on_text: 'Yes',
|
on_text: 'Yes',
|
||||||
off_text: 'No' }
|
off_text: 'No' }
|
||||||
|
- unless @sponsor.responsibe[:responsible_name].blank?
|
||||||
|
%tr
|
||||||
|
%td.col-md-2
|
||||||
|
%b Responsible's name
|
||||||
|
%td
|
||||||
|
= @sponsor.responsibe[:responsible_name]
|
||||||
|
- unless @sponsor.responsibe[:responsible_email].blank?
|
||||||
|
%tr
|
||||||
|
%td.col-md-2
|
||||||
|
%b Responsible's email
|
||||||
|
%td
|
||||||
|
= @sponsor.responsibe[:responsible_email]
|
||||||
- if @sponsor.description?
|
- if @sponsor.description?
|
||||||
%tr
|
%tr
|
||||||
%td.col-md-2
|
%td.col-md-2
|
||||||
|
|
@ -74,7 +86,7 @@
|
||||||
off_text: 'No' }
|
off_text: 'No' }
|
||||||
|
|
||||||
|
|
||||||
- if @sponsor.swag.length > 0
|
- if @sponsor.swag.any?
|
||||||
%tr
|
%tr
|
||||||
%td.col-md-2
|
%td.col-md-2
|
||||||
%b Swag's Type
|
%b Swag's Type
|
||||||
|
|
@ -101,7 +113,7 @@
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
%table.table
|
%table.table
|
||||||
- if @sponsor.carrier_index > 0
|
- if @sponsor.swag_transportation.any?
|
||||||
%tr
|
%tr
|
||||||
%td.col-md-2
|
%td.col-md-2
|
||||||
%b Courrier's name
|
%b Courrier's name
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,6 @@ class AddSwagsToSponsors < ActiveRecord::Migration
|
||||||
add_column :sponsors, :swag, :text
|
add_column :sponsors, :swag, :text
|
||||||
add_column :sponsors, :swag_transportation, :text
|
add_column :sponsors, :swag_transportation, :text
|
||||||
add_column :sponsors, :state, :string
|
add_column :sponsors, :state, :string
|
||||||
|
add_column :sponsors, :responsibe, :text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -478,6 +478,7 @@ ActiveRecord::Schema.define(version: 20170822173332) do
|
||||||
t.text "swag"
|
t.text "swag"
|
||||||
t.text "swag_transportation"
|
t.text "swag_transportation"
|
||||||
t.string "state"
|
t.string "state"
|
||||||
|
t.text "responsibe"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "sponsorship_levels", force: :cascade do |t|
|
create_table "sponsorship_levels", force: :cascade do |t|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue