Files
redline.com.pl/modules/inpostship/views/js/inpostship_back.js
2024-11-11 18:46:54 +01:00

249 lines
7.6 KiB
JavaScript

/**
* NOTICE OF LICENSE
*
* This file is licenced under the Software License Agreement.
* With the purchase or the installation of the software in your application
* you accept the licence agreement.
*
* You must not modify, adapt or create derivative works of this source code
*
* @author PrestaHelp.com
* @copyright 2019 PrestaHelp
* @license LICENSE.txt
*/
$(document).ready(function(){
if (typeof tooltip != 'undefined') {
$('.label-tooltip').tooltip();
}
$(document).on('click', '.select_all', function(e) {
if ($(this).is(':checked')) {
$('.select_one').each(function() {
$(this).prop('checked', 'checked').change();
});
} else {
$('.select_one').each(function() {
$(this).removeAttr('checked').change();
});
}
});
$(document).on('click', '.select_pww_all', function(e) {
if ($(this).is(':checked')) {
$('.select_pww_one').each(function() {
$(this).prop('checked', 'checked').change();
});
} else {
$('.select_pww_one').each(function() {
$(this).removeAttr('checked').change();
});
}
});
$(document).on('change', '.select_ins_all', function(e) {
let ins = $(this).val();
$('.select_one').each(function() {
if ($(this).is(':checked')) {
$(this).closest('tr').find('.select_ins_one').val(ins).change();
}
});
});
$(document).on('change', '.select_sendtype_all', function(e) {
let ins = $(this).val();
$('.select_one').each(function() {
let service = $(this).data('service');
if ($(this).is(':checked')) {
if (ins == 'parcel_locker') {
if (service != 5 && service != 6 && service != 2) {
$(this).closest('tr').find('.select_sendtype_one').val(ins).change();
}
} else {
$(this).closest('tr').find('.select_sendtype_one').val(ins).change();
}
}
});
});
$(document).on('change', '.select_packtype_all', function(e) {
let pt = $(this).val();
$('.select_one').each(function() {
if ($(this).is(':checked')) {
$(this).closest('tr').find('.select_packtype_one').val(pt).change();
}
});
});
$('.selectAllCheckbox').on('click', function () {
var chked = false;
if ($(this).is(':checked')) {
chked = true;
}
$('.chBox').each(function() {
if (chked) {
$(this).attr('checked', 'checked')
} else {
$(this).removeAttr('checked')
}
});
});
$('.settingsInpost').on('click', function() {
$('.alertInpost').remove();
var mapType = $('#INPOSTSHIP_MAP_TYPE').val();
if (mapType == 'google') {
var api = $('#INPOSTSHIP_GOOGLE_MAPS_API').val();
if (api == '') {
$('#INPOSTSHIP_GOOGLE_MAPS_API').after('<p class="alert alert-danger alertInpost">Wybrałeś jako typ mapy Google Maps. Musisz podać klucz API aby działały poprawnie!</p>');
return false;
}
return true;
}
return true;
});
$('.btnToPrepare').on('click', function(){
var html = $(this).html();
$(this).html(html + '<i class="icon-spin animation"></i>');
});
$('.btnToAll').on('click', function() {
var error = 0;
$('.errorSize').each(function() {
$(this).removeClass('errorSize');
});
var owner = $('#ownSize');
if (owner.is(':checked')) {
var s1 = parseInt($('#size1').val());
var s2 = parseInt($('#size2').val());
var s3 = parseInt($('#size3').val());
if (s1 > 350) {
error = 1;
$('#size1').addClass('errorSize');
}
if (s2 > 240) {
error = 1;
$('#size2').addClass('errorSize');
}
if (s3 > 240) {
error = 1;
$('#size3').addClass('errorSize');
}
}
var rnumber = $('#refNumber').val();
if (rnumber.length < 3) {
$('#refNumber').addClass('errorSize');
error = 1;
}
var recEmail = $('#recEmail').val();
if (recEmail.length < 1) {
$('#recEmail').addClass('errorSize');
error = 1;
}
var recPhone = $('#recPhone').val();
if (recPhone.length < 1) {
$('#recPhone').addClass('errorSize');
error = 1;
}
var ins = $('#ins').val();
var total = $('#totalOrder').val();
if (ins < total) {
$('#ins').addClass('errorSize');
error = 1;
}
if (error == 1) {
return false;
}
$(this).find('span').text('trwa tworzenie przesyłki...');
});
$('.add-package').click(function(){
$('.packageCreate').toggle();
});
$('#ajax-update-point').click(function(){
$('.ajax-inpost-result').empty();
pointSteps();
});
});
function pointSteps() {
$('.ajax-inpost-result').append('<div class="alert alert-info"></div>');
setPointStep1();
}
function setPointStep1() {
$.ajax({
url: step1url+'?action=deletePoint',
dataType: 'json',
method: 'get',
success: function() {
$('.ajax-inpost-result div').append('<p>Krok 1 - baza punktów wyczyszczona.</p>');
setPointStep2();
}
});
}
async function setPointStep2() {
if (points_count === undefined) {
// var points_count = 0;
}
if (points_all === undefined) {
// var points_all = 0;
}
$('.ajax-inpost-result div').append('<p>Krok 2 - Import punktów z Inpost.</p>');
$('.ajax-inpost-result div').append('<p class="st2"><span>0</span> z '+points_all+' <small></small></p><br /><div class="progresBarPoints"><div class="progress">\n' +
' <div class="progress-bar bg-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>\n' +
'</div></div>');
var i;
var all = 0;
var progress = 0;
for (let i = 1; i <= points_count; i++) {
all = await inport(i, all);
var current = Math.ceil(all / 100);
progress = Math.ceil((i * 100) / points_count);
$('.progresBarPoints .progress-bar').css('width', progress+'%');
$('.progresBarPoints .progress-bar').attr('aria-valuenow', progress);
$('.progresBarPoints .progress-bar').text(progress+' %');
if (points_all == all) {
stepPoint3();
}
if (i == points_count) {
// stepPoint3();
}
}
}
function inport(i, all)
{
var state = $.ajax({
url: step1url+'?action=addPoint&page='+i,
dataType: 'json',
method: 'get',
success: function(data) {
var current_count = parseInt($('.st2 > span').html());
var data_count = parseInt(data);
all = current_count+data_count;
$('.st2 > span').text(current_count+data_count);
}
});
return state;
}
function stepPoint3()
{
$('.ajax-inpost-result div').append('<p>Krok 3 Zakończono import. Zaraz nastąpi przeładowanie strony.<span class="ccc"></span></p>');
var time = 5;
setInterval(function() {
$('.ccc').text(' (za '+time+'s)');
time--;
}, 1000);
setTimeout(function() {
window.location.reload(true);
}, 5000);
}