agregar otros tipos de campo #51

This commit is contained in:
f 2018-06-22 15:58:49 -03:00
parent dedd6b4e4c
commit cdff6f523c
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
7 changed files with 67 additions and 1 deletions

View file

@ -4,7 +4,7 @@ class Post
class TemplateField
attr_reader :post, :contents, :key
STRING_VALUES = %w[string text url number email].freeze
STRING_VALUES = %w[string text url number email password date year].freeze
def initialize(post, key, contents)
@post = post
@ -27,14 +27,29 @@ class Post
contents.fetch('min', 0)
end
# TODO volver elegante!
def type
return @type if @type
case
when email?
@type = 'email'
when url?
@type = 'url'
when number?
@type = 'number'
when password?
@type = 'password'
when date?
@type = 'date'
when year?
@type = 'year'
when text_area?
@type = 'text_area'
when string?
@type = 'text'
# TODO volver a hacer funcionar esto y ahorranos los multiple:
# false
when string? && contents.split('/', 2).count == 2
@type = 'select'
when nested?
@ -80,6 +95,31 @@ class Post
value == 'text'
end
def url?
value == 'url'
end
def email?
value == 'email' || value == 'mail'
end
alias :mail? :email?
def date?
value == 'date'
end
def password?
value == 'password'
end
def number?
value == 'number'
end
def year?
value == 'year'
end
# Si la plantilla es simple no está admitiendo Hashes como valores
def simple?
!complex?

View file

@ -0,0 +1,4 @@
= date_field_tag field_name_for_post_as_string(name),
value,
class: 'form-control',
required: template.required?

View file

@ -0,0 +1,4 @@
= email_field_tag field_name_for_post_as_string(name),
value,
class: 'form-control',
required: template.required?

View file

@ -0,0 +1,6 @@
= number_field_tag field_name_for_post_as_string(name),
value,
class: 'form-control',
required: template.required?,
max: template.max > 0 ? template.max : nil,
min: template.min

View file

@ -0,0 +1,4 @@
= password_field_tag field_name_for_post_as_string(name),
value,
class: 'form-control',
required: template.required?

View file

@ -0,0 +1,4 @@
= url_field_tag field_name_for_post_as_string(name),
value,
class: 'form-control',
required: template.required?

View file

@ -0,0 +1,4 @@
= number_field_tag field_name_for_post_as_string(name),
value,
class: 'form-control',
required: template.required?