Add #show for sponsors

This commit is contained in:
nasia 2017-08-18 16:07:19 +03:00
parent de1fa448a2
commit 336c1e86bd
9 changed files with 147 additions and 11 deletions

View file

@ -4,11 +4,16 @@ module Admin
load_and_authorize_resource :sponsor, through: :conference
before_action :sponsorship_level_required, only: [:index, :new]
attr_accessor :type, :quantity
def index
authorize! :index, Sponsor.new(conference_id: @conference.id)
end
def edit; end
def show; end
def edit
end
def new
@sponsor = @conference.sponsors.new
@ -27,8 +32,8 @@ module Admin
def update
if @sponsor.update_attributes(sponsor_params)
redirect_to admin_conference_sponsors_path(
conference_id: @conference.short_title),
redirect_to admin_conference_sponsor_path(
conference_id: @conference.short_title, id: @sponsor.id),
notice: 'Sponsor successfully updated.'
else
flash.now[:error] = "Update sponsor failed: #{@sponsor.errors.full_messages.join('. ')}."
@ -47,10 +52,15 @@ module Admin
end
end
def generate_swags_hash(type, quantity)
swags_hash[type.to_s] = quantity.to_i
end
private
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,
:payed, :swags, :swags_received, :company_address, :vat_registration, :has_banner)
end
def sponsorship_level_required

View file

@ -0,0 +1,20 @@
.row
.col-md-12
.page-header
%h1
Edit
= @sponsor.name
.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 :picture
= f.input :website_url
= f.input :sponsorship_level, collection: @conference.sponsorship_levels
= f.input :company_address
= f.input :vat_registration
= 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

@ -8,12 +8,16 @@
= @sponsor.name
.row
.col-md-8
= semantic_form_for(@sponsor, url: (@sponsor.new_record? ? admin_conference_sponsors_path : admin_conference_sponsor_path(@conference.short_title, @sponsor))) do |f|
= semantic_form_for(@sponsor, url: (admin_conference_sponsors_path)) do |f|
= f.input :name
= f.input :description
= image_tag f.object.picture.thumb.url if f.object.picture?
= f.input :picture
= f.input :website_url
= f.input :sponsorship_level, collection: @conference.sponsorship_levels
-# = f.input :type
-# = f.input :quantity
-# - generate_swags_hash(type, quantity)
%p.text-right
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }

View file

@ -0,0 +1 @@
= render 'edit_form'

View file

@ -21,7 +21,7 @@
%td
= image_tag(sponsor.picture.thumb.url, width: '20%')
%td
= sponsor.name
= link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor)
%td
= truncate(sponsor.description)
%td

View file

@ -0,0 +1,78 @@
.row
.col-md-12
%h2
= image_tag(@sponsor.picture.thumb.url, size: '20%', alt: '')
= @sponsor.name
.row
.col-md-12
.btn-group.pull-right
= link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, @sponsor),
method: :get, class: 'btn btn-primary'
= link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, @sponsor),
method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete the sponsor #{@sponsor.name}?" }
.col-md-12
%table.table
%tr
%td.col-md-2
%b Sponsorship payed?
%td
= check_box_tag @conference.short_title, @sponsor.id, @sponsor.swags,
method: :patch, url: payed_admin_conference_sponsor_path(@conference.short_title, @sponsor.id),
class: 'switch-checkbox', data: { size: 'small',
off_color: 'warning',
on_text: 'Yes',
off_text: 'No' }
- if @sponsor.description?
%tr
%td.col-md-2
%b Description
%td
= markdown(@sponsor.description)
%tr
%td.col-md-2
%b Sponsorship Level
%td
= @sponsor.sponsorship_level.title
(
= @sponsor.sponsorship_level.position
)
%tr
%td.col-md-2
%b Website url
%td
= link_to @sponsor.website_url, @sponsor.website_url
%tr
%td.col-md-2
%b Has swags?
%td
= check_box_tag @conference.short_title, @sponsor.id, @sponsor.swags,
method: :patch, url: swags_admin_conference_sponsor_path(@conference.short_title, @sponsor.id),
class: 'switch-checkbox', data: { size: 'small',
off_color: 'warning',
on_text: 'Yes',
off_text: 'No' }
- if @sponsor.company_address
%tr
%td.col-md-2
%b Company's address
%td
= @sponsor.company_address
- if @sponsor.vat_registration
%tr
%td.col-md-2
%b Campany's VAT Registration Number
%td
= @sponsor.vat_registration
- if @sponsor.swags
%tr
%td.col-md-2
%b Swags received?
%td
= check_box_tag @conference.short_title, @sponsor.id, @sponsor.swags,
method: :patch, url: swags_received_admin_conference_sponsor_path(@conference.short_title, @sponsor.id),
class: 'switch-checkbox', data: { size: 'small',
off_color: 'warning',
on_text: 'Yes',
off_text: 'No' }