2012-10-17 20:45:52 +02:00
|
|
|
- content_for :javascript do
|
2011-05-27 14:09:01 +02:00
|
|
|
:javascript
|
|
|
|
$(function() {
|
2014-01-25 15:19:50 +01:00
|
|
|
$('#stock_changes').on('touchclick', '.destroy_stock_change', function() {
|
2013-06-13 23:33:24 +02:00
|
|
|
$(this).prev('input').val('1'); // check for destruction
|
2016-08-12 15:54:28 +02:00
|
|
|
|
2013-06-13 23:33:24 +02:00
|
|
|
var stock_change = $(this).closest('tr');
|
|
|
|
stock_change.hide(); // do not remove (to ensure destruction)
|
2013-06-26 17:56:20 +02:00
|
|
|
stock_change.removeAttr('id'); // remove id to allow re-adding
|
|
|
|
mark_article_for_delivery( stock_change.data('id') );
|
2011-05-27 14:09:01 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2014-01-25 15:19:50 +01:00
|
|
|
$('#stock_changes').on('touchclick', '.remove_new_stock_change', function() {
|
2013-06-13 23:33:24 +02:00
|
|
|
var stock_change = $(this).closest('tr');
|
|
|
|
stock_change.remove();
|
2013-06-26 17:56:20 +02:00
|
|
|
mark_article_for_delivery( stock_change.data('id') );
|
2011-05-27 14:09:01 +02:00
|
|
|
return false;
|
|
|
|
})
|
2016-08-12 15:54:28 +02:00
|
|
|
|
2013-06-26 15:16:52 +02:00
|
|
|
$('#new_stock_article').removeAttr('disabled').select2({
|
2016-08-12 15:54:28 +02:00
|
|
|
tags: true,
|
2013-06-26 15:16:52 +02:00
|
|
|
placeholder: '#{t '.create_stock_article'}',
|
2013-12-18 17:34:45 +01:00
|
|
|
data: #{articles_for_select2(@supplier.articles).to_json},
|
2016-08-12 15:54:28 +02:00
|
|
|
createTag: function(data) {
|
2013-06-26 15:16:52 +02:00
|
|
|
return {
|
|
|
|
id: 'new',
|
2016-08-12 15:54:28 +02:00
|
|
|
name: data.term, // store for ajax request
|
|
|
|
text: data.term + ' (#{t '.create_from_blank'})'
|
2013-06-26 15:16:52 +02:00
|
|
|
};
|
|
|
|
}
|
2016-08-12 15:54:28 +02:00
|
|
|
}).on('select2:select', function(e) {
|
|
|
|
var selectedArticle = e.params.data;
|
|
|
|
if (!selectedArticle) {
|
2013-06-26 15:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if('new' == selectedArticle.id) {
|
2013-06-18 10:48:19 +02:00
|
|
|
$.ajax({
|
2013-12-07 16:42:25 +01:00
|
|
|
url: '#{new_stock_article_path}',
|
2013-06-18 10:48:19 +02:00
|
|
|
type: 'get',
|
2016-08-12 15:54:28 +02:00
|
|
|
data: {stock_article: {name: selectedArticle.name, supplier_id: #{@supplier.id}}},
|
2013-06-18 10:48:19 +02:00
|
|
|
contentType: 'application/json; charset=UTF-8'
|
|
|
|
});
|
2016-08-12 15:54:28 +02:00
|
|
|
$('#new_stock_article').val('').trigger('change');
|
2013-06-26 15:16:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if('' != selectedArticle.id) {
|
|
|
|
$.ajax({
|
2013-12-07 16:42:25 +01:00
|
|
|
url: '#{derive_stock_articles_path}',
|
2013-06-26 15:16:52 +02:00
|
|
|
type: 'get',
|
|
|
|
data: {old_article_id: selectedArticle.id},
|
|
|
|
contentType: 'application/json; charset=UTF-8'
|
|
|
|
});
|
2016-08-12 15:54:28 +02:00
|
|
|
$('#new_stock_article').val('').trigger('change');
|
2013-06-26 15:16:52 +02:00
|
|
|
return true;
|
2013-06-18 10:48:19 +02:00
|
|
|
}
|
|
|
|
});
|
2016-08-12 15:54:28 +02:00
|
|
|
|
2013-12-07 16:42:25 +01:00
|
|
|
// Subscribe to database changes.
|
|
|
|
// See publish/subscribe design pattern in /doc.
|
|
|
|
$(document).on('StockArticle#create', function(e) {
|
|
|
|
$.ajax({
|
|
|
|
url: '#{form_on_stock_article_create_supplier_deliveries_path(@supplier)}',
|
|
|
|
type: 'get',
|
|
|
|
data: {id: e.stock_article_id},
|
|
|
|
contentType: 'application/json; charset=UTF-8'
|
|
|
|
});
|
|
|
|
});
|
2016-08-12 15:54:28 +02:00
|
|
|
|
2013-12-07 16:42:25 +01:00
|
|
|
$(document).on('StockArticle#update', function(e) {
|
|
|
|
$.ajax({
|
|
|
|
url: '#{form_on_stock_article_update_supplier_deliveries_path(@supplier)}',
|
|
|
|
type: 'get',
|
|
|
|
data: {id: e.stock_article_id},
|
|
|
|
contentType: 'application/json; charset=UTF-8'
|
|
|
|
});
|
|
|
|
});
|
2011-05-27 14:09:01 +02:00
|
|
|
});
|
2016-08-12 15:54:28 +02:00
|
|
|
|
2013-06-26 17:56:20 +02:00
|
|
|
function mark_article_for_delivery(stock_article_id) {
|
2013-06-13 23:33:24 +02:00
|
|
|
var articleTr = $('#stock_article_' + stock_article_id);
|
2013-06-26 17:56:20 +02:00
|
|
|
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');
|
|
|
|
}
|
2013-06-13 23:33:24 +02:00
|
|
|
}
|
2013-06-26 17:56:20 +02:00
|
|
|
function is_article_available_for_delivery(stock_article_id) {
|
|
|
|
return ( 0 == $('#stock_change_stock_article_' + stock_article_id).length );
|
2013-06-13 23:33:24 +02:00
|
|
|
}
|
2011-05-27 14:09:01 +02:00
|
|
|
|
2013-06-26 15:16:52 +02:00
|
|
|
= simple_form_for [@supplier, @delivery], validate: true do |f|
|
2013-06-26 17:56:20 +02:00
|
|
|
= f.error_notification
|
|
|
|
= base_errors f.object
|
|
|
|
= f.association :supplier, :as => :hidden
|
2016-08-12 15:54:28 +02:00
|
|
|
|
2013-06-26 15:16:52 +02:00
|
|
|
%h2= t '.title_select_stock_articles'
|
2013-07-16 22:01:56 +02:00
|
|
|
%table#stock_articles_for_adding.table.table-hover.stupidtable
|
2013-06-26 15:16:52 +02:00
|
|
|
%thead
|
|
|
|
%tr
|
2013-12-12 00:13:19 +01:00
|
|
|
%th.default-sort{:data => {:sort => 'string'}}= Article.model_name.human
|
|
|
|
%th= heading_helper StockArticle, :price
|
|
|
|
%th= heading_helper StockArticle, :unit
|
|
|
|
%th= heading_helper StockArticle, :article_category
|
|
|
|
%th= t 'ui.actions'
|
2013-07-12 21:15:12 +02:00
|
|
|
%tfoot
|
|
|
|
%tr
|
|
|
|
%th{:colspan => 5}
|
2013-12-18 17:34:45 +01:00
|
|
|
- if @supplier.articles.empty?
|
2013-12-07 16:42:25 +01:00
|
|
|
= link_to t('.create_stock_article'), new_stock_article_path, :remote => true, :class => 'btn'
|
2013-07-14 22:00:38 +02:00
|
|
|
- else
|
2016-08-12 15:54:28 +02:00
|
|
|
%select#new_stock_article{:style => 'width: 500px;'}
|
2013-06-26 15:16:52 +02:00
|
|
|
%tbody
|
2013-12-18 17:34:45 +01:00
|
|
|
- for article in articles_for_table(@supplier.stock_articles)
|
2013-06-26 15:16:52 +02:00
|
|
|
= render :partial => 'stock_article_for_adding', :locals => {:article => article}
|
2016-08-12 15:54:28 +02:00
|
|
|
|
2013-06-26 15:16:52 +02:00
|
|
|
%h2= t '.title_fill_quantities'
|
2013-07-16 22:01:56 +02:00
|
|
|
%table.table#stock_changes.stupidtable
|
2013-06-26 15:16:52 +02:00
|
|
|
%thead
|
|
|
|
%tr
|
2013-12-14 13:34:58 +01:00
|
|
|
%th.default-sort{:data => {:sort => 'string'}}= Article.model_name.human
|
2013-12-12 00:13:19 +01:00
|
|
|
%th= heading_helper StockArticle, :price
|
|
|
|
%th= heading_helper StockArticle, :unit
|
2013-12-14 13:34:58 +01:00
|
|
|
%th= heading_helper GroupOrderArticle, :quantity # quantity to order, although technically this will be a StockChange
|
2013-12-12 00:13:19 +01:00
|
|
|
%th= t 'ui.actions'
|
2013-06-26 15:16:52 +02:00
|
|
|
%tbody
|
|
|
|
= f.simple_fields_for :stock_changes do |stock_change_form|
|
|
|
|
= render :partial => 'stock_change_fields', :locals => {:f => stock_change_form}
|
2016-08-12 15:54:28 +02:00
|
|
|
|
2013-06-26 15:16:52 +02:00
|
|
|
%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)
|