@digital-blueprint/checkin-app
Version:
[GitHub Repository](https://github.com/digital-blueprint/checkin-app) | [npmjs package](https://www.npmjs.com/package/@digital-blueprint/checkin-app) | [Unpkg CDN](https://unpkg.com/browse/@digital-blueprint/checkin-app/) | [Checkin Bundle](https://github
103 lines (94 loc) • 11.6 kB
JavaScript
let e,t,n,i=e=>e;function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},s.apply(this,arguments)}
/*!
* License: LGPL-2.1-or-later
* Dependencies:
*
* @webcomponents/scoped-custom-element-registry: 0.0.9 (BSD-3-Clause)
* @dbp-toolkit/app-shell: 0.3.4 (LGPL-2.1-or-later)
* @dbp-toolkit/language-select: 0.3.2 (LGPL-2.1-or-later)
* @dbp-toolkit/common: 0.3.5 (LGPL-2.1-or-later)
* @dbp-toolkit/auth: 0.3.2 (LGPL-2.1-or-later)
* event-target-shim: 6.0.2 (MIT)
* @dbp-toolkit/notification: 0.3.2 (LGPL-2.1-or-later)
* @dbp-toolkit/theme-switcher: 0.0.6 (LGPL-2.1-or-later)
* path-to-regexp: 6.2.0 (MIT)
* universal-router: 9.1.0 (MIT)
* generateUrls: 9.1.0 (MIT)
* @dbp-toolkit/matomo: 0.2.7 (LGPL-2.1-or-later)
* @dbp-toolkit/qr-code-scanner: 0.3.3 (LGPL-2.1-or-later)
* async-mutex: 0.4.0 (MIT)
* select2: 4.0.13 (MIT)
*/import{S as a,A as r,t as o,I as c,g as l,b as u,f as h,u as d,m as p,i as m,q as g,x as b}from"./notification.fWOMSAA9.es.js";import{e as f,c as y}from"./activity.pxR99eKk.es.js";import{c as v}from"./utils.uVgKQcsS.es.js";function w(e,t){const n=`${t}: -`;let i=e.search(n);if(-1===i)throw new Error("ID not found");let s=e.substring(i+n.length).trim().split("-");if(0===s.length||s.length>2)throw new Error("invalid list format");1===s.length&&s.push("");let a=s[0],r=s[1],o=null;if(""===a)throw new Error("invalid location format");if(""===r)o=null;else{if(isNaN(parseInt(r,10)))throw new Error("invalid seat format");o=parseInt(r,10)}return[a,o]}function k(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var j="shared/select2.min.ae5735562faabd1a.css";class $ extends(a(r)){constructor(){super(),Object.assign($.prototype,f),this.entryPointUrl="",this.$select=null,this.active=!1,this.selectId="check-in-place-select-"+o(24),this.value="",this.object=null,this.ignoreValueUpdate=!1,this.isSearching=!1,this.lastResult={},this.showReloadButton=!1,this.reloadButtonTitle="",this.showCapacity=!1,this.auth={},this._i18n=y(),this.lang=this._i18n.language,this._onDocumentClicked=this._onDocumentClicked.bind(this)}static get scopedElements(){return{"dbp-icon":c}}$(e){return"string"==typeof e?this._jquery(this.shadowRoot.querySelector(e)):this._jquery(e)}static get properties(){return s({},super.properties,{lang:{type:String},active:{type:Boolean,attribute:!1},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"},showCapacity:{type:Boolean,attribute:"show-capacity"},auth:{type:Object}})}clear(){this.object=null,this.$(this).attr("data-object",""),this.$(this).attr("value",""),this.$(this).data("object",null),this.$select.val(null).trigger("change").trigger("select2:unselect")}async connectedCallback(){this._jquery=(await import("./jquery.KP-bImxq.es.js").then((function(e){return e.j}))).default,(0,(await import("./select2.0f0urm8X.es.js").then((function(e){return e.s}))).default)(window,this._jquery),await super.connectedCallback(),await this.updateComplete;this.$select=this.$("#"+this.selectId),this.select2IsInitialized()||this.initSelect2(),document.addEventListener("click",this._onDocumentClicked)}disconnectedCallback(){document.removeEventListener("click",this._onDocumentClicked),super.disconnectedCallback()}_onDocumentClicked(e){if(e.composedPath().includes(this))return;const t=this.$("#"+this.selectId);console.assert(t.length,"select2 missing"),this.select2IsInitialized(t)&&t.select2("close")}initSelect2(e=!1){const t=this,n=this.$(this);if(null===this.$select||null===this.entryPointUrl)return!1;const i=v(this.entryPointUrl,"/checkin/places");if(this.$select&&this.$select.hasClass("select2-hidden-accessible")&&(this.$select.select2("destroy"),this.$select.off("select2:select"),this.$select.off("select2:closing")),this.$select.select2({width:"100%",language:"de"===this.lang?{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"Bitte "+(e.minimum-e.input.length)+" Zeichen mehr eingeben, es kann nach mehreren Teilen von Namen gesucht werden"},loadingMore:function(){return"Lade mehr Ergebnisse…"},maximumSelected:function(e){var t="Sie können nur "+e.maximum+" Eintr";return 1===e.maximum?t+="ag":t+="äge",t+=" auswählen"},noResults:function(){return"Keine Übereinstimmungen gefunden"},searching:function(){return"Suche…"},removeAllItems:function(){return"Entferne alle Gegenstände"}}:{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 1!=t&&(n+="s"),n},inputTooShort:function(e){return"Please enter "+(e.minimum-e.input.length)+" or more characters, you can also search for multiple parts of names"},loadingMore:function(){return"Loading more results…"},maximumSelected:function(e){var t="You can only select "+e.maximum+" item";return 1!=e.maximum&&(t+="s"),t},noResults:function(){return"No results found"},searching:function(){return"Searching…"},removeAllItems:function(){return"Remove all items"}},minimumInputLength:2,placeholder:this._i18n.t("check-in-place-select.placeholder"),dropdownParent:this.$("#check-in-place-select-dropdown"),ajax:{delay:500,url:i,contentType:"application/ld+json",beforeSend:function(e){e.setRequestHeader("Authorization","Bearer "+t.auth.token),t.isSearching=!0},data:function(e){return{search:e.term.trim()}},processResults:function(e){t.$("#check-in-place-select-dropdown").addClass("select2-bug"),t.lastResult=e;const n=e["hydra:member"],i=[];return n.forEach((e=>{i.push({id:e["@id"],maximumPhysicalAttendeeCapacity:e.maximumPhysicalAttendeeCapacity,text:t.generateOptionText(e)})})),{results:i}},error:(e,t,n)=>{this.handleXhrError(e,t,n)},complete:(e,n)=>{t.isSearching=!1}}}).on("select2:open",(function(e){const n=e.target.id;t.$(".select2-search__field[aria-controls='select2-"+n+"-results']").each((function(e,t){t.focus()}))})).on("select2:select",(function(e){t.$("#check-in-place-select-dropdown").removeClass("select2-bug");const i=e.params.data.id,s=e.params.data.maximumPhysicalAttendeeCapacity;t.object=((e,t,n="@id")=>{const i=t["hydra:member"];if(void 0!==i)for(const t of i)if(t[n]===e)return t})(i,t.lastResult);const a=t.object.identifier;n.attr("data-object",JSON.stringify(t.object)),n.data("object",t.object);const r=t.object.name;n.attr("value")!==i&&(t.ignoreValueUpdate=!0,n.attr("value",i),t.dispatchEvent(new CustomEvent("change",{detail:{value:i,capacity:s,room:a,name:r},bubbles:!0})))})).on("select2:closing",(e=>{t.isSearching&&e.preventDefault()})),!e&&""!==this.value){const e=this.entryPointUrl+this.value;fetch(e,{headers:{"Content-Type":"application/ld+json",Authorization:"Bearer "+this.auth.token}}).then((e=>{if(!e.ok)throw e;return e.json()})).then((e=>{t.object=e;const i=e["@id"],s=e.maximumPhysicalAttendeeCapacity,a=e.name,r=e.identifier,o=new Option(t.generateOptionText(e),i,!0,!0);n.attr("data-object",JSON.stringify(e)),n.data("object",e),t.$select.append(o).trigger("change"),t.dispatchEvent(new CustomEvent("change",{detail:{value:i,capacity:s,room:r,name:a},bubbles:!0}))})).catch((e=>{console.log(e),t.clear()}))}return!0}generateOptionText(e){let t=e.name;if(this.showCapacity&&void 0!==e.maximumPhysicalAttendeeCapacity&&null!==e.maximumPhysicalAttendeeCapacity){t+=` (${e.maximumPhysicalAttendeeCapacity})`}return t}update(e){e.forEach(((e,t)=>{switch(t){case"lang":this._i18n.changeLanguage(this.lang),this.select2IsInitialized()&&this.initSelect2(!0);break;case"value":!this.ignoreValueUpdate&&this.select2IsInitialized()&&this.initSelect2(),this.ignoreValueUpdate=!1;break;case"entryPointUrl":this.initSelect2(!0);break;case"auth":this.active=!!this.auth.token,!this.active||e&&e.token||this.initSelect2()}})),super.update(e)}select2IsInitialized(){return null!==this.$select&&this.$select.hasClass("select2-hidden-accessible")}reloadClick(){null!==this.object&&this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0}))}static get styles(){return[l(),u(),h(),d(),p(),m(e||(e=i`
.select2-control.control {
width: 100%;
}
.field .button.control {
display: flex;
align-items: center;
justify-content: center;
border: var(--dbp-border);
border-color: var(--dbp-muted);
-moz-border-radius-topright: var(--dbp-border-radius);
-moz-border-radius-bottomright: var(--dbp-border-radius);
line-height: 100%;
}
.field .button.control dbp-icon {
top: 0;
}
input {
border-radius: 0;
}
input[type='search'] {
-webkit-appearance: none;
}
/* https://github.com/select2/select2/issues/5457 */
.select2-bug .loading-results {
display: none !important;
}
.select2-container--default .select2-selection--single,
.select2-dropdown,
.select2-container--default .select2-search--dropdown .select2-search__field {
background: var(--dbp-background);
border: var(--dbp-border);
border-color: var(--dbp-muted);
}
.select2-dropdown {
background-color: var(--dbp-background);
}
`))]}render(){const e=g(j),s=this._i18n;return b(t||(t=i`
<link rel="stylesheet" href="${0}" />
<style>
#${0} {
width: 100%;
}
</style>
<div class="select">
<div class="field has-addons">
<div class="select2-control control">
<!-- https://select2.org-->
<select
id="${0}"
name="check-in-place"
class="select"
?disabled=${0}>
${0}
</select>
</div>
<a
class="control button"
id="reload-button"
?disabled=${0}
="${0}"
style="display: ${0}"
title="${0}">
<dbp-icon name="reload"></dbp-icon>
</a>
</div>
<div id="check-in-place-select-dropdown"></div>
</div>
`),e,this.selectId,this.selectId,!this.active,this.active?"":b(n||(n=i`
<option value="" disabled selected>
${0}
</option>
`),s.t("check-in-place-select.login-required")),null===this.object,this.reloadClick,this.showReloadButton?"flex":"none",this.reloadButtonTitle)}}export{$ as C,k as e,w as p,j as s};
//# sourceMappingURL=check-in-place-select.6YIWD7RZ.es.js.map