@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
473 lines (465 loc) • 17.4 kB
JavaScript
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
* xtend: MIT
* fuzzy: (MIT)
* suggestions: ISC
*/
import { L as t, c as e, a as i, j as s } from "./shared/library-select.cb305ad9.es.js";
import { S as n, B as r, M as o, s as a, i as l, g as h, a as d, b as c, d as u, y as p, o as f, e as b } from "./shared/_commonjsHelpers.01af1198.es.js";
import { L as g } from "./shared/library-book-offer-select.7fc31707.es.js";
import { R as y } from "./shared/reload-button.3d235359.es.js";
import "./shared/utils.287bbaa6.es.js";
import "./shared/jsonld.3c83677b.es.js";
var m = function m() {
for (var t = {}, e = 0; e < arguments.length; e++) {
var i = arguments[e];
for (var s in i) v.call(i, s) && (t[s] = i[s]);
}
return t;
},
v = Object.prototype.hasOwnProperty;
var k,
I = {};
k = {
get exports() {
return I;
},
set exports(t) {
I = t;
}
}, function () {
var t = {};
k.exports = t, t.simpleFilter = function (e, i) {
return i.filter(function (i) {
return t.test(e, i);
});
}, t.test = function (e, i) {
return null !== t.match(e, i);
}, t.match = function (t, e, i) {
i = i || {};
var s,
n = 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++) s = e[u], c[u] === t[n] ? (s = h + s + d, n += 1, l += 1 + l) : l = 0, a += l, r[r.length] = s;
return n === t.length ? (a = c === t ? 1 / 0 : a, {
rendered: r.join(""),
score: a
}) : null;
}, t.filter = function (e, i, s) {
return i && 0 !== i.length ? "string" != typeof e ? i : (s = s || {}, i.reduce(function (i, n, r, o) {
var a = n;
s.extract && (a = s.extract(n));
var l = t.match(e, a, s);
return null != l && (i[i.length] = {
string: l.rendered,
score: l.score,
index: r,
original: n
}), i;
}, []).sort(function (t, e) {
var i = e.score - t.score;
return i || t.index - e.index;
})) : [];
};
}();
var w = function w(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;
};
w.prototype.show = function () {
this.element.style.display = "block";
}, w.prototype.hide = function () {
this.element.style.display = "none";
}, w.prototype.add = function (t) {
this.items.push(t);
}, w.prototype.clear = function () {
this.items = [], this.active = 0;
}, w.prototype.isEmpty = function () {
return !this.items.length;
}, w.prototype.isVisible = function () {
return "block" === this.element.style.display;
}, w.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();
}, w.prototype.drawItem = function (t, e) {
var i = document.createElement("li"),
s = document.createElement("a");
e && (i.className += " active"), s.innerHTML = t.string, i.appendChild(s), this.element.appendChild(i), i.addEventListener("mousedown", function () {
this.selectingListItem = !0;
}.bind(this)), i.addEventListener("mouseup", function () {
this.handleMouseUp.call(this, t);
}.bind(this));
}, w.prototype.handleMouseUp = function (t) {
this.selectingListItem = !1, this.component.value(t.original), this.clear(), this.draw();
}, w.prototype.move = function (t) {
this.active = t, this.draw();
}, w.prototype.previous = function () {
this.move(0 === this.active ? this.items.length - 1 : this.active - 1);
}, w.prototype.next = function () {
this.move(this.active === this.items.length - 1 ? 0 : this.active + 1);
}, w.prototype.drawError = function (t) {
var e = document.createElement("li");
e.innerHTML = t, this.element.appendChild(e), this.show();
};
var L = m,
E = I,
O = w,
$ = function $(t, e, i) {
return i = i || {}, this.options = L({
minLength: 2,
limit: 5,
filter: !0,
hideOnBlur: !0
}, i), this.el = t, this.data = e || [], this.list = new O(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;
};
$.prototype.handleKeyUp = function (t) {
40 !== t && 38 !== t && 27 !== t && 13 !== t && 9 !== t && this.handleInputChange(this.el.value);
}, $.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();
}
}, $.prototype.handleBlur = function () {
!this.list.selectingListItem && this.options.hideOnBlur && this.list.hide();
}, $.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);
}
}, $.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));
}, $.prototype.handleFocus = function () {
this.list.isEmpty() || this.list.show(), this.list.selectingListItem = !1;
}, $.prototype.update = function (t) {
this.data = t, this.handleKeyUp();
}, $.prototype.clear = function () {
this.data = [], this.list.clear();
}, $.prototype.normalize = function (t) {
return t = t.toLowerCase();
}, $.prototype.match = function (t, e) {
return t.indexOf(e) > -1;
}, $.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");
}, $.prototype.getCandidates = function (t) {
var e = {
pre: "<strong>",
post: "</strong>",
extract: function (t) {
return this.getItemValue(t);
}.bind(this)
};
t(this.options.filter ? E.filter(this.query, this.data, e).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)));
}, $.prototype.getItemValue = function (t) {
return t;
}, $.prototype.render = function (t, e) {
if (e) return e;
for (var i = t.original ? this.getItemValue(t.original) : this.getItemValue(t), s = this.normalize(i), n = s.lastIndexOf(this.query); n > -1;) {
var r = n + this.query.length;
i = i.slice(0, n) + "<strong>" + i.slice(n, r) + "</strong>" + i.slice(r), n = s.slice(0, n).lastIndexOf(this.query);
}
return i;
}, $.prototype.renderError = function (t) {
this.list.drawError(t);
};
var C = $,
x = C;
"undefined" != typeof window && (window.Suggestions = C);
class j extends n(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": g,
"dbp-button": r,
"dbp-mini-spinner": o,
"dbp-reload-button": y
};
}
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 s(this._(t));
}
connectedCallback() {
super.connectedCallback();
const t = this,
e = this._i18n;
this.updateComplete.then(() => {
const i = t.$(this.getScopedTagName("dbp-sublibrary-book-offer-select")),
n = 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 = s(this).data("object"), t.bookOfferId = t.bookOffer["@id"], n.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 => {
new x(r, t["hydra:member"]);
});
}).on("unselect", function (e) {
console.log("unselect"), t.bookOffer = null, t.bookOfferId = "", s(t).attr("book-offer-id", null), o.hide();
}), n.on("input", function () {
t.$("#send").prop("disabled", "" === s(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(n);
const l = {
locationIdentifier: n.val()
};
console.log(l), console.log(JSON.stringify(l)), s.ajax({
url: o,
type: "PUT",
contentType: "application/json",
beforeSend: function (e) {
e.setRequestHeader("Authorization", "Bearer " + t.auth.token);
},
data: JSON.stringify(l),
success: function (s) {
a({
summary: e.t("success-summary"),
body: e.t("success-body", {
name: t.bookOffer.name || ""
}),
type: "success",
timeout: 5
}), i[0].clear();
},
error: (e, i, s) => {
t.handleXhrError(e, i, s);
},
complete: function (e, i, s) {
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 l(_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;
}
`), h(), d(), c());
}
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 = u("shared/suggestions.668c8aad3ba887d2.css"),
e = this._i18n;
return p(_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}"
="${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}
=${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, f({
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"), f({
hidden: this.isLoggedIn() || this.isLoading()
}), e.t("error-login-message"), f({
hidden: this.hasLibraryPermissions() || !this.isLoggedIn() || this.isLoading()
}), e.t("error-permission-message"), f({
hidden: !this.isLoading()
}));
}
}
b("dbp-sublibrary-shelving", j);
//# sourceMappingURL=dbp-sublibrary-shelving.js.map