Files
opensem/resources/views/Shop/Admin/Articles/partials/prices.blade.php
2020-06-20 01:51:40 +02:00

116 lines
3.3 KiB
PHP

@include('Shop.Admin.Articles.partials.prices.block_price_new')
<div id="append_price" class="row">
@include('Shop.Admin.Articles.partials.prices.list-prices')
</div>
<button type="button" class="btn btn-sm btn-primary add-new-price">Ajouter un tarif <i class="fa fa-plus"></i></button>
@push('js')
<script>
function append_price() {
// handle_append_attribute();
$('.select2').select2();
handle_change_attribute();
load_attribute_values($('.attributes-value'), $('.attributes-family').val());
}
$("#append_price").appender({
rowSection: '.row-new-price',
type: '.row-price',
addBtn: '.add-new-price',
appendEffect: 'slide',
addClass: 'animated bounceInLeft',
rowNumber: '.row-price-number',
deleteBtn: '.delete-new-price-btn',
callback: append_price,
rowNumberStart: 2,
hideSection: true
});
function append_attribute() {
}
function handle_append_attribute(selector) {
console.log('handle_append_attribute');
$(".append_attribute").appender({
rowSection: '.row-new-attribute',
type: '.row-attribute',
addBtn: '.add-new-attribute',
appendEffect: 'slide',
addClass: 'animated bounceInLeft',
rowNumber: '.row-attribute-number',
deleteBtn: '.delete-new-attribute-btn',
callback: append_attribute,
rowNumberStart: 2,
hideSection: true
});
}
function handle_change_attribute() {
$('.attributes-family').change( function() {
var family_id = $(this).val();
var $family = $(this);
var $parent = $family.parent().parent();
var $selector = $parent.find('.attributes-value');
load_attribute_values($selector, family_id);
});
}
function init_attribute_values() {
$('.attributes-family').each( function() {
var family_id = $(this).val();
var $family = $(this);
var $parent = $family.parent().parent();
var $selector = $parent.find('.attributes-value');
load_attribute_values($selector, family_id);
value_id = $selector.data('id');
$selector.val(value_id).trigger('change');
});
}
function load_attribute_values($selector, family_id) {
$.ajax({
url : "{{ route('Shop.Admin.ArticleAttributeValues.getOptionsByFamily') }}",
method : 'POST',
data: { family_id: family_id },
success : function(data) {
$selector.empty().select2({data: data});
}
});
}
function handle_delete_price() {
$('.delete-price-btn').click(function() {
var $selector = $(this).parents('.row-price');
var id = $selector.find('.price_id').val();
confirm_delete(id, laroute.route('Shop.Admin.ArticlePrices.destroy', {id : id}), function() {
$selector.remove();
});
});
}
function handle_prices() {
$('.price-item').change(function() {
tax_selected = $(this).parent().prev().find('select option:selected').text();
price_taxed = $(this).val() * (1 + (tax_selected / 100));
$(this).parent().parent().find('.price-taxed-item').val(price_taxed);
})
}
function handle_prices_taxed() {
$('.price-taxed-item').change(function() {
tax_selected = $(this).parent().prev().find('select option:selected').text();
console.log($(this).parent().prev());
price = $(this).val() / (1 + (tax_selected / 100));
$(this).parent().parent().find('.price-item').val(price);
})
}
</script>
@endpush