5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-07 10:15:44 +00:00
panel/app/views/posts/_form.haml

100 lines
4.1 KiB
Plaintext
Raw Normal View History

2018-02-02 22:20:31 +00:00
- unless @post.errors.empty?
.alert.alert-danger
%ul
- @post.errors.each do |_,error|
2018-02-02 22:20:31 +00:00
%li= error
2018-02-10 23:45:11 +00:00
-# TODO seleccionar la dirección por defecto según el idioma actual
- direction = @post.get_front_matter(:dir) || 'ltr'
2018-02-10 16:09:42 +00:00
-# string para configurar la clase con direccion de texto
2018-02-10 23:45:11 +00:00
- field_class = "form-control #{direction}"
-# TODO habilitar form_for
- if @post.new?
2018-02-23 19:20:51 +00:00
- url = site_posts_path(@site, lang: @lang)
- method = :post
- else
2018-02-23 19:20:51 +00:00
- url = site_post_path(@site, @post, lang: @lang)
- method = :patch
= form_tag url, method: method, class: 'form' do
2018-01-31 20:29:27 +00:00
.form-group
= submit_tag t('posts.save'), class: 'btn btn-success'
.form-group
= label_tag 'post_dir', t('posts.dir')
= select_tag 'post[dir]',
2018-02-11 18:23:20 +00:00
options_for_select([[t('posts.ltr'), 'ltr'], [t('posts.rtl'), 'rtl']], direction),
{ class: 'form-control' }
2018-02-25 01:10:37 +00:00
%small.text-muted.form-text= t('posts.dir_help')
2018-01-31 20:29:27 +00:00
.form-group
2018-02-25 01:10:37 +00:00
= label_tag 'post_title', t('posts.title')
= text_field 'post', 'title', value: @post.title, class: field_class
2018-02-10 23:45:11 +00:00
.form-group{class: direction}
2018-02-25 01:10:37 +00:00
= render 'layouts/help', help: [ t('help.markdown.intro'),
t('help.distraction_free_html'),
t('help.preview_html') ]
2018-01-31 20:29:27 +00:00
= text_area_tag 'post[content]', @post.content, autofocus: true,
class: 'post-content'
2018-01-31 20:29:27 +00:00
.form-group
= label_tag 'post_date', t('posts.date')
= date_field 'post', 'date', value: @post.date.try(:strftime, '%F'),
2018-01-31 20:29:27 +00:00
class: 'form-control'
%small.text-muted.form-text= t('posts.date_help')
.form-group
2018-02-25 01:10:37 +00:00
= render 'layouts/help', help: t('help.autocomplete_html')
2018-01-31 20:29:27 +00:00
= label_tag 'post_categories', t('posts.categories')
= select_tag 'post[categories][]',
options_for_select(@site.categories(lang: @lang), @post.categories),
{ class: 'form-control select2', multiple: 'multiple' }
2018-01-31 20:29:27 +00:00
.form-group
= label_tag 'post_tags', t('posts.tags')
= select_tag 'post[tags][]',
options_for_select(@site.tags(lang: @lang), @post.tags),
{ class: 'form-control select2', multiple: 'multiple' }
2018-02-02 22:20:31 +00:00
.form-group
= label_tag 'post_slug', t('posts.slug')
= text_field 'post', 'slug', value: @post.slug,
class: 'form-control'
%small.text-muted.form-text= t('posts.slug_help')
2018-02-08 14:05:05 +00:00
.form-group
= label_tag 'post_permalink', t('posts.permalink')
= text_field 'post', 'permalink', value: @post.get_front_matter(:permalink),
class: 'form-control'
%small.text-muted.form-text= t('posts.permalink_help')
.form-group
= label_tag 'post_layout', t('posts.layout')
= select_tag 'post[layout]',
2018-05-11 16:24:30 +00:00
options_for_select(@site.layouts, @post.get_front_matter(:layout)),
2018-02-08 14:05:05 +00:00
{ class: 'form-control select2' }
%small.text-muted.form-text= t('posts.layout_help')
- if @site.i18n?
- @site.translations.each do |lang|
- next if lang == @lang
.form-group
= label_tag 'post_lang', t("posts.lang.#{lang}")
= select_tag "post[lang][#{lang}]",
options_for_select(@site.posts_for(lang).map { |p| [p.title, p.id] },
@post.get_front_matter(:lang).try(:dig, lang)),
{ class: 'form-control select2' }
%small.text-muted.form-text= t('posts.lang_help')
2018-05-11 20:00:45 +00:00
- @post.template_fields.each do |template|
- next unless type = @post.template_form_type_for(template)
.form-group
= label_tag "post_#{template}", template.humanize
- name = "post[#{template}]"
- value = @post.new? ? @post.template_values_for(template) : @post.get_front_matter(template)
2018-05-11 20:00:45 +00:00
- case type
- when 'text'
= text_field 'post', template,
value: value,
class: 'form-control'
- when 'text_area'
= text_area_tag name, value, class: 'form-control'
- when 'check_box'
2018-05-14 21:44:38 +00:00
= hidden_field 'post', template, value: 'false'
= check_box_tag name, 'true', value == 'true', class: 'form-control'
2018-05-11 20:00:45 +00:00
- when 'select'
= select_tag name, options_for_select(@post.template_values_for(template), @post.get_front_matter(template)),
2018-05-14 19:27:29 +00:00
{ class: 'form-control select2',
multiple: @post.template_multiple_values?(template) }
2018-02-08 20:54:34 +00:00
.form-group
= submit_tag t('posts.save'), class: 'btn btn-success'