2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-12 15:08:19 -06:00
|
|
|
class AdminEmailTemplateSerializer < ApplicationSerializer
|
2015-11-20 11:30:04 -06:00
|
|
|
attributes :id, :title, :subject, :body, :can_revert?
|
2015-11-12 15:08:19 -06:00
|
|
|
|
|
|
|
def id
|
|
|
|
object
|
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
2017-01-04 18:02:38 -06:00
|
|
|
if I18n.exists?("#{object}.title")
|
|
|
|
I18n.t("#{object}.title")
|
|
|
|
else
|
|
|
|
object.gsub(/.*\./, "").titleize
|
|
|
|
end
|
2015-11-12 15:08:19 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def subject
|
2015-11-27 23:46:13 -06:00
|
|
|
if I18n.exists?("#{object}.subject_template.other")
|
|
|
|
@subject = nil
|
|
|
|
else
|
|
|
|
@subject ||= I18n.t("#{object}.subject_template")
|
|
|
|
end
|
2015-11-12 15:08:19 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
2015-11-20 11:30:04 -06:00
|
|
|
@body ||= I18n.t("#{object}.text_body_template")
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_revert?
|
2019-07-01 20:53:16 -05:00
|
|
|
subject_key = "#{object}.subject_template"
|
|
|
|
body_key = "#{object}.text_body_template"
|
|
|
|
keys = [subject_key, body_key]
|
|
|
|
if options[:overridden_keys]
|
|
|
|
keys.any? { |k| options[:overridden_keys].include?(k) }
|
|
|
|
else
|
|
|
|
TranslationOverride.exists?(locale: I18n.locale, translation_key: keys)
|
2015-11-20 11:30:04 -06:00
|
|
|
end
|
2015-11-12 15:08:19 -06:00
|
|
|
end
|
|
|
|
end
|