Merge pull request #905 from Ana06/languages

Languages
This commit is contained in:
Henne Vogelsang 2016-06-15 16:55:12 +02:00 committed by GitHub
commit dcae196d2b
16 changed files with 115 additions and 13 deletions

View file

@ -26,7 +26,7 @@ module Admin
private
def program_params
params.require(:program).permit(:rating, :schedule_public, :schedule_fluid)
params.require(:program).permit(:rating, :schedule_public, :schedule_fluid, :languages)
end
end
end

View file

@ -20,10 +20,12 @@ class ProposalController < ApplicationController
def new
@user = User.new
@url = conference_program_proposal_index_path(@conference.short_title)
@languages = @program.languages_list
end
def edit
@url = conference_program_proposal_path(@conference.short_title, params[:id])
@languages = @program.languages_list
end
def create
@ -144,7 +146,7 @@ class ProposalController < ApplicationController
def event_params
params.require(:event).permit(:event_type_id, :track_id, :difficulty_level_id,
:title, :subtitle, :abstract, :description,
:require_registration, :max_attendees)
:require_registration, :max_attendees, :language)
end
def user_params

View file

@ -51,6 +51,7 @@ class Program < ActiveRecord::Base
before_create :create_event_types
before_create :create_difficulty_levels
validate :check_languages_format
##
# Checcks if the program has rating enabled
@ -82,6 +83,10 @@ class Program < ActiveRecord::Base
(!conference.email_settings.program_schedule_public_subject.blank? && !conference.email_settings.program_schedule_public_body.blank?)
end
def languages_list
self.languages.split(',').map {|l| ISO_639.find(l).english_name} if self.languages.present?
end
private
##
@ -112,4 +117,20 @@ class Program < ActiveRecord::Base
color: '#EF6E69')
true
end
##
# Check if languages string has the right format. Used as validation.
#
def check_languages_format
return unless self.languages.present?
# All white spaces are removed to allow languages to be separated by ',' and ', '. The languages string without spaces is saved
self.languages = self.languages.delete(' ').downcase
errors.add(:languages, 'must be two letters separated by commas') && return unless
self.languages.match(/^$|(\A[a-z][a-z](,[a-z][a-z])*\z)/).present?
languages_array = self.languages.split(',')
# We check that languages are not repeated
errors.add(:languages, "can't be repeated") && return unless languages_array.uniq!.nil?
# We check if every language is a valid ISO 639-1 language
errors.add(:languages, 'must be ISO 639-1 valid codes') unless languages_array.select{ |x| ISO_639.find(x).nil? }.empty?
end
end

View file

@ -98,6 +98,14 @@
off_text: 'No' }
- if @event.require_registration
= registered_text(@event)
-if @program.languages.present?
%tr
%td
%b Language
%td
= @event.language
- if !@event.room.nil?
%tr
%td

View file

@ -22,6 +22,9 @@
%b Submitter
%th
%b Speaker
-if @program.languages.present?
%th
%b Language
%th
%b Requires Registration
%th
@ -83,6 +86,10 @@
- else
Unknown speaker
-if @program.languages.present?
%td
= event.language
%td.text-center{'data-order' => "#{event.require_registration}"}
= check_box_tag @conference.short_title, event.id, event.require_registration,
method: :patch, url: "/admin/conference/#{@conference.short_title}/program/events/#{event.id}?event[require_registration]=",

View file

@ -4,9 +4,10 @@
%h1 Program
.row
.col-md-8
= semantic_form_for(@program, :url => admin_conference_program_path(@conference.short_title),:html => {:multipart => true}) do |f|
= semantic_form_for(@program, url: admin_conference_program_path(@conference.short_title), html: {multipart: true}) do |f|
= f.input :schedule_public, label: "Show Schedule on the home and splash page"
= f.input :schedule_fluid, label: "Allow submitters to change their event after it is scheduled"
= f.input :rating, :hint => "Enter the number of different rating levels you want to have for voting on proposals. Enter 0 if you do not want to vote on proposals."
= f.input :rating, hint: 'Enter the number of different rating levels you want to have for voting on proposals. Enter 0 if you do not want to vote on proposals.'
= f.input :languages, hint: "Enter the languages allowed for events as values of #{link_to('ISO 639-1', 'http://www.loc.gov/standards/iso639-2/php/code_list.php', target: "_blank")} language codes separated with commas. The first language would be the default language. Leave it blank if you do not want to specify languages.".html_safe
%p.text-right
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}
= f.action :submit, as: :button, button_html: {class: 'btn btn-primary'}

View file

@ -31,6 +31,10 @@
Difficulty Levels:
%dd
= difficulty_levels(@conference)
%dt
Languages:
%dd
= @program.languages
%dt
Public Schedule
%dd#schedule_public

View file

@ -14,6 +14,11 @@
data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length }]},
include_blank: false, label: 'Type', input_html: { class: 'select-help-toggle' }
- if @program.languages.present?
= f.input :language, as: :select,
collection: @languages,
include_blank: false, label: 'Language', input_html: { class: 'select-help-toggle' }
- @conference.program.event_types.each do |event_type|
%span{ class: 'help-block select-help-text event_event_type_id collapse', id: "#{event_type.id}-help" }
= event_type.description

View file

@ -31,6 +31,11 @@
data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length }]},
include_blank: false, label: 'Type', input_html: { class: 'select-help-toggle' }
- if @program.languages.present?
= f.input :language, as: :select,
collection: @languages,
include_blank: false, label: 'Language', input_html: { class: 'select-help-toggle' }
- @program.event_types.each do |event_type|
%span{ class: 'help-block event_event_type_id collapse', id: "#{event_type.id}-help" }
= event_type.description