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

335 lines (329 loc) 12 kB
let _ = t => t, _t, _t2, _t3; 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 */ import { L as e, c as t, a as s, i } from "./shared/library-select.cb305ad9.es.js"; import { S as a, M as r, B as o, i as n, g as l, a as d, b, y as h, o as c, p as u, e as p } from "./shared/_commonjsHelpers.01af1198.es.js"; import { P as y } from "./shared/person-select.503b43f7.es.js"; import { L as f } from "./shared/library-book-offer-select.7fc31707.es.js"; import { g } from "./shared/utils.287bbaa6.es.js"; import { R as m } from "./shared/reload-button.3d235359.es.js"; import "./shared/jsonld.3c83677b.es.js"; class k extends a(e) { constructor() { super(), this.auth = {}, this._i18n = t(), 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(e) { e.forEach((e, t) => { "lang" === t && this._i18n.changeLanguage(this.lang); }), super.update(e); } 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(e) { await this.updateCreateLoan(); } async updateCreateLoan() { let e = this.shadowRoot.querySelector("dbp-sublibrary-book-offer-select").dataset.object; const t = this.shadowRoot.querySelector("#create-loan-block"), s = this.shadowRoot.querySelector("#loans-loading"); if (this.status = null, !e) return this.status = null, this.bookOffer = null, this.bookOfferId = "", void (t.style.display = "none"); e = JSON.parse(e); const a = e["@id"]; this.bookOffer = e, 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 (e) { return void (await this.handleFetchError(e, 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" }, t.style.display = "block"); } getSublibraryCode() { return this.sublibrary.code; } onPersonSelectChanged(e) { const t = e.target, s = JSON.parse(t.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(e) { e.preventDefault(); const t = e.currentTarget; try { await this.onSubmitClickedInternal(e); } finally { t.stop(); } } async onSubmitClickedInternal(e) { const t = this._("input[type='date']"), s = this._("input[type='time']"); let a = t.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/json", Authorization: "Bearer " + this.auth.token }, body: JSON.stringify(n) }); if (l.ok) { this._(this.getScopedTagName("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(e) { this.sublibraryIri = e.detail.value, this.sublibrary = e.detail.object; } onReloadButtonClicked(e) { this.updateCreateLoan(); } render() { const e = new Date().toISOString(); let t = new Date(); t.setMonth(t.getMonth() + 1); const s = t.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}" show-details> </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(e), 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