<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>
<div class="modal fade" id="edit-product-rate-modal" data-backdrop="static" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title"><?php print CommonLanguage::getMessage('product_rate'); ?></h4>
            </div>
            <div class="modal-body">
                <form id="service_form2" method="POST" onsubmit="return false">
                    <div class="row">
                        <?php echo Forms::AlertDiv('rate_alert'); ?>
                        <div class="col-xs-12">
                            <input type="text" id="setting_current_value2" value="<?php echo smc_session()['default_setting']['product_rate']; ?>" name="setting_value2" class="form-control"   required />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button type="button" class="btn btn-primary" id = "submitRate"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('serviceDisabler'); ?>
        </div>
    </div>
</div>
<script>
    var setting_current_value2;
    var product_rate = <?php echo json_encode(smc_session()['default_setting']['product_rate']); ?>;
    $(function(){

        $('#edit-product-rate-modal').on('shown.bs.modal',function(){
            // $('#edit-product-rate-modal').modal('show')
            console.log('product_rate');
            console.log(product_rate);
            $('#setting_current_value2').val(product_rate);
         });
        $("#submitRate").on('click',function(){
            if (!$("#service_form2").valid())
                return;
                
            $("#serviceDisabler").removeClass('hidden');
            var Data = new FormData(document.getElementById("service_form2"));
            console.log(Data);
            $.ajax({
                url: "RestaurantAjax/submitProductRate",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            hideModalAlert('edit-product-rate-modal', 'rate_alert');
                            setting_current_value2 = $('#setting_current_value2').val();
                            product_rate = $('#setting_current_value2').val();
                            $('#setting_current_value2').val(setting_current_value2);
                        }
                        AddAlert("#rate_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#serviceDisabler").addClass('hidden');
                }
            });
        });
    });
</script>