From 6350a330438de3186f0d576f304f4f93cd4ef925 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 20 Jun 2018 13:54:41 -0300 Subject: [PATCH] convertir en un fieldset con columnas --- app/views/posts/template_field/_nested.haml | 6 +++ app/views/posts/template_field/_table.haml | 55 +++++++++++---------- config/locales/en.yml | 4 ++ config/locales/es.yml | 4 ++ 4 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 app/views/posts/template_field/_nested.haml diff --git a/app/views/posts/template_field/_nested.haml b/app/views/posts/template_field/_nested.haml new file mode 100644 index 00000000..532e479d --- /dev/null +++ b/app/views/posts/template_field/_nested.haml @@ -0,0 +1,6 @@ +.form-group + = label_tag name.join('_'), template.help, id: name.join('_') + = render "posts/template_field/#{template.type}", + template: template, + name: name, + value: value diff --git a/app/views/posts/template_field/_table.haml b/app/views/posts/template_field/_table.haml index 2101d54b..3ae34387 100644 --- a/app/views/posts/template_field/_table.haml +++ b/app/views/posts/template_field/_table.haml @@ -1,25 +1,30 @@ -- template = local_assigns[:template] -%table.table.table-condensed.table-striped - %thead - %tr - - template.nested_fields.each do |nf| - %td= nf.help || nf.human - %td - - if template.array? - %button.btn.btn-success= t('posts.row.add') - %tbody - %tr - - template.nested_fields.each do |nf| - - value = @post.new? ? nf.values : @post.get_front_matter(template)[nf] - -# Si el template es un array, quiere decir que esperamos un array de hashes. - -# El 0 luego es reemplazado por un id temporal - - if template.array? - - name = [template.key, '', nf.key] - - else - - name = [template.key, nf.key] - %td= render "posts/template_field/#{nf.type}", - template: nf, - name: name, - value: value - - if template.array? - %td= fa_icon 'close', title: t('posts.row.del') +.field-items{class: template.key} + %small.text-muted= t('posts.table') + - if template.array? + .clearfix + %button.btn.btn-success= t('posts.row.add') + .field-item{class: template.key} + - if template.array? + .clearfix + %small.pull-right + = fa_icon 'close', title: t('posts.row.del') + = t('posts.row.del') + -# Separar los campos en dos columnas + - template.nested_fields.each_slice(2).to_a.each do |group| + .form-row + - group.each do |nf| + .col + -# Si el template es un array, quiere decir que esperamos un array de hashes. + -# El valor vacío luego es reemplazado por un id temporal + - if template.array? + - name = [template.key, '', nf.key] + - else + - name = [template.key, nf.key] + - if @post.new? + - value = nf.values + - else + - value = @post.get_front_matter(template)[nf] + = render 'posts/template_field/nested', + template: nf, + value: value, + name: name diff --git a/config/locales/en.yml b/config/locales/en.yml index 69bc2893..17ca46c6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -207,3 +207,7 @@ en: private: '🔒 The values of this field will remain private' select: placeholder: 'Type to filter available options' + table: 'This field is a group of fields, you can add more groups with the "Add group" button or remove them with the "Remove group" button.' + row: + add: 'Add group' + del: 'Remove group' diff --git a/config/locales/es.yml b/config/locales/es.yml index d8479053..d84cb8f9 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -203,3 +203,7 @@ es: private: '🔒 Los valores de este campo serán privados' select: placeholder: 'Empieza a escribir para filtrar las opciones disponibles' + table: 'Este campo es un grupo de campos, puede agregar los que necesites con el botón "Agregar grupo" o eliminar los que no con "Eliminar grupo"' + row: + add: 'Agregar grupo' + del: 'Eliminar grupo'