2018-06-25 20:28:09 +00:00
|
|
|
-# Crea un contenedor para todos los campos agrupados
|
2018-06-22 23:28:01 +00:00
|
|
|
.field-groups{class: template.key}
|
2018-06-25 20:28:09 +00:00
|
|
|
-# Si es un array de valores, indicar a las usuarias que pueden
|
|
|
|
-# agregar más campos
|
2018-06-20 16:54:41 +00:00
|
|
|
- if template.array?
|
2018-06-21 17:34:49 +00:00
|
|
|
%small.text-muted= t('posts.table')
|
2018-06-25 20:28:09 +00:00
|
|
|
|
|
|
|
-# El grupo individual, tenemos que crear uno si el post es nuevo, o
|
|
|
|
-# todos los que sean necesarios si estamos editando un post.
|
2018-07-24 18:44:31 +00:00
|
|
|
-# Obtenemos todos los valores. Puede ser un Hash o un Array
|
|
|
|
-# Creamos un array con un elemento solo para poder tener acceso a :each
|
2018-07-24 19:28:58 +00:00
|
|
|
- groups = @post.get_front_matter(name)
|
2018-07-24 18:44:31 +00:00
|
|
|
-# TODO volver a revisar cuando get_front_matter() tenga valores por defecto
|
|
|
|
- groups = [{}] unless groups
|
2018-06-27 22:03:21 +00:00
|
|
|
- if groups.is_a? Hash
|
|
|
|
- groups = [ groups ]
|
2018-06-25 20:28:09 +00:00
|
|
|
- groups.each_with_index do |group, i|
|
|
|
|
-# A partir del segundo grupo todos son extra
|
|
|
|
- classes = (i > 0) ? [template.key, 'extra'] : [template.key]
|
|
|
|
.field-group{class: classes.join(' ')}
|
|
|
|
-# Crear el botón de borrado si vamos a tener varias filas.
|
|
|
|
-# Luego por CSS ocultamos el primero.
|
|
|
|
- if template.array?
|
|
|
|
.clearfix
|
2018-07-24 18:44:31 +00:00
|
|
|
%button.btn.btn-warning.btn-sm.pull-right.remove-group{data: { group: template.key }}
|
2018-07-23 20:15:01 +00:00
|
|
|
= fa_icon 'close', title: t('posts.row.del', group: template.key.humanize)
|
|
|
|
= t('posts.row.del', group: template.key.humanize)
|
2018-06-25 20:28:09 +00:00
|
|
|
-# Separar los campos en dos columnas
|
2018-07-24 21:13:02 +00:00
|
|
|
- cols = template.cols || 2
|
|
|
|
- template.nested_fields.each_slice(cols).to_a.each do |col|
|
2018-07-23 20:42:51 +00:00
|
|
|
.form-row{class: "align-items-#{template.align || 'start'}"}
|
2018-06-25 20:28:09 +00:00
|
|
|
- col.each do |nf|
|
2018-07-24 21:31:31 +00:00
|
|
|
- last = template.nested_fields.last == nf
|
|
|
|
- odd = (template.nested_fields.count % cols) != 0
|
2018-07-24 21:34:06 +00:00
|
|
|
%div{class: (nf.nested? || (last && odd)) ? 'col-md-12' : "col-md-#{12/cols}"}
|
2018-06-25 20:28:09 +00:00
|
|
|
-# Si el template es un array, quiere decir que esperamos un array de hashes.
|
2018-07-24 18:44:31 +00:00
|
|
|
-# XXX usamos local_name para hacerlo recursivo y sumar el
|
|
|
|
-# name después, sin modificarlo recursivamente.
|
2018-06-25 20:28:09 +00:00
|
|
|
- if template.array?
|
2018-07-24 18:44:31 +00:00
|
|
|
- local_name = [i.to_s, nf.key]
|
2018-06-25 20:28:09 +00:00
|
|
|
- else
|
2018-07-24 18:44:31 +00:00
|
|
|
- local_name = [nf.key]
|
2018-06-25 20:28:09 +00:00
|
|
|
- if @post.new?
|
|
|
|
- value = nf.values
|
|
|
|
- else
|
|
|
|
-# Si el campo es un array, groups es un array de hashes
|
|
|
|
-# y group un hash. De lo contrarios, groups va a ser un
|
|
|
|
-# Hash
|
2018-07-24 19:28:58 +00:00
|
|
|
-# TODO cambiar por get_front_matter
|
2018-06-27 22:03:21 +00:00
|
|
|
- value = (template.array? || template.nested?) ? group[nf.key] : groups[nf.key]
|
2018-06-25 20:28:09 +00:00
|
|
|
= render 'posts/template_field/nested',
|
|
|
|
template: nf,
|
|
|
|
value: value,
|
2018-07-24 18:44:31 +00:00
|
|
|
name: [name, local_name].flatten
|
2018-06-22 23:28:01 +00:00
|
|
|
.extra-groups
|
|
|
|
- if template.array?
|
|
|
|
.clearfix
|
2018-07-23 20:42:51 +00:00
|
|
|
%button.btn.btn-success.btn-block.add-group{data: { group: template.key }}= t('posts.row.add', group: template.key.humanize)
|