<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>
<div class="modal fade" id="edit-service-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('service'); ?></h4>
            </div>
            <div class="modal-body">
                <form id="service_form" method="POST" onsubmit="return false">
                    <div class="row">
                        <?php echo Forms::AlertDiv('service_alert'); ?>
                        <div class="col-xs-12">
                            <input type="number" id="setting_current_value" name="setting_value" class="form-control" value="" min="0" max="100" 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 = "submitService"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('serviceDisabler'); ?>
        </div>
    </div>
</div>
<script>
    var setting_current_value;
    $(function(){
        $('#edit-service-modal').on('shown.bs.modal',function(){
//            $('#edit-service-modal').modal('show')
            $('#setting_current_value').val(setting_current_value ? setting_current_value : '<?php echo smc_session()['default_setting']['pos_service'];?>')
        });
        $("#submitService").on('click',function(){
            if (!$("#service_form").valid())
                return;
            $("#serviceDisabler").removeClass('hidden');
            var Data = new FormData(document.getElementById("service_form"));
            $.ajax({
                url: "RestaurantAjax/submitService",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            hideModalAlert('edit-service-modal', 'service_alert');
                            setting_current_value = $('#setting_current_value').val();
                        }
                        AddAlert("#service_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#serviceDisabler").addClass('hidden');
                }
            });
        });
    });
</script>