Skip to content
Snippets Groups Projects
Commit fa2a21ec authored by Arnaud Levy's avatar Arnaud Levy
Browse files

limit inheritance to rich texts

parent c1124211
No related branches found
No related tags found
No related merge requests found
...@@ -5,22 +5,12 @@ module WithInheritance ...@@ -5,22 +5,12 @@ module WithInheritance
def self.rich_text_areas_with_inheritance(*properties) def self.rich_text_areas_with_inheritance(*properties)
properties.each do |property| properties.each do |property|
has_rich_text property has_rich_text property
has_inheritance_methods property define_method :"best_#{property}" do
end best(property)
end end
define_method :"best_#{property}_source" do
def self.values_with_inheritance(*properties) best_source(property)
properties.each do |property| end
has_inheritance_methods property
end
end
def self.has_inheritance_methods(property)
define_method :"best_#{property}" do
best(property)
end
define_method :"best_#{property}_source" do
best_source(property)
end end
end end
end end
...@@ -35,8 +25,6 @@ module WithInheritance ...@@ -35,8 +25,6 @@ module WithInheritance
def best_source(property) def best_source(property)
value = send(property) value = send(property)
return nil if !value.blank? # There is a value, no inheritance needed return nil if !value.blank? # There is a value, no inheritance needed
best_value = best(property) best(property)&.record
best_value.is_a?(ActionText::RichText) ? best_value.record
: ancestors.detect { |ancestor| ancestor.public_send(property) == best_value }
end end
end end
...@@ -47,8 +47,6 @@ class Education::Program < ApplicationRecord ...@@ -47,8 +47,6 @@ class Education::Program < ApplicationRecord
:pricing, :pricing,
:registration :registration
values_with_inheritance :description
attr_accessor :skip_websites_categories_callback attr_accessor :skip_websites_categories_callback
has_one_attached_deletable :featured_image has_one_attached_deletable :featured_image
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
<h5 class="card-title mb-0"><%= t('education.program.useful_informations') %></h5> <h5 class="card-title mb-0"><%= t('education.program.useful_informations') %></h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :description %> <%= f.input :description %>
<%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :registration %> <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :registration %>
<%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :pricing %> <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :pricing %>
<%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :duration %> <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :duration %>
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
program = f.object program = f.object
best_prop_value = program.public_send("best_#{property}") best_prop_value = program.public_send("best_#{property}")
best_prop_source = program.public_send("best_#{property}_source") best_prop_source = program.public_send("best_#{property}_source")
is_rich_text = best_prop_value.is_a?(ActionText::RichText)
as = is_rich_text ? :rich_text_area : :text
id = "#{property}Collapse" id = "#{property}Collapse"
%> %>
<% if best_prop_source %> <% if best_prop_source %>
...@@ -19,7 +17,7 @@ id = "#{property}Collapse" ...@@ -19,7 +17,7 @@ id = "#{property}Collapse"
</a> </a>
</div> </div>
<div class="collapse" id="<%= id %>"> <div class="collapse" id="<%= id %>">
<%= f.input property, as: as, label: false %> <%= f.input property, as: :rich_text_area, label: false %>
<div class="bg-light p-2 mt-n2"> <div class="bg-light p-2 mt-n2">
<b><%= t 'admin.inheritance.sentence_html', link: link_to(best_prop_source, [:admin, best_prop_source]) %></b><br> <b><%= t 'admin.inheritance.sentence_html', link: link_to(best_prop_source, [:admin, best_prop_source]) %></b><br>
<%= best_prop_value %> <%= best_prop_value %>
...@@ -27,5 +25,5 @@ id = "#{property}Collapse" ...@@ -27,5 +25,5 @@ id = "#{property}Collapse"
</div> </div>
</div> </div>
<% else %> <% else %>
<%= f.input property, as: as %> <%= f.input property, as: :rich_text_area %>
<% end %> <% end %>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment