update
This commit is contained in:
614
devel.html
614
devel.html
@@ -1,468 +1,186 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>[TITLE]</title>
|
||||
<meta name="keywords" content="[META_KEYWORDS]">
|
||||
<meta name="description" content="[META_DESCRIPTION]">
|
||||
[META_INDEX]
|
||||
[CSS]
|
||||
[JAVA_SCRIPT]
|
||||
</head>
|
||||
<body>
|
||||
<div id="top">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-7">
|
||||
[KONTENER:1]
|
||||
</div>
|
||||
<div class="col-12 col-sm-5" id="mini-login">
|
||||
[UZYTKOWNIK_MINI_LOGOWANIE]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-4">
|
||||
<a href="/" id="logo" title="">
|
||||
<img src="/images/logo.svg" alt="">
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-12 col-sm-5">
|
||||
<!--[WYSZUKIWARKA]-->
|
||||
</div>
|
||||
<div class="col-12 col-sm-3">
|
||||
[KOSZYK]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="main-menu">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
[MENU:1]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="mobile-menu-btn">
|
||||
<i class="fa fa-bars"></i>
|
||||
</div>
|
||||
<div id="category-view">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-4 col-lg-3 left-column">
|
||||
<div class="title">Kategorie</div>
|
||||
[KATEGORIE]
|
||||
</div>
|
||||
<div class="col-12 col-md-8 col-lg-9">
|
||||
[ZAWARTOSC]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="last-on-blog">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div id="title">[PHP] global $lang; echo $lang['strefa-rodzica'];[/PHP]</div>
|
||||
<div id="subtitle">[PHP] global $lang; echo ucfirst( $lang['najnowsze-porady'] );[/PHP]</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="ornament">
|
||||
<img src="/images/ornament.svg" alt="">
|
||||
</div>
|
||||
<div class="row">
|
||||
[AKTUALNOSCI:9:3]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="promo-text">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
[KONTENER:2]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
[KONTENER:3]
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-4">
|
||||
[NEWSLETTER]
|
||||
</div>
|
||||
<div class="col-12 col-md-8">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-4">
|
||||
<div class="title">O firmie</div>
|
||||
[MENU:2]
|
||||
</div>
|
||||
<div class="col-12 col-md-4">
|
||||
<div class="title">Dla klientów</div>
|
||||
[MENU:3]
|
||||
</div>
|
||||
<div class="col-12 col-md-4">
|
||||
<div class="title">Moje konto</div>
|
||||
[MENU:4]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Geocode Cache Tester</title>
|
||||
<style>
|
||||
:root { --gap: 12px; --radius: 12px; }
|
||||
* { box-sizing: border-box; }
|
||||
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; margin: 0; background: #0f172a; color: #e2e8f0; }
|
||||
.wrap { max-width: 880px; margin: 40px auto; padding: 0 20px; }
|
||||
h1 { font-size: 1.6rem; margin: 0 0 8px; }
|
||||
p.lead { color: #94a3b8; margin: 0 0 24px; }
|
||||
|
||||
// ==UserScript==
|
||||
// @name A
|
||||
// @version 1
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
form { display: flex; gap: var(--gap); flex-wrap: wrap; align-items: center; background: #111827; padding: 16px; border: 1px solid #1f2937; border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.25) inset; }
|
||||
label { font-size: .95rem; color: #cbd5e1; }
|
||||
input[type="text"] { flex: 1 1 420px; min-width: 260px; padding: 12px 14px; border-radius: 10px; border: 1px solid #334155; background: #0b1220; color: #e2e8f0; outline: none; }
|
||||
input[type="text"]::placeholder { color: #64748b; }
|
||||
button { padding: 12px 16px; border-radius: 10px; border: 1px solid #334155; background: #0b3b7a; color: #e2e8f0; cursor: pointer; }
|
||||
button.secondary { background: #0b1220; }
|
||||
button:disabled { opacity: .6; cursor: progress; }
|
||||
|
||||
window.onload = function() {
|
||||
const currentUrl = window.location.href;
|
||||
.status { margin: 14px 0 0; font-size: .95rem; color: #94a3b8; min-height: 1.2em; }
|
||||
|
||||
const patterns = [
|
||||
/^https:\/\/projectpro\.apilo\.com\/order\/order\/news\/?$/,
|
||||
/^https:\/\/projectpro\.apilo\.com\/order\/order\/in-progress\/?$/,
|
||||
/^https:\/\/projectpro\.apilo\.com\/order\/order\/to-send\/?$/,
|
||||
/^https:\/\/projectpro\.apilo\.com\/order\/order\/completed\/?$/,
|
||||
/^https:\/\/projectpro\.apilo\.com\/order\/order\/all\/?$/
|
||||
];
|
||||
.card { background: #0b1220; border: 1px solid #1f2937; border-radius: var(--radius); padding: 16px; margin-top: 18px; }
|
||||
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
||||
.kv { background: #0a0f1a; border: 1px solid #1f2937; border-radius: 10px; padding: 12px; }
|
||||
.kv b { color: #cbd5e1; display: inline-block; min-width: 160px; }
|
||||
.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; border: 1px solid #334155; background: #0a0f1a; }
|
||||
.ok { color: #a7f3d0; }
|
||||
.warn { color: #fbbf24; }
|
||||
.err { color: #fca5a5; }
|
||||
|
||||
if (patterns.some(pattern => pattern.test(currentUrl))) {
|
||||
waitForTableAndSetImage();
|
||||
attachTableReloadListener();
|
||||
details { margin-top: 10px; }
|
||||
pre { background: #010409; border: 1px solid #111827; padding: 12px; border-radius: 10px; overflow: auto; }
|
||||
|
||||
.examples { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.examples a { font-size: .9rem; text-decoration: none; color: #cbd5e1; border: 1px dashed #374151; padding: 6px 10px; border-radius: 999px; }
|
||||
|
||||
@media (max-width: 720px) { .grid { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<h1>Tester geokodowania z cache (PHP + MySQL)</h1>
|
||||
<p class="lead">Wpisz <b>adres</b> albo <b>"lat,lng"</b>. Front wywołuje <code>geocode-cache.php</code>, który najpierw sprawdza cache w MySQL, a dopiero potem pyta Google. W odpowiedzi zobaczysz, czy wynik pochodzi z cache.</p>
|
||||
|
||||
<form id="geo-form">
|
||||
<label for="query">Adres lub współrzędne:</label>
|
||||
<input id="query" type="text" placeholder="np. Stefana Okrzei 14, Brzeziny lub 51.7592,19.4550" required />
|
||||
<button id="submit" type="submit">Geokoduj</button>
|
||||
<button id="clear" type="button" class="secondary">Wyczyść</button>
|
||||
</form>
|
||||
|
||||
<div id="status" class="status"></div>
|
||||
|
||||
<div class="examples">
|
||||
<span class="pill">Przykłady:</span>
|
||||
<a href="#" data-q="Stefana Okrzei 14, Brzeziny">Brzeziny, Okrzei 14</a>
|
||||
<a href="#" data-q="Rokicińska 130, Andrespol">Andrespol, Rokicińska 130</a>
|
||||
<a href="#" data-q="52.2297,21.0122">52.2297,21.0122</a>
|
||||
</div>
|
||||
|
||||
<div id="result" class="card" hidden>
|
||||
<div class="grid">
|
||||
<div class="kv"><b>Źródło</b> <span id="from_cache" class="pill"></span></div>
|
||||
<div class="kv"><b>Adres sformatowany</b> <span id="formatted_address"></span></div>
|
||||
<div class="kv"><b>Szerokość (lat)</b> <span id="lat"></span></div>
|
||||
<div class="kv"><b>Długość (lng)</b> <span id="lng"></span></div>
|
||||
<div class="kv"><b>Place ID</b> <span id="place_id"></span></div>
|
||||
<div class="kv"><b>Dostawca</b> <span id="provider"></span></div>
|
||||
</div>
|
||||
<details>
|
||||
<summary>Surowa odpowiedź JSON</summary>
|
||||
<pre id="raw"></pre>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// >>> DOSTOSUJ TO POLE DO SWOJEJ ŚCIEŻKI BACKENDU <<<
|
||||
const API_URL = '/geocode-cache.php';
|
||||
|
||||
const $ = (sel) => document.querySelector(sel);
|
||||
const $$ = (sel) => Array.from(document.querySelectorAll(sel));
|
||||
|
||||
function isLatLng(str) {
|
||||
return /^-?\d+(?:\.\d+)?\s*,\s*-?\d+(?:\.\d+)?$/.test(String(str).trim());
|
||||
}
|
||||
|
||||
function waitForTableAndSetImage() {
|
||||
const intervalId = setInterval(() => {
|
||||
let dataTables_scrollBody = document.getElementsByClassName('dataTables_scrollBody');
|
||||
if (dataTables_scrollBody.length > 0) {
|
||||
let dataTables_tbody = dataTables_scrollBody[0].getElementsByTagName('tbody')[0];
|
||||
let rows = dataTables_tbody.getElementsByTagName('tr');
|
||||
|
||||
if (rows.length > 0) {
|
||||
clearInterval(intervalId); // Zatrzymanie dalszego wykonywania setInterval
|
||||
setImageToProduct();
|
||||
}
|
||||
}
|
||||
}, 100); // Sprawdza co 100ms, można dostosować czas
|
||||
}
|
||||
|
||||
function attachTableReloadListener() {
|
||||
const table = document.querySelector('.dataTables_scrollBody table');
|
||||
if (table) {
|
||||
// Tworzymy obserwatora zmian w DOM
|
||||
const observer = new MutationObserver((mutationsList, observer) => {
|
||||
for (const mutation of mutationsList) {
|
||||
if (mutation.type === 'childList') {
|
||||
// Wykonaj kod po zmianie w tabeli (dodanie/usunięcie wierszy)
|
||||
console.log('Table content changed');
|
||||
waitForTableAndSetImage();
|
||||
break; // Zatrzymujemy iterację po pierwszej znalezionej zmianie
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Konfiguracja obserwatora do nasłuchiwania zmian w zawartości tabeli
|
||||
observer.observe(table.querySelector('tbody'), { childList: true });
|
||||
async function geocode(query) {
|
||||
const params = new URLSearchParams();
|
||||
if (isLatLng(query)) {
|
||||
const [lat, lng] = String(query).split(',').map(v => parseFloat(v.trim()));
|
||||
params.set('lat', lat);
|
||||
params.set('lng', lng);
|
||||
} else {
|
||||
params.set('q', query);
|
||||
}
|
||||
|
||||
const res = await fetch(API_URL + '?' + params.toString(), {
|
||||
method: 'GET',
|
||||
headers: { 'Accept': 'application/json' },
|
||||
cache: 'no-store',
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||
|
||||
const data = await res.json();
|
||||
if (data && data.error) throw new Error(data.error);
|
||||
if (!data || typeof data.lat !== 'number' || typeof data.lng !== 'number') {
|
||||
throw new Error('Nieprawidłowa odpowiedź API');
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function setImageToProduct(img = '') {
|
||||
let dataTables_scrollBody = document.getElementsByClassName('dataTables_scrollBody');
|
||||
if (dataTables_scrollBody.length > 0) {
|
||||
let dataTables_tbody = dataTables_scrollBody[0].getElementsByTagName('tbody')[0];
|
||||
let rows = dataTables_tbody.getElementsByTagName('tr');
|
||||
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
let cells = rows[i].getElementsByTagName('td');
|
||||
|
||||
if (cells.length > 1) {
|
||||
let secondCellText = cells[1].textContent.trim();
|
||||
let domain;
|
||||
|
||||
if (secondCellText.includes('marianek.pl')) {
|
||||
domain = 'marianek.pl';
|
||||
} else if (secondCellText.includes('pomysloweprezenty.pl')) {
|
||||
domain = 'pomysloweprezenty.pl';
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cells.length >= 5) {
|
||||
let fifthCell = cells[4];
|
||||
let divsInFifthCell = fifthCell.children;
|
||||
|
||||
for (let i = 0; i < divsInFifthCell.length; i++) {
|
||||
let currentDiv = divsInFifthCell[i];
|
||||
let imgDiv = currentDiv.getElementsByTagName('div')[0];
|
||||
let dataDiv = currentDiv.getElementsByTagName('div')[1];
|
||||
|
||||
if (dataDiv) {
|
||||
let skuText = dataDiv.innerHTML.match(/SKU:\s*([A-Za-z0-9-]+)/);
|
||||
|
||||
if (skuText && skuText[1]) {
|
||||
getProductData(skuText[1], domain).then(data => {
|
||||
if (!data) {
|
||||
console.log('Product not found:', skuText[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Product found:', skuText[1]);
|
||||
imgDiv.innerHTML = '';
|
||||
const imgElement = makeImg(data);
|
||||
imgDiv.appendChild(imgElement);
|
||||
|
||||
// Dodanie eventu na hover
|
||||
imgElement.addEventListener('mouseover', function() {
|
||||
showLargeImage(data, imgElement);
|
||||
});
|
||||
|
||||
imgElement.addEventListener('mouseout', function() {
|
||||
hideLargeImage();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function setStatus(text, type = '') {
|
||||
const el = $('#status');
|
||||
el.textContent = text || '';
|
||||
el.className = 'status ' + (type || '');
|
||||
}
|
||||
|
||||
function makeImg(src = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png') {
|
||||
const img = document.createElement('img');
|
||||
img.src = src;
|
||||
img.alt = 'image';
|
||||
img.className = 'img-fluid center-block';
|
||||
img.style.maxWidth = '48px';
|
||||
img.style.maxHeight = '48px';
|
||||
|
||||
return img;
|
||||
function renderResult(data) {
|
||||
$('#result').hidden = false;
|
||||
const pill = $('#from_cache');
|
||||
pill.textContent = data.from_cache ? 'cache' + (data.stale ? ' (stare)' : '') : 'google';
|
||||
pill.className = 'pill ' + (data.from_cache ? 'ok' : 'warn');
|
||||
$('#formatted_address').textContent = data.formatted_address || '\u2013';
|
||||
$('#lat').textContent = Number(data.lat).toFixed(6);
|
||||
$('#lng').textContent = Number(data.lng).toFixed(6);
|
||||
$('#place_id').textContent = data.place_id || '\u2013';
|
||||
$('#provider').textContent = data.provider || '\u2013';
|
||||
$('#raw').textContent = JSON.stringify(data, null, 2);
|
||||
}
|
||||
|
||||
function showLargeImage(src, imgElement) {
|
||||
const largeImg = document.createElement('img');
|
||||
largeImg.src = src;
|
||||
largeImg.style.position = 'absolute';
|
||||
largeImg.style.maxWidth = '400px';
|
||||
largeImg.style.maxHeight = '400px';
|
||||
largeImg.style.border = '1px solid #ccc';
|
||||
largeImg.style.background = '#fff';
|
||||
largeImg.style.zIndex = '1000';
|
||||
largeImg.style.top = imgElement.getBoundingClientRect().top + window.scrollY + 'px';
|
||||
largeImg.style.left = imgElement.getBoundingClientRect().left + imgElement.offsetWidth + 10 + 'px';
|
||||
largeImg.id = 'largeImagePreview';
|
||||
|
||||
document.body.appendChild(largeImg);
|
||||
function clearResult() {
|
||||
$('#result').hidden = true;
|
||||
$('#raw').textContent = '';
|
||||
$('#formatted_address').textContent = '';
|
||||
$('#lat').textContent = '';
|
||||
$('#lng').textContent = '';
|
||||
$('#place_id').textContent = '';
|
||||
$('#provider').textContent = '';
|
||||
$('#from_cache').textContent = '';
|
||||
}
|
||||
|
||||
function hideLargeImage() {
|
||||
const largeImg = document.getElementById('largeImagePreview');
|
||||
if (largeImg) {
|
||||
largeImg.remove();
|
||||
}
|
||||
}
|
||||
$('#geo-form').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const btn = $('#submit');
|
||||
const q = $('#query').value.trim();
|
||||
if (!q) return;
|
||||
|
||||
async function getProductData(sku, domain) {
|
||||
let url;
|
||||
if (domain === 'marianek.pl') {
|
||||
url = `https://marianek.pl/api/v1/product.php?sku=${sku}`;
|
||||
} else if (domain === 'pomysloweprezenty.pl') {
|
||||
url = `https://pomysloweprezenty.pl/api/v1/product.php?sku=${sku}`;
|
||||
} else {
|
||||
console.error('Unsupported domain:', domain);
|
||||
return null;
|
||||
}
|
||||
clearResult();
|
||||
setStatus('Szukam\u2026', '');
|
||||
btn.disabled = true;
|
||||
try {
|
||||
const data = await geocode(q);
|
||||
renderResult(data);
|
||||
setStatus(data.from_cache ? 'Trafienie w cache \u2013 szybko i tanio \u26A1' : 'Świeży wynik z Google \u2013 zapisano do cache', data.from_cache ? 'ok' : 'warn');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
setStatus('Błąd: ' + (err?.message || err), 'err');
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
$('#clear').addEventListener('click', () => {
|
||||
$('#query').value = '';
|
||||
clearResult();
|
||||
setStatus('');
|
||||
$('#query').focus();
|
||||
});
|
||||
|
||||
const data = await response.json(); console.log(data);
|
||||
return data.img;
|
||||
} catch (error) {
|
||||
console.error('Error fetching product data: ' + url, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$$('.examples a').forEach(a => a.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
const q = e.currentTarget.getAttribute('data-q');
|
||||
$('#query').value = q;
|
||||
$('#geo-form').dispatchEvent(new Event('submit'));
|
||||
}));
|
||||
|
||||
const currentUrl = window.location.href;
|
||||
const pattern = /^https:\/\/projectpro\.apilo\.com\/warehouse\/shipment\/new-for-order\/.+/;
|
||||
|
||||
if (pattern.test(currentUrl)) {
|
||||
const portletBody = document.querySelector('.kt-portlet__body');
|
||||
if (portletBody) {
|
||||
const buttonContainer = document.createElement('div');
|
||||
buttonContainer.className = 'custom-button-container';
|
||||
buttonContainer.style.display = 'flex';
|
||||
buttonContainer.style.gap = '10px';
|
||||
buttonContainer.style.marginBottom = '15px';
|
||||
portletBody.parentNode.insertBefore(buttonContainer, portletBody);
|
||||
|
||||
const buttonP2D = createButton('Inpost P2D', '#007bff', 'P2D.inpost', 'RZE14N||RZE14N');
|
||||
const buttonD2D = createButton('Inpost D2D', '#ff7800', 'D2D.inpostkurier');
|
||||
const buttonD2P = createButton('Inpost D2P', '#28a745', 'D2P.inpost');
|
||||
const buttonP2P = createButton('Inpost P2P', '#ffc107', 'P2P.inpost', 'RZE14N||RZE14N');
|
||||
|
||||
buttonContainer.appendChild(buttonP2D);
|
||||
buttonContainer.appendChild(buttonD2D);
|
||||
buttonContainer.appendChild(buttonD2P);
|
||||
buttonContainer.appendChild(buttonP2P);
|
||||
}
|
||||
}
|
||||
|
||||
function createButton(text, backgroundColor, method, dropoffPoint = null) {
|
||||
const button = document.createElement('button');
|
||||
button.textContent = text;
|
||||
button.style.background = backgroundColor;
|
||||
button.style.display = 'inline-flex';
|
||||
button.style.width = '200px';
|
||||
button.style.height = '40px';
|
||||
button.style.alignItems = 'center';
|
||||
button.style.justifyContent = 'center';
|
||||
button.style.color = '#FFF';
|
||||
button.style.border = 'none';
|
||||
button.style.cursor = 'pointer';
|
||||
|
||||
button.addEventListener('click', () => handleShipment(method, dropoffPoint));
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
async function handleShipment(method, dropoffPoint = null) {
|
||||
try {
|
||||
await selectPackageType();
|
||||
await setShipmentMethod(method);
|
||||
if (dropoffPoint) {
|
||||
await setDropoffPoint(dropoffPoint);
|
||||
}
|
||||
await setParcelWeight('1');
|
||||
await submitShipment();
|
||||
} catch (error) {
|
||||
console.error('Wystąpił błąd: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
function retryUntilSuccess(fn, interval = 500, retries = 10) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const attempt = async () => {
|
||||
try {
|
||||
const result = await fn();
|
||||
resolve(result);
|
||||
} catch (err) {
|
||||
if (retries === 0) {
|
||||
reject(err);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
retries--;
|
||||
attempt();
|
||||
}, interval);
|
||||
}
|
||||
}
|
||||
};
|
||||
attempt();
|
||||
});
|
||||
}
|
||||
|
||||
function selectPackageType() {
|
||||
return retryUntilSuccess(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const selectElement = document.getElementById('warehousebundle_shipment_packageType');
|
||||
if (selectElement) {
|
||||
selectElement.value = 'package';
|
||||
const event = document.createEvent('HTMLEvents');
|
||||
event.initEvent('change', true, false);
|
||||
selectElement.dispatchEvent(event);
|
||||
resolve();
|
||||
} else {
|
||||
reject('Nie znaleziono elementu packageType');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function setShipmentMethod(method) {
|
||||
return retryUntilSuccess(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const methodElement = document.getElementById('warehousebundle_shipment_method');
|
||||
if (methodElement) {
|
||||
methodElement.value = method;
|
||||
const methodEvent = document.createEvent('HTMLEvents');
|
||||
methodEvent.initEvent('change', true, false);
|
||||
methodElement.dispatchEvent(methodEvent);
|
||||
resolve();
|
||||
} else {
|
||||
reject('Nie znaleziono elementu shipment_method');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function setDropoffPoint(dropoffPoint) {
|
||||
return retryUntilSuccess(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const dropoffPointElement = document.getElementById('warehousebundle_shipment_preferences_dropoffPoint');
|
||||
if (dropoffPointElement) {
|
||||
dropoffPointElement.value = dropoffPoint;
|
||||
const dropoffPointEvent = document.createEvent('HTMLEvents');
|
||||
dropoffPointEvent.initEvent('change', true, false);
|
||||
dropoffPointElement.dispatchEvent(dropoffPointEvent);
|
||||
resolve();
|
||||
} else {
|
||||
reject('Nie znaleziono elementu dropoffPoint');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function setParcelWeight(weight) {
|
||||
return retryUntilSuccess(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const weightElement = document.getElementById('warehousebundle_shipment_shipmentParcels_0_weight');
|
||||
if (weightElement) {
|
||||
weightElement.value = weight;
|
||||
const weightEvent = document.createEvent('HTMLEvents');
|
||||
weightEvent.initEvent('change', true, false);
|
||||
weightElement.dispatchEvent(weightEvent);
|
||||
resolve();
|
||||
} else {
|
||||
reject('Nie znaleziono elementu shipmentParcels_0_weight');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function submitShipment() {
|
||||
return retryUntilSuccess(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const submitButton = document.getElementById('warehousebundle_shipment_buttons_submit');
|
||||
if (submitButton) {
|
||||
submitButton.click();
|
||||
resolve();
|
||||
} else {
|
||||
reject('Nie znaleziono przycisku submit');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
// autofocus
|
||||
$('#query').focus();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user