| Line -... |
Line 1... |
| - |
|
1 |
const SCHEME_DETAILS_CONTAINER = "scheme-details-container";
|
| - |
|
2 |
|
| 1 |
$(function() {
|
3 |
$(function() {
|
| 2 |
$(document).on('click', ".create-scheme", function() {
|
4 |
$(document).on('click', ".create-scheme", function() {
|
| 3 |
loadScheme("main-content");
|
5 |
loadScheme("main-content");
|
| 4 |
});
|
6 |
});
|
| 5 |
$(document).on('click', ".scheme-details", function() {
|
7 |
$(document).on('click', ".scheme-details", function() {
|
| 6 |
var schemeId = $(this).attr('data');
|
8 |
var schemeId = $(this).attr('data');
|
| 7 |
console.log("schemeId = " + schemeId);
|
9 |
console.log("schemeId = " + schemeId);
|
| 8 |
loadSchemeDetails(schemeId, "scheme-details-container");
|
10 |
loadSchemeDetails(schemeId, SCHEME_DETAILS_CONTAINER);
|
| 9 |
});
|
11 |
});
|
| 10 |
$(document).on('click', ".active-scheme", function() {
|
12 |
$(document).on('click', ".active-scheme", function() {
|
| 11 |
var schemeId = $(this).attr('data');
|
13 |
var schemeId = $(this).attr('data');
|
| 12 |
console.log("active-scheme id : " + schemeId);
|
14 |
console.log("active-scheme id : " + schemeId);
|
| 13 |
var start = $("#schemes-paginated .start").text();
|
15 |
var start = $("#schemes-paginated .start").text();
|
| Line 165... |
Line 167... |
| 165 |
alert("Scheme ID and at least one Model are required");
|
167 |
alert("Scheme ID and at least one Model are required");
|
| 166 |
return;
|
168 |
return;
|
| 167 |
}
|
169 |
}
|
| 168 |
// Filter out catalogs that already exist in the scheme
|
170 |
// Filter out catalogs that already exist in the scheme
|
| 169 |
var existingCatalogs = [];
|
171 |
var existingCatalogs = [];
|
| 170 |
$('#scheme-details-container tr[data-catalogid]').each(function() {
|
172 |
$('#' + SCHEME_DETAILS_CONTAINER + ' tr[data-catalogid]').each(function() {
|
| 171 |
existingCatalogs.push(String($(this).data('catalogid')));
|
173 |
existingCatalogs.push(String($(this).data('catalogid')));
|
| 172 |
});
|
174 |
});
|
| 173 |
var requestedIds = catalogIds.split(",");
|
175 |
var requestedIds = catalogIds.split(",");
|
| 174 |
var duplicates = requestedIds.filter(function(id) { return existingCatalogs.indexOf(id.trim()) >= 0; });
|
176 |
var duplicates = requestedIds.filter(function(id) { return existingCatalogs.indexOf(id.trim()) >= 0; });
|
| 175 |
var newIds = requestedIds.filter(function(id) { return existingCatalogs.indexOf(id.trim()) < 0; });
|
177 |
var newIds = requestedIds.filter(function(id) { return existingCatalogs.indexOf(id.trim()) < 0; });
|
| Line 221... |
Line 223... |
| 221 |
processSellout(fofoOrderInvoiceNumber);
|
223 |
processSellout(fofoOrderInvoiceNumber);
|
| 222 |
}
|
224 |
}
|
| 223 |
|
225 |
|
| 224 |
});
|
226 |
});
|
| 225 |
|
227 |
|
| - |
|
228 |
// --- scheme details fragment (scheme-details.vm) ----------------------
|
| - |
|
229 |
// These live here rather than in the template because that fragment is
|
| - |
|
230 |
// injected with .html(), which re-executes any inline <script> it carries,
|
| - |
|
231 |
// and a successful save re-injects it. Binding there stacked one more
|
| - |
|
232 |
// $(document) listener per load until a single click fired N identical PUTs
|
| - |
|
233 |
// and the idempotency guard rejected all but the first. Scheme-level values
|
| - |
|
234 |
// are read from data- attributes at click time, so a handler always acts on
|
| - |
|
235 |
// the scheme currently on screen instead of the one it was rendered with.
|
| - |
|
236 |
$(document).on('click', ".add-scheme", function() {
|
| - |
|
237 |
$("#newItemToSchemeModal").modal({ backdrop: true, show: true });
|
| - |
|
238 |
});
|
| - |
|
239 |
|
| - |
|
240 |
$(document).on('hidden.bs.modal', "#newItemToSchemeModal", function() {
|
| - |
|
241 |
$("#addSchemeForm").trigger("reset");
|
| - |
|
242 |
});
|
| - |
|
243 |
|
| - |
|
244 |
$(document).on('shown.bs.modal', "#newItemToSchemeModal", function() {
|
| - |
|
245 |
var root = schemeDetailsRoot(this);
|
| - |
|
246 |
initSingleDatePicker($('input[name="addItemStartDate"]'), root.attr('data-scheme-start'), "down");
|
| - |
|
247 |
initSingleDatePicker($('input[name="addItemEndDate"]'), root.attr('data-scheme-end'), "down");
|
| - |
|
248 |
var categoryId = $('#modal-category-list').val();
|
| - |
|
249 |
if (categoryId) {
|
| - |
|
250 |
loadSchemeModalBrands(categoryId);
|
| - |
|
251 |
}
|
| - |
|
252 |
});
|
| - |
|
253 |
|
| - |
|
254 |
$(document).on('change', "#modal-category-list", function() {
|
| - |
|
255 |
var categoryId = $(this).val();
|
| - |
|
256 |
if (categoryId) {
|
| - |
|
257 |
loadSchemeModalBrands(categoryId);
|
| - |
|
258 |
}
|
| - |
|
259 |
});
|
| - |
|
260 |
|
| - |
|
261 |
$(document).on('click', ".edit-item-dates", function() {
|
| - |
|
262 |
var row = $(this).closest('tr');
|
| - |
|
263 |
var root = schemeDetailsRoot(this);
|
| - |
|
264 |
toggleItemDateEdit(row, true);
|
| - |
|
265 |
var startInput = row.find('.edit-start-date');
|
| - |
|
266 |
var endInput = row.find('.edit-end-date');
|
| - |
|
267 |
// An item with no window of its own opens on the scheme's own window.
|
| - |
|
268 |
if (!startInput.data('daterangepicker')) {
|
| - |
|
269 |
initSingleDatePicker(startInput, startInput.val() || root.attr('data-scheme-start'), "down");
|
| - |
|
270 |
initSingleDatePicker(endInput, endInput.val() || root.attr('data-scheme-end'), "down");
|
| - |
|
271 |
}
|
| - |
|
272 |
});
|
| - |
|
273 |
|
| - |
|
274 |
$(document).on('click', ".cancel-item-dates", function() {
|
| - |
|
275 |
toggleItemDateEdit($(this).closest('tr'), false);
|
| - |
|
276 |
});
|
| - |
|
277 |
|
| - |
|
278 |
$(document).on('click', ".save-item-dates", function() {
|
| - |
|
279 |
var row = $(this).closest('tr');
|
| - |
|
280 |
var startDate = row.find('.edit-start-date').val();
|
| - |
|
281 |
var endDate = row.find('.edit-end-date').val();
|
| - |
|
282 |
if (!startDate || !endDate) {
|
| - |
|
283 |
alert("Both start date and end date are required");
|
| - |
|
284 |
return;
|
| - |
|
285 |
}
|
| - |
|
286 |
updateSchemeItemWindow(schemeDetailsRoot(this).attr('data-scheme-id'),
|
| - |
|
287 |
row.data('schemeitemid'), startDate, endDate);
|
| - |
|
288 |
});
|
| - |
|
289 |
|
| 226 |
$(document).on('click', ".delete-schemes", function() {
|
290 |
$(document).on('click', ".delete-schemes", function() {
|
| 227 |
if (confirm("Delete model from Scheme?") == true) {
|
291 |
if (confirm("Delete model from Scheme?") == true) {
|
| 228 |
schemeId = $(this).data('schemeid');
|
292 |
schemeId = $(this).data('schemeid');
|
| 229 |
catalogId = $(this).data('catalogid');
|
293 |
catalogId = $(this).data('catalogid');
|
| 230 |
deleteScheme(schemeId, catalogId);
|
294 |
deleteScheme(schemeId, catalogId);
|
| Line 327... |
Line 391... |
| 327 |
$("#scheme-item-search-button").click();
|
391 |
$("#scheme-item-search-button").click();
|
| 328 |
}
|
392 |
}
|
| 329 |
});
|
393 |
});
|
| 330 |
});
|
394 |
});
|
| 331 |
|
395 |
|
| - |
|
396 |
// Every brand/model picker on the scheme screens wants the same multiselect;
|
| - |
|
397 |
// the label set was the only thing that genuinely varied between the copies.
|
| - |
|
398 |
// Pass overrides for the rare case that also needs a different width.
|
| 332 |
function configureTagListingItemsDescriptionDropDown() {
|
399 |
function configureMultiselect(selector, label, overrides) {
|
| 333 |
$('.catalogItemsDescription').multiselect({
|
400 |
$(selector).multiselect($.extend({
|
| 334 |
includeSelectAllOption: true,
|
401 |
includeSelectAllOption: true,
|
| - |
|
402 |
multiple: true,
|
| 335 |
maxHeight: 200,
|
403 |
maxHeight: 200,
|
| 336 |
buttonWidth: '180px',
|
404 |
buttonWidth: '180px',
|
| 337 |
numberDisplayed: 1,
|
405 |
numberDisplayed: 1,
|
| 338 |
nonSelectedText: 'Models',
|
406 |
nonSelectedText: label,
|
| 339 |
nSelectedText: ' - Models Selected',
|
407 |
nSelectedText: ' - ' + label + ' Selected',
|
| 340 |
allSelectedText: 'All Models Selected',
|
408 |
allSelectedText: 'All ' + label + ' Selected',
|
| 341 |
enableFiltering: true,
|
409 |
enableFiltering: true,
|
| 342 |
enableCaseInsensitiveFiltering: true
|
410 |
enableCaseInsensitiveFiltering: true
|
| - |
|
411 |
}, overrides || {}));
|
| - |
|
412 |
}
|
| - |
|
413 |
|
| - |
|
414 |
function configureTagListingItemsDescriptionDropDown() {
|
| - |
|
415 |
configureMultiselect('.catalogItemsDescription', 'Models');
|
| - |
|
416 |
}
|
| - |
|
417 |
|
| - |
|
418 |
// The fragment root carries the scheme's id and window as data- attributes.
|
| - |
|
419 |
// Falls back to the container when the caller sits outside the root.
|
| - |
|
420 |
function schemeDetailsRoot(el) {
|
| - |
|
421 |
var root = $(el).closest('[data-scheme-id]');
|
| - |
|
422 |
return root.length ? root : $('#' + SCHEME_DETAILS_CONTAINER + ' [data-scheme-id]').first();
|
| - |
|
423 |
}
|
| - |
|
424 |
|
| - |
|
425 |
function toggleItemDateEdit(row, editing) {
|
| - |
|
426 |
row.find('.date-display').toggle(!editing);
|
| - |
|
427 |
row.find('.date-edit').toggle(editing);
|
| - |
|
428 |
row.find('.edit-item-dates').toggle(!editing);
|
| - |
|
429 |
row.find('.save-item-dates, .cancel-item-dates').toggle(editing);
|
| - |
|
430 |
}
|
| - |
|
431 |
|
| - |
|
432 |
// Row values are rendered DD/MM/YYYY; scheme-level fallbacks are raw timestamps.
|
| - |
|
433 |
function initSingleDatePicker(input, value, drops) {
|
| - |
|
434 |
var startMoment = /^\d{2}\/\d{2}\/\d{4}$/.test(value || '')
|
| - |
|
435 |
? moment(value, 'DD/MM/YYYY')
|
| - |
|
436 |
: moment(value);
|
| - |
|
437 |
input.daterangepicker($.extend(getSingleDatePicker(startMoment), { "drops": drops }));
|
| - |
|
438 |
}
|
| - |
|
439 |
|
| - |
|
440 |
// Re-run on every injection: unlike the delegated handlers these bind directly
|
| - |
|
441 |
// to elements that the fragment replaces, so they cannot be bound once up front.
|
| - |
|
442 |
function initSchemeDetails(domId) {
|
| - |
|
443 |
var root = $('#' + domId).find('[data-scheme-id]');
|
| - |
|
444 |
if (root.length === 0) {
|
| - |
|
445 |
return;
|
| - |
|
446 |
}
|
| - |
|
447 |
root.find('input[name="extendSchemeById"]').daterangepicker($.extend(getSingleDatePicker(), { "drops": "up" }));
|
| - |
|
448 |
initSingleDatePicker(root.find('input[name="expireSchemeById"]'), root.attr('data-scheme-end'), "up");
|
| - |
|
449 |
}
|
| - |
|
450 |
|
| - |
|
451 |
// The modal reuses the page-level brand/model endpoints; its selects are re-id'd
|
| - |
|
452 |
// so they do not clash with the create-scheme page rendered behind it.
|
| - |
|
453 |
function loadSchemeModalBrands(categoryId) {
|
| - |
|
454 |
loadBrandsByCategory('modal-brand-list', categoryId, function() {
|
| - |
|
455 |
$('#modal-brand-list select').attr('id', 'modal-tag-listing-brands');
|
| - |
|
456 |
configureMultiselect('#modal-tag-listing-brands', 'Brands');
|
| - |
|
457 |
$('#modal-tag-listing-brands').on('change', function() {
|
| - |
|
458 |
var brands = $(this).val();
|
| - |
|
459 |
if (brands) {
|
| - |
|
460 |
loadSchemeModalModels(categoryId, brands);
|
| - |
|
461 |
}
|
| - |
|
462 |
});
|
| - |
|
463 |
});
|
| - |
|
464 |
}
|
| - |
|
465 |
|
| - |
|
466 |
function loadSchemeModalModels(categoryId, brands) {
|
| - |
|
467 |
loadCatalogDescriptionByBrands('modal-models-list', categoryId, brands, function() {
|
| - |
|
468 |
$('#modal-models-list select').addClass('modalCatalogItems');
|
| - |
|
469 |
configureMultiselect('.modalCatalogItems', 'Models', { buttonWidth: '220px' });
|
| 343 |
});
|
470 |
});
|
| 344 |
}
|
471 |
}
|
| 345 |
|
472 |
|
| 346 |
function schemesDownload() {
|
473 |
function schemesDownload() {
|
| 347 |
let pickerData = getDatesFromPicker('input[name="startEndDateTime"]')
|
474 |
let pickerData = getDatesFromPicker('input[name="startEndDateTime"]')
|
| Line 366... |
Line 493... |
| 366 |
"brand-list", categoryId);
|
493 |
"brand-list", categoryId);
|
| 367 |
}
|
494 |
}
|
| 368 |
}
|
495 |
}
|
| 369 |
|
496 |
|
| 370 |
function loadSchemeDetails(schemeId, domId) {
|
497 |
function loadSchemeDetails(schemeId, domId) {
|
| - |
|
498 |
domId = domId || SCHEME_DETAILS_CONTAINER;
|
| 371 |
doGetAjaxRequestHandler(context + "/getSchemeById?schemeId=" + schemeId,
|
499 |
doGetAjaxRequestHandler(context + "/getSchemeById?schemeId=" + schemeId,
|
| 372 |
function(response) {
|
500 |
function(response) {
|
| 373 |
$('#' + domId).html(response);
|
501 |
$('#' + domId).html(response);
|
| - |
|
502 |
initSchemeDetails(domId);
|
| 374 |
window.dispatchEvent(new Event('resize'));
|
503 |
window.dispatchEvent(new Event('resize'));
|
| 375 |
});
|
504 |
});
|
| 376 |
}
|
505 |
}
|
| 377 |
|
506 |
|
| - |
|
507 |
function updateSchemeItemWindow(schemeId, schemeItemId, startDate, endDate) {
|
| - |
|
508 |
doPutAjaxRequestHandler(context + "/scheme/item/window?schemeItemId=" + schemeItemId
|
| - |
|
509 |
+ "&startDate=" + encodeURIComponent(toIsoDateTime(startDate, false))
|
| - |
|
510 |
+ "&endDate=" + encodeURIComponent(toIsoDateTime(endDate, true)),
|
| - |
|
511 |
function(response) {
|
| - |
|
512 |
loadSchemeDetails(schemeId, SCHEME_DETAILS_CONTAINER);
|
| - |
|
513 |
});
|
| - |
|
514 |
}
|
| - |
|
515 |
|
| 378 |
function activeScheme(schemeId, offset, domId) {
|
516 |
function activeScheme(schemeId, offset, domId) {
|
| 379 |
doPutAjaxRequestHandler(context + "/activeSchemeById?schemeId=" + schemeId
|
517 |
doPutAjaxRequestHandler(context + "/activeSchemeById?schemeId=" + schemeId
|
| 380 |
+ "&offset=" + offset, function(response) {
|
518 |
+ "&offset=" + offset, function(response) {
|
| 381 |
$('#' + domId).html(response);
|
519 |
$('#' + domId).html(response);
|
| 382 |
$('#scheme-details-container').html('');
|
520 |
$('#' + SCHEME_DETAILS_CONTAINER).html('');
|
| 383 |
});
|
521 |
});
|
| 384 |
}
|
522 |
}
|
| 385 |
|
523 |
|
| 386 |
function expireScheme(schemeId, expireDate, domId) {
|
524 |
function expireScheme(schemeId, expireDate, domId) {
|
| 387 |
doPutAjaxRequestHandler(context + "/expireSchemeById?schemeId=" + schemeId
|
525 |
doPutAjaxRequestHandler(context + "/expireSchemeById?schemeId=" + schemeId
|
| 388 |
+ "&expireTimestamp=" + expireDate, function(
|
526 |
+ "&expireTimestamp=" + expireDate, function(
|
| 389 |
response) {
|
527 |
response) {
|
| 390 |
alert("Scheme - " + schemeId + " marked for expiry successfully!");
|
528 |
alert("Scheme - " + schemeId + " marked for expiry successfully!");
|
| 391 |
$('#' + domId).html(response);
|
529 |
$('#' + domId).html(response);
|
| 392 |
$('#scheme-details-container').html('');
|
530 |
$('#' + SCHEME_DETAILS_CONTAINER).html('');
|
| 393 |
});
|
531 |
});
|
| 394 |
}
|
532 |
}
|
| 395 |
|
533 |
|
| 396 |
function extendAllScheme(extendDate) {
|
534 |
function extendAllScheme(extendDate) {
|
| 397 |
doPostAjaxRequestWithJsonHandler(context + "/extendAllSchemes", JSON
|
535 |
doPostAjaxRequestWithJsonHandler(context + "/extendAllSchemes", JSON
|
| Line 442... |
Line 580... |
| 442 |
$('#' + domId).html(response);
|
580 |
$('#' + domId).html(response);
|
| 443 |
|
581 |
|
| 444 |
});
|
582 |
});
|
| 445 |
}
|
583 |
}
|
| 446 |
|
584 |
|
| 447 |
function loadCatalogDescriptionByBrands(domId, categoryId, brands) {
|
585 |
function loadCatalogDescriptionByBrands(domId, categoryId, brands, afterRender) {
|
| 448 |
let brandsString = brands.join(",")
|
586 |
let brandsString = brands.join(",")
|
| 449 |
doGetAjaxRequestHandler(`${context}/getCatalogDescriptionByBrands?categoryId=${categoryId}&brands=${brandsString}`,
|
587 |
doGetAjaxRequestHandler(`${context}/getCatalogDescriptionByBrands?categoryId=${categoryId}&brands=${brandsString}`,
|
| 450 |
function(response) {
|
588 |
function(response) {
|
| 451 |
$('#' + domId).html(response);
|
589 |
$('#' + domId).html(response);
|
| 452 |
configureTagListingItemsDescriptionDropDown();
|
590 |
(afterRender || configureTagListingItemsDescriptionDropDown)();
|
| 453 |
});
|
591 |
});
|
| 454 |
|
592 |
|
| 455 |
}
|
593 |
}
|
| 456 |
|
594 |
|
| 457 |
function loadBrandsByCategory(domId, categoryId) {
|
595 |
function loadBrandsByCategory(domId, categoryId, afterRender) {
|
| 458 |
doGetAjaxRequestHandler(`${context}/getBrandsByCategory?categoryId=${categoryId}`,
|
596 |
doGetAjaxRequestHandler(`${context}/getBrandsByCategory?categoryId=${categoryId}`,
|
| 459 |
function(response) {
|
597 |
function(response) {
|
| 460 |
$('#' + domId).html(response);
|
598 |
$('#' + domId).html(response);
|
| 461 |
configureBrandsDropDown();
|
599 |
(afterRender || configureBrandsDropDown)();
|
| 462 |
});
|
600 |
});
|
| 463 |
}
|
601 |
}
|
| 464 |
|
602 |
|
| 465 |
function schemes(domId) {
|
603 |
function schemes(domId) {
|
| 466 |
doGetAjaxRequestHandler(context + "/getSchemes", function(response) {
|
604 |
doGetAjaxRequestHandler(context + "/getSchemes", function(response) {
|
| Line 535... |
Line 673... |
| 535 |
if (endDate) payload.endDate = toIsoDateTime(endDate, true);
|
673 |
if (endDate) payload.endDate = toIsoDateTime(endDate, true);
|
| 536 |
doPostAjaxRequestWithJsonHandler(context + '/addItemToScheme', JSON
|
674 |
doPostAjaxRequestWithJsonHandler(context + '/addItemToScheme', JSON
|
| 537 |
.stringify(payload), function(response) {
|
675 |
.stringify(payload), function(response) {
|
| 538 |
$('#newItemToSchemeModal').modal('hide');
|
676 |
$('#newItemToSchemeModal').modal('hide');
|
| 539 |
alert("Item Added to scheme successfully");
|
677 |
alert("Item Added to scheme successfully");
|
| 540 |
loadSchemeDetails(schemeIds, "scheme-details-container");
|
678 |
loadSchemeDetails(schemeIds, SCHEME_DETAILS_CONTAINER);
|
| 541 |
});
|
679 |
});
|
| 542 |
}
|
680 |
}
|
| 543 |
|
681 |
|
| 544 |
function updateSchemes(schemeIds, catalogIds) {
|
682 |
function updateSchemes(schemeIds, catalogIds) {
|
| 545 |
doPostAjaxRequestWithJsonHandler(context + '/schemes/update', JSON
|
683 |
doPostAjaxRequestWithJsonHandler(context + '/schemes/update', JSON
|
| Line 579... |
Line 717... |
| 579 |
function deleteScheme(schemeId, catalogId) {
|
717 |
function deleteScheme(schemeId, catalogId) {
|
| 580 |
doDeleteAjaxRequestHandler(context + "/schemes/delete?schemeId=" + schemeId
|
718 |
doDeleteAjaxRequestHandler(context + "/schemes/delete?schemeId=" + schemeId
|
| 581 |
+ "&catalogId=" + catalogId, function(response) {
|
719 |
+ "&catalogId=" + catalogId, function(response) {
|
| 582 |
if (response == 'true') {
|
720 |
if (response == 'true') {
|
| 583 |
alert("Model Deleted successfully from Scheme");
|
721 |
alert("Model Deleted successfully from Scheme");
|
| 584 |
loadSchemeDetails(schemeId, "scheme-details-container");
|
722 |
loadSchemeDetails(schemeId, SCHEME_DETAILS_CONTAINER);
|
| 585 |
}
|
723 |
}
|
| 586 |
});
|
724 |
});
|
| 587 |
}
|
725 |
}
|
| 588 |
|
726 |
|
| 589 |
|
727 |
|