diff --git a/app/assets/javascripts/validation.js b/app/assets/javascripts/validation.js index 41a7f91..b815e26 100644 --- a/app/assets/javascripts/validation.js +++ b/app/assets/javascripts/validation.js @@ -24,4 +24,8 @@ $(document).on('turbolinks:load', function() { form.addClass('was-validated'); }); + + $('.submit-post-incomplete').click(function(e) { + $('.sending_help').removeClass('d-none'); + }); }); diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 59b3a3c..865e8c0 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index b099444..5fd8ba8 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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? diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index b78757b..75fa9e9 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -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') diff --git a/config/locales/en.yml b/config/locales/en.yml index 875f59e..cf2b21b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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' diff --git a/config/locales/es.yml b/config/locales/es.yml index 7a70f03..3593f7e 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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'