diff --git a/src/base-element.js b/src/base-element.js new file mode 100644 index 0000000000000000000000000000000000000000..01d03fb6e7c43d6e24ac9e2c6ad4e1816de45f02 --- /dev/null +++ b/src/base-element.js @@ -0,0 +1,62 @@ +import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element"; + +export class BaseLitElement extends AdapterLitElement { + constructor() { + super(); + this.auth = {}; + } + + static get properties() { + return { + ...super.properties, + auth: { type: Object }, + }; + } + + _(selector) { + return this.shadowRoot === null ? this.querySelector(selector) : this.shadowRoot.querySelector(selector); + } + + _hasSignaturePermissions(roleName) { + return (this.auth.person && Array.isArray(this.auth.person.roles) && this.auth.person.roles.indexOf(roleName) !== -1); + } + + _updateAuth() { + this._loginStatus = this.auth['login-status']; + // Every time isLoggedIn()/isLoading() return something different we request a re-render + let newLoginState = [this.isLoggedIn(), this.isLoading()]; + if (this._loginState.toString() !== newLoginState.toString()) { + this.requestUpdate(); + } + this._loginState = newLoginState; + } + + update(changedProperties) { + changedProperties.forEach((oldValue, propName) => { + switch (propName) { + case "auth": + this._updateAuth(); + break; + } + }); + + super.update(changedProperties); + } + + connectedCallback() { + super.connectedCallback(); + + this._loginStatus = ''; + this._loginState = []; + } + + isLoggedIn() { + return (this.auth.person !== undefined && this.auth.person !== null); + } + + isLoading() { + if (this._loginStatus === "logged-out") + return false; + return (!this.isLoggedIn() && this.auth.token !== undefined); + } +} diff --git a/src/dbp-signature-lit-element.js b/src/dbp-signature-lit-element.js index 89e2c55c480e22377ead459e91897f87e1858405..570535f2208cd904ef9acfbdb1300518fc271ed0 100644 --- a/src/dbp-signature-lit-element.js +++ b/src/dbp-signature-lit-element.js @@ -1,69 +1,8 @@ import * as utils from "./utils"; -import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element"; import * as commonUtils from "@dbp-toolkit/common/utils"; +import {BaseLitElement} from './base-element.js'; -export class DBPSignatureBaseLitElement extends AdapterLitElement { - constructor() { - super(); - this.auth = {}; - } - - static get properties() { - return { - ...super.properties, - auth: { type: Object }, - }; - } - - _(selector) { - return this.shadowRoot === null ? this.querySelector(selector) : this.shadowRoot.querySelector(selector); - } - - _hasSignaturePermissions(roleName) { - return (this.auth.person && Array.isArray(this.auth.person.roles) && this.auth.person.roles.indexOf(roleName) !== -1); - } - - _updateAuth() { - this._loginStatus = this.auth['login-status']; - // Every time isLoggedIn()/isLoading() return something different we request a re-render - let newLoginState = [this.isLoggedIn(), this.isLoading()]; - if (this._loginState.toString() !== newLoginState.toString()) { - this.requestUpdate(); - } - this._loginState = newLoginState; - } - - update(changedProperties) { - changedProperties.forEach((oldValue, propName) => { - switch (propName) { - case "auth": - this._updateAuth(); - break; - } - }); - - super.update(changedProperties); - } - - connectedCallback() { - super.connectedCallback(); - - this._loginStatus = ''; - this._loginState = []; - } - - isLoggedIn() { - return (this.auth.person !== undefined && this.auth.person !== null); - } - - isLoading() { - if (this._loginStatus === "logged-out") - return false; - return (!this.isLoggedIn() && this.auth.token !== undefined); - } -} - -export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { +export default class DBPSignatureLitElement extends BaseLitElement { constructor() { super(); this.queuedFiles = [];