2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-13 05:08:19 +08:00
|
|
|
class AdminEmailTemplateSerializer < ApplicationSerializer
|
2015-11-21 01:30:04 +08:00
|
|
|
attributes :id, :title, :subject, :body, :can_revert?
|
2015-11-13 05:08:19 +08:00
|
|
|
|
|
|
|
def id
|
|
|
|
object
|
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
2017-01-05 08:02:38 +08:00
|
|
|
if I18n.exists?("#{object}.title")
|
|
|
|
I18n.t("#{object}.title")
|
|
|
|
else
|
|
|
|
object.gsub(/.*\./, '').titleize
|
|
|
|
end
|
2015-11-13 05:08:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def subject
|
2015-11-28 13:46:13 +08:00
|
|
|
if I18n.exists?("#{object}.subject_template.other")
|
|
|
|
@subject = nil
|
|
|
|
else
|
|
|
|
@subject ||= I18n.t("#{object}.subject_template")
|
|
|
|
end
|
2015-11-13 05:08:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
2015-11-21 01:30:04 +08:00
|
|
|
@body ||= I18n.t("#{object}.text_body_template")
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_revert?
|
|
|
|
current_body, current_subject = body, subject
|
|
|
|
|
|
|
|
I18n.overrides_disabled do
|
|
|
|
return I18n.t("#{object}.subject_template") != current_subject ||
|
|
|
|
I18n.t("#{object}.text_body_template") != current_body
|
|
|
|
end
|
2015-11-13 05:08:19 +08:00
|
|
|
end
|
|
|
|
end
|