From 7be0fc33b1cb9f2980534fcef69e9be39422c70c Mon Sep 17 00:00:00 2001 From: f Date: Wed, 20 Jun 2018 12:25:52 -0300 Subject: [PATCH] si la tabla de datos es un array, tenemos que poder agregar filas --- app/views/posts/template_field/_check_box.haml | 3 +-- app/views/posts/template_field/_table.haml | 14 ++++++++++++-- app/views/posts/template_field/_text.haml | 5 ++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/views/posts/template_field/_check_box.haml b/app/views/posts/template_field/_check_box.haml index 8b9a07d7..be014953 100644 --- a/app/views/posts/template_field/_check_box.haml +++ b/app/views/posts/template_field/_check_box.haml @@ -1,5 +1,4 @@ -- root, field_name = field_name_for_post(name) -= hidden_field root, field_name, value: 'false' += hidden_field_tag field_name_for_post_as_string(name), value: 'false' = check_box_tag field_name_for_post_as_string(name), 'true', value == 'true', diff --git a/app/views/posts/template_field/_table.haml b/app/views/posts/template_field/_table.haml index 3f9ce3a4..2101d54b 100644 --- a/app/views/posts/template_field/_table.haml +++ b/app/views/posts/template_field/_table.haml @@ -4,12 +4,22 @@ %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: [template.key, nf.key], + name: name, value: value - %td= fa_icon 'close', title: 'Eliminar' + - if template.array? + %td= fa_icon 'close', title: t('posts.row.del') diff --git a/app/views/posts/template_field/_text.haml b/app/views/posts/template_field/_text.haml index 4395df88..5384f4cb 100644 --- a/app/views/posts/template_field/_text.haml +++ b/app/views/posts/template_field/_text.haml @@ -1,7 +1,6 @@ -# Si el campo está anidado, la raíz del atributo name tiene que -# contener los demás elementos del template superior -- root, field_name = field_name_for_post(name) -= text_field root, field_name, - value: local_assigns[:value], += text_field_tag field_name_for_post_as_string(name), + value, class: 'form-control', required: template.required?