2019-05-08 15:24:11 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-23 21:19:08 +08:00
|
|
|
class ResultText < ApplicationRecord
|
2019-03-11 20:43:50 +08:00
|
|
|
include TinyMceImages
|
2023-08-11 20:48:20 +08:00
|
|
|
include ActionView::Helpers::TextHelper
|
2019-03-20 21:40:18 +08:00
|
|
|
|
2023-09-04 19:58:11 +08:00
|
|
|
auto_strip_attributes :name, nullify: false
|
|
|
|
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
|
2016-09-21 21:35:23 +08:00
|
|
|
auto_strip_attributes :text, nullify: false
|
2019-05-08 15:24:11 +08:00
|
|
|
validates :text, length: { maximum: Constants::RICH_TEXT_MAX_LENGTH }
|
|
|
|
|
2023-07-26 21:29:13 +08:00
|
|
|
belongs_to :result, inverse_of: :result_texts, touch: true
|
|
|
|
has_one :result_orderable_element, as: :orderable, dependent: :destroy
|
2023-08-11 20:48:20 +08:00
|
|
|
|
2023-08-23 21:05:31 +08:00
|
|
|
def duplicate(result, position = nil)
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
new_result_text = result.result_texts.create!(
|
|
|
|
text: text
|
|
|
|
)
|
|
|
|
|
|
|
|
# Copy results tinyMce assets
|
|
|
|
clone_tinymce_assets(new_result_text, result.my_module.team)
|
|
|
|
|
|
|
|
result.result_orderable_elements.create!(
|
|
|
|
position: position || result.result_orderable_elements.length,
|
|
|
|
orderable: new_result_text
|
|
|
|
)
|
|
|
|
|
|
|
|
new_result_text
|
|
|
|
end
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|