Skip to content

Commit

Permalink
Add phone number state to event
Browse files Browse the repository at this point in the history
  • Loading branch information
feliciaan committed Jan 12, 2017
1 parent f0b71af commit edef9a1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ def check_in
end

def event_params
params.require(:event).permit(:name, :club_id, :location, :website, :contact_email, :start_date, :end_date, :description, :bank_number, :registration_close_date, :registration_open_date, :show_ticket_count, :signature, :registration_cancelable)
puts "phone_nummber_state", params[:phone_number_state]
params.require(:event).permit(:name, :club_id, :location, :website, :contact_email, :start_date, :end_date, :description, :registration_cancelable, :phone_number_state, :bank_number, :registration_close_date, :registration_open_date, :show_ticket_count, :signature)
end

def event_create_params
params.require(:event).permit(:name, :club_id, :location, :website, :contact_email, :start_date, :end_date, :description)
params.require(:event).permit(:name, :club_id, :location, :website, :contact_email, :start_date, :end_date, :description, :registration_cancelable, :phone_number_state)
end
end
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def form_number_field(f, tag)
render partial: "form_number_field", locals: {f: f, tag: tag}
end

def form_radio_field(f, tag, selected_state, states)
render partial: "form_radio_field", locals: {f: f, tag: tag, selected_state: selected_state, states: states}
end

def form_collection_select(f, *args)
# This line enable passing optional arguments such as include_blank to the
# partial. If nothing is passed, an empty options hash is appended.
Expand Down
3 changes: 3 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ class Event < ActiveRecord::Base

has_many :periods, dependent: :destroy

enum phone_number_state: [:optional, :required, :disabled]

validates :description, presence: true
validates :end_date, presence: true
validates :location, presence: true
validates :contact_email, presence: true
validates :name, presence: true
validates :club, presence: true
validates :start_date, presence: true
validates :phone_number_state, presence: true

This comment has been minimized.

Copy link
@TomNaessens

TomNaessens Jan 12, 2017

Member

Shouldn't the presence be conditional to the event requires_phone_number state?

This comment has been minimized.

Copy link
@feliciaan

feliciaan Jan 12, 2017

Author Member

?

This comment has been minimized.

Copy link
@TomNaessens

TomNaessens Jan 12, 2017

Member

Oh, I thought this was on the registration model, nevermind :)


validates :contact_email, email: true
validates_with IBANValidator
Expand Down
7 changes: 7 additions & 0 deletions app/views/application/_form_radio_field.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="form-group btn-group" data-toggle="buttons">
<p><strong><%= tag.to_s.humanize %>:</strong></p>

<% states.each do |state, _| %>
<label class="btn btn-primary<%= ' active ' if state.to_s == selected_state %>"> <%= f.radio_button(tag, state) %><%= state.to_s.capitalize %></label>
<% end %>
</div>
2 changes: 2 additions & 0 deletions app/views/events/_general_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<%= form_date_field f, :start_date, "start", datepicker_time(f.object.start_date) %>
<%= form_date_field f, :end_date, "end", datepicker_time(f.object.end_date) %>
<%= form_check_box f, :registration_cancelable %>
<%= form_radio_field f, :phone_number_state, @event.phone_number_state, Event.phone_number_states %>
<%= form_fancy_text_area f, :description %>
<%= f.button :submit, class: 'btn btn-primary' %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170111204432_add_phone_number_enum_to_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPhoneNumberEnumToEvent < ActiveRecord::Migration
def change
add_column :events, :phone_number_state, :integer, default: 0
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170111155856) do
ActiveRecord::Schema.define(version: 20170111204432) do

create_table "access_levels", force: :cascade do |t|
t.string "name"
Expand Down Expand Up @@ -105,6 +105,7 @@
t.boolean "registration_open", default: true
t.text "signature"
t.boolean "registration_cancelable"
t.integer "phone_number_state", default: 0
end

create_table "included_zones", force: :cascade do |t|
Expand Down

0 comments on commit edef9a1

Please sign in to comment.