From 71bdf3bfcc882e28d5c5a5fd9f94d218e88511f3 Mon Sep 17 00:00:00 2001 From: JuliusR Date: Mon, 14 Oct 2019 09:25:34 +0200 Subject: [PATCH] Allow to copy articles (PR #673, #541) --- app/controllers/articles_controller.rb | 5 +++++ app/views/articles/_article.html.haml | 12 ++++++++---- app/views/articles/_articles.html.haml | 6 +++--- app/views/articles/copy.js.haml | 2 ++ config/routes.rb | 1 + 5 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 app/views/articles/copy.js.haml diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index a4a4f733..fa681197 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -36,6 +36,11 @@ class ArticlesController < ApplicationController render :layout => false end + def copy + @article = @supplier.articles.find(params[:article_id]).dup + render :layout => false + end + def create @article = Article.new(params[:article]) if @article.valid? && @article.save diff --git a/app/views/articles/_article.html.haml b/app/views/articles/_article.html.haml index 2c5bc41e..33d753d7 100644 --- a/app/views/articles/_article.html.haml +++ b/app/views/articles/_article.html.haml @@ -11,7 +11,11 @@ = number_to_currency(article.price) %td= number_to_percentage(article.tax) if article.tax != 0 %td= number_to_currency(article.deposit) if article.deposit != 0 - %td= link_to t('ui.edit'), edit_supplier_article_path(@supplier, article), - :remote => true, class: 'btn btn-mini' - %td= link_to t('ui.delete'), [@supplier, article], - :method => :delete, :data => {:confirm => t('ui.confirm_delete', name: article.name)}, :remote => true, class: 'btn btn-mini btn-danger' + %td + = link_to t('ui.edit'), edit_supplier_article_path(@supplier, article), + remote: true, class: 'btn btn-mini' + = link_to t('ui.copy'), supplier_article_copy_path(@supplier, article), + remote: true, class: 'btn btn-mini' + = link_to t('ui.delete'), [@supplier, article], + method: :delete, data: {confirm: t('ui.confirm_delete', name: article.name)}, + remote: true, class: 'btn btn-mini btn-danger' diff --git a/app/views/articles/_articles.html.haml b/app/views/articles/_articles.html.haml index ae667863..51948a33 100644 --- a/app/views/articles/_articles.html.haml +++ b/app/views/articles/_articles.html.haml @@ -15,10 +15,10 @@ %th{:style => "width: 5em;"}= heading_helper Article, :price %th{:style => "width: 3.5em;"}= heading_helper Article, :tax %th{:style => "width: 4em;"}= heading_helper Article, :deposit - %th{:style => "width: 3em;"} - + %th + %tbody#listbody - + - unless @articles.empty? - for article in @articles = render(article) diff --git a/app/views/articles/copy.js.haml b/app/views/articles/copy.js.haml new file mode 100644 index 00000000..504f5527 --- /dev/null +++ b/app/views/articles/copy.js.haml @@ -0,0 +1,2 @@ +$('#modalContainer').html('#{j(render("form"))}'); +$('#modalContainer').modal(); diff --git a/config/routes.rb b/config/routes.rb index b718b636..87338884 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -125,6 +125,7 @@ Foodsoft::Application.routes.draw do end resources :articles do + get :copy collection do post :update_selected get :edit_all