From c995f578772a830ace5a738de55bdb6312a7e5f0 Mon Sep 17 00:00:00 2001 From: Chrisbr Date: Sun, 5 Oct 2014 18:58:47 +0200 Subject: [PATCH] Fixes the proposal abstract word count javascript functions fix #510 --- app/assets/javascripts/osem.js | 18 ++++++++++++++++ app/helpers/proposal_helper.rb | 13 ----------- app/views/proposal/_proposal_form.html.haml | 24 +++++---------------- 3 files changed, 23 insertions(+), 32 deletions(-) delete mode 100644 app/helpers/proposal_helper.rb diff --git a/app/assets/javascripts/osem.js b/app/assets/javascripts/osem.js index 0b411529..68e6f55d 100644 --- a/app/assets/javascripts/osem.js +++ b/app/assets/javascripts/osem.js @@ -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, { diff --git a/app/helpers/proposal_helper.rb b/app/helpers/proposal_helper.rb deleted file mode 100644 index f5b565fc..00000000 --- a/app/helpers/proposal_helper.rb +++ /dev/null @@ -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 diff --git a/app/views/proposal/_proposal_form.html.haml b/app/views/proposal/_proposal_form.html.haml index d1174766..cc3cd6ff 100644 --- a/app/views/proposal/_proposal_form.html.haml +++ b/app/views/proposal/_proposal_form.html.haml @@ -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"} \ No newline at end of file