Linearize and clean up delivery form
This commit is contained in:
parent
bf32e72414
commit
dd70b84ef0
16 changed files with 170 additions and 155 deletions
|
|
@ -16,18 +16,48 @@
|
|||
unmark_article_unavailable_for_delivery( stock_change.data('id') );
|
||||
return false;
|
||||
})
|
||||
$('#copy_from_article').select2({
|
||||
placeholder: '#{t '.copy_order_article'}',
|
||||
allowClear: true
|
||||
|
||||
$('#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) {
|
||||
if(e.val != '') {
|
||||
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',
|
||||
data: {old_article_id: e.val},
|
||||
data: {stock_article: {name: selectedArticle.text}},
|
||||
contentType: 'application/json; charset=UTF-8'
|
||||
});
|
||||
$('#copy_from_article').select2('data', null);
|
||||
$('#new_stock_article').select2('data', null);
|
||||
return true;
|
||||
}
|
||||
if('' != selectedArticle.id) {
|
||||
$.ajax({
|
||||
url: '#{new_stock_article_supplier_deliveries_path(@supplier)}',
|
||||
type: 'get',
|
||||
data: {old_article_id: selectedArticle.id},
|
||||
contentType: 'application/json; charset=UTF-8'
|
||||
});
|
||||
$('#new_stock_article').select2('data', null);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -47,67 +77,45 @@
|
|||
return articleTr.hasClass('unavailable');
|
||||
}
|
||||
|
||||
-# remove validate true for the form, because it disabled html5 validation
|
||||
-# is there anything broken with the simple_form validation? (bootstrap issue?)
|
||||
= simple_form_for [@supplier, @delivery] do |f|
|
||||
= simple_form_for [@supplier, @delivery], validate: true do |f|
|
||||
= f.hidden_field :supplier_id
|
||||
.row-fluid
|
||||
|
||||
.span6
|
||||
%h2= t '.title_select_stock_articles'
|
||||
.well.well-small
|
||||
.btn-toolbar
|
||||
.btn-group
|
||||
= link_to t('.new_stock_article'), new_stock_article_supplier_deliveries_path(@supplier), remote: true, class: 'btn'
|
||||
= select_tag(:copy_from_article, options_for_select(articles_for_select(@supplier)))
|
||||
%table.table.table-condensed.table-hover#stock_articles_for_adding
|
||||
%thead
|
||||
%tr
|
||||
%th
|
||||
= t '.article'
|
||||
%span.sorter-bar.default-sort-asc{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-name'}}
|
||||
%th= t '.unit'
|
||||
%th= t '.price'
|
||||
%th= t '.vat'
|
||||
%th
|
||||
= t '.category'
|
||||
%span.sorter-bar{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-category'}}
|
||||
%th= t '.actions'
|
||||
%tbody
|
||||
- for article in stock_articles_for_table(@supplier)
|
||||
= render :partial => 'stock_article_for_adding', :locals => {:article => article}
|
||||
%h2= t '.title_select_stock_articles'
|
||||
.well.well-small
|
||||
.btn-toolbar
|
||||
.btn-group
|
||||
%input#new_stock_article{:style => 'width: 500px;'}
|
||||
%table.table.table-condensed.table-hover#stock_articles_for_adding
|
||||
%thead
|
||||
%tr
|
||||
%th
|
||||
= t '.article'
|
||||
%span.sorter-bar.default-sort-asc{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-name'}}
|
||||
%th= t '.price'
|
||||
%th
|
||||
= t '.category'
|
||||
%span.sorter-bar{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-category'}}
|
||||
%th= t '.actions'
|
||||
%tbody
|
||||
- for article in stock_articles_for_table(@supplier)
|
||||
= render :partial => 'stock_article_for_adding', :locals => {:article => article}
|
||||
|
||||
.span6
|
||||
%h2= t '.title_fill_quantities'
|
||||
<!-- = f.inspect -->
|
||||
%table.table.table-condensed#stock_changes
|
||||
%thead
|
||||
%tr
|
||||
%th
|
||||
= t '.article'
|
||||
%span.sorter-bar.default-sort-asc{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-name'}}
|
||||
%th= t '.price_per_unit'
|
||||
%th= t '.quantity'
|
||||
%th= t '.actions'
|
||||
%tbody
|
||||
-# see also the partial 'stock_change' which is used for AJAX updates!
|
||||
-# see also the partial 'stock_change' which is used for AJAX updates!
|
||||
-# see also the partial 'stock_change' which is used for AJAX updates!
|
||||
= f.simple_fields_for :stock_changes do |stock_change_form|
|
||||
- stock_change = stock_change_form.object
|
||||
%tr{:id => "stock_change_stock_article_#{stock_change.stock_article.id}", :data => {:id => stock_change.stock_article.id}}
|
||||
%td.sort-by-name
|
||||
= stock_change_form.association :stock_article, :as => :hidden
|
||||
%span.stock_article_name= stock_change.stock_article.name
|
||||
%td.numeric.price-per-unit #{number_to_currency stock_change.stock_article.price}/#{stock_change.stock_article.unit}
|
||||
%td= stock_change_form.input :quantity, :wrapper => :intable, :input_html => {:class => 'stock-change-quantity', :autocomplete => :off}
|
||||
%td
|
||||
= stock_change_form.hidden_field :_destroy
|
||||
= link_to t('.remove_article'), "#", :class => 'destroy_stock_change btn btn-small'
|
||||
|
||||
%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)
|
||||
%h2= t '.title_fill_quantities'
|
||||
%table.table.table-condensed#stock_changes
|
||||
%thead
|
||||
%tr
|
||||
%th
|
||||
= t '.article'
|
||||
%span.sorter-bar.default-sort-asc{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-name'}}
|
||||
%th= t '.price'
|
||||
%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)
|
||||
|
|
|
|||
|
|
@ -1,16 +1,11 @@
|
|||
- css_class = ( @delivery and @delivery.includes_article? article ) ? ( 'unavailable' ) : ( false )
|
||||
%tr{:id => "stock_article_#{article.id}", :class => css_class}
|
||||
%td.sort-by-name
|
||||
= article.name
|
||||
%td.numeric= article.unit
|
||||
%td.numeric= number_to_currency article.price
|
||||
%td.numeric= number_to_percentage article.tax
|
||||
%td.sort-by-name= article.name
|
||||
%td #{number_to_currency article.price}/#{article.unit}
|
||||
%td.sort-by-category= article.article_category.name
|
||||
%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'
|
||||
- if @delivery and @delivery.includes_article? article
|
||||
= 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', disabled: 'disabled'
|
||||
- else
|
||||
= 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'
|
||||
- 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
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
- url = ( stock_article.new_record? ) ? ( add_stock_article_supplier_deliveries_path(@supplier) ) : ( update_stock_article_supplier_deliveries_path(@supplier) )
|
||||
= simple_form_for stock_article, url: url, remote: true do |f|
|
||||
= f.hidden_field :supplier_id
|
||||
- unless stock_article.new_record?
|
||||
= f.hidden_field :id
|
||||
- url = ( stock_article.new_record? ) ? ( create_stock_article_supplier_deliveries_path(@supplier) ) : ( update_stock_article_supplier_deliveries_path(@supplier) )
|
||||
= simple_form_for stock_article, url: url, remote: true, validate: true do |f|
|
||||
= f.association :supplier, :as => :hidden
|
||||
= f.hidden_field :id unless stock_article.new_record?
|
||||
.modal-header
|
||||
= link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'}
|
||||
%h3= t 'activerecord.models.stock_article'
|
||||
|
|
@ -21,4 +20,4 @@
|
|||
= f.association :article_category
|
||||
.modal-footer
|
||||
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
||||
= f.submit class: 'btn btn-primary'
|
||||
= f.submit :class => 'btn btn-primary', 'data-disable-with' => t('ui.please_wait')
|
||||
|
|
|
|||
|
|
@ -1,12 +1,6 @@
|
|||
-# see also the partial 'form' which is used for existing stock_changes when loading the edit!
|
||||
-# see also the partial 'form' which is used for existing stock_changes when loading the edit!
|
||||
-# see also the partial 'form' which is used for existing stock_changes when loading the edit!
|
||||
= simple_fields_for "delivery[new_stock_changes][]", stock_change, validate: true do |f|
|
||||
- f.object.quantity = '' if 0 == f.object.quantity
|
||||
%tr{:id => "stock_change_stock_article_#{stock_change.stock_article.id}", :data => {:id => stock_change.stock_article.id}}
|
||||
%td.sort-by-name
|
||||
= f.association :stock_article, :as => :hidden
|
||||
%span.stock_article_name= stock_change.stock_article.name
|
||||
%td.numeric.price-per-unit #{number_to_currency stock_change.stock_article.price}/#{stock_change.stock_article.unit}
|
||||
%td= f.input :quantity, :wrapper => :intable, :input_html => {:class => 'stock-change-quantity', :autocomplete => :off}
|
||||
%td= link_to t('.remove_article'), "#", :class => 'remove_new_stock_change btn btn-small'
|
||||
- if stock_change.stock_article.new_record?
|
||||
= simple_fields_for "delivery[new_stock_changes_new_stock_article][]", stock_change do |f|
|
||||
= render :partial => 'stock_change_fields', :locals => {:f => f}
|
||||
- else
|
||||
= simple_fields_for "delivery[new_stock_changes][]", stock_change do |f|
|
||||
= render :partial => 'stock_change_fields', :locals => {:f => f}
|
||||
|
|
|
|||
9
app/views/deliveries/_stock_change_fields.html.haml
Normal file
9
app/views/deliveries/_stock_change_fields.html.haml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
- stock_change = f.object
|
||||
- stock_article = stock_change.stock_article
|
||||
%tr{:id => "stock_change_stock_article_#{stock_article.id}", :data => {:id => stock_article.id}}
|
||||
%td.sort-by-name
|
||||
%span.stock_article_name= stock_change.stock_article.name
|
||||
= f.association :stock_article, :as => :hidden
|
||||
%td.price-per-unit #{number_to_currency stock_article.price}/#{stock_change.stock_article.unit}
|
||||
%td= f.input :quantity, :wrapper => :intable, :input_html => {:class => 'stock-change-quantity', :autocomplete => :off}
|
||||
%td= stock_change_remove_link f
|
||||
|
|
@ -1,20 +1,24 @@
|
|||
if(!is_article_unavailable_for_delivery(<%= @stock_change.stock_article.id %>)) {
|
||||
<%# would be easier to return in the opposite case, but how? %>
|
||||
(function(w) {
|
||||
if(is_article_unavailable_for_delivery(<%= @stock_change.stock_article.id %>)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mark_article_unavailable_for_delivery(<%= @stock_change.stock_article.id %>);
|
||||
|
||||
(function(w) {
|
||||
$('#stock_changes tr').removeClass('success');
|
||||
|
||||
var stock_change = $(
|
||||
'<%= j(render(:partial => 'stock_change', :locals => {:stock_change => @stock_change})) %>'
|
||||
).addClass('success');
|
||||
|
||||
$('#stock_changes').append(stock_change);
|
||||
updateSort('#stock_changes');
|
||||
|
||||
var quantity = w.prompt('<%= j(t('.how_many_units', :unit => @stock_change.stock_article.unit, :name => @stock_change.stock_article.name)) %>'); <%# how to properly escape here? %>
|
||||
$('input.stock-change-quantity', stock_change).val(quantity);
|
||||
})(window);
|
||||
|
||||
}
|
||||
var quantity = w.prompt('<%= j(t('.how_many_units', :unit => @stock_change.stock_article.unit, :name => @stock_change.stock_article.name)) %>'); <%# how to properly escape here? %>
|
||||
if(null === quantity) {
|
||||
unmark_article_unavailable_for_delivery(<%= @stock_change.stock_article.id %>); // think wisely before changing this: What about double clicks on "deliver" button?
|
||||
return false;
|
||||
}
|
||||
|
||||
$('#stock_changes tr').removeClass('success');
|
||||
|
||||
var stock_change = $(
|
||||
'<%= j(render(:partial => 'stock_change', :locals => {:stock_change => @stock_change})) %>'
|
||||
).addClass('success');
|
||||
|
||||
$('input.stock-change-quantity', stock_change).val(quantity);
|
||||
|
||||
$('#stock_changes').append(stock_change);
|
||||
updateSort('#stock_changes');
|
||||
})(window);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ $('div.container-fluid').prepend(
|
|||
);
|
||||
|
||||
(function() {
|
||||
// update entry in stock_article table
|
||||
|
||||
$('#stock_articles_for_adding tr').removeClass('success');
|
||||
|
||||
var old_entry = $('#stock_article_<%= @stock_article.id %>');
|
||||
|
|
@ -11,14 +13,15 @@ $('div.container-fluid').prepend(
|
|||
'<%= j(render(:partial => 'stock_article_for_adding', :locals => {:article => @stock_article, :delivery => @delivery})) %>'
|
||||
).addClass('success');
|
||||
|
||||
if(unavailable) {
|
||||
stock_article_for_adding.addClass('unavailable');
|
||||
$('.button-add-stock-change', stock_article_for_adding).attr('disabled', 'disabled');
|
||||
}
|
||||
|
||||
old_entry.replaceWith(stock_article_for_adding);
|
||||
updateSort('#stock_articles_for_adding');
|
||||
|
||||
if(unavailable) {
|
||||
mark_article_unavailable_for_delivery(<%= @stock_article.id %>);
|
||||
}
|
||||
|
||||
// update entry in stock_changes table
|
||||
|
||||
$('#stock_changes tr').removeClass('success');
|
||||
|
||||
var stock_change_entry = $('#stock_change_stock_article_<%= @stock_article.id %>');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue