Merge pull request #11 from CactusPuppy/176894810/add_summision_text

Add submission text to event proposals
This commit is contained in:
CactusPuppy 2021-03-01 23:38:06 -08:00 committed by GitHub
commit 207046dc65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 147 additions and 14 deletions

View file

@ -149,15 +149,21 @@ function word_count(text, divId, maxcount) {
/* Wait for the DOM to be ready before attaching events to the elements */
$( document ).ready(function() {
/* Set the minimum and maximum proposal abstract word length */
/* Set the minimum and maximum proposal abstract and submission text word length */
$("#event_event_type_id").change(function () {
var $selected = $("#event_event_type_id option:selected")
var max = $selected.data("max-words");
var min = $selected.data("min-words");
$("#abstract-maximum-word-count").text(max);
$("#submission-maximum-word-count").text(max);
$("#abstract-minimum-word-count").text(min);
$("#submission-minimum-word-count").text(min);
word_count($('#event_abstract').get(0), 'abstract-count', max);
word_count($('#event_submission_text').get(0), 'submission-count', max);
// Set the placeholder text for the abstract
$('#event_submission_text').attr("placeholder", $selected.data("help"));
})
.trigger('change');
@ -167,6 +173,13 @@ $( document ).ready(function() {
var max = $selected.data("max-words");
word_count(this, 'abstract-count', max);
} );
/* Count the submission text length */
$("#event_submission_text").bind('change keyup paste input', function() {
var $selected = $("event_event_type_id option:selected")
var max = $selected.data("max-words");
word_count(this, 'submission-count', max);
});
});
/* Commodity function for modal windows */

View file

@ -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?

View file

@ -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: []
)

View file

@ -18,6 +18,7 @@
# require_registration :boolean
# start_time :datetime
# state :string default("new"), not null
# submission_text :text
# subtitle :string
# title :string not null
# week :integer
@ -73,6 +74,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 +219,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
@ -341,16 +347,28 @@ class Event < ApplicationRecord
errors.add(:max_attendees, "cannot be more than the room's capacity (#{room.size})") if max_attendees && (max_attendees > room.size)
end
def abstract_limit
# If we don't have an event type, there is no need to count anything
return unless event_type && abstract
def word_limit(field)
# If we don't have an event type or the requested field, don't count
return unless event_type && respond_to?(field) && self[field]
len = abstract.split.size
len = self[field].split.size
# TODO: Use different limits for different text fields
# Uncomment the two lines below this when the separate word limits are implemented.
# max_words = event_type["maximum_#{field}_length"]
# min_words = event_type["minimum_#{field}_length"]
max_words = event_type.maximum_abstract_length
min_words = event_type.minimum_abstract_length
errors.add(:abstract, "cannot have less than #{min_words} words") if len < min_words
errors.add(:abstract, "cannot have more than #{max_words} words") if len > max_words
errors.add(field.to_sym, "cannot have less than #{min_words} words") if len < min_words
errors.add(field.to_sym, "cannot have more than #{max_words} words") if len > max_words
end
def abstract_limit
word_limit(:abstract)
end
def submission_limit
word_limit(:submission_text)
end
# TODO: create a module to be mixed into model to perform same operation

View file

@ -18,6 +18,7 @@
# require_registration :boolean
# start_time :datetime
# state :string default("new"), not null
# submission_text :text
# subtitle :string
# title :string not null
# week :integer

View file

@ -113,6 +113,10 @@
%td
%b Abstract
%td= markdown(@event.abstract)
%tr
%td
%b Submission Description
%td= markdown(@event.submission_text)
%tr
%td
%b Requirements

View file

@ -13,7 +13,7 @@
= f.input :event_type_id, as: :select,
collection: @conference.program.event_types.map {|type| ["#{type.title} - #{show_time(type.length)}", type.id,
data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length }]},
data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length, help: type.description }]},
include_blank: false, label: 'Type', input_html: { class: 'select-help-toggle' }
- if @program.languages.present?
@ -46,6 +46,22 @@
250
words.
%br
= f.input :submission_text, input_html: { rows: 5, data: { provide: 'markdown' }, placeholder: '' },
hint: markdown_hint('Only conference organizers will read this.')
%p
You have used
%span#submission-count #{@event.submission_word_count}
words. Submission descriptions must be between
%span#submission-minimum-word-count
0
and
%span#submission-maximum-word-count
250
words.
- if current_user.is_admin? or @program.cfp.enable_registrations?
= f.inputs 'Enable pre-registration' do
= f.input :require_registration, label: 'Require participants to register to your event'

View file

@ -61,6 +61,22 @@
250
words.
= f.input :submission_text, input_html: { rows: 5, data: { provide: 'markdown' } },
hint: markdown_hint
%p
You have used
%span#submission-count #{@event.submission_word_count}
words. Submission descriptions must be between
%span#submission-minimum-word-count
0
and
%span#submission-maximum-word-count
250
words.
- if @program.cfp.enable_registrations?
= f.input :require_registration, label: 'Require participants to register to your event'