| 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 |
|
| 34815 |
vikas |
30 |
function resetForm(form) {
|
|
|
31 |
$(form).trigger('reset');
|
|
|
32 |
$('#imgPreview').attr("src","");
|
|
|
33 |
$('#imageId').val("");
|
|
|
34 |
}
|
|
|
35 |
|
| 34814 |
vikas |
36 |
$(document).on('click', ".category-list", function () {
|
|
|
37 |
|
|
|
38 |
doGetAjaxRequestHandler(context + "/categories",
|
|
|
39 |
(response) => {
|
|
|
40 |
$('#main-content').html(response);
|
|
|
41 |
initializeSelect('#parent_id', 'parent');
|
|
|
42 |
// Remove category
|
|
|
43 |
$('#manageCategory').on('click', '.removeExisting', function () {
|
|
|
44 |
if (confirm("Are you sure you want to remove this row?")) {
|
|
|
45 |
$(this).closest('tr').remove();
|
|
|
46 |
}
|
|
|
47 |
});
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
$('#categories').on('click', '.view-category', function (ev) {
|
|
|
51 |
ev.preventDefault();
|
| 34815 |
vikas |
52 |
let categoryId = $(this).parent().parent('tr').data('id');
|
|
|
53 |
doGetAjaxRequestHandler(context + "/categories/"+categoryId,(response) => {
|
|
|
54 |
response = JSON.parse(response);
|
|
|
55 |
$('#category_id').val(response.id);
|
|
|
56 |
$('#parent_id').val(response.parentCategoryId).trigger('change');
|
|
|
57 |
$('#label').val(response.label);
|
|
|
58 |
$('#display_name').val(response.displayName);
|
|
|
59 |
$('#description').val(response.description);
|
|
|
60 |
$('#imageId').val(response.imageId);
|
|
|
61 |
$('#featured').prop('checked', response.featured);
|
|
|
62 |
if(response.imageId > 0) {
|
|
|
63 |
const img = $('#imgPreview');
|
|
|
64 |
img.attr("src","http://localhost:8080/document/" + response.imageId);
|
|
|
65 |
}
|
| 34814 |
vikas |
66 |
$('#manageCategory').modal('show');
|
|
|
67 |
});
|
|
|
68 |
});
|
|
|
69 |
|
|
|
70 |
// Initialize DataTable
|
|
|
71 |
$('#categories').DataTable();
|
|
|
72 |
|
|
|
73 |
});
|
|
|
74 |
});
|
|
|
75 |
|
|
|
76 |
$(document).on('click', ".save_category", function () {
|
|
|
77 |
const requiredFields = $('#label, #display_name, #description');
|
|
|
78 |
if (!validateRequiredFields(requiredFields)) {
|
|
|
79 |
alert('Please fill all required fields.');
|
|
|
80 |
return;
|
|
|
81 |
}
|
|
|
82 |
const params = {
|
|
|
83 |
id: parseInt($('#category_id').val()) || 0,
|
|
|
84 |
parentCategoryId: parseInt($('#parent_id').val()),
|
|
|
85 |
label: $('#label').val(),
|
|
|
86 |
displayName: $('#display_name').val(),
|
|
|
87 |
description: $('#description').val(),
|
|
|
88 |
imageId: parseInt($('#imageId').val()),
|
|
|
89 |
featured: $('#featured').prop('checked'),
|
|
|
90 |
};
|
|
|
91 |
console.log('params',params);
|
|
|
92 |
doAjaxRequestWithJsonHandler(context + "/categories", "POST", JSON.stringify(params), (response) => {
|
|
|
93 |
if (response) {
|
|
|
94 |
$('.category-list').trigger('click');
|
|
|
95 |
$('#manageCategory').modal('hide');
|
|
|
96 |
alert("Saved successfully");
|
|
|
97 |
} else {
|
|
|
98 |
alert("Something went wrong!");
|
|
|
99 |
}
|
|
|
100 |
});
|
|
|
101 |
});
|
|
|
102 |
|
|
|
103 |
$(document).on('click', ".delete-category", function() {
|
|
|
104 |
const id = parseInt($(this).closest('td').data('id')) || 0;
|
|
|
105 |
if (confirm("Are you sure you want to delete this record")) {
|
|
|
106 |
if (id > 0) {
|
|
|
107 |
doDeleteAjaxRequestHandler(context + "/categories/" + id, (response) => {
|
|
|
108 |
if (response) {
|
|
|
109 |
$(this).parent('td').closest('tr').remove();
|
|
|
110 |
$('.category-list').trigger('click');
|
|
|
111 |
alert("Deleted successfully");
|
|
|
112 |
} else {
|
|
|
113 |
alert("Something went wrong!");
|
|
|
114 |
}
|
|
|
115 |
});
|
|
|
116 |
} else {
|
|
|
117 |
$(this).parent('td').closest('tr').remove();
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
});
|