foodsoft/app/views/deliveries/_form.html.haml

137 lines
4.9 KiB
Text
Raw Normal View History

2012-10-17 20:45:52 +02:00
- content_for :javascript do
:javascript
$(function() {
$('#stock_changes').on('click', '.destroy_stock_change', function() {
$(this).prev('input').val('1'); // check for destruction
var stock_change = $(this).closest('tr');
stock_change.hide(); // do not remove (to ensure destruction)
stock_change.removeAttr('id'); // remove id to allow re-adding
mark_article_for_delivery( stock_change.data('id') );
return false;
});
$('#stock_changes').on('click', '.remove_new_stock_change', function() {
var stock_change = $(this).closest('tr');
stock_change.remove();
mark_article_for_delivery( stock_change.data('id') );
return false;
})
2013-06-26 15:16:52 +02:00
$('#new_stock_article').removeAttr('disabled').select2({
placeholder: '#{t '.create_stock_article'}',
data: #{articles_for_select2(@supplier).to_json},
createSearchChoice: function(term) {
return {
id: 'new',
text: term
};
},
formatResult: function(result, container, query, escapeMarkup) {
if(result.id == 'new') {
return result.text + ' (#{t '.create_from_blank'})';
}
var markup=[];
Select2.util.markMatch(result.text, query.term, markup, escapeMarkup);
return markup.join("");
}
}).on('change', function(e) {
2013-06-26 15:16:52 +02:00
var selectedArticle = $(e.currentTarget).select2('data');
if(!selectedArticle) {
return false;
}
if('new' == selectedArticle.id) {
$.ajax({
url: '#{new_stock_article_supplier_deliveries_path(@supplier)}',
type: 'get',
2013-06-26 15:16:52 +02:00
data: {stock_article: {name: selectedArticle.text}},
contentType: 'application/json; charset=UTF-8'
});
2013-06-26 15:16:52 +02:00
$('#new_stock_article').select2('data', null);
return true;
}
if('' != selectedArticle.id) {
$.ajax({
2013-07-07 14:14:32 +02:00
url: '#{derive_stock_article_supplier_deliveries_path(@supplier)}',
2013-06-26 15:16:52 +02:00
type: 'get',
data: {old_article_id: selectedArticle.id},
contentType: 'application/json; charset=UTF-8'
});
$('#new_stock_article').select2('data', null);
return true;
}
});
2013-06-26 19:57:38 +02:00
enablePriceTooltips();
});
function mark_article_for_delivery(stock_article_id) {
var articleTr = $('#stock_article_' + stock_article_id);
if( is_article_available_for_delivery(stock_article_id) ) {
articleTr.removeClass('unavailable');
$('.button-add-stock-change', articleTr).removeAttr('disabled');
}
else {
articleTr.addClass('unavailable');
$('.button-add-stock-change', articleTr).attr('disabled', 'disabled');
}
}
function is_article_available_for_delivery(stock_article_id) {
return ( 0 == $('#stock_change_stock_article_' + stock_article_id).length );
}
2013-06-26 19:57:38 +02:00
function enablePriceTooltips(context) {
$('[data-toggle~="tooltip"]', context).tooltip({
animation: false,
html: true,
placement: 'left'
});
}
2013-06-26 15:16:52 +02:00
= simple_form_for [@supplier, @delivery], validate: true do |f|
= f.error_notification
= base_errors f.object
= f.association :supplier, :as => :hidden
2013-06-26 15:16:52 +02:00
%h2= t '.title_select_stock_articles'
%table.table.table-hover#stock_articles_for_adding
2013-06-26 15:16:52 +02:00
%thead
%tr
%th.dom-sort-triggerer.default-sort{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-name'}}
2013-06-26 15:16:52 +02:00
= t '.article'
%th= t '.price'
%th= t '.unit'
%th= t '.category'
2013-06-26 15:16:52 +02:00
%th= t '.actions'
%tfoot
%tr
%th{:colspan => 5}
- if articles_for_select2(@supplier).empty?
= link_to t('.create_stock_article'), new_stock_article_supplier_deliveries_path(@supplier), :remote => true, :class => 'btn'
- else
%input#new_stock_article{:style => 'width: 500px;'}
2013-06-26 15:16:52 +02:00
%tbody
- for article in stock_articles_for_table(@supplier)
= render :partial => 'stock_article_for_adding', :locals => {:article => article}
2013-06-26 15:16:52 +02:00
%h2= t '.title_fill_quantities'
%table.table#stock_changes
2013-06-26 15:16:52 +02:00
%thead
%tr
%th.dom-sort-triggerer.default-sort{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-name'}}
2013-06-26 15:16:52 +02:00
= t '.article'
%th= t '.price'
%th= t '.unit'
2013-06-26 15:16:52 +02:00
%th= t '.quantity'
%th= t '.actions'
%tbody
= f.simple_fields_for :stock_changes do |stock_change_form|
= render :partial => 'stock_change_fields', :locals => {:f => stock_change_form}
%h2= t '.title_finish_delivery'
= f.input :delivered_on, as: :date_picker
= f.input :note, input_html: {size: '35x4'}
.form-actions
= f.submit class: 'btn btn-primary'
= link_to t('ui.or_cancel'), supplier_deliveries_path(@supplier)