Separate actions for new StockArticle

This commit is contained in:
Julius Rapp 2013-07-07 14:14:32 +02:00
parent 69060a6da6
commit 4a208c83c0
6 changed files with 32 additions and 14 deletions

View file

@ -50,19 +50,25 @@ class DeliveriesController < ApplicationController
redirect_to supplier_deliveries_url(@supplier)
end
# three possibilites to fill a new_stock_article form
# (1) start from blank or use params
def new_stock_article
if params[:old_stock_article_id]
old_article = StockArticle.find_by_id(params[:old_stock_article_id])
elsif params[:old_article_id]
old_article = Article.find_by_id(params[:old_article_id])
old_article = old_article.becomes(StockArticle) unless old_article.nil?
@stock_article = @supplier.stock_articles.build(params[:stock_article])
render :layout => false
end
unless old_article.nil?
@stock_article = old_article.dup
else
@stock_article = @supplier.stock_articles.build(params[:stock_article])
# (2) StockArticle as template
def copy_stock_article
@stock_article = StockArticle.find(params[:old_stock_article_id]).dup
render :layout => false
end
# (3) non-stock Article as template
def derive_stock_article
@stock_article = Article.find(params[:old_article_id]).becomes(StockArticle).dup
render :layout => false
end

View file

@ -52,7 +52,7 @@
}
if('' != selectedArticle.id) {
$.ajax({
url: '#{new_stock_article_supplier_deliveries_path(@supplier)}',
url: '#{derive_stock_article_supplier_deliveries_path(@supplier)}',
type: 'get',
data: {old_article_id: selectedArticle.id},
contentType: 'application/json; charset=UTF-8'

View file

@ -6,6 +6,6 @@
%td
.btn-group
= link_to t('.action_edit'), edit_stock_article_supplier_deliveries_path(@supplier, :stock_article_id => article.id), remote: true, class: 'btn btn-mini'
= link_to t('.action_other_price'), new_stock_article_supplier_deliveries_path(@supplier, :old_stock_article_id => article.id), remote: true, class: 'btn btn-mini'
= link_to t('.action_other_price'), copy_stock_article_supplier_deliveries_path(@supplier, :old_stock_article_id => article.id), remote: true, class: 'btn btn-mini'
- deliver_button_disabled = ( @delivery and @delivery.includes_article? article ) ? ( 'disabled' ) : ( false )
= link_to t('.action_add_to_delivery'), add_stock_change_supplier_deliveries_path(@supplier, :stock_article_id => article.id), :method => :post, remote: true, class: 'button-add-stock-change btn btn-mini btn-primary', disabled: deliver_button_disabled

View file

@ -0,0 +1,5 @@
$('#modalContainer').html(
'<%= j(render(:partial => "stock_article_form", :locals => {:stock_article => @stock_article})) %>'
);
$('#modalContainer').modal();

View file

@ -0,0 +1,5 @@
$('#modalContainer').html(
'<%= j(render(:partial => "stock_article_form", :locals => {:stock_article => @stock_article})) %>'
);
$('#modalContainer').modal();

View file

@ -105,6 +105,8 @@ Foodsoft::Application.routes.draw do
post :add_stock_change, :on => :collection
get :new_stock_article, :on => :collection
get :copy_stock_article, :on => :collection
get :derive_stock_article, :on => :collection
post :create_stock_article, :on => :collection
get :edit_stock_article, :on => :collection