Browse Source

Let translation controls save nil translations

development
Godwin 8 years ago
parent
commit
92a9224716
  1. 4
      app/assets/stylesheets/bumbleberry-settings.json
  2. 5
      app/controllers/application_controller.rb
  3. 15
      app/controllers/conference_administration_controller.rb
  4. 8
      app/helpers/application_helper.rb

4
app/assets/stylesheets/bumbleberry-settings.json

@ -5,8 +5,8 @@
"chrome": ["51"]
},
"development": {
"and_chr": ["54"],
"chrome": ["54"],
"and_chr": ["55"],
"chrome": ["55"],
"edge": ["13"],
"firefox": ["48"],
"ie": ["11"],

5
app/controllers/application_controller.rb

@ -740,4 +740,9 @@ class ApplicationController < LinguaFrancaApplicationController
@registration.city = last_registration_data.city if last_registration_data.city.present?
end
end
# Set empty HTML values to nil, sometimes we will get values such as '<p> </p>' in rich edits, this will help to make sure they are actually empty
def html_value(value)
return value.present? && ActionView::Base.full_sanitizer.sanitize(value).strip.present? ? value : nil
end
end

15
app/controllers/conference_administration_controller.rb

@ -772,7 +772,7 @@ class ConferenceAdministrationController < ApplicationController
def admin_update_description
params[:info].each do | locale, value |
@this_conference.set_column_for_locale(:info, locale, value)
@this_conference.set_column_for_locale(:info, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
@ -793,7 +793,7 @@ class ConferenceAdministrationController < ApplicationController
def admin_update_payment_message
begin
params[:payment_message].each do | locale, value |
@this_conference.set_column_for_locale(:payment_message, locale, value)
@this_conference.set_column_for_locale(:payment_message, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
@ -1096,10 +1096,6 @@ class ConferenceAdministrationController < ApplicationController
else
event = Event.new(conference_id: @this_conference.id, locale: I18n.locale)
end
# save title and info
event.title = LinguaFranca::ActiveRecord::UntranslatedValue.new(params[:title]) unless event.title! == params[:title]
event.info = LinguaFranca::ActiveRecord::UntranslatedValue.new(params[:info]) unless event.info! == params[:info]
# save schedule data
event.event_location_id = params[:event_location]
@ -1107,8 +1103,11 @@ class ConferenceAdministrationController < ApplicationController
event.end_time = event.start_time + params[:time_span].to_f.hours
# save translations
(params[:info_translations] || {}).each do | locale, value |
event.set_column_for_locale(:title, locale, value, current_user.id) unless value = event._title(locale)
(params[:info] || {}).each do | locale, value |
event.set_column_for_locale(:title, locale, html_value(value), current_user.id) unless value = event._title(locale)
end
(params[:title] || {}).each do | locale, value |
event.set_column_for_locale(:info, locale, value, current_user.id) unless value = event._info(locale)
end

8
app/helpers/application_helper.rb

@ -1313,7 +1313,7 @@ module ApplicationHelper
field_options.each do | name, __options |
_options = __options.deep_dup
# add the field
value = object.is_a?(Hash) ? object[locale.to_sym] : object.get_column_for_locale!(name, locale)
value = object.is_a?(Hash) ? object[locale.to_sym] : object.get_column_for_locale!(name, locale, false)
# use the default value if we need to
if _options[:default].present? && value.blank?
@ -1368,7 +1368,7 @@ module ApplicationHelper
class: class_name, data: { locale: locale }).html_safe
# add the field
value = object.is_a?(Hash) ? object[locale.to_sym] : object.get_column_for_locale!(name, locale)
value = object.is_a?(Hash) ? object[locale.to_sym] : object.get_column_for_locale!(name, locale, false)
# use the default value if we need to
if options[:default].present? && value.blank?
@ -1412,11 +1412,11 @@ module ApplicationHelper
if options[:label] == false
label_id = options[:labelledby]
elsif options[:label].present?
html += label_tag(id, nil, id: label_id) do
html += label_tag([name, id], nil, id: label_id) do
_(options[:label], :t, vars: options[:vars] || {})
end
else
html += label_tag(id, nil, id: label_id)
html += label_tag([name, id], nil, id: label_id)
end
if options[:help].present?

Loading…
Cancel
Save