
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        <?php echo app('translator')->getFromJson('front.Add'); ?>
        <small>
            <?php if($is_raw): ?>
                مادة خام
            <?php else: ?>
            <?php echo app('translator')->getFromJson('front.product'); ?>
            <?php endif; ?>
        </small>
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
    </h1>
</section>
<!-- Main content -->
<form id="productForm" enctype="multipart/form-data"  action="<?php echo e(route('products.store')); ?>" method="post">
    <?php echo e(csrf_field()); ?>

    <input value="<?php echo e(request()->req); ?>" name="reqType" type="hidden">
    <?php echo $__env->make('products._form', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
</form>

<?php if(request()->req=='ajax'): ?>
    <script>
        $(function () {

            $(document).on('change','.productUnitSelector',function(){
                var selectedunit = '';
                $(".productUnitSelector").each(function(){
                    option = $(this).find('option:selected');
                    if(option.val()){
                        selectedunit += '<option value="'+option.val()+'">'+option.text()+'</option>';
                    }
                });
                $(".storeUnites").each(function(){
                    $(this).html(selectedunit);
                });

            });
            $("#productForm").submit(function(e) {
                e.preventDefault();
                var form = $(this);
                var url = form.attr('action');
                e.preventDefault();
                $.ajax({
                    type: "POST",
                    url: url,
                    data: form.serialize(),
                    success: function(name)
                    {
                        $typeaheadSearch.typeahead('val',name);
                        setTimeout(function(){
                            if($('.tt-selectable').length==1)
                            {
                                $('.tt-selectable').first().click();
                            }
                        },1000);
                       $('#addPersonModal').modal('toggle');
                    }
                });
            });
        });
    </script>
<?php endif; ?>
