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

edit refactor, clean!

parent d4a92685
No related branches found
No related tags found
No related merge requests found
Showing
with 53 additions and 105 deletions
module Admin::BlocksHelper
def block_component_edit(property, **options)
block_component_render :edit, property, **options
render "admin/communication/blocks/components/edit",
property: property,
**options
end
def block_component_preview(property, **options)
......@@ -15,14 +17,4 @@ module Admin::BlocksHelper
property: property,
**options
end
protected
def block_component_render(view, property, **options)
template = options.has_key?(:template) ? options[:template]
: @block.template
component = template.public_send "#{property}_component"
partial = "admin/communication/blocks/components/#{component.kind}/#{view}"
render partial, property: property, template: template, **options
end
end
......@@ -139,6 +139,10 @@ class Communication::Block::Template::Base
data['layout']
end
def kind
block.template_kind
end
def blob_with_id(id)
university.active_storage_blobs.find id
end
......
<%
template ||= @block.template
component = template.public_send "#{property}_component"
i18n = "admin.communication.blocks.templates.#{template.kind}.edit"
template ||= @block.template
root_template = template == @block.template
if root_template
model = 'data'
dom_id = "#{property}"
i18n_component = "#{i18n}.#{property}"
else
# Nested element
model = 'element'
dom_id = "'element-' + index + '-#{property}'"
i18n_component = "#{i18n}.element.#{property}"
end
label ||= t "#{i18n_component}.label"
placeholder ||= t "#{i18n_component}.placeholder"
partial = "admin/communication/blocks/components/#{component.kind}/edit"
local_assigns[:template] = template
local_assigns[:component] = component
local_assigns[:model] = model
local_assigns[:dom_id] = dom_id
local_assigns[:label] = label
local_assigns[:placeholder] = placeholder
%>
<%= render partial, **local_assigns %>
......@@ -2,9 +2,10 @@
template ||= @block.template
component = template.public_send "#{property}_component"
value = template.public_send(property).to_s
partial = "admin/communication/blocks/components/#{component.kind}/preview"
local_assigns[:template] = template
local_assigns[:component] = component
local_assigns[:value] = value
partial = "admin/communication/blocks/components/#{component.kind}/preview"
%>
<%= render partial, **local_assigns %>
......@@ -4,11 +4,12 @@ component = template.public_send "#{property}_component"
value = template.public_send property
depth ||= 3
indentation = ' ' * depth
partial = "admin/communication/blocks/components/#{component.kind}/static"
local_assigns[:template] = template
local_assigns[:component] = component
local_assigns[:value] = value
local_assigns[:depth] = depth
local_assigns[:indentation] = indentation
partial = "admin/communication/blocks/components/#{component.kind}/static"
%>
<%= render partial, **local_assigns %>
<%
template_kind = @block.template_kind
i18n = "admin.communication.blocks.templates.#{template_kind}.edit"
template ||= @block.template
root_template = template == @block.template
if root_template
model = 'data'
dom_id = "#{property}"
i18n_component = "#{i18n}.#{property}"
else
# Nested element
model = 'element'
dom_id = "'element-' + index + '-#{property}'"
i18n_component = "#{i18n}.element.#{property}"
end
label ||= t 'admin.communication.blocks.components.image.input.label'
remove ||= t 'admin.communication.blocks.components.image.input.remove'
label = t 'admin.communication.blocks.components.image.input.label'
remove = t 'admin.communication.blocks.components.image.input.remove'
%>
<div class="mb-3">
<div v-if="!<%= model %>.<%= property %>.id">
......
<%
horizontal ||= false
template = @block.template
template_kind = @block.template_kind
layouts = template.class.layouts
%>
<% if horizontal %><div class="row"><% end %>
<% layouts.each do |layout| %>
<%
name = t "admin.communication.blocks.templates.#{template_kind}.layouts.#{layout}.label"
description = t "admin.communication.blocks.templates.#{template_kind}.layouts.#{layout}.description"
name = t "admin.communication.blocks.templates.#{template.kind}.layouts.#{layout}.label"
description = t "admin.communication.blocks.templates.#{template.kind}.layouts.#{layout}.description"
%>
<% if horizontal %><div class="col-md-4"><% end %>
<div class="card mb-4">
......@@ -33,7 +31,7 @@ layouts = template.class.layouts
</div>
</div>
<div class="col-md-6">
<%= image_tag "communication/blocks/templates/#{template_kind}/#{layout}.png",
<%= image_tag "communication/blocks/templates/#{template.kind}/#{layout}.png",
alt: name,
class: 'img-fluid' %>
</div>
......
<%
template_kind = @block.template_kind
i18n = "admin.communication.blocks.templates.#{template_kind}.edit"
template ||= @block.template
root_template = template == @block.template
if root_template
model = 'data'
dom_id = "#{property}"
i18n_component = "#{i18n}.#{property}"
else
# Nested element
model = 'element'
dom_id = "'element-' + index + '-#{property}'"
i18n_component = "#{i18n}.element.#{property}"
end
label ||= t "#{i18n_component}.label"
placeholder ||= t "#{i18n_component}.placeholder"
%>
<label class="form-label"
aria-label="<%= label %>"
:for="<%= dom_id.html_safe %>">
<label class="form-label" aria-label="<%= label %>" :for="<%= dom_id.html_safe %>">
<%= label %>
</label>
<div class="summernote mb-3">
......
<%
template_kind = @block.template_kind
i18n = "admin.communication.blocks.templates.#{template_kind}.edit"
template ||= @block.template
root_template = template == @block.template
if root_template
model = 'data'
dom_id = "#{property}"
i18n_component = "#{i18n}.#{property}"
else
# Nested element
model = 'element'
dom_id = "'element-' + index + '-#{property}'"
i18n_component = "#{i18n}.element.#{property}"
end
label ||= t "#{i18n_component}.label"
placeholder ||= t "#{i18n_component}.placeholder"
%>
<label class="form-label"
aria-label="<%= label %>"
:for="<%= dom_id.html_safe %>">
<label class="form-label" aria-label="<%= label %>" :for="<%= dom_id.html_safe %>">
<%= label%>
</label>
<input :id="<%= dom_id.html_safe %>"
......
<%
template_kind = @block.template_kind
i18n = "admin.communication.blocks.templates.#{template_kind}.edit"
template ||= @block.template
root_template = template == @block.template
if root_template
model = 'data'
dom_id = "#{property}"
i18n_component = "#{i18n}.#{property}"
else
# Nested element
model = 'element'
dom_id = "'element-' + index + '-#{property}'"
i18n_component = "#{i18n}.element.#{property}"
end
label ||= t "#{i18n_component}.label"
placeholder ||= t "#{i18n_component}.placeholder"
rows ||= 3
%>
<% rows ||= 3 %>
<label class="form-label"
aria-label="<%= label %>"
:for="<%= dom_id.html_safe %>">
<label class="form-label" aria-label="<%= label %>" :for="<%= dom_id.html_safe %>">
<%= label %>
</label>
<textarea :id="<%= dom_id.html_safe %>"
......
<%= block_component_preview :image %>
<%= block_component_preview :image_alt %>
<%= block_component_preview :image_credit %>
<%= block_component_preview :notes %>
<p class="small mb-0">
<%= block_component_preview :image_alt %>
<%= block_component_preview :image_credit %>
</p>
<%= block_component_preview :text %>
<%= block_component_preview :notes %>
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