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

98 lines (94 loc) 9.18 kB
let e=e=>e,t,n,r;function i(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 a(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?i(Object(n),!0).forEach(function(t){o(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function o(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(e){var t=c(e,`string`);return typeof t==`symbol`?t:t+``}function c(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 */ import{a as l,c as u,d,i as f,s as p,t as m}from"./shared/library-select.BChQfqNA.js";import{B as h,D as g,E as _,M as v,S as y,T as b,V as x,_ as S,b as C,d as w}from"./shared/styles.D8JNhv4k.js";import{i as T}from"./shared/utils.CukL588_.js";import{t as E}from"./shared/library-book-offer-select.p6M2VRoA.js";var D=d(f(),1);v(`dbp-sublibrary-return-book`,class extends _(l){constructor(){super(),this.auth={},this._i18n=p(),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":m,"dbp-sublibrary-book-offer-select":E,"dbp-mini-spinner":g,"dbp-button":S}}static get properties(){return a(a({},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(0,D.default)(this._(e))}getSublibraryCode(){return this.sublibraryIri.includes(`-`)?this.sublibraryIri.split(`-`)[1]:``}connectedCallback(){super.connectedCallback();let e=this,t=this._i18n;this.updateComplete.then(()=>{let n=e.$(`dbp-sublibrary-book-offer-select`),r=e.$(`#return-book-block`),i=e.$(`#loans-loading`);n.change(function(){e.bookOffer=(0,D.default)(this).data(`object`),e.bookOfferId=e.bookOffer[`@id`],e.updateSubmitButtonDisabled();let n=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}})),i.show(),fetch(n,{headers:{"Content-Type":`application/ld+json`,Authorization:`Bearer `+e.auth.token}}).then(e=>{if(i.hide(),!e.ok)throw e;return e.json()}).then(t=>{let n=t[`hydra:member`];n.length>0?(e.loan=n[0],e.loanId=e.loan[`@id`],console.log(e.loan),e.loadBorrower(e.loan.borrower),e.status={summary:u(`return-book.info-existing-loans-summary`),body:u(`return-book.info-existing-loans-body`)},r.show()):e.status={summary:u(`return-book.error-no-existing-loans-summary`),body:u(`return-book.error-no-existing-loans-body`)}}).catch(n=>{e.handleFetchError(n,t.t(`renew-loan.error-load-loans-summary`))})}).on(`unselect`,function(e){r.hide()}),e.$(`#send`).click(r=>{r.preventDefault(),console.log(`send`);let i=e.entryPointUrl+e.bookOfferId+`/return?library=`+e.getSublibraryCode();console.log(`dbp-sublibrary-return-book: #send.click() apiUrl = `+i),D.default.ajax({url:i,type:`POST`,contentType:`application/ld+json`,beforeSend:function(t){t.setRequestHeader(`Authorization`,`Bearer `+e.auth.token)},data:`{}`,success:function(r){n[0].clear(),e.status={summary:u(`return-book.success-summary`),body:t.t(`return-book.success-body`,{personName:e.borrowerName})}},error:(t,n,r)=>{e.handleXhrError(t,n,r)},complete:function(t,n,r){e._(`#send`).stop(),e.updateSubmitButtonDisabled()}})})})}async onBookSelectChanged(e){this.status=null}updateSubmitButtonDisabled(){this.$(`#send`).prop(`disabled`,this.bookOfferId===``)}update(e){e.forEach((e,t)=>{t===`lang`&&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`),e==null)return;let 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=T(e)})}static get styles(){return x(t||=e` ${0} ${0} ${0} .hidden { display: none; } #return-book-block { display: none; } #return-book-block input { width: 100%; } `,b(),C(),y())}onSublibraryChanged(e){this.sublibraryIri=e.detail.value}_onLoginClicked(e){this.sendSetPropertyEvent(`requested-login-status`,`logged-in`),e.preventDefault()}render(){let t=this._i18n;return h(n||=e` <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-sublibrary-book-offer-select subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth" @change=${0} @unselect=${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} <a href="#" @click="${0}">${0}</a> </div> <div class="notification is-danger ${0}"> ${0} </div> <div class="${0}"> <dbp-mini-spinner></dbp-mini-spinner> </div> `,w({hidden:!this.isLoggedIn()||!this.hasLibraryPermissions()||this.isLoading()}),t.t(`organization-select.label`),this.sublibraryIri,this.onSublibraryChanged,t.t(`library-book-offer-select.headline`),this.onBookSelectChanged,this.onBookSelectChanged,this.bookOfferId,this.sublibraryIri,this.bookOffer?t.t(`return-book.button-refresh-title`,{name:this.bookOffer.name}):``,t.t(`return-book.mini-spinner-text`),t.t(`return-book.borrower`),this.borrowerName,t.t(`return-book.submit`),this.status?h(r||=e` <br /> <div class="notification is-info"> <h4>${0}</h4> ${0} </div> `,t.t(this.status.summary),t.t(this.status.body)):``,w({hidden:this.isLoggedIn()||this.isLoading()}),t.t(`error-login-message`),this._onLoginClicked,t.t(`error-login-link`),w({hidden:this.hasLibraryPermissions()||!this.isLoggedIn()||this.isLoading()}),t.t(`error-permission-message`),w({hidden:!this.isLoading()}))}}); //# sourceMappingURL=dbp-sublibrary-return-book.js.map