UNPKG

@digital-blueprint/sublibrary-app

Version:

[GitHub Repository](https://github.com/digital-blueprint/sublibrary-app) | [npmjs package](https://www.npmjs.com/package/@digital-blueprint/sublibrary-app) | [Unpkg CDN](https://unpkg.com/browse/@digital-blueprint/sublibrary-app/) | [Sublibrary Bundle](ht

493 lines (485 loc) 18.4 kB
let _ = t => t, _t, _t2; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } /*! * License: LGPL-2.1-or-later * Dependencies: * * @webcomponents/scoped-custom-element-registry: BSD-3-Clause * @dbp-toolkit/app-shell: LGPL-2.1-or-later * @dbp-toolkit/language-select: LGPL-2.1-or-later * @dbp-toolkit/common: LGPL-2.1-or-later * @dbp-toolkit/auth: LGPL-2.1-or-later * @dbp-toolkit/notification: LGPL-2.1-or-later * @dbp-toolkit/theme-switcher: LGPL-2.1-or-later * path-to-regexp: MIT * universal-router: MIT * generateUrls: MIT * @dbp-toolkit/matomo: LGPL-2.1-or-later * @dbp-toolkit/person-select: LGPL-2.1-or-later * 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 * xtend: MIT * fuzzy: (MIT) * suggestions: ISC */ import { L as t, c as e, a as i, $ as n } from "./shared/library-select.Cpz1ozX8.es.js"; import { w as s, S as r, B as o, M as a, s as l, i as h, g as d, b as c, d as u, p, x as f, e as b, k as g } from "./shared/notification.BYDDIHux.es.js"; import { L as y } from "./shared/library-book-offer-select.D75H9YDl.es.js"; import { R as m } from "./shared/reload-button.CDzxUV-T.es.js"; import "./shared/utils.BB2hXqy_.es.js"; import "./shared/utils.C137cI6N.es.js"; var v, k; var w, I, L, E, O, $, C, x = { exports: {} }; function j() { return w || (w = 1, t = x, function () { var e = {}; t.exports = e, e.simpleFilter = function (t, i) { return i.filter(function (i) { return e.test(t, i); }); }, e.test = function (t, i) { return null !== e.match(t, i); }, e.match = function (t, e, i) { i = i || {}; var n, s = 0, r = [], o = e.length, a = 0, l = 0, h = i.pre || "", d = i.post || "", c = i.caseSensitive && e || e.toLowerCase(); t = i.caseSensitive && t || t.toLowerCase(); for (var u = 0; u < o; u++) n = e[u], c[u] === t[s] ? (n = h + n + d, s += 1, l += 1 + l) : l = 0, a += l, r[r.length] = n; return s === t.length ? (a = c === t ? 1 / 0 : a, { rendered: r.join(""), score: a }) : null; }, e.filter = function (t, i, n) { return i && 0 !== i.length ? "string" != typeof t ? i : (n = n || {}, i.reduce(function (i, s, r, o) { var a = s; n.extract && (a = n.extract(s)); var l = e.match(t, a, n); return null != l && (i[i.length] = { string: l.rendered, score: l.score, index: r, original: s }), i; }, []).sort(function (t, e) { var i = e.score - t.score; return i || t.index - e.index; })) : []; }; }()), x.exports; var t; } function S() { if (O) return E; O = 1; var t = function () { if (k) return v; k = 1, v = function () { for (var e = {}, i = 0; i < arguments.length; i++) { var n = arguments[i]; for (var s in n) t.call(n, s) && (e[s] = n[s]); } return e; }; var t = Object.prototype.hasOwnProperty; return v; }(), e = j(), i = function () { if (L) return I; L = 1; var t = function t(t) { return this.component = t, this.items = [], this.active = 0, this.wrapper = document.createElement("div"), this.wrapper.className = "suggestions-wrapper", this.element = document.createElement("ul"), this.element.className = "suggestions", this.wrapper.appendChild(this.element), this.selectingListItem = !1, t.el.parentNode.insertBefore(this.wrapper, t.el.nextSibling), this; }; return t.prototype.show = function () { this.element.style.display = "block"; }, t.prototype.hide = function () { this.element.style.display = "none"; }, t.prototype.add = function (t) { this.items.push(t); }, t.prototype.clear = function () { this.items = [], this.active = 0; }, t.prototype.isEmpty = function () { return !this.items.length; }, t.prototype.isVisible = function () { return "block" === this.element.style.display; }, t.prototype.draw = function () { if (this.element.innerHTML = "", 0 !== this.items.length) { for (var t = 0; t < this.items.length; t++) this.drawItem(this.items[t], this.active === t); this.show(); } else this.hide(); }, t.prototype.drawItem = function (t, e) { var i = document.createElement("li"), n = document.createElement("a"); e && (i.className += " active"), n.innerHTML = t.string, i.appendChild(n), this.element.appendChild(i), i.addEventListener("mousedown", function () { this.selectingListItem = !0; }.bind(this)), i.addEventListener("mouseup", function () { this.handleMouseUp.call(this, t); }.bind(this)); }, t.prototype.handleMouseUp = function (t) { this.selectingListItem = !1, this.component.value(t.original), this.clear(), this.draw(); }, t.prototype.move = function (t) { this.active = t, this.draw(); }, t.prototype.previous = function () { this.move(0 === this.active ? this.items.length - 1 : this.active - 1); }, t.prototype.next = function () { this.move(this.active === this.items.length - 1 ? 0 : this.active + 1); }, t.prototype.drawError = function (t) { var e = document.createElement("li"); e.innerHTML = t, this.element.appendChild(e), this.show(); }, I = t; }(), n = function n(e, n, s) { return s = s || {}, this.options = t({ minLength: 2, limit: 5, filter: !0, hideOnBlur: !0 }, s), this.el = e, this.data = n || [], this.list = new i(this), this.query = "", this.selected = null, this.list.draw(), this.el.addEventListener("keyup", function (t) { this.handleKeyUp(t.keyCode); }.bind(this), !1), this.el.addEventListener("keydown", function (t) { this.handleKeyDown(t); }.bind(this)), this.el.addEventListener("focus", function () { this.handleFocus(); }.bind(this)), this.el.addEventListener("blur", function () { this.handleBlur(); }.bind(this)), this.el.addEventListener("paste", function (t) { this.handlePaste(t); }.bind(this)), this.render = this.options.render ? this.options.render.bind(this) : this.render.bind(this), this.getItemValue = this.options.getItemValue ? this.options.getItemValue.bind(this) : this.getItemValue.bind(this), this; }; return n.prototype.handleKeyUp = function (t) { 40 !== t && 38 !== t && 27 !== t && 13 !== t && 9 !== t && this.handleInputChange(this.el.value); }, n.prototype.handleKeyDown = function (t) { switch (t.keyCode) { case 13: case 9: this.list.isEmpty() || (this.list.isVisible() && t.preventDefault(), this.value(this.list.items[this.list.active].original), this.list.hide()); break; case 27: this.list.isEmpty() || this.list.hide(); break; case 38: this.list.previous(); break; case 40: this.list.next(); } }, n.prototype.handleBlur = function () { !this.list.selectingListItem && this.options.hideOnBlur && this.list.hide(); }, n.prototype.handlePaste = function (t) { if (t.clipboardData) this.handleInputChange(t.clipboardData.getData("Text"));else { var e = this; setTimeout(function () { e.handleInputChange(t.target.value); }, 100); } }, n.prototype.handleInputChange = function (t) { this.query = this.normalize(t), this.list.clear(), this.query.length < this.options.minLength ? this.list.draw() : this.getCandidates(function (t) { for (var e = 0; e < t.length && (this.list.add(t[e]), e !== this.options.limit - 1); e++); this.list.draw(); }.bind(this)); }, n.prototype.handleFocus = function () { this.list.isEmpty() || this.list.show(), this.list.selectingListItem = !1; }, n.prototype.update = function (t) { this.data = t, this.handleKeyUp(); }, n.prototype.clear = function () { this.data = [], this.list.clear(); }, n.prototype.normalize = function (t) { return t = t.toLowerCase(); }, n.prototype.match = function (t, e) { return t.indexOf(e) > -1; }, n.prototype.value = function (t) { if (this.selected = t, this.el.value = this.getItemValue(t), document.createEvent) { var e = document.createEvent("HTMLEvents"); e.initEvent("change", !0, !1), this.el.dispatchEvent(e); } else this.el.fireEvent("onchange"); }, n.prototype.getCandidates = function (t) { var i = { pre: "<strong>", post: "</strong>", extract: function (t) { return this.getItemValue(t); }.bind(this) }; t(this.options.filter ? e.filter(this.query, this.data, i).map(function (t) { return { original: t.original, string: this.render(t.original, t.string) }; }.bind(this)) : this.data.map(function (t) { return { original: t, string: this.render(t) }; }.bind(this))); }, n.prototype.getItemValue = function (t) { return t; }, n.prototype.render = function (t, e) { if (e) return e; for (var i = t.original ? this.getItemValue(t.original) : this.getItemValue(t), n = this.normalize(i), s = n.lastIndexOf(this.query); s > -1;) { var r = s + this.query.length; i = i.slice(0, s) + "<strong>" + i.slice(s, r) + "</strong>" + i.slice(r), s = n.slice(0, s).lastIndexOf(this.query); } return i; }, n.prototype.renderError = function (t) { this.list.drawError(t); }, E = n; } var V = function () { if (C) return $; C = 1; var t = S(); return $ = t, "undefined" != typeof window && (window.Suggestions = t), $; }(), B = s(V); class P extends r(t) { constructor() { super(), this.auth = {}, this._i18n = e(), this.lang = this._i18n.language, this.entryPointUrl = "", this.bookOfferId = "", this.bookOffer = null, this.sublibraryIri = "", this.sublibrary = null; } static get scopedElements() { return { "dbp-library-select": i, "dbp-sublibrary-book-offer-select": y, "dbp-button": o, "dbp-mini-spinner": a, "dbp-reload-button": m }; } static get properties() { return _extends({}, super.properties, { lang: { type: String }, entryPointUrl: { type: String, attribute: "entry-point-url" }, bookOfferId: { type: String, attribute: "book-offer-id", reflect: !0 }, bookOffer: { type: Object, attribute: !1 }, sublibraryIri: { type: String, attribute: "sublibrary-iri", reflect: !0 }, auth: { type: Object } }); } getSublibraryCode() { return this.sublibrary.code; } $(t) { return n(this._(t)); } connectedCallback() { super.connectedCallback(); const t = this, e = this._i18n; this.updateComplete.then(() => { const i = t.$("dbp-sublibrary-book-offer-select"), s = t.$("#location-identifier"), r = t._("#location-identifier"), o = t.$("#location-identifier-block"); i.change(function () { console.log("change"), console.log(i.val()), console.log(i.attr("value")), console.log(i.prop("value")), t.bookOffer = n(this).data("object"), t.bookOfferId = t.bookOffer["@id"], s.val(t.bookOffer.locationIdentifier).trigger("input"), o.show(); const e = t.entryPointUrl + t.bookOfferId + "/location-identifiers"; t.setAttribute("book-offer-id", t.bookOfferId), t.dispatchEvent(new CustomEvent("change", { detail: { type: "book-offer-id", value: t.bookOfferId } })), fetch(e, { headers: { "Content-Type": "application/ld+json", Authorization: "Bearer " + t.auth.token } }).then(t => t.json()).then(t => { let e = t["hydra:member"].map(t => t.identifier); new B(r, e); }); }).on("unselect", function (e) { console.log("unselect"), t.bookOffer = null, t.bookOfferId = "", n(t).attr("book-offer-id", null), o.hide(); }), s.on("input", function () { t.$("#send").prop("disabled", "" === n(this).val()); }), t.$("#send").click(r => { r.preventDefault(), console.log("send"); const o = t.entryPointUrl + i.val() + "?library=" + t.getSublibraryCode(); console.log(o), console.log(s); const a = { locationIdentifier: s.val() }; console.log(a), console.log(JSON.stringify(a)), n.ajax({ url: o, type: "PATCH", contentType: "application/merge-patch+json", beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + t.auth.token); }, data: JSON.stringify(a), success: function (n) { l({ summary: e.t("success-summary"), body: e.t("success-body", { name: t.bookOffer.name || "" }), type: "success", timeout: 5 }), i[0].clear(); }, error: (e, i, n) => { t.handleXhrError(e, i, n); }, complete: function (e, i, n) { t._("#send").stop(); } }); }); }); } update(t) { t.forEach((t, e) => { "lang" === e && this._i18n.changeLanguage(this.lang); }), super.update(t); } onLanguageChanged(t) { this.lang = t.detail.lang; } static get styles() { return h(_t || (_t = _` ${0} ${0} ${0} .hidden { display: none; } #location-identifier-block { display: none; } #location-identifier-block input { width: 100%; border-radius: var(--dbp-border-radius); } dbp-sublibrary-book-offer-select { width: 100%; margin-right: 4px; } .book-offer-select-container { display: flex; } `), d(), c(), u()); } onSublibraryChanged(t) { this.sublibraryIri = t.detail.value, this.sublibrary = t.detail.object; } onReloadButtonClicked(t) { this.$("dbp-sublibrary-book-offer-select").trigger("change"); } render() { const t = p("shared/suggestions.668c8aad3ba887d2.css"), e = this._i18n; return f(_t2 || (_t2 = _` <link rel="stylesheet" href="${0}" /> <form class="${0}"> <div class="field"> <label class="label">${0}</label> <div class="control"> <dbp-library-select subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth" value="${0}" @change="${0}"></dbp-library-select> </div> </div> <div class="field"> <label class="label">${0}</label> <div class="control book-offer-select-container"> <dbp-sublibrary-book-offer-select subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth" value="${0}" sublibrary-iri="${0}"></dbp-sublibrary-book-offer-select> <dbp-reload-button ?disabled=${0} @click=${0} title="${0}" ></dbp-reload-button> </div> </div> <div id="location-identifier-block"> <div class="field"> <label class="label">${0}</label> <div class="control"> <input class="input" id="location-identifier" type="text" placeholder="${0}" /> </div> </div> <div class="field"> <div class="control"> <dbp-button id="send" disabled="disabled" value="${0}" type=""></dbp-button> </div> </div> </div> </form> <div class="notification is-warning ${0}"> ${0} </div> <div class="notification is-danger ${0}"> ${0} </div> <div class="${0}"> <dbp-mini-spinner></dbp-mini-spinner> </div> `), t, b({ hidden: !this.isLoggedIn() || !this.hasLibraryPermissions() || this.isLoading() }), e.t("organization-select.label"), this.sublibraryIri, this.onSublibraryChanged, e.t("library-book-offer-select.headline"), this.bookOfferId, this.sublibraryIri, !this.bookOffer, this.onReloadButtonClicked, this.bookOffer ? e.t("shelving.button-refresh-title", { name: this.bookOffer.name }) : "", e.t("location-identifier.headline"), e.t("location-identifier.placeholder"), e.t("location-identifier.submit"), b({ hidden: this.isLoggedIn() || this.isLoading() }), e.t("error-login-message"), b({ hidden: this.hasLibraryPermissions() || !this.isLoggedIn() || this.isLoading() }), e.t("error-permission-message"), b({ hidden: !this.isLoading() })); } } g("dbp-sublibrary-shelving", P); //# sourceMappingURL=dbp-sublibrary-shelving.js.map