Add minimum/maximum word lengths to session types
This commit is contained in:
parent
8a7efa65d7
commit
57520bb7a9
19 changed files with 133 additions and 61 deletions
|
|
@ -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');
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
12
app/helpers/proposal_helper.rb
Normal file
12
app/helpers/proposal_helper.rb
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
} );
|
||||
|
|
@ -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
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# 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|
|
||||
t.date "start_date", :null => false
|
||||
|
|
@ -104,8 +104,10 @@ ActiveRecord::Schema.define(:version => 20130120104029) do
|
|||
|
||||
create_table "event_types", :force => true do |t|
|
||||
t.integer "conference_id"
|
||||
t.string "title", :null => false
|
||||
t.integer "length", :default => 30
|
||||
t.string "title", :null => false
|
||||
t.integer "length", :default => 30
|
||||
t.integer "minimum_abstract_length", :default => 0
|
||||
t.integer "maximum_abstract_length", :default => 500
|
||||
end
|
||||
|
||||
create_table "events", :force => true do |t|
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
BIN
public/assets/application-d14966b224ff14b11626ff9e2d845328.js.gz
Normal file
BIN
public/assets/application-d14966b224ff14b11626ff9e2d845328.js.gz
Normal file
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
|
|
@ -41,8 +41,8 @@ person_tiny.png: person_tiny-eb905998ae5686c9eeb2693a7bc0f898.png
|
|||
person_tiny/index.png: person_tiny-eb905998ae5686c9eeb2693a7bc0f898.png
|
||||
rails.png: rails-a3386665c05a2d82f711a4aaa72d247c.png
|
||||
rails/index.png: rails-a3386665c05a2d82f711a4aaa72d247c.png
|
||||
application.js: application-986409c25606174904024db627737590.js
|
||||
application/index.js: application-986409c25606174904024db627737590.js
|
||||
application.js: application-d14966b224ff14b11626ff9e2d845328.js
|
||||
application/index.js: application-d14966b224ff14b11626ff9e2d845328.js
|
||||
application.css: application-bcc3d2bf9bcd0688a30ee4cc370479fc.css
|
||||
application/index.css: application-bcc3d2bf9bcd0688a30ee4cc370479fc.css
|
||||
loading.gif: loading-b7ff30d20adcf2b850f420d17048930c.gif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue