UNPKG

@dbp-topics/sublibrary

Version:

[GitLab Repository](https://github.com/digital-blueprint/sublibrary-app) | [npmjs package](https://www.npmjs.com/package/@dbp-topics/sublibrary) | [Unpkg CDN](https://unpkg.com/browse/@dbp-topics/sublibrary/) | [Sublibrary Bundle](https://gitlab.tugraz.at

345 lines (337 loc) 12.1 kB
let _ = t => t, _t, _t2; function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } /*! * License: LGPL-2.1-or-later * Dependencies: * * @dbp-toolkit/common: LGPL-2.1-or-later * jquery: MIT * select2: MIT * @dbp-toolkit/resource-select: LGPL-2.1-or-later * @babel/runtime: MIT * i18next: MIT * @lit/reactive-element: BSD-3-Clause * lit-html: BSD-3-Clause * lit-element: BSD-3-Clause * @open-wc/dedupe-mixin: MIT * @open-wc/scoped-elements: MIT * datatables.net: MIT * datatables.net-responsive: MIT * datatables.net-responsive-dt: MIT * datatables.net-dt: MIT * jszip: (MIT OR GPL-3.0-or-later) * datatables.net-buttons-dt: MIT * datatables.net-buttons: MIT * @dbp-toolkit/data-table-view: LGPL-2.1-or-later * @dbp-toolkit/person-select: LGPL-2.1-or-later */ import { s as e, j as t, c as s, b as n } from "./library-select.cb305ad9.es.js"; import { f as i } from "./utils.287bbaa6.es.js"; import { J as l } from "./jsonld.3c83677b.es.js"; import { S as r, A as o, m as a, I as c, q as u, i as d, g as h, a as b, l as m, t as p, c as g, d as f, y as v } from "./_commonjsHelpers.01af1198.es.js"; e(window, t); class y extends r(o) { constructor() { super(), this._i18n = s(), this.lang = this._i18n.language, this.auth = {}, this.entryPointUrl = "", this.jsonld = null, this.$select = null, this.selectId = "book-offer-select-" + a(24), this.value = "", this.object = null, this.ignoreValueUpdate = !1, this.lastResult = {}, this.showReloadButton = !1, this.reloadButtonTitle = "", this.sublibraryIri = "", this._onDocumentClicked = this._onDocumentClicked.bind(this); } static get scopedElements() { return { "dbp-icon": c }; } $(e) { return t(this.shadowRoot.querySelector(e)); } static get properties() { return _extends({}, super.properties, { lang: { type: String }, entryPointUrl: { type: String, attribute: "entry-point-url" }, value: { type: String }, object: { type: Object, attribute: !1 }, showReloadButton: { type: Boolean, attribute: "show-reload-button" }, reloadButtonTitle: { type: String, attribute: "reload-button-title" }, sublibraryIri: { type: String, attribute: "sublibrary-iri" }, auth: { type: Object } }); } close() { this.$select.select2("close"); } clear() { this.object = null, t(this).attr("data-object", ""), t(this).data("object", null), this.$select.val(null).trigger("change").trigger("select2:unselect"); } connectedCallback() { super.connectedCallback(), document.addEventListener("click", this._onDocumentClicked), this.updateComplete.then(() => { this.$select = this.$("#" + this.selectId), this.$select.disabled = !0, this.initJSONLD(); }); } disconnectedCallback() { document.removeEventListener("click", this._onDocumentClicked), super.disconnectedCallback(); } _onDocumentClicked(e) { if (!e.composedPath().includes(this)) { const _e = this.$("#" + this.selectId); _e.length && this.select2IsInitialized(_e) && _e.select2("close"); } } initJSONLD(e = !1) { const t = this; l.getInstance(this.entryPointUrl).then(function (s) { t.jsonld = s, u(() => t.initSelect2(e), 1e4, 100); }, {}, this.lang); } isInt(e) { return !isNaN(e) && (0 | (t = parseFloat(e))) === t; var t; } initSelect2(e = !1) { const s = this, n = t(this); if (null === this.jsonld) return !1; const l = this.jsonld.getApiUrlForEntityName("LibraryBookOffer"), r = { id: "@id", text: "http://schema.org/name" }; if (null === this.$select) return !1; if (this.$select.hasClass("select2-hidden-accessible") && (this.$select.select2("destroy"), this.$select.off("select2:select"), this.$select.off("select2:unselect")), this.$select.select2({ width: "100%", language: "de" === this.lang ? { errorLoading: function () { return "Die Ergebnisse konnten nicht geladen werden."; }, inputTooLong: function (e) { return "Bitte " + (e.input.length - e.maximum) + " Zeichen weniger eingeben"; }, inputTooShort: function (e) { return "Es kann nur nach vollständigen Barcodes gesucht werden, bitte " + (e.minimum - e.input.length) + " Zeichen mehr eingeben"; }, loadingMore: function () { return "Lade mehr Ergebnisse…"; }, maximumSelected: function (e) { var t = "Sie können nur " + e.maximum + " Eintr"; return 1 === e.maximum ? t += "ag" : t += "äge", t += " auswählen"; }, noResults: function () { return "Keine Übereinstimmungen gefunden"; }, searching: function () { return "Suche…"; }, removeAllItems: function () { return "Entferne alle Gegenstände"; } } : { errorLoading: function () { return "The results could not be loaded."; }, inputTooLong: function (e) { var t = e.input.length - e.maximum, s = "Please delete " + t + " character"; return 1 != t && (s += "s"), s; }, inputTooShort: function (e) { return "You can only search for complete barcodes, please enter " + (e.minimum - e.input.length) + " or more characters"; }, loadingMore: function () { return "Loading more results…"; }, maximumSelected: function (e) { var t = "You can only select " + e.maximum + " item"; return 1 != e.maximum && (t += "s"), t; }, noResults: function () { return "No results found"; }, searching: function () { return "Searching…"; }, removeAllItems: function () { return "Remove all items"; } }, minimumInputLength: 3, allowClear: !0, placeholder: this._i18n.t("library-book-offer-select.placeholder"), dropdownParent: this.$("#library-book-offer-select-dropdown"), ajax: { delay: 250, url: l, contentType: "application/ld+json", beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + s.auth.token); }, data: function (e) { let t = e.term.trim(); return s.isInt(t) || "+" === t.substr(0, 1) || "@" === t.substr(0, 1) || (t = "+" + t), { barcode: t, sublibrary: s.sublibraryIri.split("/").slice(-1)[0] }; }, processResults: function (e) { s.$("#library-book-offer-select-dropdown").addClass("select2-bug"), s.lastResult = e; return { results: s.jsonld.transformMembers(e, r) }; }, error: (e, t, n) => { s.handleXhrError(e, t, n); } } }).on("select2:select", function (e) { s.$("#library-book-offer-select-dropdown").removeClass("select2-bug"); const t = e.params.data.id; s.object = i(t, s.lastResult), void 0 !== s.object && (n.attr("data-object", JSON.stringify(s.object)), n.data("object", s.object), n.attr("value") !== t && (s.ignoreValueUpdate = !0, n.attr("value", t), s.value = t, s.dispatchEvent(new CustomEvent("change", { detail: { value: t } })))); }).on("select2:unselect", function (e) { s.object = null, n.attr("data-object", ""), n.data("object", {}), s.ignoreValueUpdate = !0, n.attr("value", ""), s.value = "", s.dispatchEvent(new CustomEvent("unselect")); }), !e && "" !== this.value && "null" !== this.value) { const _e2 = this.entryPointUrl + this.value; fetch(_e2, { headers: { "Content-Type": "application/ld+json", Authorization: "Bearer " + s.auth.token } }).then(e => { if (!e.ok) throw e; return e.json(); }).then(e => { s.object = e; const t = e["@id"], i = new Option(e.name, t, !0, !0); n.attr("data-object", JSON.stringify(e)), n.data("object", e), s.$select.val(null).append(i).trigger("change"), s.dispatchEvent(new CustomEvent("change", { detail: { value: t }, bubbles: !0 })); }).catch(() => { s.clear(); }); } return !0; } update(e) { e.forEach((e, t) => { switch (t) { case "lang": this._i18n.changeLanguage(this.lang), this.select2IsInitialized() && this.initSelect2(!0); break; case "sublibraryIri": this.sublibraryIri || (this.sublibraryIri = ""), this.$select && (this.$select.enable = this.sublibraryIri.includes("-")); break; case "value": !this.ignoreValueUpdate && this.select2IsInitialized() && this.initSelect2(), this.ignoreValueUpdate = !1; break; case "entryPointUrl": this.initJSONLD(!0); } }), super.update(e); } select2IsInitialized() { return null !== this.$select && this.$select.hasClass("select2-hidden-accessible"); } reloadClick() { null !== this.object && this.dispatchEvent(new CustomEvent("change", { detail: { value: this.value }, bubbles: !0 })); } static get styles() { return d(_t || (_t = _` ${0} ${0} ${0} ${0} ${0} .select2-control.control { width: 100%; } .select select { height: 2em; } .field .button.control { display: flex; align-items: center; justify-content: center; border: 1px solid var(--dbp-override-muted); -moz-border-radius-topright: var(--dbp-border-radius); -moz-border-radius-bottomright: var(--dbp-border-radius); line-height: 100%; } .field:not(:last-child) { margin-bottom: 0; } .field .button.control dbp-icon { top: 0; } /* https://github.com/select2/select2/issues/5457 */ .select2-bug .loading-results { display: none !important; } `), h(), b(), m(), p(), g()); } render() { const e = f(n); return v(_t2 || (_t2 = _` <link rel="stylesheet" href="${0}" /> <style> #${0} { width: 100%; } li.select2-selection__choice { white-space: normal; } </style> <div class="select"> <div class="field has-addons"> <div class="select2-control control"> <!-- https://select2.org--> <select id="${0}" name="book-offer" class="select"></select> </div> <a class="control button" id="reload-button" ?disabled=${0} @click="${0}" style="display: ${0}" title="${0}"> <dbp-icon name="reload"></dbp-icon> </a> </div> <div id="library-book-offer-select-dropdown"></div> </div> `), e, this.selectId, this.selectId, null === this.object, this.reloadClick, this.showReloadButton ? "flex" : "none", this.reloadButtonTitle); } } export { y as L }; //# sourceMappingURL=library-book-offer-select.7fc31707.es.js.map