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(); $("#comments-div").hide();
}); });
function word_count(text, divId) { function word_count(text, divId, maxcount) {
var r = 0; var r = 0;
var input = text.value.replace(/\s/g,' '); var input = text.value.replace(/\s/g,' ');
var word_array = input.split(' '); var word_array = input.split(' ');
@ -71,4 +71,11 @@ function word_count(text, divId) {
} }
$('#' + divId).text(r); $('#' + 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 :people_attributes
params[:event].delete :person 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 if submitter[:public_name] != @person.public_name || submitter[:biography] != @person.biography
@person.update_attributes(submitter) @person.update_attributes(submitter)
end end
event = Event.find_by_id(params[:id]) 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.") redirect_to(conference_proposal_index_path(:conference_id => @conference.short_title), :notice => "'#{event.title}' was successfully updated.")
else rescue Exception => e
redirect_to session[:return_to], :alert => "'#{event.title}' was NOT updated!" redirect_to edit_conference_proposal_path(@conference.short_title, @event), :alert => e.message
end end
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 before_create :generate_guid
validate :abstract_limit validate :abstract_limit
validate :biography_exists
validates :title, :presence => true validates :title, :presence => true
validates :abstract, :presence => true validates :abstract, :presence => true
@ -130,11 +131,24 @@ class Event < ActiveRecord::Base
private private
def abstract_limit def abstract_limit
if self.abstract.split.size > 250 len = self.abstract.split.size
errors.add(:abstract, "cannot have more than 250 words") 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
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 def generate_guid
begin begin
guid = SecureRandom.urlsafe_base64 guid = SecureRandom.urlsafe_base64

View file

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

View file

@ -2,6 +2,8 @@
<%= f.inputs do %> <%= f.inputs do %>
<%= f.input :title %> <%= f.input :title %>
<%= f.input :length, :input_html => {:size => 3} %> <%= 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 %> <%= remove_association_link :event_type, f %>
<% end %> <% end %>
</div> </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." = 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) = image_tag current_user.person.avatar(:small)
= p.input :avatar, :label => "Picture", :hint => "Upload a new picture." = 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 You have used
%span#biography-count #{current_user.person.biography_word_count} %span#biography-count #{current_user.person.biography_word_count}
words. Biographies are limited to 150 words. words. Biographies are limited to 150 words.

View file

@ -1,25 +1,28 @@
.span12 .span12
= semantic_form_for(@event, :url => @url) do |f| = semantic_form_for(@event, :url => @url) do |f|
%section#basic %section#basic
= f.inputs :name => "Basic Information" do = f.inputs :name => "Session Information" do
= f.input :title, :required => true = f.input :title, :required => true
= f.input :subtitle = 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 You have used
%span#abstract-count #{@event.abstract_word_count} %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
%br %br
= f.input :description, :input_html => {:rows => 5}, :hint => "This will only be shown to organizers, not to attendees." = 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 %section#information
= f.inputs :name => "Your Information" do = f.inputs :name => "Your Information" do
= semantic_fields_for @person do |p| = semantic_fields_for @person do |p|
= p.input :public_name, :required => true = 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 :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 You have used
%span#biography-count #{@person.biography_word_count} %span#biography-count #{@person.biography_word_count}
words. Biographies are limited to 150 words. words. Biographies are limited to 150 words.
@ -32,3 +35,18 @@
biography for each. biography for each.
= f.input :proposal_additional_speakers, :input_html => {:rows => 5}, :label => false = 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"} = 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);
} );

View file

@ -0,0 +1,6 @@
class AddMinimumAndMaximumAbstractLengthsToEventTypes < ActiveRecord::Migration
def change
add_column :event_types, :minimum_abstract_length, :integer, :default => 0
add_column :event_types, :maximum_abstract_length, :integer, :default => 500
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130120104029) do ActiveRecord::Schema.define(:version => 20130131100257) do
create_table "call_for_papers", :force => true do |t| create_table "call_for_papers", :force => true do |t|
t.date "start_date", :null => false t.date "start_date", :null => false
@ -106,6 +106,8 @@ ActiveRecord::Schema.define(:version => 20130120104029) do
t.integer "conference_id" t.integer "conference_id"
t.string "title", :null => false t.string "title", :null => false
t.integer "length", :default => 30 t.integer "length", :default => 30
t.integer "minimum_abstract_length", :default => 0
t.integer "maximum_abstract_length", :default => 500
end end
create_table "events", :force => true do |t| create_table "events", :force => true do |t|

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -41,8 +41,8 @@ person_tiny.png: person_tiny-eb905998ae5686c9eeb2693a7bc0f898.png
person_tiny/index.png: person_tiny-eb905998ae5686c9eeb2693a7bc0f898.png person_tiny/index.png: person_tiny-eb905998ae5686c9eeb2693a7bc0f898.png
rails.png: rails-a3386665c05a2d82f711a4aaa72d247c.png rails.png: rails-a3386665c05a2d82f711a4aaa72d247c.png
rails/index.png: rails-a3386665c05a2d82f711a4aaa72d247c.png rails/index.png: rails-a3386665c05a2d82f711a4aaa72d247c.png
application.js: application-986409c25606174904024db627737590.js application.js: application-d14966b224ff14b11626ff9e2d845328.js
application/index.js: application-986409c25606174904024db627737590.js application/index.js: application-d14966b224ff14b11626ff9e2d845328.js
application.css: application-bcc3d2bf9bcd0688a30ee4cc370479fc.css application.css: application-bcc3d2bf9bcd0688a30ee4cc370479fc.css
application/index.css: application-bcc3d2bf9bcd0688a30ee4cc370479fc.css application/index.css: application-bcc3d2bf9bcd0688a30ee4cc370479fc.css
loading.gif: loading-b7ff30d20adcf2b850f420d17048930c.gif loading.gif: loading-b7ff30d20adcf2b850f420d17048930c.gif