fix articles_for_select2 helper

This commit is contained in:
wvengen 2013-12-18 17:34:45 +01:00
parent 2b511ee559
commit 1ab09b41bd
4 changed files with 14 additions and 17 deletions

View File

@ -10,12 +10,17 @@ module DeliveriesHelper
end
end
def articles_for_select2(supplier)
supplier.articles.undeleted.reorder('articles.name ASC').map {|a| {:id => a.id, :text => "#{a.name} (#{number_to_currency a.price}/#{a.unit})"} }
def articles_for_select2(articles, except = [], &block)
articles = articles.reorder('articles.name ASC')
articles.reject! {|a| not except.index(a.id).nil? } if except
block_given? or block = Proc.new {|a| "#{a.name} (#{number_to_currency a.price}/#{a.unit})" }
articles.map do |a|
{:id => a.id, :text => block.call(a)}
end
end
def stock_articles_for_table(supplier)
supplier.stock_articles.undeleted.reorder('articles.name ASC')
def articles_for_table(articles)
articles.undeleted.reorder('articles.name ASC')
end
def stock_change_remove_link(stock_change_form)

View File

@ -1,12 +1,3 @@
# :encoding:utf-8:
module Finance::ReceiveHelper
# TODO currently duplicate a bit of DeliveriesHelper.articles_for_select2
# except is an array of article id's to omit
def articles_for_select2(supplier, except = [])
articles = supplier.articles.reorder('articles.name ASC')
articles.reject! {|a| not except.index(a.id).nil? } if except
articles.map do |a|
{:id => a.id, :text => "#{a.name} (#{a.unit_quantity}#{a.unit})"}
end
end
end

View File

@ -20,7 +20,7 @@
$('#new_stock_article').removeAttr('disabled').select2({
placeholder: '#{t '.create_stock_article'}',
data: #{articles_for_select2(@supplier).to_json},
data: #{articles_for_select2(@supplier.articles).to_json},
createSearchChoice: function(term) {
return {
id: 'new',
@ -115,12 +115,12 @@
%tfoot
%tr
%th{:colspan => 5}
- if articles_for_select2(@supplier).empty?
- if @supplier.articles.empty?
= link_to t('.create_stock_article'), new_stock_article_path, :remote => true, :class => 'btn'
- else
%input#new_stock_article{:style => 'width: 500px;'}
%tbody
- for article in stock_articles_for_table(@supplier)
- for article in articles_for_table(@supplier.stock_articles)
= render :partial => 'stock_article_for_adding', :locals => {:article => article}
%h2= t '.title_fill_quantities'

View File

@ -1,7 +1,8 @@
- new_article_data = articles_for_select2(@order.articles, @order_articles.map(&:article_id)) {|a| "#{a.name} (#{a.unit_quantity}#{a.unit})" }
- content_for :javascript do
:javascript
var new_article_data = #{articles_for_select2(@order, @order_articles.map(&:article_id)).to_json};
var new_article_data = #{new_article_data.to_json};
function update_delta(input) {
var units = $(input).val();