This commit is contained in:
2024-05-15 08:42:10 +07:00
parent 4e9930841c
commit 6ee294d14b
2 changed files with 70 additions and 68 deletions

View File

@@ -1,17 +1,16 @@
"use strict"; "use strict";
const AdminFunction = (() => { const AdminFunctions = (() => {
function capNhatTrangThaiMenu(hideMenuBig) { function toggleMenuVisibility(hideLargeMenu) {
if (hideMenuBig === false) { const contentContainer = $('#js-admin-content-container');
$('#js-admin-content-container').addClass('show-large-menu'); const largeMenu = $('#js-menu-big');
} const smallMenu = $('#js-menu-small');
else { const searchForm = $('#js-form-search');
$('#js-admin-content-container').removeClass('show-large-menu'); contentContainer.toggleClass('show-large-menu', !hideLargeMenu);
} largeMenu.toggleClass('hidden', hideLargeMenu);
$('#js-menu-big').toggleClass('hidden', hideMenuBig); smallMenu.toggleClass('hidden', !hideLargeMenu);
$('#js-menu-small').toggleClass('hidden', !hideMenuBig); searchForm.toggleClass('menu-hide', hideLargeMenu);
$('#js-form-search').toggleClass('menu-hide', hideMenuBig); localStorage.setItem(hideLargeMenu ? 'menu_big' : 'menu_small', 'hidden');
localStorage.setItem(hideMenuBig ? 'menu_big' : 'menu_small', 'hidden'); localStorage.removeItem(hideLargeMenu ? 'menu_small' : 'menu_big');
localStorage.removeItem(hideMenuBig ? 'menu_small' : 'menu_big');
} }
function debounce(func, wait, immediate) { function debounce(func, wait, immediate) {
let timeout = null; let timeout = null;
@@ -31,35 +30,36 @@ const AdminFunction = (() => {
func.apply(context, args); func.apply(context, args);
}; };
} }
function add_product_to_category(id) { function addProductToCategory(productId) {
$('#status_' + id).html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Đang xử lý..</span>'); const statusElement = $('#status_' + productId);
statusElement.html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Processing...</span>');
setTimeout(() => { setTimeout(() => {
$('#status_' + id).html(''); statusElement.html('');
}, 1000); }, 1000);
} }
function run_search(holder) { function searchSuggestions(inputSelector) {
$(holder).keyup(debounce(function () { $(inputSelector).keyup(debounce(function () {
//const inputString = $(this).val();
$('#js-show-search').show(); $('#js-show-search').show();
}, 300, false)); // Cast debounce to any to avoid type inference issues }, 300, false));
$('body').click(function () { $('body').click(function () {
$("#js-show-search").hide(); $('#js-show-search').hide();
}); });
} }
function update_product_hot(id) { function markProductAsHot(productId) {
$('#js-status-hottype-' + id).html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Đang xử lý..</span>'); const statusElement = $('#js-status-hottype-' + productId);
statusElement.html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Processing...</span>');
setTimeout(() => { setTimeout(() => {
$('#js-status-hottype-' + id).html(''); statusElement.html('');
}, 1000); }, 1000);
} }
function searchSelect(holder) { function initializeSearchDropdown(selector) {
$(holder).select2(); $(selector).select2();
} }
return { return {
capNhatTrangThaiMenu, toggleMenuVisibility,
add_product_to_category, addProductToCategory,
run_search, searchSuggestions,
searchSelect, initializeSearchDropdown,
update_product_hot markProductAsHot
}; };
})(); })();

View File

@@ -1,26 +1,28 @@
"use strict"; "use strict";
interface AdminFunction { interface AdminFunctions {
capNhatTrangThaiMenu(hideMenuBig: boolean): void; toggleMenuVisibility(hideLargeMenu: boolean): void;
add_product_to_category(id: string): void; addProductToCategory(productId: string): void;
run_search(holder: string): void; searchSuggestions(inputSelector: string): void;
searchSelect(holder: string): void; initializeSearchDropdown(selector: string): void;
update_product_hot(id: string): void; markProductAsHot(productId: string): void;
} }
const AdminFunction: AdminFunction = (() => { const AdminFunctions: AdminFunctions = (() => {
function capNhatTrangThaiMenu(hideMenuBig: boolean): void {
if (hideMenuBig === false) {
$('#js-admin-content-container').addClass('show-large-menu');
} else {
$('#js-admin-content-container').removeClass('show-large-menu');
}
$('#js-menu-big').toggleClass('hidden', hideMenuBig); function toggleMenuVisibility(hideLargeMenu: boolean): void {
$('#js-menu-small').toggleClass('hidden', !hideMenuBig); const contentContainer = $('#js-admin-content-container');
$('#js-form-search').toggleClass('menu-hide', hideMenuBig); const largeMenu = $('#js-menu-big');
localStorage.setItem(hideMenuBig ? 'menu_big' : 'menu_small', 'hidden'); const smallMenu = $('#js-menu-small');
localStorage.removeItem(hideMenuBig ? 'menu_small' : 'menu_big'); const searchForm = $('#js-form-search');
contentContainer.toggleClass('show-large-menu', !hideLargeMenu);
largeMenu.toggleClass('hidden', hideLargeMenu);
smallMenu.toggleClass('hidden', !hideLargeMenu);
searchForm.toggleClass('menu-hide', hideLargeMenu);
localStorage.setItem(hideLargeMenu ? 'menu_big' : 'menu_small', 'hidden');
localStorage.removeItem(hideLargeMenu ? 'menu_small' : 'menu_big');
} }
function debounce(func: (...args: any[]) => void, wait: number, immediate: boolean) { function debounce(func: (...args: any[]) => void, wait: number, immediate: boolean) {
@@ -40,41 +42,41 @@ const AdminFunction: AdminFunction = (() => {
}; };
} }
function addProductToCategory(productId: string): void {
function add_product_to_category(id: string): void { const statusElement = $('#status_' + productId);
$('#status_' + id).html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Đang xử lý..</span>'); statusElement.html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Processing...</span>');
setTimeout(() => { setTimeout(() => {
$('#status_' + id).html(''); statusElement.html('');
}, 1000); }, 1000);
} }
function run_search(holder: string): void { function searchSuggestions(inputSelector: string): void {
$(holder).keyup(debounce(function (this: HTMLInputElement) { // Ensure 'this' context is of type HTMLInputElement $(inputSelector).keyup(debounce(function (this: HTMLInputElement) {
//const inputString = $(this).val();
$('#js-show-search').show(); $('#js-show-search').show();
}, 300, false) as any); // Cast debounce to any to avoid type inference issues }, 300, false) as any);
$('body').click(function () { $('body').click(function () {
$("#js-show-search").hide(); $('#js-show-search').hide();
}); });
} }
function update_product_hot(id: string): void { function markProductAsHot(productId: string): void {
$('#js-status-hottype-' + id).html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Đang xử lý..</span>'); const statusElement = $('#js-status-hottype-' + productId);
statusElement.html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Processing...</span>');
setTimeout(() => { setTimeout(() => {
$('#js-status-hottype-' + id).html(''); statusElement.html('');
}, 1000); }, 1000);
} }
function searchSelect(holder: string): void { function initializeSearchDropdown(selector: string): void {
$(holder).select2(); $(selector).select2();
} }
return { return {
capNhatTrangThaiMenu, toggleMenuVisibility,
add_product_to_category, addProductToCategory,
run_search, searchSuggestions,
searchSelect, initializeSearchDropdown,
update_product_hot markProductAsHot
}; };
})(); })();