Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
7.6 kB
1
Indexable
Never
<script>
    $(document).ready(function () {
        $('#customer_id').change(function () {
            var customerId = $(this).val();
            
            if (customerId) {
                $.ajax({
                    url: '{{ route('admin.packages.getCustomerCountry') }}',
                    type: 'GET',
                    data: { customer_id: customerId },
                    success: function (response) {
                        if (response.country) {
                            $('#country').val(response.country);
                        } else {
                            toastr.error('No country found for the selected customer.');
                        }
                    },
                    error: function () {
                        toastr.error('An error occurred while fetching the country.');
                    }
                });
            } else {
                $('#country').val('');
            }
        });
    });
</script>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const addNewRowButton = document.getElementById('addNewRow');
        const serviceFieldsContainer = document.getElementById('serviceFieldsContainer');
    
        addNewRowButton.addEventListener('click', function() {
            const newRow = document.createElement('div');
            newRow.classList.add('row', 'servicefieldsRow');
            newRow.innerHTML = `
                <div class="col-2">
                    <div class="form-group">
                        <input type="text" class="form-control" name="package_service_name[]" placeholder="Service Name">
                    </div>
                </div>
                
                <div class="col-2">
                    <div class="form-group">
                        <input type="text" class="form-control" name="express_shipping_price[]" placeholder="express_shipping">
                    </div>
                </div>
                <div class="col-2">
                    <div class="form-group">
                        <input type="text" class="form-control" name="handling_price[]" placeholder="handling_price">
                    </div>
                </div>

                <div class="col-2">
                    <div class="form-group">
                        <input type="text" class="form-control" name="insurance_price[]" placeholder="insurance_price">
                    </div>
                </div>

                <div class="col-2">
                    <div class="form-group">
                        <input type="text" class="form-control" name="delivery_time[]" placeholder="delivery_time">
                    </div>
                </div>
    
                <div class="col-2">
                    <div class="input-group">
                        <div class="custom-file">
                            <input type="file" class="custom-file-input" name="package_service_logo[]">
                            <label class="custom-file-label">Choose logo</label>
                        </div>
                    </div>
                </div>
    
                <div class="col-1 text-left">
                    <a href="javascript:void(0);" class="btn btn-danger btn-sm remove-row"><i class="fa fa-trash"></i></a>
                </div>
            `;
            serviceFieldsContainer.appendChild(newRow);
        });
    
        serviceFieldsContainer.addEventListener('click', function(event) {
            if (event.target.closest('.remove-row')) {
                event.target.closest('.servicefieldsRow').remove();
            }
        });
    });
</script>    

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const addNewRowButton = document.getElementById('addNewRowItem');
        const serviceFieldsContainer = document.getElementById('packageItemFieldsContainer');
    
        addNewRowButton.addEventListener('click', function() {
            const newRow = document.createElement('div');
            newRow.classList.add('row', 'packageItemFieldsRow');
            newRow.innerHTML = `
                <div class="col-3">
                    <div class="form-group">
                        <input type="text" class="form-control" name="item_name[]" placeholder="item_name">
                    </div>
                </div>
                
                <div class="col-2">
                    <div class="form-group">
                        <input type="text" class="form-control" name="item_quantity[]" placeholder="item_quantity">
                    </div>
                </div>
                <div class="col-2">
                    <div class="form-group">
                        <input type="text" class="form-control" name="item_price[]" placeholder="item_price">
                    </div>
                </div>
                <div class="col-2">
                    <div class="form-group">
                        <input type="text" class="form-control" name="package_value[]" placeholder="package_value">
                    </div>
                </div>
    
                <div class="col-1 text-right">
                    <a href="javascript:void(0);" class="btn btn-danger btn-sm remove-row"><i class="fa fa-trash"></i></a>
                </div>
            `;
            serviceFieldsContainer.appendChild(newRow);
        });
    
        serviceFieldsContainer.addEventListener('click', function(event) {
            if (event.target.closest('.remove-row')) {
                event.target.closest('.packageItemFieldsRow').remove();
            }
        });
    });
</script>

<script>
    Dropzone.autoDiscover = false;

    var myDropzone = new Dropzone("#dropzone", {
        url: "{{ route('admin.packages.store') }}",
        autoProcessQueue: false,
        paramName: "photo_path[]",
        uploadMultiple: true,
        parallelUploads: 10,
        addRemoveLinks: true,
        maxFilesize: 100, 
        acceptedFiles: ".jpeg,.jpg,.png,.gif",
        init: function() {
            var myDropzone = this;

            $('#submit-all').on('click', function(e) {
                e.preventDefault();

                if (myDropzone.getQueuedFiles().length > 0) {
                    myDropzone.processQueue();
                } else {
                    savePackage();
                }
            });

            myDropzone.on("sending", function(file, xhr, formData) {
                $('#mainForm').serializeArray().forEach(function(field) {
                    formData.append(field.name, field.value);
                });
            });

            myDropzone.on("queuecomplete", function() {
                savePackage();
            });
        }
    });

    function savePackage() {
        $.ajax({
            url: "{{ route('admin.packages.store') }}",
            method: "POST",
            data: new FormData($('#mainForm')[0]),
            contentType: false,
            processData: false,
            success: function(response) {
                toastr.success('Package created successfully!');
                
            },
            error: function(xhr) {
                let errors = xhr.responseJSON.errors;
                $.each(errors, function(key, value) {
                    toastr.error(value);
                });
            }
        });
    }
</script>
Leave a Comment