agregar otros tipos de campo #51
This commit is contained in:
parent
dedd6b4e4c
commit
cdff6f523c
7 changed files with 67 additions and 1 deletions
|
@ -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?
|
||||
|
|
4
app/views/posts/template_field/_date.haml
Normal file
4
app/views/posts/template_field/_date.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
= date_field_tag field_name_for_post_as_string(name),
|
||||
value,
|
||||
class: 'form-control',
|
||||
required: template.required?
|
4
app/views/posts/template_field/_email.haml
Normal file
4
app/views/posts/template_field/_email.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
= email_field_tag field_name_for_post_as_string(name),
|
||||
value,
|
||||
class: 'form-control',
|
||||
required: template.required?
|
6
app/views/posts/template_field/_number.haml
Normal file
6
app/views/posts/template_field/_number.haml
Normal 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
|
4
app/views/posts/template_field/_password.haml
Normal file
4
app/views/posts/template_field/_password.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
= password_field_tag field_name_for_post_as_string(name),
|
||||
value,
|
||||
class: 'form-control',
|
||||
required: template.required?
|
4
app/views/posts/template_field/_url.haml
Normal file
4
app/views/posts/template_field/_url.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
= url_field_tag field_name_for_post_as_string(name),
|
||||
value,
|
||||
class: 'form-control',
|
||||
required: template.required?
|
4
app/views/posts/template_field/_year.haml
Normal file
4
app/views/posts/template_field/_year.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
= number_field_tag field_name_for_post_as_string(name),
|
||||
value,
|
||||
class: 'form-control',
|
||||
required: template.required?
|
Loading…
Reference in a new issue