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"] "chrome": ["51"]
}, },
"development": { "development": {
"and_chr": ["54"], "and_chr": ["55"],
"chrome": ["54"], "chrome": ["55"],
"edge": ["13"], "edge": ["13"],
"firefox": ["48"], "firefox": ["48"],
"ie": ["11"], "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? @registration.city = last_registration_data.city if last_registration_data.city.present?
end end
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 end

15
app/controllers/conference_administration_controller.rb

@ -772,7 +772,7 @@ class ConferenceAdministrationController < ApplicationController
def admin_update_description def admin_update_description
params[:info].each do | locale, value | 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 end
@this_conference.save @this_conference.save
set_success_message @admin_step set_success_message @admin_step
@ -793,7 +793,7 @@ class ConferenceAdministrationController < ApplicationController
def admin_update_payment_message def admin_update_payment_message
begin begin
params[:payment_message].each do | locale, value | 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 end
@this_conference.save @this_conference.save
set_success_message @admin_step set_success_message @admin_step
@ -1097,18 +1097,17 @@ class ConferenceAdministrationController < ApplicationController
event = Event.new(conference_id: @this_conference.id, locale: I18n.locale) event = Event.new(conference_id: @this_conference.id, locale: I18n.locale)
end 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 # save schedule data
event.event_location_id = params[:event_location] event.event_location_id = params[:event_location]
event.start_time = Date.parse(params[:day]) + params[:time].to_f.hours event.start_time = Date.parse(params[:day]) + params[:time].to_f.hours
event.end_time = event.start_time + params[:time_span].to_f.hours event.end_time = event.start_time + params[:time_span].to_f.hours
# save translations # save translations
(params[:info_translations] || {}).each do | locale, value | (params[:info] || {}).each do | locale, value |
event.set_column_for_locale(:title, locale, value, current_user.id) unless value = event._title(locale) 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) event.set_column_for_locale(:info, locale, value, current_user.id) unless value = event._info(locale)
end end

8
app/helpers/application_helper.rb

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

Loading…
Cancel
Save