diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index b24882f3..f5e68165 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -175,7 +175,7 @@ module Admin def event_params params.require(:event).permit( # Set also in proposals controller - :title, :subtitle, :event_type_id, :abstract, :description, :require_registration, :difficulty_level_id, + :title, :subtitle, :event_type_id, :abstract, :submission_text, :description, :require_registration, :difficulty_level_id, # Set only in admin/events controller :track_id, :state, :language, :is_highlight, :max_attendees, # Not used anymore? diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index adfdbea0..bf1b3adc 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -170,7 +170,7 @@ class ProposalsController < ApplicationController def event_params params.require(:event).permit(:event_type_id, :track_id, :difficulty_level_id, - :title, :subtitle, :abstract, :description, + :title, :subtitle, :abstract, :submission_text, :description, :require_registration, :max_attendees, :language, speaker_ids: [], volunteer_ids: [] ) diff --git a/app/models/event.rb b/app/models/event.rb index 0370926b..dd86efec 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -73,6 +73,7 @@ class Event < ApplicationRecord before_create :generate_guid validate :abstract_limit + validate :submission_limit validate :before_end_of_conference, on: :create validates :title, presence: true validates :abstract, presence: true @@ -217,6 +218,10 @@ class Event < ApplicationRecord abstract.to_s.split.size end + def submission_word_count + submission_text.to_s.split.size + end + def self.get_state_color(state) COLORS[state.to_sym] || '#00FFFF' # azure end @@ -353,6 +358,18 @@ class Event < ApplicationRecord errors.add(:abstract, "cannot have more than #{max_words} words") if len > max_words end + def submission_limit + # If we don't have an event type, there is no need to count anything + return unless event_type && submission_text + + len = submission_text.split.size + max_words = event_type.maximum_abstract_length + min_words = event_type.minimum_abstract_length + + errors.add(:submission_text, "cannot have less than #{min_words} words") if len < min_words + errors.add(:submission_text, "cannot have more than #{max_words} words") if len > max_words + end + # TODO: create a module to be mixed into model to perform same operation # venue.rb has same functionality which can be shared # TODO: rename guid to UUID as guid is specifically Microsoft term