var searchVisible = 0;
var transparent = true;
var mobile_device = false;
// Material Bootstrap Wizard Functions
function initMaterialBootstrap(tsys_main_data) {
$(".pre-loader").hide();
setTimeout(function () {
$.material.init();
}, 200);
/* Activate the tooltips */
$('[rel="tooltip"]').tooltip();
// Code for the Validator
$('.wizard-card form').each(function (e, th) {
$(th).validate({
ignore: [],
rules: validation,
messages: validation_messages,
showErrors: function (message, element) {
//console.log(message, element);
element.forEach(function (e) {
$(e.element).parents('div.form-group').addClass('has-error');
$(e.element).parents('div.form-group > label').addClass('has-error');
});
},
onclick: function (element, event) {
//console.log(element);
if (element.tagName !== 'SELECT') {
if ($(element).is(":checked")) {
// $(element).parents('div.form-group').removeClass('has-error');
} else {
// $(element).parents('div.form-group').addClass('has-error');
}
}
}
});
});
//Mark the tab clicked
$("[data-toggle='tab']").click(function () {
$("[data-toggle='tab']").removeClass('i-am-target');
$(this).addClass('i-am-target');
});
// Wizard Initialization
$('.wizard-card').bootstrapWizard({
'tabClass': 'nav nav-pills',
'nextSelector': '.btn-next',
'previousSelector': '.btn-previous',
onNext: function (tab, navigation, index) {
$(".i-am-target").removeClass('i-am-target');
$(".nav-pills li.active").next().find('a').addClass('i-am-target');
const ID = $(tab).find('a')[0].hash;
var show = $('a.i-am-target').parent().attr('data-index');
if (ID === '#additional-location') {
var id = $(".aside li.active a").attr('href');
saveData(id, 'TSYSApp__c', '.wizard-card', show);
} else {
saveData(ID, 'TSYSApp__c', '.wizard-card', show);
}
return false;
},
onPrevious: function (tab, navigation, index) {
$(".i-am-target").removeClass('i-am-target');
$(".nav-pills li.active").prev().find('a').addClass('i-am-target');
const ID = $(tab).find('a')[0].hash;
var show = $('a.i-am-target').parent().attr('data-index');
if (ID === '#additional-location') {
var id = $(".aside li.active a").attr('href');
saveData(id, 'TSYSApp__c', '.wizard-card', show);
} else {
saveData(ID, 'TSYSApp__c', '.wizard-card', show);
}
return false;
},
onInit: function (tab, navigation, index) {
//check number of tabs and fill the entire row
var $total = navigation.find('li').length;
var $wizard = navigation.closest('.wizard-card');
var $first_li = navigation.find('li:first-child a').html();
var $moving_div = $('
' + $first_li + '
');
$('.wizard-card .wizard-navigation > ul').append($moving_div);
navigation.find('li:first-child a').trigger('click');
refreshAnimation($wizard, index);
$('.moving-tab').css('transition', 'transform 0s');
},
onTabClick: function (tab, navigation, index) {
const ID = $(tab).find('a')[0].hash;
var show = $('a.i-am-target').parent().attr('data-index');
if (ID === '#additional-location') {
var id = $(".aside li.active a").attr('href');
saveData(id, 'TSYSApp__c', '.wizard-card', show);
} else {
saveData(ID, 'TSYSApp__c', '.wizard-card', show);
}
return false;
},
onTabShow: function (tab, navigation, index) {
//Hide save button on welcome tab
if ($("#Welcome").hasClass('active')) {
$(".btn-save").hide();
} else {
$(".btn-save").show();
}
//scroll to top
//window.location.hash = $(tab).find('a')[0].hash;
$("html").animate({ scrollTop: 0 }, "fast", function () {
//Update hash
if (history.pushState) {
history.pushState(null, null, $(tab).find('a')[0].hash);
}
else {
location.hash = $(tab).find('a')[0].hash;
}
});
$(".tab-pane.active").find("h3.info-text").removeClass("drawn");
var $total = navigation.find('li').length;
var $current = index + 1;
var $wizard = navigation.closest('.wizard-card');
// If it's the last tab then hide the last button and show the finish instead
if ($current >= $total) {
$($wizard).find('.btn-next').hide();
$($wizard).find('.btn-save').hide();
$($wizard).find('.btn-finishtop').hide();
$($wizard).find('.btn-finishbottom').show();
$($wizard).find('.btn-previoustop').hide();
$($wizard).find('.btn-previousbottom').show();
}
else {
$($wizard).find('.btn-next').show();
$($wizard).find('.btn-finish').hide();
$($wizard).find('.btn-previous').show();
}
//POA-99 - Remove NEXT button from the top of the MA title page
if ($("#Welcome").hasClass('active')) {
$($wizard).find('.btn-nexttop').hide();
$($wizard).find('.btn-previous').hide();
}
var button_text = navigation.find('li:nth-child(' + $current + ') a').html();
setTimeout(function () {
$('.moving-tab').text(button_text);
$(".header").text(button_text);
}, 150);
var checkbox = $('.footer-checkbox');
if (!index == 0) {
$(checkbox).css({
'opacity': '0',
'visibility': 'hidden',
'position': 'absolute'
});
} else {
$(checkbox).css({
'opacity': '1',
'visibility': 'visible'
});
}
refreshAnimation($wizard, index);
}
});
$(window).bind('hashchange', function (e) {
e.preventDefault();
});
//Additional Location Tabs
$(".aside").bootstrapWizard({
'tabClass': 'sub-nav',
onTabClick: function (tab, navigation, index) {
const ID = $(tab).find('a')[0].hash;
var show = $('a.i-am-target').parent().attr('data-index');
if (ID === '#additional-location') {
var id = $(".aside li.active a").attr('href');
saveData(id, 'TSYSApp__c', '.aside', show);
} else {
saveData(ID, 'TSYSApp__c', '.aside', show);
}
return false;
},
onTabShow: function (tab, navigation, index) {
$(".tab-pane.active").find("h3.info-text").removeClass("drawn");
}
});
// Prepare the preview for profile picture
//$(".wizard-file").change(function () {
// readURL(this);
//});
$('[data-toggle="wizard-radio"]').click(function () {
wizard = $(this).closest('.wizard-card');
wizard.find('[data-toggle="wizard-radio"]').removeClass('active');
$(this).addClass('active');
$(wizard).find('[type="radio"]').removeAttr('checked');
$(this).find('[type="radio"]').attr('checked', 'true');
});
$('[data-toggle="wizard-checkbox"]').click(function () {
if ($(this).hasClass('active')) {
$(this).removeClass('active');
$(this).find('[type="checkbox"]').removeAttr('checked');
} else {
$(this).addClass('active');
$(this).find('[type="checkbox"]').attr('checked', 'true');
}
});
$('.set-full-height').css('height', 'auto');
//SAVE Button
$(".btn-save").click(function () {
$(".tab-pane.active").find("h3.info-text").removeClass("drawn");
const ID = $(".nav-pills li.active a").attr('href');
if (ID === '#additional-location') {
var id = $(".aside li.active a").attr('href');
saveData(id, 'TSYSApp__c');
} else {
var id = $(".nav-pills li.active a").attr('href');
saveData(id, 'TSYSApp__c');
}
});
//Modal SAVE Button | POA-142
$(".btn-save-modal").click(function () {
var id = $(this).attr('data-terminal');
var name = $(`form[data-terminal="${id}"]`).find('.modal-title > b').text();
saveMerchantTerminal(id, name);
});
//FINISH button
$(".btn-finish").click(function () {
var s = '';
var is_error = false;
debugger;
//validate payment details dropdown selection
var myPaymentDetailsform = $(`form#Payment-Details [name="Equi_Info_Equipment_Billing__c"]`);
if (myPaymentDetailsform.val() === '') {
is_error = true;
s = $('a[href="#' + $('.wizard-card form#Payment-Details').attr('id') + '"]').text() + ', ' + s;
}
//validate all tabs except payment details
$('.wizard-card form').not("form#Payment-Details").each(function (e, th) {
var sc = $(th).valid();
// console.log(sc, th);
// console.log(th);
if (!sc) {
is_error = true;
s = $('a[href="#' + $(th).attr('id') + '"]').text() + ', ' + s;
}
});
var uploadValidation = validateUploadFields();
//5739
ValidateGovernmentIssueIDIsRequired();
debugger;
//validate if error
if (is_error) {
//saveData(null, 'TSYSApp__c', null, null, true);
$('.alert').removeClass('alert-success').addClass('alert-danger').find('strong').text('There is an error on the following tabs:');
var trim = s.replace(/(^,)|(, $)/g, "");
if (!uploadValidation.valid && !trim.includes(uploadValidation.tab)) {
trim += ', ' + uploadValidation.tab;
}
$(".alert").find('span').text(trim);
$('.alert').show();
} else if (!uploadValidation.valid) {
$('.alert').removeClass('alert-success').addClass('alert-danger').find('strong').text('There is an error on the following tabs:');
$(".alert").find('span').text(uploadValidation.tab);
$('.alert').show();
}
else {
//savedata
saveData(null, 'TSYSApp__c', null, null, true, tsys_main_data);
}
});
//Hide alert message
$("[data-hide]").on("click", function () {
$("." + $(this).attr("data-hide")).removeClass('alert-success').addClass('alert-danger').find('strong').text('Error!');
$("." + $(this).attr("data-hide")).hide();
// -or-, see below
// $(this).closest("." + $(this).attr("data-hide")).hide()
});
//Hamburger
$("#menu").click(function () {
$(this).toggleClass("open");
$(".wizard-navigation > ul").slideToggle();
});
//multiselect auto focus
$("select.multiple").off().on('focusin', function (e) {
$(this).siblings().addClass("open");
}).on('focusout', function (e) {
$(this).siblings().removeClass("open");
});
//checkbox and radioboxes autofocus
$("input[type='radio']").off().on('focusin', function (e) {
$("input[type = 'radio']").siblings('.circle').removeClass('active');
$(this).siblings('.circle').addClass('active');
}).on('focusout', function (e) {
$("input[type = 'radio']").siblings('.circle').removeClass('active');
});
$('input[type="checkbox"]').off().on('focusin', function (e) {
$("input[type='checkbox']").siblings(".checkbox-material").find(".check").removeClass('active');
$(this).siblings(".checkbox-material").find(".check").addClass('active');
}).on('focusout', function (e) {
$("input[type='checkbox']").siblings(".checkbox-material").find(".check").removeClass('active');
});
$(".custom-collapse").click(function () {
$(this).toggleClass("expand").nextUntil("tr.custom-collapse").slideToggle(150);
if ($(this).hasClass("expand")) {
$(this).find(".material-icons").text("arrow_right");
} else {
$(this).find(".material-icons").text("arrow_drop_down");
}
});
//prevent scrolling when spacebar is hit
window.onkeydown = function (e) {
if (e.keyCode === 32 && e.target === document.body) {
e.preventDefault();
}
};
//keep checkbox in focus
$('input[type="checkbox"]').change(function (e) {
var that = this;
setTimeout(function (e) {
$(that).focus();
}, 0);
});
//Popover
$("input[type='file']").change(function (e) {
var id = $(this).attr('id');
var total = 0;
var files = Object.values(e.target.files);
var attachFilename = e.target.value;
files.forEach((el) => {
total += Number(el.size);
});
//converts bytes to mb
var size = bytesToSize(total);
//prevent from uploading files > 3MB;
//prevent from uploading files > 25MB;
if (size > 25) {
alert("Maximum Size allowed per document is 25 MB");
e.stopPropagation;
return false;
}
//Hom-81 File extension validation
if (attachFilename != '') {
var checkimg = attachFilename.toLowerCase();
var isValid = validate_fileupload(checkimg);
if (isValid == false) {
alert("Accepted File Types are PDF, WORD, EXCEL, JPEG, CSV, PNG or ZIP");
return false;
} else {
$(this).parent().parent().removeClass('has-error');
}
}
updateFilesList(id, e.target.files);
});
//Hom-81 File extension validation
function validate_fileupload(fileName) {
var allowed_extensions = new Array("jpeg", "jpg", "png", "zip", "pdf", "docx", "doc", "xlsx", "xls", "csv");
var file_extension = fileName.split('.').pop().toLowerCase(); // split function will split the filename by dot(.), and pop function will pop the last element from the array which will give you the extension as well. If there will be no extension then it will return the filename.
for (var i = 0; i <= allowed_extensions.length; i++) {
if (allowed_extensions[i] == file_extension) {
return true; // valid file extension
}
}
return false;
}
//init popover
$('[data-toggle="popover"]').popover({
html: true,
title: "Files",
content: function () {
var id = $(this).attr('data-id');
var index = tsys_files.map(function (e) { return e.id; }).indexOf(id);
var index2 = tsys_saved_files.map(function (e) { return e.id; }).indexOf(id);
var files = tsys_files[index].data;
var saved_files = tsys_saved_files[index2] ? tsys_saved_files[index2].data : { length: 0 };
var a = "";
if (files !== null) {
if (files.length > 0) {
for (var val of files) {
a += "
" + val.name + "delete
";
}
}
//show saved attachments
if (saved_files.length > 0) {
for (var val of saved_files) {
if (val.isDeleted !== 'true') {
a += "
" + val.name + "delete
";
}
}
}
if (files.length === 0 && saved_files.length === 0) {
a += "
No File
";
}
} else if (saved_files.length > 0) {
//show saved attachments
for (var val of saved_files) {
if (val.isDeleted !== 'true') {
a += "
" + val.name + "delete
";
}
}
}
else {
a += "
No File
";
}
a += '
';
return a;
},
placement: "bottom"
});
//Text editor data change event
//quill.on('text-change', function (delta, oldDelta, source) {
// $("#editor-container").closest('form').data('changed', true);
//});
//delete files
$(document).on('click', '.popover-content-remove', function (e) {
var type = $(this).attr('data-type');
var id = $(this).attr('data-target');
var name = $(this).attr('data-name');
ConfirmDialog("Do you really want to delete this file?", (isDelete) => {
if (isDelete) {
//mark the form changed if file is deleted
$(this).closest('form').data('changed', true);
if (type === 'saved') {
var index = tsys_saved_files.map(function (e) { return e.id; }).indexOf(id);
tsys_saved_files[index].data.forEach((e) => {
if (e.name === name) {
e.isDeleted = 'true';
}
});
var total = $('#' + id).parents(".picture-container").siblings(".popover-container").find("span.file-total-viewer").text();
$('#' + id).parents(".picture-container").siblings(".popover-container").find("span.file-total-viewer").text(Number(total) - 1);
//Remove combo files when deleted
var combo = $(`#${id}`).attr('data-combo');
if (combo) {
var index2 = tsys_saved_files.map(function (e) { return e.id; }).indexOf(combo);
tsys_saved_files[index2].data.forEach((e) => {
if (e.name === name) {
e.isDeleted = 'true';
}
});
}
} else {
var index = tsys_files.map(function (e) { return e.id; }).indexOf(id);
var files = Object.values(tsys_files[index].data);
var newArr = files.filter((e) => { return e.name !== name; });
if (newArr.length < 1) {
//Reset the file to remove the element
var $el = $(`#${id}`);
$el.wrap('