guardar para después

This commit is contained in:
f 2018-12-14 12:12:17 -03:00
parent 346761d164
commit 914ea7f65c
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
6 changed files with 20 additions and 1 deletions

View file

@ -24,4 +24,8 @@ $(document).on('turbolinks:load', function() {
form.addClass('was-validated');
});
$('.submit-post-incomplete').click(function(e) {
$('.sending_help').removeClass('d-none');
});
});

View file

@ -45,6 +45,10 @@ class PostsController < ApplicationController
@post = Post.new(site: @site, lang: @lang, template: @template)
@post.update_attributes(repair_nested_params(post_params))
# El post se guarda como incompleto si se envió con "guardar para
# después"
@post.update_attributes({incomplete: params[:commit_incomplete].present?})
# Las usuarias pueden especificar una autora, de la contrario por
# defecto es la usuaria actual
if current_user.is_a? Usuaria
@ -59,6 +63,7 @@ class PostsController < ApplicationController
flash[:success] = @site.config.dig('thanks')
redirect_to site_posts_path(@site, lang: @lang)
else
@invalid = true
render 'posts/new'
end
end

View file

@ -266,6 +266,7 @@ class Post
add_error validate: I18n.t('posts.errors.slug_with_path') if slug.try(:include?, '/')
# XXX este es un principio de validación de plantillas, aunque no es
# recursivo
return if fetch_front_matter('incomplete', false)
template_fields.each do |tf|
errors = [get_front_matter(tf.key)].flatten.compact
if tf.image? && errors.map { |i| File.exist?(File.join(site.path, i)) }.none?

View file

@ -19,10 +19,16 @@
- method = :patch
- if pre = @post.template.get_front_matter('pre')
= render 'layouts/help', help: CommonMarker.render_doc(pre).to_html
= form_tag url, method: method, class: 'form', novalidate: true, multipart: true do
= form_tag url,
method: method,
class: "form #{@invalid ? 'was-validated' : ''}",
novalidate: true,
multipart: true do
= hidden_field_tag 'template', params[:template]
.form-group
= submit_tag t('posts.save'), class: 'btn btn-success submit-post'
= submit_tag t('posts.save_incomplete'), class: 'btn btn-info submit-post-incomplete', name: 'commit_incomplete'
.invalid_help.alert.alert-danger.d-none= @site.config.dig('invalid_help') || t('posts.invalid_help')
.sending_help.alert.alert-success.d-none= @site.config.dig('sending_help') || t('posts.sending_help')
- if current_user.is_a? Usuaria
@ -127,6 +133,7 @@
.invalid-feedback= t('posts.invalid')
.form-group
= submit_tag t('posts.save'), class: 'btn btn-success submit-post'
= submit_tag t('posts.save_incomplete'), class: 'btn btn-info submit-post-incomplete', name: 'commit_incomplete'
.invalid_help.alert.alert-danger.d-none= @site.config.dig('invalid_help') || t('posts.invalid_help')
.sending_help.alert.alert-success.d-none= @site.config.dig('sending_help') || t('posts.sending_help')
- if post = @post.template.get_front_matter('post')

View file

@ -173,6 +173,7 @@ en:
index: 'Posts'
edit: 'Edit'
save: 'Save'
save_incomplete: 'Save for later'
author: 'Author'
author_help: 'You can change the authorship of the post. If your site accepts guests, changing the authorship to an e-mail address will allow them to edit the post.'
date: 'Publication date'

View file

@ -178,6 +178,7 @@ es:
index: 'Artículos'
edit: 'Editar'
save: 'Guardar'
save_incomplete: 'Guardar para después'
author: 'Autorx'
author_help: 'Puedes cambiar la autoría del artículo aquí. Si el sitio acepta invitadxs, poner la dirección de correo de alguien aquí le permite editarlo.'
date: 'Fecha de publicación'