var WORK_FLOW = WORK_FLOW || {};
var Lightico = Lightico || {};
var Resources = Resources || {};
WORK_FLOW.view = (function () {
var m_finishTitle = '', m_finishContent = '', m_finishRedirectURL = '', m_finishFormId = '', m_introFormId = '', m_skipFinish = false, m_closeDisabled = false;
var documentsAnalysisPeding = []
var init = function (startTitle, startContent, finishTitle, finishContent, finishRedirectURL, finishFormId, introFormId, skipFinish, closeEnabled, isWorkflowLevelConsent, disableConsentPopup, fullPage, modalFormClass) {
initIntroForm(introFormId, startTitle, startContent);
m_closeDisabled = closeEnabled !== undefined ? !closeEnabled : false;
m_finishTitle = finishTitle;
m_skipFinish = skipFinish;
m_finishContent = finishContent;
m_finishRedirectURL = finishRedirectURL ? finishRedirectURL : '';
m_finishFormId = finishFormId != '00000000-0000-0000-0000-000000000000' ? finishFormId : '';
$('#blueimp-gallery').find('.navigation').show();
$mainContainer.find('.payment-title-wrapper').remove();
$workflowTemplate.find('.form-content').removeClass('download-files');
$workflowTemplate.find('.button-right').removeClass('disabled');
// show
$modalView.find('.modal-form').removeClass('active');
if (modalFormClass && introFormId === '00000000-0000-0000-0000-000000000000') {
$modalView.find('.modal-form').addClass(modalFormClass);
}
if (!isWorkflowLevelConsent && !disableConsentPopup) {
$modalFillForm.addClass('active');
$modalView.addClass("visible");
if (!isMobile || fullPage) {
$modalView.addClass('desktop');
$('.workflow-desktop-close').show();
$mainCardBox.removeClass('with-out-box-shadow');
$mainContainer.find('.form-header-classic').addClass('visible');
$mainContainer.find('.form-header-classic').show();
$mainContainer.find('.form-header-classic .form-steps').empty();
$mainContainer.find('.form-header-classic .close-wizard #close_wizard').hide()
}
}
if (!closeEnabled) {
$mainContainer.find('.form-header-classic .close-wizard #close_wizard').hide().off('click');
}
};
var updateProgressBarTitle = function (title) {
if (title == 'Document request') {
title = Resources.documentRequest.title;
}
$mainContainer.find('.form-header-classic .form-steps').find('.form-step').find('p').text(title);
$mainContainer.find('.main-card-box .page-progress .page-name').text(title);
};
var toggleProgressBar = function(show) {
if (show) {
$mainContainer.find('.form-header-classic').show();
} else {
$mainContainer.find('.form-header-classic').hide();
}
}
var toggleRoom = function(show) {
if (show) {
$mainContainer.find('.form-header-transparent').show();
} else {
$mainContainer.find('.form-header-transparent').hide();
}
}
var updateProgressBar = function (currentStep, totalSteps, title) {
if (currentStep != null) {
var stepSize = parseInt(100 / totalSteps);
var updateStep = (currentStep * stepSize);
if (currentStep === totalSteps) {
updateStep = 100;
}
$('.easypie-chart').data('easyPieChart').update(updateStep);
$mainContainer.find('.form-header-classic .form-steps').find('.form-step').removeClass('hidden');
$mainContainer.find('.form-header-classic .form-steps').find('.form-step').data('step', currentStep).find('.form-step-icon').find('b').text(currentStep);
$mainContainer.find('.form-header-classic .form-steps').find('.form-step').data('step', currentStep).find('.form-step-icon').find('span').text(totalSteps);
$mainContainer.find('.main-card-box .page-progress .page-pagger .asset-current-page-number').text(currentStep);
$mainContainer.find('.main-card-box .page-progress .page-pagger .asset-total-pages').text(totalSteps);
}
updateProgressBarTitle(title);
}
var updatePageHeader = function (currentStep, totalSteps, name) {
if (!totalSteps) return;
$('.form-page-header').remove();
$mainContainer.find('.form-content')
.prepend('
');
}
var initTemplate = function (setSteps, disableClose) {
Lightico.api.sendCoBrowseEvent(this, 'click', '');
$modalView.removeClass("visible");
if ($modalView.hasClass('desktop')){
$modalView.removeClass('desktop');
$('.workflow-desktop-close').hide();
}
$modalView.find('.modal-form').removeClass('active');
$modalFillForm.removeClass('active');
$workflowTemplate.find('.upload-buttons').remove();
$workflowTemplate.find('.form-content').css('overflow-y', 'auto');
initSteps();
initProgressBar();
$mainContainer.find('.form-header-classic .form-steps').append('');
let counters = {
totalSteps: 0
};
setSteps(counters);
// finish step
if (!m_skipFinish) {
counters.totalSteps++;
$mainContainer.find('.form-header-classic .form-steps').find('.form-step').addClass('hidden');
$mainContainer.find('.form-header-classic .form-steps').find('.form-step').find('.form-step-icon').find('span').text(counters.totalSteps);
let finishDivContent = '\
' + m_finishTitle + '
' + m_finishContent + '
\
\
';
if (m_finishFormId != '') {
$.ajax({
cache: false,
async: false,
type: "POST",
url: 'Handlers/GetHtmlForm.ashx?sid=' + m_sessionData.sessionId,
data: { sessionId: m_sessionData.sessionId, direction: m_sessionData.direction, id: m_finishFormId },
dataType: "json",
success: function (response) {
if (response.m && response.m != '') {
finishDivContent = '\
';
}
},
error: function (textStatus, errorThrown) {
}
});
}
$workflowTemplate.find('.form-last-page').hide().empty().append(finishDivContent);
}
$workflowTemplate.find('.form-last-page button').off('click').on('click', function (e) {
e.preventDefault();
if ($(this).attr('data-redirect')) {
var url = $(this).attr('data-redirect');
if(isSelfServiceSession){
parent.reDirectByUrl(url);
}
else{
window.location.replace(url);
}
}
else {
Lightico.api.showRoom();
Lightico.api.sendCoBrowseEvent(this, 'click', '');
resetWizardForm();
WORK_FLOW.functions.hideReassignForm();
COMMON.ui.setMainBackground();
if (window.parent) {
window.parent.postMessage({
'func': 'closed'
}, "*");
}
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.callback && window.webkit.messageHandlers.callback.postMessage) {
window.webkit.messageHandlers.callback.postMessage('close');
}
if (typeof Android !== 'undefined') {
Android.onMessage('close');
}
}
});
if (m_closeDisabled) {
$mainContainer.find('.form-header-classic .close-wizard #close_wizard').hide().off('click');
}
else {
$mainContainer.find('.form-header-classic .close-wizard #close_wizard').show().off('click').on('click', function (e) {
COMMON.ui.setMainBackground();
WORK_FLOW.functions.hideReassignForm();
WORK_FLOW.functions.hideAssignForm()
$workflowTemplate.find('.reassign-last-page').hide();
e.preventDefault();
Lightico.api.showRoom();
Lightico.api.closeGallery();
resetWizardForm();
if (navigator.userAgent.indexOf("MSIE") == -1 && navigator.userAgent.indexOf("Trident") == -1 && isMobile) {
window.ABBYY.WebCapture.stopCapture();
}
COMMON.functions.cubesLoader.hide();
});
}
if(isSelfServiceSession){
$mainContainer.find('.form-header-classic .close-wizard #close_wizard').hide().off('click');
}
return counters.totalSteps;
};
var appendUploadButtons = function (data) {
if ($workflowTemplate.find('.upload-files').length == 0)
$workflowTemplate.find('.form-content div').first().append('' + Resources.attachment_title + '
');
else
$workflowTemplate.find('.upload-files').empty();
$(data).each(function (_key, _item) {
var buttonHTML = '';
$workflowTemplate.find('.upload-files').append(buttonHTML);
if (_item.DATA_EXTRACTION && _item.TOTAL_UPLOADED > 0) {
const uploadButton = $workflowTemplate.find('button.capture_doc[id="' + _item.ID + '"]');
uploadButton.addClass('upload-done');
uploadButton.css("pointer-events", "none");
uploadButton.css("cursor", "not-allowed");
}
});
};
var showLastPage = function (workflowId) {
var showSendCompletedWorkflow = function (redirect) {
var $sendCompletedWorkflowContainer = $('.send-completed-workflow-container');
var $sendCompletedButton = $('.send-completed-button');
$sendCompletedWorkflowContainer.css('display', 'flex');
if (!redirect) {
$('input#sendCompletedworkflowCheckBox').remove();
$('#sendCompletedworkflowCheckBoxContainer label').css('cursor', 'default');
}
$sendCompletedWorkflowContainer.parent().show().find('.bottom-desktop').hide();
$('#work-flow-template').css('justify-content', 'space-between');
var $bottomControlls = $('#work-flow-template').find('.bottom.controlls');
$bottomControlls.css('transition', 'none');
$('.form-last-page .modal-primary-button').hide();
if (redirect) {
$('.send-completed-button #redirectAndSendBtn').show();
if (allowSendWorkflowToCustomer) {
$('#sendCompletedworkflowCheckBoxContainer').show();
}
else {
$('#sendCompletedworkflowCheckBoxContainer').hide();
}
$('.send-completed-button #sendCompletedWorkflowBtn').hide();
}
else {
$sendCompletedButton.css('justify-content', 'center');
$('.send-completed-workflow-container .send-completed-title');
$('.send-completed-button button').click(function () {
$('#sendCompletedWorkflowBtn').prop('disabled', 'disabled');
$('#sendCompletedWorkflowBtn').css('cursor', 'default');
parent.sendCompletedWorkflow(m_autoOpenFileId);
});
}
}
var showSelfServiceLastPage = function (redirect) {
$workflowTemplate.find('.bottom').hide();
hideWorkFlowSteps();
$('.self-service-last-page').show();
COMMON.functions.cubesLoader.hide();
var $sendCompletedWorkflow = $('.self-service-last-page .send-completed-workflow');
if (redirect) {
$('#lastPageSendCompletedWorkflowBtn').hide();
//$('#lastPageSendCompletedworkflowCheckBox').show();
$sendCompletedWorkflow.addClass('no-copy');
$sendCompletedWorkflow.css('display', 'flex');
var $lastPagRredirectAndSendBtn = $('#lastPagRredirectAndSendBtn')
$lastPagRredirectAndSendBtn.show();
$('.self-service-last-page .well-done .send-completed-workflow .send-button');
$lastPagRredirectAndSendBtn.off('click').on('click', function (e) {
var sendCompletedworkflow = $('#lastPageSendCompletedworkflowCheckBox').is(":checked");
if (allowSendWorkflowToCustomer && sendCompletedworkflow) {
parent.sendCompletedWorkflow(m_autoOpenFileId);
}
parent.reDirectByUrl(m_finishRedirectURL);
});
if (!allowSendWorkflowToCustomer) {
$sendCompletedWorkflow.find('.sub-title').hide();
}
}
else {
if (allowSendWorkflowToCustomer) {
var $sendButton = $(' .send-button');
$sendButton.css('display', 'flex');
$sendButton.css('justify-content', 'center');
$sendCompletedWorkflow.css('display', 'flex');
var $sendCompletedWorkflowBtn = $('.self-service-last-page .send-completed-workflow button');
$sendCompletedWorkflowBtn.click(function () {
$sendCompletedWorkflowBtn.prop('disabled', 'disabled');
$sendCompletedWorkflowBtn.css('cursor', 'default');
parent.sendCompletedWorkflow(m_autoOpenFileId);
});
}
}
}
var hideWorkFlowSteps = function(){
$workflowTemplate.find('.form-content').addClass('no-buttons');
$workflowTemplate.find('.form-content').hide();
$workflowTemplate.find('.upload-files').hide();
$workflowTemplate.find('form').hide();
}
if (m_skipFinish) {
if (m_finishRedirectURL) {
if(isSelfServiceSession){
showSelfServiceLastPage(m_finishRedirectURL);
}
else{
window.location.replace(m_finishRedirectURL);
}
} else {
if(isSelfServiceSession){
showSelfServiceLastPage();
}
else{
Lightico.api.showRoom();
const fakeElement = $workflowTemplate.find('.form-last-page button')[0];
Lightico.api.sendCoBrowseEvent(fakeElement, 'click', '');
resetWizardForm();
COMMON.ui.setMainBackground();
if (window.parent) {
window.parent.postMessage({
'func': 'closed'
}, "*");
}
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.callback && window.webkit.messageHandlers.callback.postMessage) {
window.webkit.messageHandlers.callback.postMessage('close');
}
if (typeof Android !== 'undefined') {
Android.onMessage('close');
}
}
}
COMMON.functions.cubesLoader.hide();
} else {
if(isSelfServiceSession){
hideWorkFlowSteps();
if(m_finishRedirectURL){
showSendCompletedWorkflow(m_finishRedirectURL);
$workflowTemplate.find('#redirectAndSendBtn').off('click').on('click', function (e) {
var sendCompletedworkflow = $('.send-completed-title #sendCompletedworkflowCheckBox').is(":checked");
if(allowSendWorkflowToCustomer && sendCompletedworkflow){
parent.sendCompletedWorkflow(m_autoOpenFileId);
}
parent.reDirectByUrl(m_finishRedirectURL);
})
}else{
if(allowSendWorkflowToCustomer){
showSendCompletedWorkflow();
}
else{
$workflowTemplate.find('.bottom').hide();
}
$('.form-last-page .modal-primary-button').hide();
$workflowTemplate.find('.form-content').hide();
}
$workflowTemplate.find('.form-last-page').show();
COMMON.functions.cubesLoader.hide();
}
else{
if(m_finishRedirectURL){
$workflowTemplate.find('.form-last-page').find('button[data-redirect]').attr('data-redirect', m_finishRedirectURL);
}
$workflowTemplate.find('.bottom').hide();
$workflowTemplate.find('.form-content').addClass('no-buttons');
$workflowTemplate.find('.form-content').hide();
$workflowTemplate.find('.upload-files').hide();
$workflowTemplate.find('form').hide();
$mainCardBox.removeClass('with-out-box-shadow');
$workflowTemplate.find('.form-last-page').show();
COMMON.functions.cubesLoader.hide();
}
}
};
function initSteps() {
$workflowTemplate.find('.form-content').empty();
$workflowTemplate.find('.form-content').html('');
$mainContainer.find('.form-header-classic .form-steps').empty();
$workflowTemplate.find('.bottom').show();
$workflowTemplate.find('.form-content').removeClass('no-buttons');
$mainContainer.find('.form-header-classic .form-steps').removeClass().addClass('form-steps');
$workflowTemplate.find('.button-right').find('.text-button').text(Resources.next);
$workflowTemplate.find('.button-right').addClass('active').removeClass('hidden');
$workflowTemplate.find('.button-left').addClass('disabled').removeClass('hidden');
$workflowTemplate.find('.button-center').addClass('hidden');
$workflowTemplate.find('.bottom.controlls').addClass('multiple');
}
function initProgressBar() {
const barColor = getComputedStyle(document.documentElement).getPropertyValue('--lds-brand-color-primary');
const trackColor = getComputedStyle(document.documentElement).getPropertyValue('--lds-brand-color-background-light');
var eyePie = '';
$mainContainer.find('.form-header-classic .form-steps').prepend(eyePie);
var pieOptions = {
animate: {
duration: 800,
enabled: true
},
size: 44,
barColor: barColor,
trackColor: trackColor,
scaleColor: 'transparent',
lineWidth: 7,
lineCap: 'circle'
};
$mainContainer.find('.form-header-classic #easypie').easyPieChart(pieOptions);
$('.easypie-chart').data('easyPieChart').update(0);
}
function resetWizardForm() {
$workflowTemplate.hide();
$workflowTemplate.find('.form-content').empty();
$workflowTemplate.find('.form-content').removeClass('tick-box-form');
$workflowTemplate.attr('data-workflow-id', '');
$workflowTemplate.find('.button-extra').hide();
$workflowTemplate.find('.bottom-break').hide();
$workflowTemplate.find('.button-right')
.removeClass('disabled')
.removeClass('start-signing')
.removeClass('approve-reading')
.removeClass('scale-animation');
$workflowTemplate.find('.button-left')
.removeClass('active')
.addClass('disabled')
.find('.text-button')
.text(Resources.previous);
$workflowTemplate.find('.form-last-page').hide().empty();
$workflowTemplate.find('.form-content').show();
$mainContainer.find('.form-header-classic').hide();
$workflowTemplate.find('.inner-modal').empty();
}
function htmlDecode(input) {
var retVal = '';
var doc = new DOMParser().parseFromString(input, "text/html");
if (doc.documentElement != null)
retVal = doc.documentElement.textContent;
return retVal;
}
function initIntroForm(introFormId, startTitle, startContent) {
m_introFormId = introFormId != '00000000-0000-0000-0000-000000000000' ? introFormId : '';
if (m_introFormId) {
$.ajax({
cache: false,
async: false,
type: "POST",
url: 'Handlers/GetHtmlForm.ashx?sid=' + m_sessionData.sessionId,
data: { sessionId: m_sessionData.sessionId, direction: m_sessionData.direction, id: m_introFormId },
dataType: "json",
success: function (response) {
if (response.m && response.m != '') {
$modalFillForm.find('.form-ico').remove()
startTitle ? $modalFillForm.find('.title').text(startTitle) : $modalFillForm.find('.title').remove()
const $txtEl = $modalFillForm.find('.txt');
const $titleEl = $modalFillForm.find('.title');
const $customTxt = $modalFillForm.find('.custom-txt');
if ($customTxt.length) {
$customTxt.innerHTML = response.m;
} else {
var fakeElement = document.createElement("div");
fakeElement.className = 'custom-txt fr-view';
$('.modal-form').addClass('custom-workflow-open-close-page')
fakeElement.innerHTML = response.m;
$txtEl.after(fakeElement);
}
$txtEl.hide();
$titleEl.hide();
}
},
error: function (textStatus, errorThrown) {
if (startTitle != '')
$modalFillForm.find('.title').text(startTitle);
if (startContent != '')
$modalFillForm.find('.txt').text(startContent);
}
});
} else {
if (startTitle != '')
$modalFillForm.find('.title').text(startTitle);
if (startContent != '')
$modalFillForm.find('.txt').text(startContent);
}
}
function capturePhotoId($sourceButton, fileId, documentRequests, options, files) {
let { workflowId, stepId } = options
if ($sourceButton.attr('data-total-uploaded') != '0') {
return;
}
let documentType = {};
$(documentRequests).each(function (index, item) {
if ($sourceButton.attr('data-type-code') == item.TYPE_CODE) {
documentType.alias = item.TYPE_NAME;
documentType.DATA_EXTRACTION = item.DATA_EXTRACTION;
}
});
PHOTO_ID.capturePhoto(documentType, 'front', $sourceButton.attr('id'), { fileId: COMMON.functions.createUUID(), workflowId: workflowId, files: files, stepId: stepId, isDocumentAnalysisRequired: options.isDocumentAnalysisRequired }, function (res) {
if (!$.isEmptyObject(res)) {
$sourceButton.attr('data-total-uploaded', 1);
$sourceButton.find('.total-uploads .uploaded').text('1');
$sourceButton.addClass('upload-done');
$sourceButton.css("pointer-events", "none");
$sourceButton.css("cursor", "not-allowed");
var messageData = {
'command': '22',
'sessionId': m_sessionData.sessionId,
'message': { fileId: res.fileId, typeId: $sourceButton.attr('id'), documentRequestId: $sourceButton.attr('id') },
'direction': m_sessionData.direction,
'signRequired': false,
'fileName': res.fileName
};
sessionSocket.send(JSON.stringify(messageData));
var missingDocuments = false;
$('.upload-files button.capture_doc').each(function (index, item) {
if ($(item).attr('data-total-uploaded') == "0" || $(item).find('.check').find('.new').length)
missingDocuments = true;
});
if (missingDocuments == false) {
$workflowTemplate.find('.bottom.controlls').find('.button-right').addClass('active').removeClass('disabled');
}
}
});
}
var sendDocumentToAnalysis = function(assetId, workflowId, stepId, sourceButton, options) {
documentsAnalysisPeding.push(1)
return $.ajax({
cache: false,
async: true,
type: "POST",
url: `customer-api/sessions/${m_sessionData.sessionId}/workflows/${workflowId}/assets/${assetId}/QueryDocument`,
dataType: "json",
success: function (response) {
if (response) {
documentsAnalysisPeding.pop()
let missingDocs = isMissingDocuments()
WEB_SOCKET.functions.sendWorkflowAssetCompletedByParticipant(workflowId, stepId, assetId);
if (!missingDocs && !documentsAnalysisPeding.length) completeDocumentRequestStep(options, assetId)
return;
}
COMMON.functions.spinner.hide(sourceButton);
}
});
}
function isMissingDocuments() {
let missingDocs = false
$('.upload-files button.capture_doc').each(function (index, item) {
if ($(item).attr('data-total-uploaded') == "0" || $(item).find('.upload-state').find('.new').length) {
missingDocs = true;
}
});
return missingDocs
}
function completeDocumentRequestStep(options, fileId) {
var totalSteps = parseInt($workflowTemplate.find('.form-step-icon').find('span').text());
WORK_FLOW.view.updateProgressBar(totalSteps, totalSteps, Resources.documentRequest.upload_complete);
$workflowTemplate.find('.bottom.controlls').find('.button-right').addClass('active').removeClass('disabled');
$workflowTemplate.find('.bottom.controlls').find('.button-right').off('click').on('click', function () {
var uploadedTypeIds = [];
$workflowTemplate.find('.upload-files').find('button').each(function (index, item) {
uploadedTypeIds.push($(item).attr('id'));
});
Lightico.api.lockWizard(fileId, { isMultiSigner: options.isMultiSigner, uploadedTypes: uploadedTypeIds, isAgentLocked: options.isAgentLocked });
WORK_FLOW.view.showLastPage();
if (options.workflowId === null) {
WORK_FLOW.view.updateProgressBar(totalSteps, totalSteps, Resources.documentRequest.upload_complete);
}
})
}
function captureDocumentHandler($sourceButton, fileId, documentRequests, options, files, workflowStep) {
let needsPhotoId = false;
$(documentRequests).each(function (index, item) {
if ($sourceButton.attr('data-category-code') == item.CATEGORY_CODE && $sourceButton.attr('data-type-code') == item.TYPE_CODE) {
let photoIdAuthentication = workflowStep && workflowStep.is_idv_backward_compatiblity_supported == undefined && item.PHOTO_ID_AUTHENTICATION && item.PHOTO_ID_AUTHENTICATION === true;
if (item.DATA_EXTRACTION && item.DATA_EXTRACTION === true || photoIdAuthentication)
needsPhotoId = true;
}
});
let addActiveClass = '';
if (typeof $sourceButton.attr('data-total-uploaded') == 'undefined') {
$sourceButton.attr('data-total-uploaded', 0);
} else {
addActiveClass = $sourceButton.attr('data-total-uploaded') != 0 ? 'active' : '';
}
var uploadModalHtmlString = '\
\
\
Scan document
Upload file
\
';
var uploadButtonsHtmlString = '
';
if (!$workflowTemplate.find('.upload-files-modal[data-source-button="' + $sourceButton.attr('id') + '"]').length) {
$workflowTemplate.find('.form-content').append(uploadModalHtmlString);
$workflowTemplate.find('.upload-buttons').remove();
$workflowTemplate.find('.bottom.controlls').hide();
$workflowTemplate.append(uploadButtonsHtmlString);
if (needsPhotoId) {
$workflowTemplate.find('.btn-add-files.button-left').remove();
$workflowTemplate.find('.upload-buttons.bottom.multiple').css('justify-content', 'end');
}
}
var $uploadModal = $workflowTemplate.find('.upload-files-modal[data-source-button="' + $sourceButton.attr('id') + '"]');
function addAnother($el, e) {
e.preventDefault();
// IE FALLBACK
if (navigator.userAgent.indexOf("MSIE") != -1 || navigator.userAgent.indexOf("Trident") != -1 || !isMobile) {
$("#attachFile").click();
} else {
setTimeout(() => {
$el.find('#upload_options').toggleClass('top');
$el.find('#upload_asset').off('click').on('click', function (e) {
e.preventDefault();
$("#attachFile").click();
setTimeout(function () {
$('#upload_options.top').each(function () {
$(this).removeClass('top');
});
}, 500);
});
$el.find('#scan_document').off('click').on('click', function (e) {
e.preventDefault();
Start($('button.capture_doc[id=' + $('[data-source-button].active').attr('data-source-button') + ']'), fileId, documentRequests, options);
});
}, 100);
}
}
// "Add more files button"
$workflowTemplate.find('.btn-add-another').off('click tap').on('click tap', function (e) {
addAnother($(this), e);
});
$workflowTemplate.find('.upload-buttons.multiple #upload_asset').off('click').on('click', function (e) {
e.preventDefault();
$("#attachFile").click();
setTimeout(function () {
$('#upload_options.top').each(function () {
$(this).removeClass('top');
});
}, 500);
});
$workflowTemplate.find('.upload-buttons.multiple #scan_document').off('click').on('click', function (e) {
e.preventDefault();
Start($('button.capture_doc[id=' + $('[data-source-button].active').attr('data-source-button') + ']'), fileId, documentRequests, options);
});
function saveDraft(e, finished) {
e.preventDefault();
// form-content
$uploadModal.removeClass('active');
$workflowTemplate.find('.upload-buttons').addClass('hidden');
$workflowTemplate.find('.form-content > div').first().show();
$workflowTemplate.find('.form-content').removeClass('overflow-hidden');
// button-right
$workflowTemplate.find('.button-right').removeClass('start-signing').removeClass('approve-reading');
var $templateBtnRight = $workflowTemplate.find('.bottom.controlls').find('.button-right');
$templateBtnRight.removeClass('active');
if (options.workflowId == null) {
$templateBtnRight.find('.text-button').text(Resources.finish);
}
$sourceButton.find('.total-uploads').html($sourceButton.attr('data-total-uploaded') !== '0' ? '
' + $sourceButton.attr('data-total-uploaded') + '' : '');
var missingDocuments = false;
if ($sourceButton.attr('data-total-uploaded') !== '0' && finished) {
const completedItem = $sourceButton.find('.upload-state').find('.new');
const completedItemIcon = $sourceButton.find('.upload-state').find('.lds-icon');
if (completedItem.length) {
completedItemIcon[0].className = 'lds-icon lds-size-icon-md done icon-checked';
$sourceButton.addClass('upload-done');
}
}
$('.upload-files button.capture_doc').each(function (index, item) {
if ($(item).attr('data-total-uploaded') == "0" || $(item).find('.upload-state').find('.new').length) {
missingDocuments = true;
}
});
if (options.workflowId === null) {
if (missingDocuments === false && !documentsAnalysisPeding.length ) {
completeDocumentRequestStep(options, fileId)
}
}
else {
if (missingDocuments === false && !documentsAnalysisPeding.length ) {
completeDocumentRequestStep(options, fileId)
}
}
$workflowTemplate.find('.bottom.controlls').show();
}
// save draft
$workflowTemplate.find('.btn-add-files').off('click').on('click', function (e) {
let finished = false
saveDraft(e, finished);
});
// finish
$workflowTemplate.find('.btn-done-upload').off('click').on('click', function (e) {
let finished = true
saveDraft(e, finished);
if (options.isDocumentAnalysisRequired) {
$workflowTemplate.find('.bottom.controlls').find('.button-right').addClass('disabled')
let missingDocs = isMissingDocuments()
var $uploadIndicator = $sourceButton.find('.upload-indicator');
$uploadIndicator.addClass('active');
COMMON.functions.spinner.show($uploadIndicator, 'var(--lds-brand-color-primary)', '2px', '30px', '');
sendDocumentToAnalysis(fileId, options.workflowId, options.stepId, $uploadIndicator, options)
} else {
if (options.workflowId) {
WEB_SOCKET.functions.sendWorkflowAssetCompletedByParticipant(options.workflowId, options.stepId, fileId);
} else {
let docRequestId = $sourceButton[0].id
WEB_SOCKET.functions.updateDocumentRequestStatus(docRequestId, "done");
}
}
});
function uploadSingleImage(img, imageId, options) {
$sourceButton.attr('data-total-uploaded', parseInt($sourceButton.attr('data-total-uploaded')) + 1);
if (!needsPhotoId) {
$uploadModal.find('.title').html('
' + $sourceButton.attr('data-title') + ':
' + $sourceButton.attr('data-total-uploaded') + ' ' + Resources.pictures_found + '');
$uploadModal.find('.upload-files-holder').append('
');
}
Lightico.api.sendFile(img, fileId, $sourceButton.attr('id'), (function (fileGUID) {
return function (fileDataUrl) {
$uploadModal.find('.upload-preview-file[data-file-name="lightico_' + fileGUID + '"]').css({ 'background-image': 'url("' + fileDataUrl + '")' });
};
})(imageId), (function (fileGUID) {
return function (progressPercent) {
// Show the process for each file
$uploadModal.find('.upload-preview-file[data-file-name="lightico_' + fileGUID + '"]').find('.upload-progress-bar').css({ width: Math.round(progressPercent * 100) + '%' });
};
})(imageId), function (uploadedFileId) {
$(documentRequests).each(function (index, item) {
if (item.ID == $sourceButton.attr('id')) {
item.FILE_IDS.push(uploadedFileId);
item.TOTAL_UPLOADED += 1;
}
});
if (needsPhotoId) {
return $workflowTemplate.find('.btn-done-upload').click();
}
$uploadModal.find('.upload-preview-file[data-file-name="lightico_' + imageId + '"]').attr('data-file-id', uploadedFileId);
$uploadModal.find('.upload-preview-file[data-file-name="lightico_' + imageId + '"]').find('.preview-file').off('click').on('click', function (e) {
$workflowTemplate.hide();
$mainContainer.find('.form-header-classic').hide();
Lightico.api.previewFile('Handlers/GetFile.ashx?src=callee&sessionId=' + m_sessionData.sessionId + '&direction=' + m_sessionData.direction + '&fileId=' + uploadedFileId + '&type=img&sid=' + m_sessionData.sessionId, function () {
$workflowTemplate.show();
$mainContainer.find('.form-header-classic').show();
});
});
$uploadModal.find('.upload-preview-file[data-file-name="lightico_' + imageId + '"]').find('.delete-file').off('click').on('click', function (e) {
Lightico.api.showConfirmModal(Resources.confirm, Resources.confirm_delete_document, Resources.yes, Resources.decline, false, function () {
let assetId = $("#work-flow-template").attr("data-workflow-id");
assetId = assetId === '' ? $("#work-flow-template").attr("data-workflow-id-for-wizard-close") : assetId;
WEB_SOCKET.functions.deleteDocumentRequestUploadedFile(uploadedFileId, assetId);
$(documentRequests).each(function (index, item) {
if (item.ID == $sourceButton.attr('id')) {
item.FILE_IDS.pop(uploadedFileId);
item.TOTAL_UPLOADED -= 1;
$('#attachFile').parent().wrap('