jQuery(function () { function RetailcrmExportForm() { this.submitButton = jQuery('button[id="export-orders-submit"]').get(0); jQuery(this.submitButton).after('
', {class: 'retail-progress__loader', text: '0%'})) window.addEventListener('beforeunload', this.confirmLeave); }; RetailcrmExportForm.prototype.updateProgressBar = function () { let processedOrders = this.ordersStep * this.ordersStepSize; if (processedOrders > this.ordersCount) { processedOrders = this.ordersCount; } let processedCustomers = this.customersStep * this.customersStepSize; if (processedCustomers > this.customersCount) { processedCustomers = this.customersCount; } const processed = processedOrders + processedCustomers; const total = this.ordersCount + this.customersCount; const percents = Math.round(100 * processed / total); jQuery(this.progressBar).find('.retail-progress__loader').text(percents + '%'); jQuery(this.progressBar).find('.retail-progress__loader').css('width', percents + '%'); jQuery(this.progressBar).find('.retail-progress__loader').attr('title', processed + '/' + total); }; RetailcrmExportForm.prototype.confirmLeave = function (event) { event.preventDefault(); event.returnValue = 'Export process has been started'; } RetailcrmExportForm.prototype.exportDone = function () { window.removeEventListener('beforeunload', this.confirmLeave); alert('Done'); } window.RetailcrmExportForm = RetailcrmExportForm; if (!(typeof RetailcrmExportForm === 'undefined')) { new window.RetailcrmExportForm(); } });