@dile/crud 0.0.40 → 0.0.41

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 { DileAjaxSwitch } from "./src/DileAjaxSwitch";
2
+ customElements.define('dile-ajax-switch', DileAjaxSwitch);
@@ -0,0 +1 @@
1
+ export { DileAjaxSwitch } from "./src/DileAjaxSwitch";
@@ -0,0 +1,75 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import '@dile/ui/components/switch/switch';
3
+ import '../../ajax/ajax';
4
+ import { RequestApiAdapter } from '../../../lib/RequestApiAdapter';
5
+
6
+ export class DileAjaxSwitch 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: Boolean },
18
+ endpoint: { type: String },
19
+ checkedLabel: { type: String },
20
+ uncheckedLabel: { type: String },
21
+ loading: { type: Boolean },
22
+ method: { type: String },
23
+ requestApiAdapter: { type: Boolean },
24
+ };
25
+ }
26
+
27
+ constructor() {
28
+ super();
29
+ this.requestApiAdapter = new RequestApiAdapter();
30
+ this.method = 'patch';
31
+ }
32
+
33
+ render() {
34
+ return html`
35
+ <dile-ajax
36
+ id="elajax"
37
+ method="${this.method}"
38
+ url="${this.endpoint}"
39
+ @ajax-success="${this.doSuccessAjax}"
40
+ @ajax-error="${this.doErrorAjax}"
41
+ ></dile-ajax>
42
+ <dile-switch
43
+ ?disabled=${this.loading}
44
+ ?checked=${this.value}
45
+ useReactiveLabels
46
+ checkedLabel="${this.checkedLabel}"
47
+ uncheckedLabel="${this.uncheckedLabel}"
48
+ @dile-switch-changed=${this.save}
49
+ ></dile-switch>
50
+ `;
51
+ }
52
+
53
+ save(e) {
54
+ if(!this.loading) {
55
+ this.loading = true;
56
+ this.value = e.detail.checked;
57
+ let data = {
58
+ value: this.value
59
+ }
60
+ let elajax = this.shadowRoot.getElementById('elajax');
61
+ elajax.data = this.requestApiAdapter.adaptBooleanValue(data);
62
+ elajax.generateRequest();
63
+ }
64
+ }
65
+
66
+ doErrorAjax() {
67
+ this.loading = false;
68
+ this.value = !this.value;
69
+ }
70
+
71
+ doSuccessAjax() {
72
+ this.loading = false;
73
+ }
74
+ }
75
+
@@ -12,4 +12,7 @@ export class RequestApiAdapter {
12
12
  adaptIdsRequestData(data) {
13
13
  return data;
14
14
  }
15
+ adaptBooleanValue(data) {
16
+ return data;
17
+ }
15
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "description": "Components to create a generic crud system based on Web Components and Lit",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -24,12 +24,12 @@
24
24
  },
25
25
  "homepage": "https://dile-components.polydile.com/",
26
26
  "dependencies": {
27
- "@dile/ui": "^2.1.18",
27
+ "@dile/ui": "^2.1.19",
28
28
  "axios": "^1.7.2",
29
29
  "lit": "^2.7.0 || ^3.0.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "04e4cb1ee801ba221847efb9e8067102de43192e"
34
+ "gitHead": "6f6fd44a9d3244f6f73e29d50a00a4eb8277286b"
35
35
  }