Files
opensourcepos/app/Views/configs/table_config.php
BudsieBuds 15d0ef7c3d Bootstrap 5 WIP
- work in progress build of conversion from bootstrap 3 to 5
2026-04-02 19:53:26 +02:00

146 lines
5.5 KiB
PHP

<?php
/**
* @var array $dinner_tables
* @var array $config
*/
?>
<?= form_open('config/saveTables/', ['id' => 'table_config_form']) ?>
<?php
$title_info['config_title'] = lang('Config.table_configuration');
echo view('configs/config_header', $title_info);
?>
<ul id="table_error_message_box" class="error_message_box"></ul>
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" role="switch" id="dinner_table_enable" name="dinner_table_enable" value="dinner_table_enable" <?= $config['dinner_table_enable'] == 1 ? 'checked' : '' ?>>
<label class="form-check-label" for="dinner_table_enable"><?= lang('Config.dinner_table_enable'); ?></label>
</div>
<div class="row" id="dinner_tables">
<?= view('partial/dinner_tables', ['dinner_tables' => $dinner_tables]) ?>
</div>
<div class="d-flex justify-content-end">
<button class="btn btn-primary" type="submit" name="submit_table"><?= lang('Common.submit'); ?></button>
</div>
<?= form_close() ?>
<script type="text/javascript">
// Validation and submit handling
$(document).ready(function() {
var enable_disable_dinner_table_enable = (function() {
var dinner_table_enable = $("#dinner_table_enable").is(":checked");
$("input[name*='dinner_table']:not(input[name=dinner_table_enable])").prop("disabled", !dinner_table_enable);
if (dinner_table_enable) {
$(".add_dinner_table, .remove_dinner_table").show();
} else {
$(".add_dinner_table, .remove_dinner_table").hide();
}
return arguments.callee;
})();
$("#dinner_table_enable").change(enable_disable_dinner_table_enable);
var table_count = <?= sizeof($dinner_tables) ?>;
var hide_show_remove = function() {
if ($("input[name*='dinner_tables']:enabled").length > 1) {
$(".remove_dinner_tables").show();
} else {
$(".remove_dinner_tables").hide();
}
};
var add_dinner_table = function() {
var id = $(this).parent().find('input').attr('id');
id = id.replace(/.*?_(\d+)$/g, "$1");
var block = $(this).parent().clone(true);
var new_block = block.insertAfter($(this).parent());
var new_block_id = 'dinner_table_' + ++id;
$(new_block).find('label').html("<?= lang('Config.dinner_table') ?> " + ++table_count).attr('for', new_block_id).attr('class', 'control-label col-xs-2');
$(new_block).find('input').attr('id', new_block_id).removeAttr('disabled').attr('name', new_block_id).attr('class', 'form-control input-sm').val('');
hide_show_remove();
};
var remove_dinner_table = function() {
$(this).parent().remove();
hide_show_remove();
};
var init_add_remove_tables = function() {
$('.add_dinner_table').click(add_dinner_table);
$('.remove_dinner_table').click(remove_dinner_table);
hide_show_remove();
// Set back disabled state
enable_disable_dinner_table_enable();
};
init_add_remove_tables();
var duplicate_found = false;
// Run validator once for all fields
$.validator.addMethod('dinner_table', function(value, element) {
var value_count = 0;
$("input[name*='dinner_table']:not(input[name=dinner_table_enable])").each(function() {
value_count = $(this).val() == value ? value_count + 1 : value_count;
});
return value_count < 2;
}, "<?= lang('Config.dinner_table_duplicate') ?>");
$.validator.addMethod('valid_chars', function(value, element) {
return value.indexOf('_') === -1;
}, "<?= lang('Config.dinner_table_invalid_chars') ?>");
$('#table_config_form').validate($.extend(form_support.handler, {
submitHandler: function(form) {
$(form).ajaxSubmit({
beforeSerialize: function(arr, $form, options) {
$("input[name*='dinner_table']:not(input[name=dinner_table_enable])").prop("disabled", false);
return true;
},
success: function(response) {
$.notify({
icon: 'bi bi-bell-fill',
message: response.message
}, {
type: response.success ? 'success' : 'danger'
});
$("#dinner_tables").load('<?= "config/dinnerTables" ?>', init_add_remove_tables);
},
dataType: 'json'
});
},
errorLabelContainer: "#table_error_message_box",
rules: {
<?php
$i = 0;
foreach ($dinner_tables as $dinner_table => $table) {
?>
<?= 'dinner_table_' . ++$i ?>: {
required: true,
dinner_table: true,
valid_chars: true
},
<?php } ?>
},
messages: {
<?php
$i = 0;
foreach ($dinner_tables as $dinner_table => $table) {
?>
<?= 'dinner_table_' . ++$i ?>: "<?= lang('Config.dinner_table_required') ?>",
<?php } ?>
}
}));
});
</script>