2024-07-24 09:43:31 +02:00
|
|
|
(function() {
|
|
|
|
|
"use strict";
|
|
|
|
|
function normalizeComponent(scriptExports, render, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
|
|
|
|
|
var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
|
|
|
|
|
if (render) {
|
|
|
|
|
options.render = render;
|
|
|
|
|
options.staticRenderFns = staticRenderFns;
|
|
|
|
|
options._compiled = true;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
options._scopeId = "data-v-" + scopeId;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
exports: scriptExports,
|
|
|
|
|
options
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
const _sfc_main = {
|
2024-07-24 15:03:04 +02:00
|
|
|
__name: "MapadoCheckButton",
|
2024-07-24 09:43:31 +02:00
|
|
|
props: {
|
|
|
|
|
mapadoToken: String
|
|
|
|
|
},
|
|
|
|
|
setup(__props) {
|
|
|
|
|
const { mapadoToken } = __props;
|
|
|
|
|
const id = Vue.ref(null);
|
|
|
|
|
const icon = Vue.ref("search");
|
|
|
|
|
const theme = Vue.ref(null);
|
|
|
|
|
const text = Vue.ref("Vérifie si Mapado contient bien un événement correspondant.");
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
const idInput = document.querySelector(".k-field-name-mapadoid input");
|
|
|
|
|
id.value = idInput.value;
|
|
|
|
|
idInput.addEventListener("input", () => {
|
|
|
|
|
id.value = idInput.value;
|
|
|
|
|
});
|
|
|
|
|
}, 100);
|
2024-07-24 15:03:04 +02:00
|
|
|
function formatDateString(inputString) {
|
|
|
|
|
const splitString = inputString.split(" ");
|
|
|
|
|
const startDay = splitString[2];
|
|
|
|
|
const startMonth = splitString[3];
|
|
|
|
|
const startYear = splitString[4];
|
|
|
|
|
const endDay = splitString[9];
|
|
|
|
|
const endMonth = splitString[10];
|
|
|
|
|
const endYear = splitString[11];
|
|
|
|
|
const formattedString = `du ${startDay} ${startMonth} ${startYear} au ${endDay} ${endMonth} ${endYear}`;
|
|
|
|
|
return formattedString;
|
|
|
|
|
}
|
2024-07-24 09:43:31 +02:00
|
|
|
function connect() {
|
|
|
|
|
icon.value = "loader";
|
|
|
|
|
theme.value = "yellow";
|
|
|
|
|
const myHeaders = new Headers();
|
|
|
|
|
myHeaders.append("Authorization", "Bearer " + mapadoToken);
|
|
|
|
|
const requestOptions = {
|
|
|
|
|
method: "GET",
|
|
|
|
|
headers: myHeaders,
|
|
|
|
|
redirect: "follow"
|
|
|
|
|
};
|
|
|
|
|
fetch(
|
2024-07-29 08:57:35 +02:00
|
|
|
"https://ticketing.mapado.net/v1/ticketings/" + id.value + "?fields=id,title,slug,sellingDeviceSchedule",
|
2024-07-24 09:43:31 +02:00
|
|
|
requestOptions
|
|
|
|
|
).then((response) => {
|
|
|
|
|
console.log(response);
|
|
|
|
|
if (response.status === 404) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
"Aucun événement ne correspond à l'identifiant : " + id.value + "."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (response.status === 500) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
"Impossible de joindre le serveur Mapado. Veuillez réessayer plus tard."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return response.json();
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
icon.value = "check";
|
|
|
|
|
theme.value = "green";
|
2024-07-24 15:03:04 +02:00
|
|
|
const scheduleFirstKey = Object.keys(result.sellingDeviceSchedule)[0];
|
|
|
|
|
const schedule = formatDateString(
|
|
|
|
|
result.sellingDeviceSchedule[scheduleFirstKey].fr.toLowerCase()
|
|
|
|
|
);
|
2024-07-24 09:43:31 +02:00
|
|
|
console.log(result);
|
2024-07-29 08:57:35 +02:00
|
|
|
text.value = `<strong>Événement correspondant sur Mapado : <em>${result.title}</em>, ${schedule}</strong> (<a href="https://desk.mapado.com/mass-action/ticketing/${id.value}" target="_blank">gérer sur Mapado.</a>).`;
|
2024-07-24 09:43:31 +02:00
|
|
|
}).catch((error) => {
|
|
|
|
|
icon.value = "alert";
|
|
|
|
|
theme.value = "red";
|
|
|
|
|
text.value = "<strong>" + error + "</strong>";
|
|
|
|
|
console.log(error);
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
icon.value = "search";
|
|
|
|
|
theme.value = null;
|
|
|
|
|
}, 2e3);
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-07-24 15:03:04 +02:00
|
|
|
return { __sfc: true, id, icon, theme, text, formatDateString, connect };
|
2024-07-24 09:43:31 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var _sfc_render = function render() {
|
|
|
|
|
var _vm = this, _c = _vm._self._c, _setup = _vm._self._setupProxy;
|
|
|
|
|
return _c("div", { staticClass: "k-number-field k-field k-field-name-mapadoid" }, [_c("k-button", { attrs: { "variant": "filled", "theme": _setup.theme, "icon": _setup.icon }, on: { "click": _setup.connect } }, [_vm._v("Vérifier")]), _c("footer", { staticClass: "k-field-footer" }, [_c("div", { staticClass: "k-help k-field-help k-text" }, [_c("p", { domProps: { "innerHTML": _vm._s(_setup.text) } })])])], 1);
|
|
|
|
|
};
|
|
|
|
|
var _sfc_staticRenderFns = [];
|
|
|
|
|
_sfc_render._withStripped = true;
|
|
|
|
|
var __component__ = /* @__PURE__ */ normalizeComponent(
|
|
|
|
|
_sfc_main,
|
|
|
|
|
_sfc_render,
|
|
|
|
|
_sfc_staticRenderFns,
|
|
|
|
|
false,
|
|
|
|
|
null,
|
2024-07-24 15:03:04 +02:00
|
|
|
"402405a5"
|
2024-07-24 09:43:31 +02:00
|
|
|
);
|
2024-07-24 15:03:04 +02:00
|
|
|
__component__.options.__file = "/Users/adrienpayet/code/ntb/site/plugins/mapado-check/src/components/MapadoCheckButton.vue";
|
|
|
|
|
const MapadoCheckButton = __component__.exports;
|
|
|
|
|
window.panel.plugin("adrienpayet/mapado-check", {
|
2024-07-24 09:43:31 +02:00
|
|
|
fields: {
|
2024-07-24 15:03:04 +02:00
|
|
|
"mapado-check": MapadoCheckButton
|
2024-07-24 09:43:31 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})();
|