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)
|
||||
end
|
||||
|
||||
def show
|
||||
@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 show; end
|
||||
|
||||
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.carrier_index = @sponsor.swag_transportation.length
|
||||
end
|
||||
|
|
@ -39,6 +32,9 @@ module Admin
|
|||
|
||||
def update
|
||||
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(
|
||||
conference_id: @conference.short_title, id: @sponsor.id),
|
||||
notice: 'Sponsor successfully updated.'
|
||||
|
|
@ -124,7 +120,8 @@ 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, :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
|
||||
|
||||
def sponsorship_level_required
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ class Sponsor < ActiveRecord::Base
|
|||
|
||||
serialize :swag, Hash
|
||||
serialize :swag_transportation, Hash
|
||||
serialize :responsibe, Hash
|
||||
|
||||
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 }
|
||||
|
||||
|
|
@ -18,7 +20,6 @@ class Sponsor < ActiveRecord::Base
|
|||
|
||||
scope :confirmed, -> { where(state: 'confirmed') }
|
||||
scope :contacted, -> { where(state: 'contacted') }
|
||||
scope :to_contact, -> { where(state: 'to_contact') }
|
||||
|
||||
state_machine initial: :to_contact do
|
||||
state :to_contact
|
||||
|
|
|
|||
|
|
@ -9,6 +9,15 @@
|
|||
= semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f|
|
||||
= f.input :name
|
||||
= 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 :picture
|
||||
= 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: @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|
|
||||
= 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}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
%td
|
||||
= sponsor.amount
|
||||
%td
|
||||
- if sponsor.payed
|
||||
- if sponsor.paid
|
||||
%span.fa.fa-check.text-success
|
||||
- else
|
||||
%span.fa.fa-times.text-danger
|
||||
|
|
|
|||
|
|
@ -29,6 +29,18 @@
|
|||
off_color: 'warning',
|
||||
on_text: 'Yes',
|
||||
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?
|
||||
%tr
|
||||
%td.col-md-2
|
||||
|
|
@ -74,7 +86,7 @@
|
|||
off_text: 'No' }
|
||||
|
||||
|
||||
- if @sponsor.swag.length > 0
|
||||
- if @sponsor.swag.any?
|
||||
%tr
|
||||
%td.col-md-2
|
||||
%b Swag's Type
|
||||
|
|
@ -101,7 +113,7 @@
|
|||
.row
|
||||
.col-md-12
|
||||
%table.table
|
||||
- if @sponsor.carrier_index > 0
|
||||
- if @sponsor.swag_transportation.any?
|
||||
%tr
|
||||
%td.col-md-2
|
||||
%b Courrier's name
|
||||
|
|
|
|||
|
|
@ -10,5 +10,6 @@ class AddSwagsToSponsors < ActiveRecord::Migration
|
|||
add_column :sponsors, :swag, :text
|
||||
add_column :sponsors, :swag_transportation, :text
|
||||
add_column :sponsors, :state, :string
|
||||
add_column :sponsors, :responsibe, :text
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -478,6 +478,7 @@ ActiveRecord::Schema.define(version: 20170822173332) do
|
|||
t.text "swag"
|
||||
t.text "swag_transportation"
|
||||
t.string "state"
|
||||
t.text "responsibe"
|
||||
end
|
||||
|
||||
create_table "sponsorship_levels", force: :cascade do |t|
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue