diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index da687124..93fd32af 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -57,13 +57,32 @@ module Admin end end - def add_swags(form, index) - render partial: 'swag_fields', locals: { f: form, index: (index + 1), v_type: nil, v_quantity: 0} + def add_swags() + @sponsor.update_attributes(sponsor_params) + redirect_to edit_admin_conference_sponsor_path(@conference.short_title, @sponsor) end + def confirm + @sponsor.confirm! + if @sponsor.save + redirect_to admin_conference_sponsors_path(@conference.short_title), + notice: 'Sponsor successfully confirmed!' + else + flash[:error] = 'Sponsor couldn\' t be confirmed.' + end + end - def get_swags; end + def cancel + @sponsor.cancel! + + if @sponsor.save + redirect_to admin_conference_sponsors_path(@conference.short_title), + notice: 'Sponsor successfully canceled' + else + flash[:error] = 'Sponsor couldn\'t be canceled' + end + end def paid @sponsor.paid = !@sponsor.paid diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 6f670740..c5fa0dd0 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -1,4 +1,6 @@ class Sponsor < ActiveRecord::Base + include ActiveRecord::Transitions + belongs_to :sponsorship_level belongs_to :conference @@ -10,4 +12,25 @@ class Sponsor < ActiveRecord::Base mount_uploader :picture, PictureUploader, mount_on: :logo_file_name validates :name, :website_url, :sponsorship_level, presence: true + + scope :confirmed, -> { where(state: 'confirmed') } + scope :unconfirmed, -> { where(state: 'uncofirmed') } + + state_machine initial: :uncofirmed do + state :uncofirmed + state :confirmed + + + event :confirm do + transitions to: :confirmed, from: [:uncofirmed] + end + + event :cancel do + transitions to: :uncofirmed, from: [:confirmed] + end + end + + def transition_possible?(transition) + self.class.state_machine.events_for(current_state).include?(transition) + end end diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml deleted file mode 100644 index c5a65195..00000000 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ /dev/null @@ -1,33 +0,0 @@ -.row - .col-md-12 - .page-header - %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, 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' } - - @sponsor.swags.each_with_index do |(key, value), index| - =render partial: 'swag_fields', locals: {f: f, index: index, v_type: value[:type].to_s, v_quantity: value[:quantity].to_i} - - .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' } diff --git a/app/views/admin/sponsors/edit.html.haml b/app/views/admin/sponsors/edit.html.haml index aeb138a2..f7f1f0bd 100644 --- a/app/views/admin/sponsors/edit.html.haml +++ b/app/views/admin/sponsors/edit.html.haml @@ -1 +1,33 @@ -= render 'edit_form' +.row + .col-md-12 + .page-header + %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, 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' } + - @sponsor.swags.each_with_index do |(key, value), index| + =render partial: 'swag_fields', locals: {f: f, index: index, v_type: value[:type].to_s, v_quantity: value[:quantity].to_i} + =render partial: 'swag_fields', locals: {f: f, index: @sponsor.swag_index, v_type: nil, v_quantity: 0} + .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' } diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index 0283e346..e104b170 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -7,14 +7,17 @@ .row .col-md-12 %div{ role: 'tabpanel' } - %ul.nav.nav-tabs{ role: 'tablist' } - %li.active{ role: 'presentation'} - %a{ 'aria-controls' => 'sponsorship', 'data-toggle' => 'tab', href: '#sponsorship', role: 'tab'} Sponsorship - %li{ role: 'Swags'} - %a{ 'aria-controls' => 'swags','data-toggle' => 'tab', href: '#swags', role: 'tab'} Swags + %ul.nav.nav-tabs + %li.active + %a{'data-toggle' => 'tab', href: '#sponsorship', role: 'tab'} Sponsorship + %li + %a{'data-toggle' => 'tab', href: '#swags', role: 'tab'} Swags + %li + %a{'data-toggle' => 'tab', href: '#uncofirmed', role: 'tab'} Unconfirmed + .tab-content - #sponsorship.tab-pane.active{ role: 'tabpanel' } - - if @conference.sponsors.any? + #sponsorship.tab-pane.active + - if @conference.sponsors.confirmed.any? .row .col-md-12 %table.table.table-hover#sponsors @@ -26,7 +29,7 @@ %th Level %th Actions %tbody - - @conference.sponsors.each do |sponsor| + - @conference.sponsors.confirmed.each do |sponsor| %tr %td = image_tag(sponsor.picture.thumb.url, width: '20%') @@ -41,12 +44,18 @@ %td .btn-group = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :get, class: 'btn btn-primary' + method: :get, class: 'btn btn-mini 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}?" } + method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + - if sponsor.transition_possible? :confirm + = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :cancel + = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-default' - #swags.tab-pane.active{ role: 'tabpanel' } - - if @conference.sponsors.any? + #swags.tab-pane + - if @conference.sponsors.confirmed.any? .row .col-md-12 %table.table.table-hover#sponsors @@ -59,7 +68,7 @@ %th Received %th Actions %tbody - - @conference.sponsors.each do |sponsor| + - @conference.sponsors.confirmed.each do |sponsor| %tr %td = image_tag(sponsor.picture.thumb.url, width: '20%') @@ -69,12 +78,12 @@ - if sponsor.has_banner %span.fa.fa-check.text-success - else - %span.fa.fa-times + %span.fa.fa-times.text-danger %td - if sponsor.has_swag %span.fa.fa-check.text-success - else - %span.fa.fa-times + %span.fa.fa-times.text-danger %td - if sponsor.has_swag - sponsor.swags.each do |key, value| @@ -91,9 +100,55 @@ %td .btn-group = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :get, class: 'btn btn-primary' + method: :get, class: 'btn btn-mini 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}?" } + method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + - if sponsor.transition_possible? :confirm + = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :cancel + = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-default' + + .tab-content + #unconfirmed.tab-pane + - if @conference.sponsors.unconfirmed.any? + .row + .col-md-12 + %table.table.table-hover#sponsors + %thead + %th Logo + %th Name + %th Description + %th URL + %th Level + %th Actions + %tbody + - @conference.sponsors.unconfirmed.each do |sponsor| + %tr + %td + = image_tag(sponsor.picture.thumb.url, width: '20%') + %td + = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) + %td + = truncate(sponsor.description) + %td + = sponsor.website_url + %td + = sponsor.sponsorship_level.title + %td + .btn-group + = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :get, class: 'btn btn-mini btn-primary' + = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + - if sponsor.transition_possible? :confirm + = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :cancel + = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-default' + .row .col-md-12 = link_to 'Add Sponsor', new_admin_conference_sponsor_path(@conference.short_title), class: 'btn btn-primary pull-right' diff --git a/app/views/admin/sponsors/_form.html.haml b/app/views/admin/sponsors/new.html.haml similarity index 85% rename from app/views/admin/sponsors/_form.html.haml rename to app/views/admin/sponsors/new.html.haml index c319e1ac..5fbeed31 100644 --- a/app/views/admin/sponsors/_form.html.haml +++ b/app/views/admin/sponsors/new.html.haml @@ -10,7 +10,7 @@ .col-md-8 = semantic_form_for(@sponsor, url: (admin_conference_sponsors_path)) do |f| = f.input :name - = f.input :description + = f.input :description, input_html: { rows: 7, data: { provide: 'markdown-editable' } } = image_tag f.object.picture.thumb.url if f.object.picture? = f.input :picture = f.input :website_url diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index 6cb0adf9..abeaace8 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -43,7 +43,7 @@ = link_to @sponsor.website_url, @sponsor.website_url %tr %td.col-md-2 - %b Has swags? + %b Has swag? %td = 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]=", @@ -75,9 +75,6 @@ = value[:type] %td = value[:quantity] - - - - if @sponsor.address? %tr %td.col-md-2 diff --git a/config/routes.rb b/config/routes.rb index 84b5ba89..8d2f7099 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,7 +117,12 @@ Osem::Application.routes.draw do resources :resources resources :tickets - resources :sponsors + resources :sponsors do + member do + patch :confirm + patch :cancel + end + end resources :lodgings, except: [:show] resources :targets, except: [:show] resources :campaigns, except: [:show] diff --git a/db/migrate/20170822173332_add_swags_to_sponsors.rb b/db/migrate/20170822173332_add_swags_to_sponsors.rb index 68303239..d4901066 100644 --- a/db/migrate/20170822173332_add_swags_to_sponsors.rb +++ b/db/migrate/20170822173332_add_swags_to_sponsors.rb @@ -7,5 +7,7 @@ class AddSwagsToSponsors < ActiveRecord::Migration add_column :sponsors, :vat, :string add_column :sponsors, :has_banner, :boolean, default: false add_column :sponsors, :swags, :text + add_column :sponsors, :courrier_info, :text + add_column :sponsors, :state, :string end end diff --git a/db/schema.rb b/db/schema.rb index 34f37a5f..e6c03e37 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -468,11 +468,6 @@ 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_received" - t.string "company_address" - t.string "vat_registration" - t.text "swag_hash" t.boolean "paid", default: false t.boolean "has_swag", default: false t.boolean "swag_received" @@ -480,6 +475,8 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.string "vat" t.boolean "has_banner", default: false t.text "swags" + t.text "courrier_info" + t.string "state" end create_table "sponsorship_levels", force: :cascade do |t|