Merge pull request #513 from ChrisBr/fix_proposal_js

Fixes the proposal abstract word count javascript functions
This commit is contained in:
James Mason 2014-10-06 20:44:43 -07:00
commit 92db387822
3 changed files with 23 additions and 32 deletions

View file

@ -173,6 +173,24 @@ function word_count(text, divId, maxcount) {
}
};
/* Set the minimum and maximum proposal abstract 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);
$("#abstract-minimum-word-count").text(min);
word_count($('#event_abstract').get(0), 'abstract-count', max);
})
.trigger('change');
/* Count the proposal abstract length */
$("#event_abstract").bind('keyup', function() {
var $selected = $("#event_event_type_id option:selected")
var max = $selected.data("max-words");
word_count(this, 'abstract-count', max);
} );
/* Set the defaults for DataTables initialisation */
$.extend( true, $.fn.dataTable.defaults, {

View file

@ -1,13 +0,0 @@
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 += "min_str = '#{t.minimum_abstract_length}';\n"
str += "maxcount = #{t.maximum_abstract_length};\n"
str += "}\n\n"
end.join("\n")
str
end
end

View file

@ -10,7 +10,10 @@
= f.input :subtitle, :as => :string
%section#details
- if can? :update, @event or can? :create, @event
= f.input :event_type_id,:as => :select, :collection => @conference.event_types.map {|x| ["#{x.title} - #{show_time(x.length)}", x.id]}, :include_blank => false, :label => "Session Type"
= f.input :event_type_id, as: :select,
collection: @conference.event_types.map {|x| ["#{x.title} - #{show_time(x.length)}", x.id,
data: { min_words: x.minimum_abstract_length, max_words: x.maximum_abstract_length }]},
include_blank: false, label: 'Session Type'
- else
Event type: #{@event.event_type.title}
%br
@ -44,21 +47,4 @@
%span#biography-count #{current_user.biography_word_count}
words. Biographies are limited to 150 words.
%p.text-right
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-success"}
:javascript
var maxcount = 0;
$("#event_event_type_id").change(function () {
var str = "";
var min_str = ""
#{generate_abstract_length_js @conference}
$("#abstract-maximum-word-count").text(str);
$("#abstract-minimum-word-count").text(min_str);
word_count($('#event_abstract').get(0), 'abstract-count', maxcount);
})
.trigger('change');
$("#event_abstract").bind('keyup', function() {
word_count(this, 'abstract-count', maxcount);
} );
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-success"}