From 098d36c19765cc37099edc47fa93a8e613b662bf Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Tue, 1 Sep 2015 11:09:26 +0300 Subject: [PATCH] Introduce Volunteer Teams --- .../management/conferences_controller.rb | 4 +++- app/models/conference.rb | 4 +++- app/models/volunteer_team.rb | 17 ++++++++++++++++ .../management/conferences/_form.html.slim | 6 ++++++ .../_form_volunteer_teams.html.slim | 20 +++++++++++++++++++ config/locales/bg.yml | 7 +++++++ .../20150901074818_create_volunteer_teams.rb | 16 +++++++++++++++ 7 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 app/models/volunteer_team.rb create mode 100644 app/views/management/conferences/_form_volunteer_teams.html.slim create mode 100644 db/migrate/20150901074818_create_volunteer_teams.rb diff --git a/app/controllers/management/conferences_controller.rb b/app/controllers/management/conferences_controller.rb index 652ddd2..a72b913 100644 --- a/app/controllers/management/conferences_controller.rb +++ b/app/controllers/management/conferences_controller.rb @@ -5,6 +5,7 @@ module Management @conference.event_types.build(name: 'Event type 1') @conference.tracks.build(name: 'Track 1') @conference.halls.build(name: 'Hall 1') + @conference.volunteer_teams.build(name: 'Volunteer Team 1') end def create @@ -55,7 +56,8 @@ module Management event_types_attributes: [:id, :name, :description, :maximum_length, :minimum_length, :_destroy], tracks_attributes: [:id, :name, :color, :description, :_destroy], - halls_attributes: [:id, :name, :_destroy] + halls_attributes: [:id, :name, :_destroy], + volunteer_teams_attributes: [:id, :name, :description, :color, :_destroy] ) end end diff --git a/app/models/conference.rb b/app/models/conference.rb index 46f8acc..c1ec945 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -12,10 +12,12 @@ class Conference < ActiveRecord::Base has_many :halls has_many :event_types has_many :events + has_many :volunteer_teams has_one :call_for_participation, dependent: :destroy has_many :participants, class_name: 'User', through: :events - accepts_nested_attributes_for :tracks, :halls, :event_types, reject_if: :all_blank, allow_destroy: true + accepts_nested_attributes_for :tracks, :halls, :event_types, :volunteer_teams, + reject_if: :all_blank, allow_destroy: true after_create :create_call_for_participation diff --git a/app/models/volunteer_team.rb b/app/models/volunteer_team.rb new file mode 100644 index 0000000..183685c --- /dev/null +++ b/app/models/volunteer_team.rb @@ -0,0 +1,17 @@ +class VolunteerTeam < ActiveRecord::Base + belongs_to :conference + + validates :name, presence: true + validates :color, presence: true, format: {with: /\A#?[a-f0-9]{6}\z/i} + validates :description, presence: true + + translates :name, :description + + def color=(hex_triplet) + write_attribute :color, hex_triplet.gsub(/\A#/,'') if hex_triplet + end + + def color + "##{read_attribute :color}" + end +end diff --git a/app/views/management/conferences/_form.html.slim b/app/views/management/conferences/_form.html.slim index 9415790..df17157 100644 --- a/app/views/management/conferences/_form.html.slim +++ b/app/views/management/conferences/_form.html.slim @@ -29,5 +29,11 @@ h2 = Track.model_name.human(count: 2).mb_chars.capitalize .row = render partial: 'form_tracks', locals: {form: f} + hr + .row + .col-lg-12 + h2 = VolunteerTeam.model_name.human(count: 2).mb_chars.capitalize + .row + = render partial: 'form_volunteer_teams', locals: {form: f} .panel-footer.text-right = f.submit class: 'btn btn-primary' diff --git a/app/views/management/conferences/_form_volunteer_teams.html.slim b/app/views/management/conferences/_form_volunteer_teams.html.slim new file mode 100644 index 0000000..fb22442 --- /dev/null +++ b/app/views/management/conferences/_form_volunteer_teams.html.slim @@ -0,0 +1,20 @@ +div#volunteer_teams + = form.simple_fields_for :volunteer_teams do |ff| + .col-lg-6 + .panel.panel-default + .panel-heading + .panel-title + = VolunteerTeam.model_name.human.mb_chars.capitalize + = ff.link_to_remove icon(:remove), class: ['btn', 'btn-danger', 'btn-xs', 'pull-right'] + + .panel-body + = ff.input :name + = ff.input :color, as: :color + = ff.input :description, as: :text +.col-lg-6 + .panel.panel-default + .panel-heading + .panel-title + = t 'actions.new.title_m', model: VolunteerTeam.model_name.human + .panel-body.text-center + = form.link_to_add t('actions.create.button', model: VolunteerTeam.model_name.human), :volunteer_teams, data: {target: '#volunteer_teams'}, class: 'btn btn-success' diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 609ae3d..b6b5f49 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -72,6 +72,10 @@ bg: password: "Парола" password_confirmation: "Отново паролата" remember_me: "Запомни ме" + volunteer_team: + name: Име + description: Описание + color: Цвят errors: models: event: @@ -120,6 +124,9 @@ bg: track: one: "поток от лекции" other: "потоци от лекции" + volunteer_team: + one: "екип от доброволци" + other: "екипи от доброволци" user: one: "Потребител" other: "Потребители" diff --git a/db/migrate/20150901074818_create_volunteer_teams.rb b/db/migrate/20150901074818_create_volunteer_teams.rb new file mode 100644 index 0000000..a0fbc09 --- /dev/null +++ b/db/migrate/20150901074818_create_volunteer_teams.rb @@ -0,0 +1,16 @@ +class CreateVolunteerTeams < ActiveRecord::Migration + def up + create_table :volunteer_teams do |t| + t.references :conference, index: true, foreign_key: true + t.string :color + + t.timestamps null: false + end + VolunteerTeam.create_translation_table! name: :string, description: :text + end + + def down + drop_table :volunteer_teams + VolunteerTeam.drop_translation_table! + end +end