| 34814 |
vikas |
1 |
|
|
|
2 |
function initializeSelect(selector, type='parent') {
|
|
|
3 |
$(selector).multiselect({
|
|
|
4 |
includeSelectAllOption: false,
|
|
|
5 |
multiple: false,
|
|
|
6 |
maxHeight: 200,
|
|
|
7 |
buttonWidth: '100%',
|
|
|
8 |
numberDisplayed: 1,
|
|
|
9 |
nonSelectedText: '-- Select One --',
|
|
|
10 |
nSelectedText: ' - Selected',
|
|
|
11 |
enableFiltering: true,
|
|
|
12 |
enableCaseInsensitiveFiltering: true,
|
|
|
13 |
tags: false
|
|
|
14 |
});
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
function validateRequiredFields(fields) {
|
|
|
18 |
let isValid = true;
|
|
|
19 |
fields.each(function () {
|
|
|
20 |
if (!$(this).val()) {
|
|
|
21 |
isValid = false;
|
|
|
22 |
$(this).addClass('is-invalid');
|
|
|
23 |
} else {
|
|
|
24 |
$(this).removeClass('is-invalid');
|
|
|
25 |
}
|
|
|
26 |
});
|
|
|
27 |
return isValid;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
$(document).on('click', ".category-list", function () {
|
|
|
31 |
|
|
|
32 |
doGetAjaxRequestHandler(context + "/categories",
|
|
|
33 |
(response) => {
|
|
|
34 |
$('#main-content').html(response);
|
|
|
35 |
initializeSelect('#parent_id', 'parent');
|
|
|
36 |
// Remove category
|
|
|
37 |
$('#manageCategory').on('click', '.removeExisting', function () {
|
|
|
38 |
if (confirm("Are you sure you want to remove this row?")) {
|
|
|
39 |
$(this).closest('tr').remove();
|
|
|
40 |
}
|
|
|
41 |
});
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
$('#categories').on('click', '.view-category', function (ev) {
|
|
|
45 |
ev.preventDefault();
|
|
|
46 |
let superCatalogId = $(this).parent().parent('tr').data('id');
|
|
|
47 |
doGetAjaxRequestHandler(context + "/categories/"+superCatalogId,(response) => {
|
|
|
48 |
$('#manageCategoryBody').empty();
|
|
|
49 |
$('#manageCategoryBody').html(response);
|
|
|
50 |
$('#manageCategory').modal('show');
|
|
|
51 |
});
|
|
|
52 |
});
|
|
|
53 |
|
|
|
54 |
// Initialize DataTable
|
|
|
55 |
$('#categories').DataTable();
|
|
|
56 |
|
|
|
57 |
});
|
|
|
58 |
});
|
|
|
59 |
|
|
|
60 |
$(document).on('click', ".save_category", function () {
|
|
|
61 |
const requiredFields = $('#label, #display_name, #description');
|
|
|
62 |
if (!validateRequiredFields(requiredFields)) {
|
|
|
63 |
alert('Please fill all required fields.');
|
|
|
64 |
return;
|
|
|
65 |
}
|
|
|
66 |
const params = {
|
|
|
67 |
id: parseInt($('#category_id').val()) || 0,
|
|
|
68 |
parentCategoryId: parseInt($('#parent_id').val()),
|
|
|
69 |
label: $('#label').val(),
|
|
|
70 |
displayName: $('#display_name').val(),
|
|
|
71 |
description: $('#description').val(),
|
|
|
72 |
imageId: parseInt($('#imageId').val()),
|
|
|
73 |
featured: $('#featured').prop('checked'),
|
|
|
74 |
};
|
|
|
75 |
console.log('params',params);
|
|
|
76 |
doAjaxRequestWithJsonHandler(context + "/categories", "POST", JSON.stringify(params), (response) => {
|
|
|
77 |
if (response) {
|
|
|
78 |
$('.category-list').trigger('click');
|
|
|
79 |
$('#manageCategory').modal('hide');
|
|
|
80 |
alert("Saved successfully");
|
|
|
81 |
} else {
|
|
|
82 |
alert("Something went wrong!");
|
|
|
83 |
}
|
|
|
84 |
});
|
|
|
85 |
});
|
|
|
86 |
|
|
|
87 |
$(document).on('click', ".delete-category", function() {
|
|
|
88 |
const id = parseInt($(this).closest('td').data('id')) || 0;
|
|
|
89 |
if (confirm("Are you sure you want to delete this record")) {
|
|
|
90 |
if (id > 0) {
|
|
|
91 |
doDeleteAjaxRequestHandler(context + "/categories/" + id, (response) => {
|
|
|
92 |
if (response) {
|
|
|
93 |
$(this).parent('td').closest('tr').remove();
|
|
|
94 |
$('.category-list').trigger('click');
|
|
|
95 |
alert("Deleted successfully");
|
|
|
96 |
} else {
|
|
|
97 |
alert("Something went wrong!");
|
|
|
98 |
}
|
|
|
99 |
});
|
|
|
100 |
} else {
|
|
|
101 |
$(this).parent('td').closest('tr').remove();
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
});
|