| 34859 |
vikas |
1 |
const rightHero = `<table class="table table-bordered" id="rightHero">
|
|
|
2 |
<tr>
|
|
|
3 |
<td>
|
|
|
4 |
<img src="https://placehold.co/300x200" alt="Top Left Image" id="topLeftImage" width="300">
|
|
|
5 |
<input type="file" class="topLeftFile" style="display: none;">
|
|
|
6 |
<input type="hidden" id="topLeftFile">
|
|
|
7 |
<input id="topLeftLink" class="form-control" placeholder="Redirection Link">
|
|
|
8 |
</td>
|
|
|
9 |
<td>
|
|
|
10 |
<img src="https://placehold.co/300x200" alt="Bottom Left Image" id="bottomLeftImage" width="300">
|
|
|
11 |
<input type="file" class="bottomLeftFile" style="display: none;">
|
|
|
12 |
<input type="hidden" id="bottomLeftFile">
|
|
|
13 |
<input id="bottomLeftLink" class="form-control" placeholder="Redirection Link">
|
|
|
14 |
</td>
|
|
|
15 |
</tr>
|
|
|
16 |
<tr>
|
|
|
17 |
<td>
|
|
|
18 |
<img src="https://placehold.co/300x200" alt="Top Right Image" id="topRightImage" width="300">
|
|
|
19 |
<input type="file" class="topRightFile" style="display: none;">
|
|
|
20 |
<input type="hidden" id="topRightFile">
|
|
|
21 |
<input id="topRightLink" class="form-control" placeholder="Redirection Link">
|
|
|
22 |
</td>
|
|
|
23 |
<td>
|
|
|
24 |
<img src="https://placehold.co/300x200" alt="Bottom Right Image" id="bottomRightImage" width="300">
|
|
|
25 |
<input type="file" class="bottomRightFile" style="display: none;">
|
|
|
26 |
<input type="hidden" id="bottomRightFile">
|
|
|
27 |
<input id="bottomRightLink" class="form-control" placeholder="Redirection Link">
|
|
|
28 |
</td>
|
|
|
29 |
<td rowspan="2">
|
|
|
30 |
<img src="https://placehold.co/600x400" alt="Hero Image" id="heroImage" width="300">
|
|
|
31 |
<input type="file" class="heroFile" style="display: none;">
|
|
|
32 |
<input type="hidden" id="heroFile">
|
|
|
33 |
<input id="heroLink" class="form-control" placeholder="Redirection Link">
|
|
|
34 |
</td>
|
|
|
35 |
</tr>
|
|
|
36 |
</table>`,
|
|
|
37 |
leftHero = `<table class="table table-bordered" id="leftHero">
|
|
|
38 |
<tr>
|
|
|
39 |
<td rowspan="2">
|
|
|
40 |
<img src="https://placehold.co/600x400" alt="Hero Image" id="heroImage" width="300">
|
|
|
41 |
<input type="file" class="heroFile" style="display: none;">
|
|
|
42 |
<input type="hidden" id="heroFile">
|
|
|
43 |
<input id="heroLink" class="form-control" placeholder="Redirection Link">
|
|
|
44 |
</td>
|
|
|
45 |
<td>
|
|
|
46 |
<img src="https://placehold.co/300x200" alt="Top Left Image" id="topLeftImage" width="300">
|
|
|
47 |
<input type="file" class="topLeftFile" style="display: none;">
|
|
|
48 |
<input type="hidden" id="topLeftFile">
|
|
|
49 |
<input id="topLeftLink" class="form-control" placeholder="Redirection Link">
|
|
|
50 |
</td>
|
|
|
51 |
<td>
|
|
|
52 |
<img src="https://placehold.co/300x200" alt="Bottom Left Image" id="bottomLeftImage" width="300">
|
|
|
53 |
<input type="file" class="bottomLeftFile" style="display: none;">
|
|
|
54 |
<input type="hidden" id="bottomLeftFile">
|
|
|
55 |
<input id="bottomLeftLink" class="form-control" placeholder="Redirection Link">
|
|
|
56 |
</td>
|
|
|
57 |
</tr>
|
|
|
58 |
<tr>
|
|
|
59 |
<td>
|
|
|
60 |
<img src="https://placehold.co/300x200" alt="Top Right Image" id="topRightImage" width="300">
|
|
|
61 |
<input type="file" class="topRightFile" style="display: none;">
|
|
|
62 |
<input type="hidden" id="topRightFile">
|
|
|
63 |
<input id="topRightLink" class="form-control" placeholder="Redirection Link">
|
|
|
64 |
</td>
|
|
|
65 |
<td>
|
|
|
66 |
<img src="https://placehold.co/300x200" alt="Bottom Right Image" id="bottomRightImage" width="300">
|
|
|
67 |
<input type="file" class="bottomRightFile" style="display: none;">
|
|
|
68 |
<input type="hidden" id="bottomRightFile">
|
|
|
69 |
<input id="bottomRightLink" class="form-control" placeholder="Redirection Link">
|
|
|
70 |
</td>
|
|
|
71 |
</tr>
|
|
|
72 |
</table>`,
|
|
|
73 |
centerHero = `<table class="table table-bordered" id="centerHero">
|
|
|
74 |
<tr>
|
|
|
75 |
<td>
|
|
|
76 |
<img src="https://placehold.co/300x200" alt="Top Left Image" id="topLeftImage" width="300">
|
|
|
77 |
<input type="file" class="topLeftFile" style="display: none;">
|
|
|
78 |
<input type="hidden" id="topLeftFile">
|
|
|
79 |
<input id="topLeftLink" class="form-control" placeholder="Redirection Link">
|
|
|
80 |
</td>
|
|
|
81 |
<td rowspan="2">
|
|
|
82 |
<img src="https://placehold.co/600x400" alt="Hero Image" id="heroImage" width="300">
|
|
|
83 |
<input type="file" class="heroFile" style="display: none;">
|
|
|
84 |
<input type="hidden" id="heroFile">
|
|
|
85 |
<input id="heroLink" class="form-control" placeholder="Redirection Link">
|
|
|
86 |
</td>
|
|
|
87 |
<td>
|
|
|
88 |
<img src="https://placehold.co/300x200" alt="Bottom Left Image" id="bottomLeftImage" width="300">
|
|
|
89 |
<input type="file" class="bottomLeftFile" style="display: none;">
|
|
|
90 |
<input type="hidden" id="bottomLeftFile">
|
|
|
91 |
<input id="bottomLeftLink" class="form-control" placeholder="Redirection Link">
|
|
|
92 |
</td>
|
|
|
93 |
</tr>
|
|
|
94 |
<tr>
|
|
|
95 |
<td>
|
|
|
96 |
<img src="https://placehold.co/300x200" alt="Top Right Image" id="topRightImage" width="300">
|
|
|
97 |
<input type="file" class="topRightFile" style="display: none;">
|
|
|
98 |
<input type="hidden" id="topRightFile">
|
|
|
99 |
<input id="topRightLink" class="form-control" placeholder="Redirection Link">
|
|
|
100 |
</td>
|
|
|
101 |
<td>
|
|
|
102 |
<img src="https://placehold.co/300x200" alt="Bottom Right Image" id="bottomRightImage" width="300">
|
|
|
103 |
<input type="file" class="bottomRightFile" style="display: none;">
|
|
|
104 |
<input type="hidden" id="bottomRightFile">
|
|
|
105 |
<input id="bottomRightLink" class="form-control" placeholder="Redirection Link">
|
|
|
106 |
</td>
|
|
|
107 |
</tr>
|
|
|
108 |
</table>`;
|
|
|
109 |
function patchSectionData(sectionData) {
|
|
|
110 |
const container = $('.style-container');
|
|
|
111 |
container.find('#heroFile').val(sectionData.hero.image.split('/').filter(Boolean).pop());
|
|
|
112 |
container.find('#heroLink').val(sectionData.hero.link);
|
|
|
113 |
container.find('#heroImage').attr('src',sectionData.hero.image);
|
|
|
114 |
|
|
|
115 |
container.find('#topLeftFile').val(sectionData.leftTop.image.split('/').filter(Boolean).pop());
|
|
|
116 |
container.find('#topLeftLink').val(sectionData.leftTop.link);
|
|
|
117 |
container.find('#topLeftImage').attr('src',sectionData.leftTop.image);
|
|
|
118 |
|
|
|
119 |
container.find('#bottomLeftFile').val(sectionData.leftBottom.image.split('/').filter(Boolean).pop());
|
|
|
120 |
container.find('#bottomLeftLink').val(sectionData.leftBottom.link);
|
|
|
121 |
container.find('#bottomLeftImage').attr('src',sectionData.leftBottom.image);
|
|
|
122 |
|
|
|
123 |
container.find('#bottomRightFile').val(sectionData.rightTop.image.split('/').filter(Boolean).pop());
|
|
|
124 |
container.find('#bottomRightLink').val(sectionData.rightTop.link);
|
|
|
125 |
container.find('#bottomRightImage').attr('src',sectionData.rightTop.image);
|
|
|
126 |
|
|
|
127 |
container.find('#topRightFile').val(sectionData.rightBottom.image.split('/').filter(Boolean).pop());
|
|
|
128 |
container.find('#topRightLink').val(sectionData.rightBottom.link);
|
|
|
129 |
container.find('#topRightImage').attr('src',sectionData.rightBottom.image);
|
|
|
130 |
}
|
|
|
131 |
$(document).on('click', ".pages-list", function () {
|
|
|
132 |
doGetAjaxRequestHandler(context + "/pages", (response) => {
|
|
|
133 |
$('#main-content').html(response);
|
|
|
134 |
//$('#pages-list').DataTable();
|
|
|
135 |
console.log('loaderDialogObj',loaderDialogObj);
|
|
|
136 |
});
|
|
|
137 |
});
|
|
|
138 |
|
|
|
139 |
$(document).on('click', '.view-page', function (ev) {
|
|
|
140 |
ev.preventDefault();
|
|
|
141 |
let pageId = $(this).parent().parent('tr').data('id');
|
|
|
142 |
doGetAjaxRequestHandler(context + "/pages/"+pageId,(response) => {
|
|
|
143 |
const sectionData = JSON.parse(response.sectionData);
|
|
|
144 |
$('#id').val(response.id);
|
|
|
145 |
$('#title').val(response.title);
|
|
|
146 |
$('#tabTitle').val(response.tabTitle);
|
|
|
147 |
$('#visible_on').val(response.visibleOn).trigger('change');
|
|
|
148 |
$('#section_order').val(response.sectionOrder);
|
|
|
149 |
$('#group').val(response.sectionGroup);
|
|
|
150 |
$('#style').val(sectionData.style+'Hero').trigger('change');
|
|
|
151 |
$('#below').val(response.sectionBelow).trigger('change');
|
|
|
152 |
$('#status').prop('checked', response.status);
|
|
|
153 |
patchSectionData(sectionData);
|
|
|
154 |
$('#managePagesModal').modal('show');
|
|
|
155 |
});
|
|
|
156 |
});
|
|
|
157 |
|
|
|
158 |
function validateRequiredFields(fields) {
|
|
|
159 |
let isValid = true;
|
|
|
160 |
fields.each(function () {
|
|
|
161 |
if (!$(this).val()) {
|
|
|
162 |
isValid = false;
|
|
|
163 |
$(this).addClass('is-invalid');
|
|
|
164 |
} else {
|
|
|
165 |
$(this).removeClass('is-invalid');
|
|
|
166 |
}
|
|
|
167 |
});
|
|
|
168 |
return isValid;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
$(document).on('click', ".save_page", function () {
|
|
|
172 |
const selectedStyle = $('#style').val();
|
|
|
173 |
const imgURL = $('#imgURL').val();
|
|
|
174 |
|
|
|
175 |
if (!selectedStyle) {
|
|
|
176 |
alert("Please select a style");
|
|
|
177 |
return;
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
const container = $('.style-container');
|
|
|
181 |
const styleEntry = {
|
|
|
182 |
style: selectedStyle.replace('Hero', '').toLowerCase(),
|
|
|
183 |
hero: {
|
|
|
184 |
image: imgURL+container.find('#heroFile').val() || '',
|
|
|
185 |
link: container.find('#heroLink').val() || ''
|
|
|
186 |
},
|
|
|
187 |
leftTop: {
|
|
|
188 |
image: imgURL+container.find('#topLeftFile').val() || '',
|
|
|
189 |
link: container.find('#topLeftLink').val() || ''
|
|
|
190 |
},
|
|
|
191 |
leftBottom: {
|
|
|
192 |
image: imgURL+container.find('#bottomLeftFile').val() || '',
|
|
|
193 |
link: container.find('#bottomLeftLink').val() || ''
|
|
|
194 |
},
|
|
|
195 |
rightTop: {
|
|
|
196 |
image: imgURL+container.find('#topRightFile').val() || '',
|
|
|
197 |
link: container.find('#topRightLink').val() || ''
|
|
|
198 |
},
|
|
|
199 |
rightBottom: {
|
|
|
200 |
image: imgURL+container.find('#bottomRightFile').val() || '',
|
|
|
201 |
link: container.find('#bottomRightLink').val() || ''
|
|
|
202 |
}
|
|
|
203 |
};
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
const params = {
|
|
|
207 |
id: $('#id').val() || 0,
|
|
|
208 |
title: $('#title').val() || 'Untitled',
|
|
|
209 |
visibleOn: $('#visible_on').val() || 'Home',
|
|
|
210 |
tabTitle: $('#tabTitle').val() || 'Untitled',
|
|
|
211 |
sectionGroup: $('#group').val() || 'Parent',
|
|
|
212 |
sectionOrder: $('#section_order').val() || 0,
|
|
|
213 |
sectionData: JSON.stringify(styleEntry),
|
|
|
214 |
sectionBelow: $('#below').val(),
|
|
|
215 |
status: $('#status').prop('checked'),
|
|
|
216 |
};
|
|
|
217 |
console.log('params:', params);
|
|
|
218 |
doAjaxRequestWithJsonHandler(context + "/pages", "POST", JSON.stringify(params), (response) => {
|
|
|
219 |
if (response) {
|
|
|
220 |
$('.pages-list').trigger('click');
|
|
|
221 |
$('#managePagesModal').modal('hide');
|
|
|
222 |
alert("Saved successfully");
|
|
|
223 |
} else {
|
|
|
224 |
alert("Something went wrong!");
|
|
|
225 |
}
|
|
|
226 |
});
|
|
|
227 |
});
|
|
|
228 |
|
|
|
229 |
$(document).on('click', ".delete-page", function() {
|
|
|
230 |
const id = parseInt($(this).closest('td').data('id')) || 0;
|
|
|
231 |
console.log("id",id);
|
|
|
232 |
if (confirm("Are you sure you want to delete this record")) {
|
|
|
233 |
if (id > 0) {
|
|
|
234 |
doDeleteAjaxRequestHandler(context + "/pages/" + id, (response) => {
|
|
|
235 |
if (response) {
|
|
|
236 |
$(this).parent('td').closest('tr').remove();
|
|
|
237 |
$('.pages-list').trigger('click');
|
|
|
238 |
alert("Deleted successfully");
|
|
|
239 |
} else {
|
|
|
240 |
alert("Something went wrong!");
|
|
|
241 |
}
|
|
|
242 |
});
|
|
|
243 |
} else {
|
|
|
244 |
$(this).parent('td').closest('tr').remove();
|
|
|
245 |
}
|
|
|
246 |
}
|
|
|
247 |
});
|
|
|
248 |
|
|
|
249 |
$(document).on('change', "#style", function() {
|
|
|
250 |
var selectedStyle = $(this).val();
|
|
|
251 |
$('.style-container').empty();
|
|
|
252 |
if (selectedStyle == 'leftHero') $('.style-container').append(leftHero);
|
|
|
253 |
if (selectedStyle == 'rightHero') $('.style-container').append(rightHero);
|
|
|
254 |
if (selectedStyle == 'centerHero') $('.style-container').append(centerHero);
|
|
|
255 |
});
|
|
|
256 |
|
|
|
257 |
$(document).on('click', '.style-container img', function () {
|
|
|
258 |
const container = $(this).closest('td');
|
|
|
259 |
const fileInput = container.find('input[type="file"]');
|
|
|
260 |
fileInput.click();
|
|
|
261 |
});
|
|
|
262 |
|
|
|
263 |
$(document).on('change', '.style-container input[type="file"]', function (event) {
|
|
|
264 |
const files = event.target.files;
|
|
|
265 |
if (files.length > 0) {
|
|
|
266 |
const container = $(this).closest('td');
|
|
|
267 |
const img = container.find('img').first();
|
|
|
268 |
const hiddenInput = container.find('input[type="hidden"]');
|
|
|
269 |
|
|
|
270 |
img.attr('src', URL.createObjectURL(files[0]));
|
|
|
271 |
img.on('load', function () {
|
|
|
272 |
URL.revokeObjectURL(img.attr('src'));
|
|
|
273 |
});
|
|
|
274 |
|
|
|
275 |
uploadDocument(files[0], function (id) {
|
|
|
276 |
hiddenInput.val(id);
|
|
|
277 |
});
|
|
|
278 |
}
|
|
|
279 |
});
|
|
|
280 |
|
|
|
281 |
$(document).on('change', '#group', function (event) {
|
|
|
282 |
if ($(this).val() == '') $('.optional').show();
|
|
|
283 |
else $('.optional').hide();
|
|
|
284 |
});
|