From 8e112b7c8d0f37003f18c01794eb38636ac07cd8 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Thu, 16 Nov 2023 15:00:58 +0100 Subject: [PATCH] climate --- .../block/template/base/with_data.rb | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/models/communication/block/template/base/with_data.rb b/app/models/communication/block/template/base/with_data.rb index 915626bdb..05de95014 100644 --- a/app/models/communication/block/template/base/with_data.rb +++ b/app/models/communication/block/template/base/with_data.rb @@ -8,15 +8,7 @@ module Communication::Block::Template::Base::WithData next unless json.has_key? component.property component.data = json[component.property] end - return unless has_element_class? # Template is not supposed to have elements at all - return unless json.has_key?('elements') # Template has no element yet - # Objects are initialized from the database, - # then data from the form replaces data from the db. - # We need to reset elements, otherwise it's never deleted. - @elements = [] - json['elements'].each do |json| - @elements << default_element(json) - end + initialize_elements json end # Reads the data from the components @@ -64,6 +56,18 @@ module Communication::Block::Template::Base::WithData !self.class.element_class.nil? end + def initialize_elements(json) + return unless has_element_class? # Template is not supposed to have elements at all + return unless json.has_key?('elements') # Template has no element yet + # Objects are initialized from the database, + # then data from the form replaces data from the db. + # We need to reset elements, otherwise it's never deleted. + @elements = [] + json['elements'].each do |json| + @elements << default_element(json) + end + end + def json_from(value) if value.is_a? String JSON.parse(value) -- GitLab