@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
290 lines (285 loc) • 10.3 kB
JavaScript
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
* @dbp-toolkit/person-select: LGPL-2.1-or-later
*/
import { L as e, c as t, a as r, j as o, i as s } from "./shared/library-select.cb305ad9.es.js";
import { S as i, M as n, B as a, i as l, g as b, a as d, b as u, y as h, o as c, e as p } from "./shared/_commonjsHelpers.01af1198.es.js";
import { L as f } from "./shared/library-book-offer-select.7fc31707.es.js";
import { g as y } from "./shared/utils.287bbaa6.es.js";
import "./shared/jsonld.3c83677b.es.js";
class g extends i(e) {
constructor() {
super(), this.auth = {}, this._i18n = t(), this.lang = this._i18n.language, this.entryPointUrl = "", this.bookOfferId = "", this.bookOffer = null, this.loanId = "", this.loan = null, this.borrower = null, this.borrowerName = "", this.status = null, this.sublibraryIri = "";
}
static get scopedElements() {
return {
"dbp-library-select": r,
"dbp-sublibrary-book-offer-select": f,
"dbp-mini-spinner": n,
"dbp-button": a
};
}
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
},
borrower: {
type: Object,
attribute: !1
},
borrowerName: {
type: String,
attribute: !1
},
status: {
type: Object,
attribute: !1
},
sublibraryIri: {
type: String,
attribute: "sublibrary-iri",
reflect: !0
},
auth: {
type: Object
}
});
}
$(e) {
return o(this._(e));
}
getSublibraryCode() {
return this.sublibraryIri.includes("-") ? this.sublibraryIri.split("-")[1] : "";
}
connectedCallback() {
super.connectedCallback();
const e = this,
t = this._i18n;
this.updateComplete.then(() => {
const r = e.$(this.getScopedTagName("dbp-sublibrary-book-offer-select")),
i = e.$("#return-book-block"),
n = e.$("#loans-loading");
r.change(function () {
e.bookOffer = o(this).data("object"), e.bookOfferId = e.bookOffer["@id"], e.updateSubmitButtonDisabled();
const r = e.entryPointUrl + e.bookOfferId + "/loans";
e.setAttribute("book-offer-id", e.bookOfferId), e.dispatchEvent(new CustomEvent("change", {
detail: {
type: "book-offer-id",
value: e.bookOfferId
}
})), n.show(), fetch(r, {
headers: {
"Content-Type": "application/ld+json",
Authorization: "Bearer " + e.auth.token
}
}).then(e => {
if (n.hide(), !e.ok) throw e;
return e.json();
}).then(t => {
const r = t["hydra:member"];
r.length > 0 ? (e.loan = r[0], e.loanId = e.loan["@id"], console.log(e.loan), e.loadBorrower(e.loan.borrower), e.status = {
summary: s("return-book.info-existing-loans-summary"),
body: s("return-book.info-existing-loans-body")
}, i.show()) : e.status = {
summary: s("return-book.error-no-existing-loans-summary"),
body: s("return-book.error-no-existing-loans-body")
};
}).catch(r => {
e.handleFetchError(r, t.t("renew-loan.error-load-loans-summary"));
});
}).on("unselect", function (e) {
i.hide();
}), e.$("#send").click(i => {
i.preventDefault(), console.log("send");
const n = e.entryPointUrl + e.bookOfferId + "/return?library=" + e.getSublibraryCode();
console.log("dbp-sublibrary-return-book: #send.click() apiUrl = " + n), o.ajax({
url: n,
type: "POST",
contentType: "application/json",
beforeSend: function (t) {
t.setRequestHeader("Authorization", "Bearer " + e.auth.token);
},
data: "{}",
success: function (o) {
r[0].clear(), e.status = {
summary: s("return-book.success-summary"),
body: t.t("return-book.success-body", {
personName: e.borrowerName
})
};
},
error: (t, r, o) => {
e.handleXhrError(t, r, o);
},
complete: function (t, r, o) {
e._("#send").stop(), e.updateSubmitButtonDisabled();
}
});
});
});
}
async onBookSelectChanged(e) {
this.status = null;
}
updateSubmitButtonDisabled() {
this.$("#send").prop("disabled", "" === this.bookOfferId);
}
update(e) {
e.forEach((e, t) => {
"lang" === t && this._i18n.changeLanguage(this.lang);
}), super.update(e);
}
onLanguageChanged(e) {
this.lang = e.detail.lang;
}
loadBorrower(e) {
if (this.borrower = null, this.borrowerName = this._i18n.t("return-book.user-name-unknown"), null == e) return;
const t = this.entryPointUrl + e;
fetch(t, {
headers: {
"Content-Type": "application/ld+json",
Authorization: "Bearer " + this.auth.token
}
}).then(e => e.json()).then(e => {
this.borrower = e, this.borrowerName = y(e);
});
}
static get styles() {
return l(_t || (_t = _`
${0}
${0}
${0}
.hidden {
display: none;
}
#return-book-block {
display: none;
}
#return-book-block input {
width: 100%;
}
`), b(), d(), u());
}
onSublibraryChanged(e) {
this.sublibraryIri = e.detail.value;
}
render() {
const e = 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}"
="${0}"></dbp-library-select>
</div>
</div>
<div class="field">
<label class="label">${0}</label>
<div class="control">
<dbp-sublibrary-book-offer-select
subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth"
=${0}
=${0}
value="${0}"
sublibrary-iri="${0}"
show-reload-button
reload-button-title="${0}"></dbp-sublibrary-book-offer-select>
</div>
</div>
<dbp-mini-spinner
id="loans-loading"
text="${0}"
style="font-size: 2em; display: none;"></dbp-mini-spinner>
<div id="return-book-block">
<div class="field">
<label class="label">${0}</label>
<div class="control">${0}</div>
</div>
<div class="field">
<div class="control">
<dbp-button
id="send"
disabled="disabled"
value="${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()
}), e.t("organization-select.label"), this.sublibraryIri, this.onSublibraryChanged, e.t("library-book-offer-select.headline"), this.onBookSelectChanged, this.onBookSelectChanged, this.bookOfferId, this.sublibraryIri, this.bookOffer ? e.t("return-book.button-refresh-title", {
name: this.bookOffer.name
}) : "", e.t("return-book.mini-spinner-text"), e.t("return-book.borrower"), this.borrowerName, e.t("return-book.submit"), this.status ? h(_t3 || (_t3 = _`
<br />
<div class="notification is-info">
<h4>${0}</h4>
${0}
</div>
`), e.t(this.status.summary), e.t(this.status.body)) : "", c({
hidden: this.isLoggedIn() || this.isLoading()
}), e.t("error-login-message"), c({
hidden: this.hasLibraryPermissions() || !this.isLoggedIn() || this.isLoading()
}), e.t("error-permission-message"), c({
hidden: !this.isLoading()
}));
}
}
p("dbp-sublibrary-return-book", g);
//# sourceMappingURL=dbp-sublibrary-return-book.js.map