@dile/crud 1.13.6 → 1.14.0

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.
@@ -0,0 +1,2 @@
1
+ import { DileSelectAjaxChange } from "./src/DileSelectAjaxChange.js";
2
+ customElements.define('dile-select-ajax-change', DileSelectAjaxChange);
@@ -0,0 +1 @@
1
+ export { DileSelectAjaxChange } from "./src/DileSelectAjaxChange.js";
@@ -0,0 +1,86 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import '@dile/ui/components/select/select.js';
3
+ import '../../ajax/ajax.js';
4
+ import { RequestApiAdapter } from '../../../lib/RequestApiAdapter.js';
5
+
6
+ export class DileSelectAjaxChange extends LitElement {
7
+ static styles = [
8
+ css`
9
+ :host {
10
+ display: block;
11
+ }
12
+ `
13
+ ];
14
+
15
+ static get properties() {
16
+ return {
17
+ value: { type: String },
18
+ endpoint: { type: String },
19
+ loading: { type: Boolean },
20
+ method: { type: String },
21
+ requestApiAdapter: { type: Object },
22
+ dataFieldName: { type: String },
23
+ };
24
+ }
25
+
26
+ constructor() {
27
+ super();
28
+ this.requestApiAdapter = new RequestApiAdapter();
29
+ this.method = 'patch';
30
+ this.dataFieldName = 'value';
31
+ this.changeHandler = this.onSelectChange.bind(this);
32
+ }
33
+
34
+ render() {
35
+ return html`
36
+ <dile-ajax
37
+ id="elajax"
38
+ method="${this.method}"
39
+ url="${this.endpoint}"
40
+ @ajax-success="${this.doSuccessAjax}"
41
+ @ajax-error="${this.doErrorAjax}"
42
+ ></dile-ajax>
43
+ <slot name="select"></slot>
44
+ `;
45
+ }
46
+
47
+ get elselect() {
48
+ return this.querySelector("select");
49
+ }
50
+
51
+ connectedCallback() {
52
+ super.connectedCallback();
53
+ if (!this.elselect) {
54
+ throw new Error('Use dile-select-ajax-change with a select element in the slot "select"');
55
+ } else {
56
+ this.elselect.addEventListener("change", this.changeHandler);
57
+ }
58
+ }
59
+
60
+ disconnectedCallback() {
61
+ super.disconnectedCallback();
62
+ if (this.elselect) {
63
+ this.elselect.removeEventListener("change", this.changeHandler);
64
+ }
65
+ }
66
+
67
+ onSelectChange(e) {
68
+ if (!this.loading) {
69
+ this.loading = true;
70
+ this.value = e.target.value;
71
+ let data = {};
72
+ data[this.dataFieldName] = this.value;
73
+ let elajax = this.shadowRoot.getElementById('elajax');
74
+ elajax.data = data;
75
+ elajax.generateRequest();
76
+ }
77
+ }
78
+
79
+ doErrorAjax() {
80
+ this.loading = false;
81
+ }
82
+
83
+ doSuccessAjax() {
84
+ this.loading = false;
85
+ }
86
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "1.13.6",
3
+ "version": "1.14.0",
4
4
  "description": "Components to create a generic crud system based on Web Components and Lit",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "bee395534b845e42cb7a4f493ba50bbc9a13944d"
34
+ "gitHead": "5cc12dde784bca3bf51a8e2cfcd537cafb72123f"
35
35
  }