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

120 lines (115 loc) 10.8 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,s as d,t as f}from"./shared/library-select.DEl5HMBb.js";import{A as p,B as m,D as h,E as g,M as _,S as v,T as y,V as b,_ as x,b as S,d as C}from"./shared/styles.Cw9eAWXA.js";import{i as w}from"./shared/utils.Bvuc5ewV.js";import{t as T}from"./shared/library-user-select.Cu2-phSe.js";import{t as E}from"./shared/library-book-offer-select.B2MtGubA.js";import{t as D}from"./shared/reload-button.7-wpigd0.js";_(`dbp-sublibrary-create-loan`,class extends g(l){constructor(){super(),this.auth={},this._i18n=d(),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":f,"dbp-library-user-select":T,"dbp-sublibrary-book-offer-select":E,"dbp-mini-spinner":h,"dbp-button":x,"dbp-reload-button":D}}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},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)=>{t===`lang`&&this._i18n.changeLanguage(this.lang)}),super.update(e)}static get styles(){return b(t||=e` ${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; } `,y(),S(),v())}async onBookSelectChanged(e){await this.updateCreateLoan()}async updateCreateLoan(){let e=this.shadowRoot.querySelector(`dbp-sublibrary-book-offer-select`).dataset.object,t=this.shadowRoot.querySelector(`#create-loan-block`),n=this.shadowRoot.querySelector(`#loans-loading`);if(this.status=null,!e){this.status=null,this.bookOffer=null,this.bookOfferId=``,t.style.display=`none`;return}e=JSON.parse(e);let r=e[`@id`];this.bookOffer=e,this.bookOfferId=r;let i=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}})),n.style.display=`block`;let a;try{if(a=await fetch(i,{headers:{"Content-Type":`application/ld+json`,Authorization:`Bearer `+this.auth.token}}),!a.ok)throw a;a=await a.json()}catch(e){await this.handleFetchError(e,this._i18n.t(`renew-loan.error-load-loans-summary`));return}finally{n.style.display=`none`}a[`hydra:member`].length>0?this.status={summary:u(`create-loan.error-existing-loans-summary`),body:u(`create-loan.error-existing-loans-body`),type:`danger`}:(this.status={summary:u(`create-loan.info-no-existing-loans-summary`),body:u(`create-loan.info-no-existing-loans-body`),type:`info`},t.style.display=`block`)}getSublibraryCode(){return this.sublibrary.code}onPersonSelectChanged(e){let t=e.target,n=JSON.parse(t.dataset.object),r=n[`@id`];this.sendButtonDisabled=!1,this.personId=r,this.person=n,this.dispatchEvent(new CustomEvent(`change`,{detail:{type:`person-id`,value:this.personId}}))}async onSubmitClicked(e){e.preventDefault();let t=e.currentTarget;try{await this.onSubmitClickedInternal(e)}finally{t.stop()}}async onSubmitClickedInternal(e){let t=this._(`input[type='date']`),n=this._(`input[type='time']`),r=t.value;n.value&&(r+=`T`+n.value);let i=new Date(r);if(i<new Date){this.status={summary:this._i18n.t(`error-summary`),body:this._i18n.t(`renew-loan.error-renew-loan-date-in-past`),type:`danger`};return}let a=this.entryPointUrl+this.bookOfferId+`/loans`,o={borrower:this.personId,library:this.getSublibraryCode(),endTime:i.toISOString()},s=await fetch(a,{method:`POST`,headers:{Accept:`application/ld+json`,"Content-Type":`application/ld+json`,Authorization:`Bearer `+this.auth.token},body:JSON.stringify(o)});s.ok?(this._(`dbp-sublibrary-book-offer-select`).clear(),this.status={summary:u(`create-loan.success-summary`),body:this._i18n.t(`create-loan.success-body`,{personName:w(this.person)}),type:`info`}):await this.handleFetchError(s)}onSublibraryChanged(e){this.sublibraryIri=e.detail.value,this.sublibrary=e.detail.object}onReloadButtonClicked(e){this.updateCreateLoan()}_onLoginClicked(e){this.sendSetPropertyEvent(`requested-login-status`,`logged-in`),e.preventDefault()}render(){let t=new Date().toISOString(),i=new Date;i.setMonth(i.getMonth()+1);let a=i.toISOString(),o=this._i18n;return m(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-library-user-select subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth" @change=${0} value="${0}"></dbp-library-user-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} <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> `,C({hidden:!this.isLoggedIn()||!this.hasLibraryPermissions()||this.isLoading()}),o.t(`organization-select.label`),this.sublibraryIri,this.onSublibraryChanged,o.t(`library-user-select.headline`),this.onPersonSelectChanged,this.personId,o.t(`library-book-offer-select.headline`),this.onBookSelectChanged,this.onBookSelectChanged,this.bookOfferId,this.sublibraryIri,!this.bookOffer,this.onReloadButtonClicked,this.bookOffer?o.t(`create-loan.button-refresh-title`,{name:this.bookOffer.name}):``,o.t(`create-loan.mini-spinner-text`),o.t(`renew-loan.end-date`),p(t),p(a),this.onSubmitClicked,o.t(`create-loan.submit`),this.sendButtonDisabled,this.status?m(r||=e` <br /> <div class="notification is-${0}"> <h4>${0}</h4> ${0} </div> `,this.status.type,o.t(this.status.summary),o.t(this.status.body)):``,C({hidden:this.isLoggedIn()||this.isLoading()}),o.t(`error-login-message`),this._onLoginClicked,o.t(`error-login-link`),C({hidden:this.hasLibraryPermissions()||!this.isLoggedIn()||this.isLoading()}),o.t(`error-permission-message`),C({hidden:!this.isLoading()}))}}); //# sourceMappingURL=dbp-sublibrary-create-loan.js.map