From 914ea7f65cf2c3863fe11239ed9187334413cdc5 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 14 Dec 2018 12:12:17 -0300 Subject: [PATCH] =?UTF-8?q?guardar=20para=20despu=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/validation.js | 4 ++++ app/controllers/posts_controller.rb | 5 +++++ app/models/post.rb | 1 + app/views/posts/_form.haml | 9 ++++++++- config/locales/en.yml | 1 + config/locales/es.yml | 1 + 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/validation.js b/app/assets/javascripts/validation.js index 41a7f91f..b815e265 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 59b3a3c9..865e8c04 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 b099444d..5fd8ba80 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 b78757b4..75fa9e9c 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 875f59e8..cf2b21b1 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 7a70f03a..3593f7ec 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'