Files
6e273a2fb1 refactor: Replace var with let/const in JavaScript files (#4503)
* refactor: Replace var with let/const in JavaScript files

- Replace var with let for variables that are reassigned
- Replace var with const for variables that are never reassigned
- Modernize manage_tables.js and nominatim.autocomplete.js
- Skip third-party libraries (imgpreview.full.jquery.js, clipboard.min.js)

Closes #4491

* refactor: Replace var with let/const in inline JavaScript

- Fixed CodeRabbit review: changed enable_actions and load_success
  from const to let in manage_tables.js (they are reassigned in init)
- Replaced all var declarations in inline JavaScript in Views with
  let (for reassigned) or const (for never reassigned)
- Modernized 48 additional files with inline JavaScript

* refactor: Replace var with let/const in remaining JS files

- Modernized gulpfile.js: 3 var declarations replaced
- Modernized app/Views/errors/html/debug.js: all var declarations replaced
- Used const for never-reassigned, let for reassigned variables

* fix: Replace remaining var declarations in Views

- Changed var  to const in sales/register.php
- Changed var  to const in configs/receipt_config.php

These were missed in the initial pass.

* fix: Replace remaining var declarations in gulpfile.js

- Converted 12 remaining var declarations to const
- All variables are function-scoped and never reassigned
- Complete coverage for this file now

* fix: Address CodeRabbit review comments

- items/manage.php: Remove duplicate let declaration for start_date
  (partial/daterangepicker already declares it)
- header_js.php: Escape CSRF hash in JavaScript context
- tax_jurisdictions.php: Fix mismatched selector (remove_tax_jurisdictions
  -> remove_tax_jurisdiction)

* style(views): Replace var with let/const and fix comment casing

- Convert var to let in items/manage.php for JS modernization
- Capitalize \"Submit\" in validation comments across tax view files

Signed-off-by: Travis Garrison <travis@chiraqbookstore.com>

---------

Signed-off-by: Travis Garrison <travis@chiraqbookstore.com>
Co-authored-by: Ollama <ollama@steganos.dev>
Co-authored-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
Co-authored-by: Travis Garrison <travis@chiraqbookstore.com>
2026-08-06 12:15:45 +04:00

155 lines
5.9 KiB
PHP

<?php
/**
* @var array $dinner_tables
* @var array $config
*/
?>
<?= form_open('config/saveTables/', ['id' => 'table_config_form', 'class' => 'form-horizontal']) ?>
<div id="config_wrapper">
<fieldset id="config_info">
<div id="required_fields_message"><?= lang('Common.fields_required_message') ?></div>
<ul id="table_error_message_box" class="error_message_box"></ul>
<div class="form-group form-group-sm">
<?= form_label(lang('Config.dinner_table_enable'), 'dinner_table_enable', ['class' => 'control-label col-xs-2']) ?>
<div class="col-xs-1">
<?= form_checkbox([
'name' => 'dinner_table_enable',
'value' => 'dinner_table_enable',
'id' => 'dinner_table_enable',
'checked' => $config['dinner_table_enable'] == 1
]) ?>
</div>
</div>
<div id="dinner_tables">
<?= view('partial/dinner_tables', ['dinner_tables' => $dinner_tables]) ?>
</div>
<?= form_submit([
'name' => 'submit_table',
'id' => 'submit_table',
'value' => lang('Common.submit'),
'class' => 'btn btn-primary btn-sm pull-right'
]) ?>
</fieldset>
</div>
<?= form_close() ?>
<script type="text/javascript">
// Validation and submit handling
$(document).ready(function() {
const enable_disable_dinner_table_enable = (function() {
const 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);
let table_count = <?= sizeof($dinner_tables) ?>;
const hide_show_remove = function() {
if ($("input[name*='dinner_tables']:enabled").length > 1) {
$(".remove_dinner_tables").show();
} else {
$(".remove_dinner_tables").hide();
}
};
const add_dinner_table = function() {
let id = $(this).parent().find('input').attr('id');
id = id.replace(/.*?_(\d+)$/g, "$1");
const block = $(this).parent().clone(true);
const new_block = block.insertAfter($(this).parent());
const 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();
};
const remove_dinner_table = function() {
$(this).parent().remove();
hide_show_remove();
};
const 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();
const duplicate_found = false;
// Run validator once for all fields
$.validator.addMethod('dinner_table', function(value, element) {
let 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({
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>