Skip to content

Commit

Permalink
Allow to copy articles
Browse files Browse the repository at this point in the history
Implements #541.
  • Loading branch information
JuliusR committed Jun 13, 2019
1 parent 7136d01 commit e0155e3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def new
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
Expand Down
12 changes: 8 additions & 4 deletions app/views/articles/_article.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 3 additions & 3 deletions app/views/articles/_articles.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/views/articles/copy.js.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$('#modalContainer').html('#{j(render("form"))}');
$('#modalContainer').modal();
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
end

resources :articles do
get :copy
collection do
post :update_selected
get :edit_all
Expand Down

0 comments on commit e0155e3

Please sign in to comment.