Add minimum/maximum word lengths to session types

This commit is contained in:
Matt Barringer 2013-01-31 14:38:58 +01:00
parent 8a7efa65d7
commit 57520bb7a9
19 changed files with 133 additions and 61 deletions

View file

@ -62,7 +62,7 @@ $(function() {
$("#comments-div").hide();
});
function word_count(text, divId) {
function word_count(text, divId, maxcount) {
var r = 0;
var input = text.value.replace(/\s/g,' ');
var word_array = input.split(' ');
@ -71,4 +71,11 @@ function word_count(text, divId) {
}
$('#' + divId).text(r);
if (r > maxcount) {
console.log("R is greater than maxcount");
$('#' + divId).css('color', 'red');
} else {
console.log("R is less than maxcount");
$('#' + divId).css('color', '#333');
}
};

View file

@ -56,16 +56,27 @@ class ProposalController < ApplicationController
params[:event].delete :people_attributes
params[:event].delete :person
if submitter[:public_name].blank?
redirect_to edit_conference_proposal_path(@conference.short_title, @event), :alert => "Your public name cannot be blank"
return
end
if submitter[:biography].blank?
redirect_to edit_conference_proposal_path(@conference.short_title, @event), :alert => "Your biography cannot be blank"
return
end
if submitter[:public_name] != @person.public_name || submitter[:biography] != @person.biography
@person.update_attributes(submitter)
end
event = Event.find_by_id(params[:id])
if event.update_attributes!(params[:event])
begin
event.update_attributes!(params[:event])
redirect_to(conference_proposal_index_path(:conference_id => @conference.short_title), :notice => "'#{event.title}' was successfully updated.")
else
redirect_to session[:return_to], :alert => "'#{event.title}' was NOT updated!"
rescue Exception => e
redirect_to edit_conference_proposal_path(@conference.short_title, @event), :alert => e.message
end
end

View file

@ -0,0 +1,12 @@
module ProposalHelper
def generate_abstract_length_js(conference)
str = ""
conference.event_types.map do |t|
str += "if ($('select option:selected').text() == '#{t.title}') {\n"
str += "str = '#{t.maximum_abstract_length}';\n"
str += "maxcount = #{t.maximum_abstract_length};\n"
str += "}\n\n"
end.join("\n")
str
end
end

View file

@ -20,6 +20,7 @@ class Event < ActiveRecord::Base
before_create :generate_guid
validate :abstract_limit
validate :biography_exists
validates :title, :presence => true
validates :abstract, :presence => true
@ -130,11 +131,24 @@ class Event < ActiveRecord::Base
private
def abstract_limit
if self.abstract.split.size > 250
errors.add(:abstract, "cannot have more than 250 words")
len = self.abstract.split.size
max = self.event_type.maximum_abstract_length
min = self.event_type.minimum_abstract_length
if len < min
errors.add(:abstract, "cannot have less than #{min} words")
end
if len > max
errors.add(:abstract, "cannot have more than #{max} words")
end
end
def biography_exists
if self.submitter.biography_word_count == 0
errors.add(:person_biography, "must be filled out")
end
end
def generate_guid
begin
guid = SecureRandom.urlsafe_base64

View file

@ -1,5 +1,5 @@
class EventType < ActiveRecord::Base
attr_accessible :title, :length
attr_accessible :title, :length, :minimum_abstract_length, :maximum_abstract_length
belongs_to :conference
end

View file

@ -2,6 +2,8 @@
<%= f.inputs do %>
<%= f.input :title %>
<%= f.input :length, :input_html => {:size => 3} %>
<%= f.input :minimum_abstract_length, :input_html => {:size => 3} %>
<%= f.input :maximum_abstract_length, :input_html => {:size => 3} %>
<%= remove_association_link :event_type, f %>
<% end %>
</div>

View file

@ -7,7 +7,7 @@
= p.input :company, :label => "Affiliation", :hint => "This could be a company, a user group, or nothing at all."
= image_tag current_user.person.avatar(:small)
= p.input :avatar, :label => "Picture", :hint => "Upload a new picture."
= p.input :biography, :input_html => {:rows => 5, "onkeyup" => "word_count(this, 'biography-count')"}, :for => :person
= p.input :biography, :input_html => {:rows => 5, "onkeyup" => "word_count(this, 'biography-count', 150)"}, :for => :person
You have used
%span#biography-count #{current_user.person.biography_word_count}
words. Biographies are limited to 150 words.

View file

@ -1,25 +1,28 @@
.span12
= semantic_form_for(@event, :url => @url) do |f|
%section#basic
= f.inputs :name => "Basic Information" do
= f.inputs :name => "Session Information" do
= f.input :title, :required => true
= f.input :subtitle
= f.input :abstract, :input_html => {:rows => 5, "onkeyup" => "word_count(this, 'abstract-count')"}, :required => true
%section#details
= f.input :event_type_id,:as => :select, :collection => @event_types, :include_blank => false, :label => "Session Type"
= f.input :abstract, :input_html => {:rows => 5},
:required => true, :label => "Session Abstract"
You have used
%span#abstract-count #{@event.abstract_word_count}
words. Abstracts are limited to 250 words.
words. Abstracts are limited to
%span#abstract-maximum-word-count
250
words.
%br
%br
= f.input :description, :input_html => {:rows => 5}, :hint => "This will only be shown to organizers, not to attendees."
%section#details
= f.inputs :name => "Session Details" do
= f.input :event_type_id,:as => :select, :collection => @event_types, :include_blank => false
%section#information
= f.inputs :name => "Your Information" do
= semantic_fields_for @person do |p|
= p.input :public_name, :required => true
= p.input :company, :label => "Affiliation", :hint => "This could be a company, a user group, or nothing at all."
= p.input :biography, :required => true, :input_html => {:rows => 5, "onkeyup" => "word_count(this, 'biography-count')"}
= p.input :biography, :required => true, :input_html => {:rows => 5, "onkeyup" => "word_count(this, 'biography-count', 150)"}
You have used
%span#biography-count #{@person.biography_word_count}
words. Biographies are limited to 150 words.
@ -32,3 +35,18 @@
biography for each.
= f.input :proposal_additional_speakers, :input_html => {:rows => 5}, :label => false
= f.action :submit, :as => :button, :label => "Submit Session", :button_html => {:class => "btn btn-primary"}
:javascript
var maxcount = 0;
$("#event_event_type_id").change(function () {
var str = "";
#{generate_abstract_length_js @conference}
$("#abstract-maximum-word-count").text(str);
word_count($('#event_abstract').get(0), 'abstract-count', maxcount);
})
.trigger('change');
$("#event_abstract").bind('keyup', function() {
word_count(this, 'abstract-count', maxcount);
} );