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

@ -49,20 +49,26 @@ class DeliveriesController < ApplicationController
flash[:notice] = I18n.t('deliveries.destroy.notice') flash[:notice] = I18n.t('deliveries.destroy.notice')
redirect_to supplier_deliveries_url(@supplier) redirect_to supplier_deliveries_url(@supplier)
end end
# three possibilites to fill a new_stock_article form
# (1) start from blank or use params
def new_stock_article def new_stock_article
if params[:old_stock_article_id] @stock_article = @supplier.stock_articles.build(params[:stock_article])
old_article = StockArticle.find_by_id(params[:old_stock_article_id])
elsif params[:old_article_id] render :layout => false
old_article = Article.find_by_id(params[:old_article_id]) end
old_article = old_article.becomes(StockArticle) unless old_article.nil?
end # (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
unless old_article.nil?
@stock_article = old_article.dup
else
@stock_article = @supplier.stock_articles.build(params[:stock_article])
end
render :layout => false render :layout => false
end end

View file

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

View file

@ -6,6 +6,6 @@
%td %td
.btn-group .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_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 ) - 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 = 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 post :add_stock_change, :on => :collection
get :new_stock_article, :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 post :create_stock_article, :on => :collection
get :edit_stock_article, :on => :collection get :edit_stock_article, :on => :collection