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

105 lines (98 loc) 10.7 kB
let e=e=>e,t,n;function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?r(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function a(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e){var t=s(e,`string`);return typeof t==`symbol`?t:t+``}function s(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)} /*! * 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/auth: LGPL-2.1-or-later * lit-html: BSD-3-Clause * @dbp-toolkit/notification: LGPL-2.1-or-later * @dbp-toolkit/theme-switcher: LGPL-2.1-or-later * universal-router: MIT * @dbp-toolkit/matomo: LGPL-2.1-or-later * xtend: MIT * fuzzy: (MIT) * suggestions: ISC * keycloak-js: Apache-2.0 * @dbp-toolkit/common: LGPL-2.1-or-later * jquery: MIT * select2: MIT * @dbp-toolkit/resource-select: LGPL-2.1-or-later * i18next: MIT * @lit/reactive-element: BSD-3-Clause * lit-element: BSD-3-Clause * @open-wc/dedupe-mixin: MIT * @open-wc/scoped-elements: MIT * dialog-polyfill: BSD * datatables.net: MIT * datatables.net-responsive: MIT * datatables.net-dt: MIT * datatables.net-responsive-dt: MIT * jszip: (MIT OR GPL-3.0-or-later) * datatables.net-buttons: MIT * datatables.net-buttons-dt: MIT * @dbp-toolkit/data-table-view: LGPL-2.1-or-later */ import{d as c,i as l,n as u,o as d,r as f,s as p}from"./library-select.DEl5HMBb.js";import{B as m,C as h,E as g,F as _,N as v,O as y,T as b,V as x,b as S,g as C,o as w,v as T,y as E}from"./styles.Cw9eAWXA.js";import{r as D}from"./utils.Bvuc5ewV.js";var O=c(l(),1),k=c(f(),1);function A(){return{errorLoading:function(){return`Die Ergebnisse konnten nicht geladen werden.`},inputTooLong:function(e){return`Bitte `+(e.input.length-e.maximum)+` Zeichen weniger eingeben`},inputTooShort:function(e){return`Es kann nur nach vollständigen Barcodes gesucht werden, bitte `+(e.minimum-e.input.length)+` Zeichen mehr eingeben`},loadingMore:function(){return`Lade mehr Ergebnisse…`},maximumSelected:function(e){var t=`Sie können nur `+e.maximum+` Eintr`;return e.maximum===1?t+=`ag`:t+=`äge`,t+=` auswählen`,t},noResults:function(){return`Keine Übereinstimmungen gefunden`},searching:function(){return`Suche…`},removeAllItems:function(){return`Entferne alle Gegenstände`}}}function j(){return{errorLoading:function(){return`The results could not be loaded.`},inputTooLong:function(e){var t=e.input.length-e.maximum,n=`Please delete `+t+` character`;return t!=1&&(n+=`s`),n},inputTooShort:function(e){return`You can only search for complete barcodes, please enter `+(e.minimum-e.input.length)+` or more characters`},loadingMore:function(){return`Loading more results…`},maximumSelected:function(e){var t=`You can only select `+e.maximum+` item`;return e.maximum!=1&&(t+=`s`),t},noResults:function(){return`No results found`},searching:function(){return`Searching…`},removeAllItems:function(){return`Remove all items`}}}var M=class r extends g(C){constructor(){super(),this._i18n=p(),this.lang=this._i18n.language,this.auth={},this.entryPointUrl=``,this.$select=null,this.selectId=`book-offer-select-`+_(24),this.value=``,this.object=null,this.ignoreValueUpdate=!1,this.lastResult={},this.showReloadButton=!1,this.reloadButtonTitle=``,this.sublibraryIri=``,Object.assign(r.prototype,d),this._onDocumentClicked=this._onDocumentClicked.bind(this),(0,k.default)(window,O.default)}static get scopedElements(){return{"dbp-icon":y}}$(e){return(0,O.default)(this.shadowRoot.querySelector(e))}static get properties(){return i(i({},super.properties),{},{lang:{type:String},entryPointUrl:{type:String,attribute:`entry-point-url`},value:{type:String},object:{type:Object,attribute:!1},showReloadButton:{type:Boolean,attribute:`show-reload-button`},reloadButtonTitle:{type:String,attribute:`reload-button-title`},sublibraryIri:{type:String,attribute:`sublibrary-iri`},auth:{type:Object}})}close(){this.$select.select2(`close`)}clear(){this.object=null,(0,O.default)(this).attr(`data-object`,``),(0,O.default)(this).data(`object`,null),this.$select.val(null).trigger(`change`).trigger(`select2:unselect`)}connectedCallback(){super.connectedCallback(),document.addEventListener(`click`,this._onDocumentClicked),this.updateComplete.then(()=>{this.$select=this.$(`#`+this.selectId),this.$select.disabled=!0,this.select2IsInitialized()||this.initSelect2()})}disconnectedCallback(){document.removeEventListener(`click`,this._onDocumentClicked),super.disconnectedCallback()}_onDocumentClicked(e){if(!e.composedPath().includes(this)){let e=this.$(`#`+this.selectId);e.length&&this.select2IsInitialized()&&e.select2(`close`)}}isInt(e){return!isNaN(e)&&function(e){return(e|0)===e}(parseFloat(e))}initSelect2(e=!1){let t=this,n=(0,O.default)(this);if(this.$select===null||this.entryPointUrl===null)return!1;let r=w(this.entryPointUrl,`/sublibrary/book-offers`);if(this.$select.hasClass(`select2-hidden-accessible`)&&(this.$select.select2(`destroy`),this.$select.off(`select2:select`),this.$select.off(`select2:unselect`)),this.$select.select2({width:`100%`,language:this.lang===`de`?A():j(),minimumInputLength:3,allowClear:!0,placeholder:this._i18n.t(`library-book-offer-select.placeholder`),dropdownParent:this.$(`#library-book-offer-select-dropdown`),ajax:{delay:250,url:r,contentType:`application/ld+json`,beforeSend:function(e){e.setRequestHeader(`Authorization`,`Bearer `+t.auth.token)},data:function(e){let n=e.term.trim();!t.isInt(n)&&n.substr(0,1)!==`+`&&n.substr(0,1)!==`@`&&(n=`+`+n);let r=t.sublibraryIri.split(`/`).slice(-1)[0];return{barcode:n,sublibrary:r}},processResults:function(e){t.$(`#library-book-offer-select-dropdown`).addClass(`select2-bug`),t.lastResult=e;let n=[];return e[`hydra:member`].forEach(e=>{n.push({id:e[`@id`],text:e.name})}),{results:n}},error:(e,n,r)=>{t.handleXhrError(e,n,r)}}}).on(`select2:select`,function(e){t.$(`#library-book-offer-select-dropdown`).removeClass(`select2-bug`);let r=e.params.data.id;t.object=D(r,t.lastResult),t.object!==void 0&&(n.attr(`data-object`,JSON.stringify(t.object)),n.data(`object`,t.object),n.attr(`value`)!==r&&(t.ignoreValueUpdate=!0,n.attr(`value`,r),t.value=r,t.dispatchEvent(new CustomEvent(`change`,{detail:{value:r}}))))}).on(`select2:unselect`,function(e){t.object=null,n.attr(`data-object`,``),n.data(`object`,{}),t.ignoreValueUpdate=!0,n.attr(`value`,``),t.value=``,t.dispatchEvent(new CustomEvent(`unselect`))}),!e&&this.value!==``&&this.value!==`null`){let e=this.entryPointUrl+this.value;fetch(e,{headers:{"Content-Type":`application/ld+json`,Authorization:`Bearer `+t.auth.token}}).then(e=>{if(!e.ok)throw e;return e.json()}).then(e=>{t.object=e;let r=e[`@id`],i=new Option(e.name,r,!0,!0);n.attr(`data-object`,JSON.stringify(e)),n.data(`object`,e),t.$select.val(null).append(i).trigger(`change`),t.dispatchEvent(new CustomEvent(`change`,{detail:{value:r},bubbles:!0}))}).catch(()=>{t.clear()})}return!0}update(e){e.forEach((e,t)=>{switch(t){case`lang`:this._i18n.changeLanguage(this.lang),this.select2IsInitialized()&&this.initSelect2(!0);break;case`sublibraryIri`:this.sublibraryIri||=``,this.$select&&(this.$select.enable=this.sublibraryIri.includes(`-`));break;case`value`:!this.ignoreValueUpdate&&this.select2IsInitialized()&&this.initSelect2(),this.ignoreValueUpdate=!1;break;case`entryPointUrl`:this.initSelect2(!0);break;case`auth`:this.auth.token&&(!e||!e.token)&&this.initSelect2();break}}),super.update(e)}select2IsInitialized(){return this.$select!==null&&this.$select.hasClass(`select2-hidden-accessible`)}reloadClick(){this.object!==null&&this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.value},bubbles:!0}))}static get styles(){return x(t||=e` ${0} ${0} ${0} ${0} ${0} .select2-control.control { width: 100%; } .select select { height: 2em; } .field .button.control { display: flex; align-items: center; justify-content: center; border: 1px solid var(--dbp-override-muted); -moz-border-radius-topright: var(--dbp-border-radius); -moz-border-radius-bottomright: var(--dbp-border-radius); line-height: 100%; } .field:not(:last-child) { margin-bottom: 0; } .field .button.control dbp-icon { top: 0; } /* https://github.com/select2/select2/issues/5457 */ .select2-bug .loading-results { display: none !important; } `,b(),S(),T(),E(),h())}render(){return m(n||=e` <link rel="stylesheet" href="${0}" /> <style> #${0} { width: 100%; } li.select2-selection__choice { white-space: normal; } </style> <div class="select"> <div class="field has-addons"> <div class="select2-control control"> <!-- https://select2.org--> <select id="${0}" name="book-offer" class="select"></select> </div> <a class="control button" id="reload-button" ?disabled=${0} @click="${0}" style="display: ${0}" title="${0}"> <dbp-icon name="reload"></dbp-icon> </a> </div> <div id="library-book-offer-select-dropdown"></div> </div> `,v(u),this.selectId,this.selectId,this.object===null,this.reloadClick,this.showReloadButton?`flex`:`none`,this.reloadButtonTitle)}};export{M as t}; //# sourceMappingURL=library-book-offer-select.B2MtGubA.js.map