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

326 lines (320 loc) 11.7 kB
let _ = t => t, _t, _t2, _t3; 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 */ import { L as t, c as e, a as s, i } from "./shared/library-select.Cpz1ozX8.es.js"; import { S as a, M as r, B as o, i as n, g as l, b as d, d as b, x as h, e as c, r as u, k as p } from "./shared/notification.BYDDIHux.es.js"; import { C as y } from "./shared/custom-person-select.BzZGLcwb.es.js"; import { L as f } from "./shared/library-book-offer-select.D75H9YDl.es.js"; import { g } from "./shared/utils.BB2hXqy_.es.js"; import { R as m } from "./shared/reload-button.CDzxUV-T.es.js"; import "./shared/utils.C137cI6N.es.js"; class k extends a(t) { constructor() { super(), this.auth = {}, this._i18n = e(), this.lang = this._i18n.language, this.entryPointUrl = "", this.bookOfferId = "", this.bookOffer = null, this.personId = "", this.person = null, this.status = null, this.sublibraryIri = "", this.sublibrary = null, this.sendButtonDisabled = !0; } static get scopedElements() { return { "dbp-library-select": s, "dbp-person-select": y, "dbp-sublibrary-book-offer-select": f, "dbp-mini-spinner": r, "dbp-button": o, "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 }, personId: { type: String, attribute: "person-id", reflect: !0 }, status: { type: Object }, sublibraryIri: { type: String, attribute: "sublibrary-iri", reflect: !0 }, sendButtonDisabled: { type: Boolean, attribute: !1 }, auth: { type: Object } }); } connectedCallback() { super.connectedCallback(); } update(t) { t.forEach((t, e) => { "lang" === e && this._i18n.changeLanguage(this.lang); }), super.update(t); } static get styles() { return n(_t || (_t = _` ${0} ${0} ${0} .hidden { display: none; } #create-loan-block { display: none; } dbp-sublibrary-book-offer-select { width: 100%; margin-right: 4px; } .book-offer-select-container { display: flex; } `), l(), d(), b()); } async onBookSelectChanged(t) { await this.updateCreateLoan(); } async updateCreateLoan() { let t = this.shadowRoot.querySelector("dbp-sublibrary-book-offer-select").dataset.object; const e = this.shadowRoot.querySelector("#create-loan-block"), s = this.shadowRoot.querySelector("#loans-loading"); if (this.status = null, !t) return this.status = null, this.bookOffer = null, this.bookOfferId = "", void (e.style.display = "none"); t = JSON.parse(t); const a = t["@id"]; this.bookOffer = t, this.bookOfferId = a; const r = this.entryPointUrl + this.bookOfferId + "/loans"; this.setAttribute("book-offer-id", this.bookOfferId), this.dispatchEvent(new CustomEvent("change", { detail: { type: "book-offer-id", value: this.bookOfferId } })), s.style.display = "block"; let o = null; try { if (o = await fetch(r, { headers: { "Content-Type": "application/ld+json", Authorization: "Bearer " + this.auth.token } }), !o.ok) throw o; o = await o.json(); } catch (t) { return void (await this.handleFetchError(t, this._i18n.t("renew-loan.error-load-loans-summary"))); } finally { s.style.display = "none"; } o["hydra:member"].length > 0 ? this.status = { summary: i("create-loan.error-existing-loans-summary"), body: i("create-loan.error-existing-loans-body"), type: "danger" } : (this.status = { summary: i("create-loan.info-no-existing-loans-summary"), body: i("create-loan.info-no-existing-loans-body"), type: "info" }, e.style.display = "block"); } getSublibraryCode() { return this.sublibrary.code; } onPersonSelectChanged(t) { const e = t.target, s = JSON.parse(e.dataset.object), i = s["@id"]; this.sendButtonDisabled = !1, this.personId = i, this.person = s, this.dispatchEvent(new CustomEvent("change", { detail: { type: "person-id", value: this.personId } })); } async onSubmitClicked(t) { t.preventDefault(); const e = t.currentTarget; try { await this.onSubmitClickedInternal(t); } finally { e.stop(); } } async onSubmitClickedInternal(t) { const e = this._("input[type='date']"), s = this._("input[type='time']"); let a = e.value; s.value && (a += "T" + s.value); const r = new Date(a); if (r < new Date()) return void (this.status = { summary: this._i18n.t("error-summary"), body: this._i18n.t("renew-loan.error-renew-loan-date-in-past"), type: "danger" }); const o = this.entryPointUrl + this.bookOfferId + "/loans", n = { borrower: this.personId, library: this.getSublibraryCode(), endTime: r.toISOString() }; let l = await fetch(o, { method: "POST", headers: { Accept: "application/ld+json", "Content-Type": "application/ld+json", Authorization: "Bearer " + this.auth.token }, body: JSON.stringify(n) }); if (l.ok) { this._("dbp-sublibrary-book-offer-select").clear(), this.status = { summary: i("create-loan.success-summary"), body: this._i18n.t("create-loan.success-body", { personName: g(this.person) }), type: "info" }; } else await this.handleFetchError(l); } onSublibraryChanged(t) { this.sublibraryIri = t.detail.value, this.sublibrary = t.detail.object; } onReloadButtonClicked(t) { this.updateCreateLoan(); } render() { const t = new Date().toISOString(); let e = new Date(); e.setMonth(e.getMonth() + 1); const s = e.toISOString(), i = this._i18n; return h(_t2 || (_t2 = _` <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"> <dbp-person-select subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth" @change=${0} value="${0}"> </dbp-person-select> </div> </div> <div class="field"> <label class="label">${0}</label> <div class="control book-offer-select-container"> <dbp-sublibrary-book-offer-select subscribe="auth:auth,lang:lang,entry-point-url:entry-point-url,auth:auth" @change=${0} @unselect=${0} value="${0}" sublibrary-iri="${0}"></dbp-sublibrary-book-offer-select> <dbp-reload-button ?disabled=${0} @click=${0} title="${0}" ></dbp-reload-button> </div> </div> <dbp-mini-spinner id="loans-loading" text="${0}" style="font-size: 2em; display: none;"></dbp-mini-spinner> <div id="create-loan-block"> <div class="field"> <label class="label">${0}</label> <input class="input" type="date" min="${0}" value="${0}" /> <input type="time" class="hidden" value="23:59:59" /> </div> <div class="field"> <div class="control"> <dbp-button id="send" @click=${0} value="${0}" ?disabled="${0}" type=""></dbp-button> </div> </div> </div> ${0} </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> `), c({ hidden: !this.isLoggedIn() || !this.hasLibraryPermissions() || this.isLoading() }), i.t("organization-select.label"), this.sublibraryIri, this.onSublibraryChanged, i.t("person-select.headline"), this.onPersonSelectChanged, this.personId, i.t("library-book-offer-select.headline"), this.onBookSelectChanged, this.onBookSelectChanged, this.bookOfferId, this.sublibraryIri, !this.bookOffer, this.onReloadButtonClicked, this.bookOffer ? i.t("shelving.button-refresh-title", { name: this.bookOffer.name }) : "", i.t("create-loan.mini-spinner-text"), i.t("renew-loan.end-date"), u(t), u(s), this.onSubmitClicked, i.t("create-loan.submit"), this.sendButtonDisabled, this.status ? h(_t3 || (_t3 = _` <br /> <div class="notification is-${0}"> <h4>${0}</h4> ${0} </div> `), this.status.type, i.t(this.status.summary), i.t(this.status.body)) : "", c({ hidden: this.isLoggedIn() || this.isLoading() }), i.t("error-login-message"), c({ hidden: this.hasLibraryPermissions() || !this.isLoggedIn() || this.isLoading() }), i.t("error-permission-message"), c({ hidden: !this.isLoading() })); } } p("dbp-sublibrary-create-loan", k); //# sourceMappingURL=dbp-sublibrary-create-loan.js.map