feat: Add IntegrationRepository and ShopProClient for managing integrations and fetching products from shopPRO API
This commit is contained in:
230
resources/modules/jquery-alerts/jquery-alerts.js
vendored
230
resources/modules/jquery-alerts/jquery-alerts.js
vendored
@@ -1,17 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
(function (factory) {
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = factory;
|
||||
if (typeof module === "object" && module.exports && typeof window === "undefined") {
|
||||
module.exports = factory(null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof window.jQuery !== "undefined") {
|
||||
factory(window.jQuery);
|
||||
}
|
||||
})(function ($) {
|
||||
if (!$ || !$.fn) {
|
||||
return;
|
||||
var win = typeof window !== "undefined" ? window : null;
|
||||
var $ = win && typeof win.jQuery !== "undefined" ? win.jQuery : null;
|
||||
factory($, win);
|
||||
})(function ($, win) {
|
||||
if (!win || !win.document) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const DEFAULTS = {
|
||||
@@ -21,52 +21,190 @@
|
||||
classPrefix: "jq-alert",
|
||||
};
|
||||
|
||||
function removeAlert($el) {
|
||||
$el.removeClass("is-visible");
|
||||
window.setTimeout(function () {
|
||||
$el.remove();
|
||||
function removeAlert(el) {
|
||||
if (!el) {
|
||||
return;
|
||||
}
|
||||
el.classList.remove("is-visible");
|
||||
win.setTimeout(function () {
|
||||
if (el.parentNode) {
|
||||
el.parentNode.removeChild(el);
|
||||
}
|
||||
}, 180);
|
||||
}
|
||||
|
||||
$.fn.orderProAlert = function (options) {
|
||||
const settings = $.extend({}, DEFAULTS, options);
|
||||
function createElement(tag, className) {
|
||||
var el = win.document.createElement(tag);
|
||||
if (className) {
|
||||
el.className = className;
|
||||
}
|
||||
return el;
|
||||
}
|
||||
|
||||
return this.each(function () {
|
||||
const $host = $(this);
|
||||
const $alert = $("<div>", {
|
||||
class: settings.classPrefix + " " + settings.classPrefix + "--" + settings.type + " is-visible",
|
||||
role: "alert",
|
||||
function getGlobalHost() {
|
||||
var id = "jq-alert-host";
|
||||
var existing = win.document.getElementById(id);
|
||||
if (existing) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
var host = createElement("div", "jq-alert-host");
|
||||
host.id = id;
|
||||
win.document.body.appendChild(host);
|
||||
return host;
|
||||
}
|
||||
|
||||
function renderAlert(host, options) {
|
||||
var settings = Object.assign({}, DEFAULTS, options || {});
|
||||
var alertEl = createElement(
|
||||
"div",
|
||||
settings.classPrefix + " " + settings.classPrefix + "--" + settings.type + " is-visible"
|
||||
);
|
||||
alertEl.setAttribute("role", "alert");
|
||||
|
||||
var content = createElement("div", settings.classPrefix + "__content");
|
||||
content.textContent = String(settings.message || "");
|
||||
alertEl.appendChild(content);
|
||||
|
||||
if (settings.dismissible) {
|
||||
var close = createElement("button", settings.classPrefix + "__close");
|
||||
close.type = "button";
|
||||
close.setAttribute("aria-label", "Close alert");
|
||||
close.textContent = "x";
|
||||
close.addEventListener("click", function () {
|
||||
removeAlert(alertEl);
|
||||
});
|
||||
alertEl.appendChild(close);
|
||||
}
|
||||
|
||||
const $content = $("<div>", {
|
||||
class: settings.classPrefix + "__content",
|
||||
text: String(settings.message || ""),
|
||||
host.appendChild(alertEl);
|
||||
|
||||
if (settings.timeout > 0) {
|
||||
win.setTimeout(function () {
|
||||
removeAlert(alertEl);
|
||||
}, settings.timeout);
|
||||
}
|
||||
|
||||
return alertEl;
|
||||
}
|
||||
|
||||
function show(options) {
|
||||
return renderAlert(getGlobalHost(), options);
|
||||
}
|
||||
|
||||
function closeConfirm(backdrop, resolve, value) {
|
||||
if (!backdrop || backdrop.getAttribute("data-closed") === "1") {
|
||||
return;
|
||||
}
|
||||
backdrop.setAttribute("data-closed", "1");
|
||||
backdrop.classList.remove("is-visible");
|
||||
win.setTimeout(function () {
|
||||
if (backdrop.parentNode) {
|
||||
backdrop.parentNode.removeChild(backdrop);
|
||||
}
|
||||
resolve(value);
|
||||
}, 180);
|
||||
}
|
||||
|
||||
function confirm(options) {
|
||||
var settings = Object.assign(
|
||||
{
|
||||
title: "Potwierdzenie",
|
||||
message: "",
|
||||
confirmLabel: "Potwierdz",
|
||||
cancelLabel: "Anuluj",
|
||||
danger: false,
|
||||
},
|
||||
options || {}
|
||||
);
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
var backdrop = createElement("div", "jq-alert-modal-backdrop is-visible");
|
||||
var modal = createElement("div", "jq-alert-modal");
|
||||
modal.setAttribute("role", "dialog");
|
||||
modal.setAttribute("aria-modal", "true");
|
||||
|
||||
var titleId = "jq-alert-modal-title-" + Date.now();
|
||||
modal.setAttribute("aria-labelledby", titleId);
|
||||
|
||||
var header = createElement("div", "jq-alert-modal__header");
|
||||
var title = createElement("h3");
|
||||
title.id = titleId;
|
||||
title.textContent = String(settings.title || "");
|
||||
header.appendChild(title);
|
||||
|
||||
var body = createElement("div", "jq-alert-modal__body");
|
||||
body.textContent = String(settings.message || "");
|
||||
|
||||
var footer = createElement("div", "jq-alert-modal__footer");
|
||||
var cancelButton = createElement("button", "btn btn--secondary");
|
||||
cancelButton.type = "button";
|
||||
cancelButton.textContent = String(settings.cancelLabel || "Anuluj");
|
||||
var confirmButton = createElement(
|
||||
"button",
|
||||
settings.danger ? "btn btn--danger" : "btn btn--primary"
|
||||
);
|
||||
confirmButton.type = "button";
|
||||
confirmButton.textContent = String(settings.confirmLabel || "Potwierdz");
|
||||
footer.appendChild(cancelButton);
|
||||
footer.appendChild(confirmButton);
|
||||
|
||||
modal.appendChild(header);
|
||||
modal.appendChild(body);
|
||||
modal.appendChild(footer);
|
||||
backdrop.appendChild(modal);
|
||||
win.document.body.appendChild(backdrop);
|
||||
|
||||
var onKeyDown = function (event) {
|
||||
if (event.key === "Escape") {
|
||||
onCancel();
|
||||
}
|
||||
};
|
||||
var cleanup = function () {
|
||||
win.document.removeEventListener("keydown", onKeyDown);
|
||||
};
|
||||
|
||||
var onConfirm = function () {
|
||||
cleanup();
|
||||
if (typeof settings.onConfirm === "function") {
|
||||
settings.onConfirm();
|
||||
}
|
||||
closeConfirm(backdrop, resolve, true);
|
||||
};
|
||||
var onCancel = function () {
|
||||
cleanup();
|
||||
if (typeof settings.onCancel === "function") {
|
||||
settings.onCancel();
|
||||
}
|
||||
closeConfirm(backdrop, resolve, false);
|
||||
};
|
||||
|
||||
confirmButton.addEventListener("click", onConfirm);
|
||||
cancelButton.addEventListener("click", onCancel);
|
||||
backdrop.addEventListener("click", function (event) {
|
||||
if (event.target === backdrop) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
win.document.addEventListener("keydown", onKeyDown);
|
||||
|
||||
$alert.append($content);
|
||||
|
||||
if (settings.dismissible) {
|
||||
const $close = $("<button>", {
|
||||
class: settings.classPrefix + "__close",
|
||||
type: "button",
|
||||
"aria-label": "Close alert",
|
||||
text: "x",
|
||||
});
|
||||
|
||||
$close.on("click", function () {
|
||||
removeAlert($alert);
|
||||
});
|
||||
|
||||
$alert.append($close);
|
||||
}
|
||||
|
||||
$host.append($alert);
|
||||
|
||||
if (settings.timeout > 0) {
|
||||
window.setTimeout(function () {
|
||||
removeAlert($alert);
|
||||
}, settings.timeout);
|
||||
}
|
||||
confirmButton.focus();
|
||||
});
|
||||
}
|
||||
|
||||
win.OrderProAlerts = {
|
||||
show: show,
|
||||
confirm: confirm,
|
||||
};
|
||||
|
||||
if ($ && $.fn) {
|
||||
$.fn.orderProAlert = function (options) {
|
||||
var settings = $.extend({}, DEFAULTS, options);
|
||||
return this.each(function () {
|
||||
renderAlert(this, settings);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return win.OrderProAlerts;
|
||||
});
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
.jq-alert-host {
|
||||
position: fixed;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
z-index: 300;
|
||||
width: min(420px, calc(100vw - 32px));
|
||||
}
|
||||
|
||||
.jq-alert {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -56,3 +64,52 @@
|
||||
color: inherit;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.jq-alert-modal-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 310;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 16px;
|
||||
background: rgba(15, 23, 42, 0.5);
|
||||
opacity: 0;
|
||||
transition: opacity 0.18s ease;
|
||||
}
|
||||
|
||||
.jq-alert-modal-backdrop.is-visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.jq-alert-modal {
|
||||
width: min(520px, 100%);
|
||||
border-radius: 10px;
|
||||
border: 1px solid #dbe3ee;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 18px 42px rgba(15, 23, 42, 0.3);
|
||||
}
|
||||
|
||||
.jq-alert-modal__header {
|
||||
padding: 14px 16px;
|
||||
border-bottom: 1px solid #e2e8f0;
|
||||
}
|
||||
|
||||
.jq-alert-modal__header h3 {
|
||||
margin: 0;
|
||||
color: #2d3748;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.jq-alert-modal__body {
|
||||
padding: 14px 16px;
|
||||
color: #4e5e6a;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.jq-alert-modal__footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
padding: 0 16px 14px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user