@dile/crud 0.0.39 → 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
+
@@ -80,7 +80,9 @@ export class DileCrudSingle extends DileI18nMixin(DileCrudMixin(LitElement)) {
80
80
  <main class="elcontainer">
81
81
  ${this.detailTemplate}
82
82
  <div class="actions" @action-success=${this.actionSuccess}>
83
- <dile-button gray .icon="${editIcon}" @click=${this.edit}>${this.updateLabelComputed(this.config.labels.updateAction, this.translations)}</dile-button>
83
+ <dile-button gray .icon="${editIcon}" @click=${this.edit}>
84
+ ${this.startUpdateLabelComputed(this.config.labels.startUpdateAction, this.translations)}
85
+ </dile-button>
84
86
  ${this.actionsTemplate}
85
87
  </div>
86
88
  </main>
@@ -58,6 +58,9 @@ export const DileCrudMixin = (superclass) => class extends superclass {
58
58
  updateLabelComputed(label, translations) {
59
59
  return label ? label : translations?.update_label ? translations.update_label : 'Save';
60
60
  }
61
+ startUpdateLabelComputed(label, translations) {
62
+ return label ? label : translations?.start_update_label ? translations.start_update_label : 'Edit';
63
+ }
61
64
  helpLabelComputed(label, translations) {
62
65
  return label ? label : translations?.help_label ? translations.help_label : 'Help';
63
66
  }
@@ -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
  }
@@ -70,6 +70,7 @@ export const defaultConfig = {
70
70
  labels: {
71
71
  // insertAction: 'Create',
72
72
  // updateAction: 'Save',
73
+ // startUpdateAction: 'Edit',
73
74
  // insertWindowTitle: 'Create an item',
74
75
  // updateWindowTitle: 'Update an item',
75
76
  // helpTitle: 'Help',
package/lib/i18n/en.js CHANGED
@@ -13,6 +13,7 @@ export const translations = {
13
13
  error_operation: (operation) => `${operation == 'insert' ? 'Insertion' : 'Update'} error`,
14
14
  insert_label: "Create",
15
15
  update_label: "Update",
16
+ start_update_label: "Edit",
16
17
  delete_label: "Delete",
17
18
  cancel_label: "Cancel",
18
19
  accept_label: "Accept",
package/lib/i18n/es.js CHANGED
@@ -13,6 +13,7 @@ export const translations = {
13
13
  error_operation: (operation) => `Se ha producido un error en la ${operation == 'insert' ? 'inserción' : 'actualización'}`,
14
14
  insert_label: "Insertar",
15
15
  update_label: "Actualizar",
16
+ start_update_label: "Editar",
16
17
  delete_label: "Borrar",
17
18
  cancel_label: "Cancelar",
18
19
  accept_label: "Aceptar",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "0.0.39",
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": "47a3da898c4ef2856603eb98b41c8e3b09bef1df"
34
+ "gitHead": "6f6fd44a9d3244f6f73e29d50a00a4eb8277286b"
35
35
  }