@teipublisher/pb-components 2.25.3 → 2.26.1-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/pb-login.js CHANGED
@@ -2,13 +2,11 @@ import { LitElement, html, css } from 'lit-element';
2
2
  import { pbMixin, waitOnce } from './pb-mixin.js';
3
3
  import { translate } from "./pb-i18n.js";
4
4
  import { registry } from "./urls.js";
5
+ import { PbDialog } from './pb-dialog.js';
5
6
  import '@polymer/iron-ajax';
6
- import '@polymer/paper-dialog';
7
- import '@polymer/paper-dialog-scrollable';
8
- import '@polymer/paper-input/paper-input.js';
9
- import '@polymer/paper-button';
10
7
  import '@polymer/iron-icons';
11
8
  import { minVersion } from './utils.js';
9
+ import { pbLightDom } from './pb-light-dom.js';
12
10
 
13
11
  /**
14
12
  * Handles login/logout. Shows a link which opens a login dialog if clicked.
@@ -20,7 +18,8 @@ import { minVersion } from './utils.js';
20
18
  * @csspart message-invalid - Block displayed if login is invalid
21
19
  * @csspart group-invalid - Text displayed if login is invalid concerning group
22
20
  */
23
- export class PbLogin extends pbMixin(LitElement) {
21
+ export class PbLogin extends pbLightDom(pbMixin(LitElement)) {
22
+
24
23
  static get properties() {
25
24
  return {
26
25
  ...super.properties,
@@ -106,8 +105,13 @@ export class PbLogin extends pbMixin(LitElement) {
106
105
 
107
106
  firstUpdated() {
108
107
  super.firstUpdated();
109
- this._checkLogin = this.shadowRoot.getElementById('checkLogin');
110
- this._loginDialog = this.shadowRoot.getElementById('loginDialog');
108
+ this._checkLogin = this.renderRoot.querySelector('.checkLogin');
109
+ this._loginDialog = this.renderRoot.querySelector('pb-dialog');
110
+
111
+ this.renderRoot.querySelector('form').addEventListener('submit', (e) => {
112
+ e.preventDefault();
113
+ this._confirmLogin();
114
+ });
111
115
 
112
116
  window.addEventListener('blur', () => {
113
117
  this._hasFocus = false;
@@ -140,75 +144,46 @@ export class PbLogin extends pbMixin(LitElement) {
140
144
  }
141
145
 
142
146
  render() {
147
+ const logoutIcon = this.fillSlot('icon-login', html`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person" viewBox="0 0 16 16">
148
+ <path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6m2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0m4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4m-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10s-3.516.68-4.168 1.332c-.678.678-.83 1.418-.832 1.664z"/>
149
+ </svg>`);
150
+ const loginIcon = this.fillSlot('icon-logout', html`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person-check" viewBox="0 0 16 16">
151
+ <path d="M12.5 16a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7m1.679-4.493-1.335 2.226a.75.75 0 0 1-1.174.144l-.774-.773a.5.5 0 0 1 .708-.708l.547.548 1.17-1.951a.5.5 0 1 1 .858.514M11 5a3 3 0 1 1-6 0 3 3 0 0 1 6 0M8 7a2 2 0 1 0 0-4 2 2 0 0 0 0 4"/>
152
+ <path d="M8.256 14a4.5 4.5 0 0 1-.229-1.004H3c.001-.246.154-.986.832-1.664C4.484 10.68 5.711 10 8 10q.39 0 .74.025c.226-.341.496-.65.804-.918Q8.844 9.002 8 9c-5 0-6 3-6 4s1 1 1 1z"/>
153
+ </svg>`);
143
154
  return html`
144
- <a href="#" @click="${this._show}" role="button" title="${this.user ? this.user : this.loginLabel}">
155
+ <a href="#" @click="${this._show}" role="button" title="${this.user ? translate(this.logoutLabel, { user: this.user }) : translate(this.loginLabel)}">
145
156
  ${
146
- this.loggedIn ?
147
- html`<iron-icon icon="${this.logoutIcon}"></iron-icon> <span class="label">${translate(this.logoutLabel, { user: this.user })}</span>` :
148
- html`<iron-icon icon="${this.loginIcon}"></iron-icon> <span class="label">${translate(this.loginLabel)}</span>`
149
- }
157
+ this.loggedIn ?
158
+ loginIcon :
159
+ logoutIcon
160
+ }
150
161
  </a>
151
162
 
152
- <paper-dialog id="loginDialog" ?modal="${this.auto}">
153
- <h2>${translate('login.login')}</h2>
154
- <paper-dialog-scrollable>
155
- <form action="login">
156
- <paper-input id="user" name="user" label="${translate('login.user')}" value="${this.user}" autofocus></paper-input>
157
- <paper-input id="password" name="password" label="${translate('login.password')}" type="password"></paper-input>
158
- <input id="logout" type="hidden" name="logout"></input>
159
- </form>
160
- <slot name="information"></slot>
161
- ${this._invalid ?
162
- html`
163
- <p id="message" part="message-invalid">${translate('login.invalid')}<span part="group-invalid">${this.group ? html` (${translate('login.requiredGroup', { group: this.group })})` : null}</span>.
164
- </p>
165
- `: null
166
- }
167
- </paper-dialog-scrollable>
168
- <div class="buttons">
169
- <paper-button autofocus @click="${this._confirmLogin}">${translate(this.loginLabel)}</paper-button>
170
- </div>
171
- </paper-dialog>
163
+ <form action="login">
164
+ <pb-dialog ?modal="${this.auto}">
165
+ <h2 slot="title"><pb-i18n key="login.login"></pb-i18n></h2>
166
+ <label>
167
+ <pb-i18n key="login.user"></pb-i18n>
168
+ <input name="user" value="${this.user}" autofocus></input>
169
+ </label>
170
+ <label>
171
+ <pb-i18n key="login.password"></pb-i18n>
172
+ <input name="password" type="password"></input>
173
+ </label>
174
+ ${ this.fillSlot('information') }
175
+ <p part="message-invalid" style="display: none;"><pb-i18n key="login.invalid"></pb-i18n><span part="group-invalid">${this.group ? html` (<pb-i18n key="login.requiredGroup" options='{ "group": "${this.group}" }'></pb-i18n>)` : null}</span>.</p>
176
+ <button autofocus slot="footer"><pb-i18n key="login.login"></pb-i18n></button>
177
+ </pb-dialog>
178
+ </form>
172
179
 
173
- <iron-ajax id="checkLogin" with-credentials
180
+ <iron-ajax class="checkLogin" with-credentials
174
181
  handle-as="json" @response="${this._handleResponse}" @error="${this._handleError}"
175
182
  method="post"
176
183
  content-type="application/x-www-form-urlencoded"></iron-ajax>
177
184
  `;
178
185
  }
179
186
 
180
- static get styles() {
181
- return css`
182
- :host {
183
- display: block;
184
- }
185
-
186
- paper-dialog {
187
- min-width: 320px;
188
- max-width: 640px;
189
- min-height: 128px;
190
- }
191
-
192
- paper-dialog h2 {
193
- background-color: #607D8B;
194
- padding: 16px 8px;
195
- margin-top: 0;
196
- color: #F0F0F0;
197
- }
198
-
199
- a {
200
- color: var(--pb-login-link-color, --pb-link-color);
201
- text-decoration: none;
202
- display: flex;
203
- gap:0.5rem;
204
- }
205
-
206
- #message {
207
- color: var(--paper-red-800);
208
- }
209
- `;
210
- }
211
-
212
187
  _show(ev) {
213
188
  ev.preventDefault();
214
189
  if (this.loggedIn) {
@@ -217,13 +192,13 @@ export class PbLogin extends pbMixin(LitElement) {
217
192
  };
218
193
  this._checkLogin.generateRequest();
219
194
  } else {
220
- this._loginDialog.open();
195
+ this._loginDialog.openDialog();
221
196
  }
222
197
  }
223
198
 
224
199
  _confirmLogin() {
225
- this.user = this.shadowRoot.getElementById('user').value;
226
- this.password = this.shadowRoot.getElementById('password').value;
200
+ this.user = this.renderRoot.querySelector('input[name="user"]').value;
201
+ this.password = this.renderRoot.querySelector('input[name="password"]').value;
227
202
  this._checkLogin.body = {
228
203
  user: this.user,
229
204
  password: this.password
@@ -238,16 +213,16 @@ export class PbLogin extends pbMixin(LitElement) {
238
213
  this.loggedIn = true;
239
214
  this.user = resp.user;
240
215
  this.groups = resp.groups;
241
- this._invalid = false;
242
- this._loginDialog.close();
216
+ this.renderRoot.querySelector('p[part="message-invalid"]').style.display = '';
217
+ this._loginDialog.closeDialog();
243
218
  } else {
244
219
  resp.userChanged = this.loggedIn;
245
220
  this.loggedIn = false;
246
221
  this.password = null;
247
- if (this._loginDialog.opened) {
248
- this._invalid = true;
222
+ if (this._loginDialog.open) {
223
+ this.renderRoot.querySelector('p[part="message-invalid"]').style.display = '';
249
224
  } else if (this.auto) {
250
- this._loginDialog.open();
225
+ this._loginDialog.openDialog();
251
226
  }
252
227
  }
253
228
  this.emitTo('pb-login', resp);
@@ -270,10 +245,11 @@ export class PbLogin extends pbMixin(LitElement) {
270
245
  userChanged: this.loggedIn,
271
246
  user: null
272
247
  };
273
- if (this._loginDialog.opened) {
274
- this._invalid = true;
248
+ if (this._loginDialog.open) {
249
+ this.renderRoot.querySelector('p[part="message-invalid"]').style.display = '';
250
+ this.requestUpdate();
275
251
  } else if (this.auto) {
276
- this._loginDialog.open();
252
+ this._loginDialog.openDialog();
277
253
  }
278
254
 
279
255
  registry.currentUser = null;
@@ -37,6 +37,9 @@ export class PbNavigation extends pbHotkeys(pbMixin(LitElement)) {
37
37
  */
38
38
  rendition : {
39
39
  type: String
40
+ },
41
+ _url: {
42
+ type: String
40
43
  }
41
44
  };
42
45
  }
@@ -64,6 +67,7 @@ export class PbNavigation extends pbHotkeys(pbMixin(LitElement)) {
64
67
  }
65
68
 
66
69
  _update(ev) {
70
+ this._url = this._computeURL(ev.detail.data);
67
71
  if (this.direction === 'forward') {
68
72
  if (ev.detail.data.next) {
69
73
  this.disabled = false;
@@ -77,13 +81,22 @@ export class PbNavigation extends pbHotkeys(pbMixin(LitElement)) {
77
81
  }
78
82
  }
79
83
 
80
- _handleClick() {
84
+ _computeURL(data) {
85
+ if (this.direction === 'backward') {
86
+ return data.previousId ? `?id=${data.previousId}` : `?root=${data.previous}`;
87
+ } else if (this.direction === 'forward') {
88
+ return data.nextId ? `?id=${data.nextId}` : `?root=${data.next}`;
89
+ }
90
+ }
91
+
92
+ _handleClick(ev) {
93
+ ev.preventDefault();
81
94
  this.emitTo('pb-navigate', { direction: this.direction });
82
95
  }
83
96
 
84
97
  render() {
85
98
  return html`
86
- <a id="button" @click="${this._handleClick}"><slot></slot></a>
99
+ <a id="button" @click="${this._handleClick}" href="${this._url}"><slot></slot></a>
87
100
  `;
88
101
  }
89
102