Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
function initializeSelect(selector, type='parent') {$(selector).multiselect({includeSelectAllOption: false,multiple: false,maxHeight: 200,buttonWidth: '100%',numberDisplayed: 1,nonSelectedText: '-- Select One --',nSelectedText: ' - Selected',enableFiltering: true,enableCaseInsensitiveFiltering: true,tags: false});}function validateRequiredFields(fields) {let isValid = true;fields.each(function () {if (!$(this).val()) {isValid = false;$(this).addClass('is-invalid');} else {$(this).removeClass('is-invalid');}});return isValid;}$(document).on('click', ".category-list", function () {doGetAjaxRequestHandler(context + "/categories",(response) => {$('#main-content').html(response);initializeSelect('#parent_id', 'parent');// Remove category$('#manageCategory').on('click', '.removeExisting', function () {if (confirm("Are you sure you want to remove this row?")) {$(this).closest('tr').remove();}});$('#categories').on('click', '.view-category', function (ev) {ev.preventDefault();let superCatalogId = $(this).parent().parent('tr').data('id');doGetAjaxRequestHandler(context + "/categories/"+superCatalogId,(response) => {$('#manageCategoryBody').empty();$('#manageCategoryBody').html(response);$('#manageCategory').modal('show');});});// Initialize DataTable$('#categories').DataTable();});});$(document).on('click', ".save_category", function () {const requiredFields = $('#label, #display_name, #description');if (!validateRequiredFields(requiredFields)) {alert('Please fill all required fields.');return;}const params = {id: parseInt($('#category_id').val()) || 0,parentCategoryId: parseInt($('#parent_id').val()),label: $('#label').val(),displayName: $('#display_name').val(),description: $('#description').val(),imageId: parseInt($('#imageId').val()),featured: $('#featured').prop('checked'),};console.log('params',params);doAjaxRequestWithJsonHandler(context + "/categories", "POST", JSON.stringify(params), (response) => {if (response) {$('.category-list').trigger('click');$('#manageCategory').modal('hide');alert("Saved successfully");} else {alert("Something went wrong!");}});});$(document).on('click', ".delete-category", function() {const id = parseInt($(this).closest('td').data('id')) || 0;if (confirm("Are you sure you want to delete this record")) {if (id > 0) {doDeleteAjaxRequestHandler(context + "/categories/" + id, (response) => {if (response) {$(this).parent('td').closest('tr').remove();$('.category-list').trigger('click');alert("Deleted successfully");} else {alert("Something went wrong!");}});} else {$(this).parent('td').closest('tr').remove();}}});