Files
opensourcepos/app/Views/partial/visibility_js.php
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

99 lines
3.2 KiB
PHP

<?php // used in reports ?>
// Utility functions for safe localStorage access
function safeSetItem(key, value) {
try {
localStorage.setItem(key, value);
} catch (e) {
console.error(`Failed to set item in localStorage: ${e.message}`);
}
}
function safeGetItem(key) {
try {
return localStorage.getItem(key);
} catch (e) {
console.error(`Failed to get item from localStorage: ${e.message}`);
return null; // Default fallback
}
}
function safeRemoveItem(key) {
try {
localStorage.removeItem(key);
} catch (e) {
console.error(`Failed to remove item from localStorage: ${e.message}`);
}
}
// Load saved column visibility from localStorage
const savedVisibility = JSON.parse(safeGetItem('columnVisibility')) || { cost: false, profit: false };
let visibleColumns = savedVisibility;
// Function to save column visibility to localStorage
function saveColumnVisibility(visibility) {
safeSetItem('columnVisibility', JSON.stringify(visibility));
}
// Apply column visibility on table initialization
function applyColumnVisibility(columns) {
return columns.map(function (col) {
if (visibleColumns[col.field] !== undefined) {
col.visible = visibleColumns[col.field]; // Apply visibility from localStorage
}
return col;
});
}
// Event listener for column visibility toggle
$('#table').on('column-switch.bs.table', function (e, field, checked) {
visibleColumns[field] = checked; // Save the visibility of this column
saveColumnVisibility(visibleColumns); // Store it in localStorage
});
// Ensure that saved column visibility is applied immediately after table load
$('#table').bootstrapTable('refreshOptions', {
columns: $('#table').bootstrapTable('getOptions').columns // Force refresh to apply column visibility
});
// Initialize visibility settings from localStorage
let summaryVisibility = JSON.parse(safeGetItem('summaryVisibility')) || { cost: false, profit: false };
// Function to apply visibility for cost and profit rows
function applySummaryVisibility() {
const rows = $('#report_summary .summary_row');
const costRow = rows.eq(rows.length - 2); // Second-to-last row
const profitRow = rows.eq(rows.length - 1); // Last row
if (summaryVisibility.cost === false) {
costRow.hide(); // Hide the cost row
} else {
costRow.show(); // Show the cost row
}
if (summaryVisibility.profit === false) {
profitRow.hide(); // Hide the profit row
} else {
profitRow.show(); // Show the profit row
}
}
// Toggle visibility when the button is clicked
$('#toggleCostProfitButton').click(function () {
summaryVisibility.cost = !summaryVisibility.cost;
summaryVisibility.profit = !summaryVisibility.profit;
safeSetItem('summaryVisibility', JSON.stringify(summaryVisibility));
applySummaryVisibility();
});
// Apply saved visibility state on page load
applySummaryVisibility();
// Initialize dialog (if editable)
const init_dialog = function () {
<?php if (isset($editable)): ?>
table_support.submit_handler('<?php echo site_url("reports/get_detailed_{$editable}_row") ?>');
dialog_support.init("a.modal-dlg");
<?php endif; ?>
};