@dile/crud 0.0.52 → 0.0.53

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.
@@ -20,6 +20,17 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
20
20
  .actions {
21
21
  margin-top: var(--dile-ajax-form-actions-margin-top, 1rem);
22
22
  padding-left: 3px;
23
+ display: flex;
24
+ gap: var(--dile-form-actions-gap, 1.2rem);
25
+ justify-content: var(--dile-form-actions-justify-content, flex-start);
26
+ }
27
+ .cancel_button {
28
+ --dile-primary-color: var(--dile-ajax-form-cancel-button-background-color, transparent);
29
+ --dile-on-primary-color: var(--dile-ajax-form-cancel-button-text-color, #303030);
30
+ --dile-primary-dark-color: var(--dile-ajax-form-cancel-button-border-color, transparent);
31
+ --dile-button-hover-background-color: var(--dile-ajax-form-cancel-button-hover-background-color, transparent);
32
+ --dile-button-hover-text-color: var(--dile-ajax-form-cancel-button-hover-text-color, #303030);
33
+ --dile-button-hover-border-color: var(--dile-ajax-form-cancel-button-hover-border-color, #303030);
23
34
  }
24
35
  `
25
36
  ];
@@ -29,6 +40,7 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
29
40
  operation: { type: String },
30
41
  endpoint: { type: String },
31
42
  actionLabel: { type: String },
43
+ cancelLabel: { type: String },
32
44
  data: { type: Object },
33
45
  relatedId: { type: String },
34
46
  loadOnInit: { type: Boolean },
@@ -37,6 +49,7 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
37
49
  setDataOnInit: { type: Boolean },
38
50
  responseAdapter: { type: Object },
39
51
  sendDataAsFormData: { type: Boolean },
52
+ showCancelButton: { type: Boolean },
40
53
  };
41
54
  }
42
55
 
@@ -71,13 +84,24 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
71
84
  return this.querySelector('#' + this.formIdentifier);
72
85
  }
73
86
 
87
+ actionLabelComputed(label, translations, operation) {
88
+ if(operation == 'insert') {
89
+ return label ? label : translations?.insert_label ? translations.insert_label : 'Insert';
90
+ }
91
+ if(operation == 'update') {
92
+ return label ? label : translations?.update_label ? translations.update_label : 'Update';
93
+ }
94
+ return translations.send_label;
95
+ }
96
+
74
97
  render() {
75
98
  return html`
76
99
  ${this.ajaxComponents}
77
100
  <slot></slot>
78
101
  <dile-inline-feedback id="feedback"></dile-inline-feedback>
79
102
  <div class="actions">
80
- <dile-button @click=${this.doAction}>${this.actionLabel}</dile-button>
103
+ <dile-button @click=${this.doAction}>${this.actionLabelComputed(this.actionLabel, this.translations, this.operation)}</dile-button>
104
+ ${this.showCancelButton ? html`<dile-button class="cancel_button" @click=${this.doCancel}>${this.translations.cancel_label}</dile-button>` : ''}
81
105
  </div>
82
106
  `;
83
107
  }
@@ -229,5 +253,15 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
229
253
  }
230
254
  return this.translations.error_operation(this.operation);
231
255
  }
256
+
257
+ doCancel() {
258
+ this.dispatchEvent(new CustomEvent('form-canceled', {
259
+ bubbles: true,
260
+ composed: true,
261
+ detail: {
262
+ data: this.form.getData()
263
+ }
264
+ }));
265
+ }
232
266
  }
233
267
 
@@ -24,6 +24,7 @@ export class DileCrudInsert extends DileI18nMixin(LitElement) {
24
24
  responseAdapter: { type: Object},
25
25
  formIdentifier: { type: String },
26
26
  sendDataAsFormData: { type: Boolean },
27
+ showCancelButton: { type: Boolean },
27
28
  };
28
29
  }
29
30
 
@@ -54,6 +55,7 @@ export class DileCrudInsert extends DileI18nMixin(LitElement) {
54
55
  formIdentifier="${this.formIdentifier}"
55
56
  language="${this.language}"
56
57
  ?sendDataAsFormData=${this.sendDataAsFormData}
58
+ ?showCancelButton=${this.showCancelButton}
57
59
  >
58
60
  ${this.formTemplate(this.belongsTo, this.relationId)}
59
61
  </dile-ajax-form>
@@ -90,7 +90,7 @@ export class DileCrudSingle extends DileI18nMixin(DileCrudMixin(LitElement)) {
90
90
  ${this.updateTemplate}
91
91
  ${this.singleActionsTemplate}
92
92
 
93
- ${this.config.templates.relations(this.element)}
93
+ ${this.element ? this.config.templates.relations(this.element) : ''}
94
94
  `;
95
95
  }
96
96
 
@@ -24,6 +24,7 @@ export class DileCrudUpdate extends DileI18nMixin(LitElement) {
24
24
  responseAdapter: { type: Object },
25
25
  formIdentifier: { type: String },
26
26
  sendDataAsFormData: { type: Boolean },
27
+ showCancelButton: { type: Boolean },
27
28
  };
28
29
  }
29
30
 
@@ -57,6 +58,7 @@ export class DileCrudUpdate extends DileI18nMixin(LitElement) {
57
58
  formIdentifier="${this.formIdentifier}"
58
59
  language="${this.language}"
59
60
  ?sendDataAsFormData=${this.sendDataAsFormData}
61
+ ?showCancelButton=${this.showCancelButton}
60
62
  >
61
63
  ${this.formTemplate()}
62
64
  </dile-ajax-form>
package/lib/i18n/en.js CHANGED
@@ -12,6 +12,7 @@ export const translations = {
12
12
  ajax_form_not_supported: "Operation not supported in dile-ajax-form use 'insert' or 'update'",
13
13
  success_operation: (operation) => operation == 'insert' ? 'The new item has been created' : 'Item updated successfully',
14
14
  error_operation: (operation) => `${operation == 'insert' ? 'Insertion' : 'Update'} error`,
15
+ send_label: "Send",
15
16
  insert_label: "Create",
16
17
  update_label: "Update",
17
18
  start_update_label: "Edit",
package/lib/i18n/es.js CHANGED
@@ -12,6 +12,7 @@ export const translations = {
12
12
  ajax_form_not_supported: "Operación no soportada por dile-ajax-form. Elige entre 'insert' o 'update'",
13
13
  success_operation: (operation) => `${operation == 'insert' ? 'Inserción' : 'Actualización'} completada con éxito`,
14
14
  error_operation: (operation) => `Se ha producido un error en la ${operation == 'insert' ? 'inserción' : 'actualización'}`,
15
+ send_label: "Enviar",
15
16
  insert_label: "Insertar",
16
17
  update_label: "Actualizar",
17
18
  start_update_label: "Editar",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
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.28",
27
+ "@dile/ui": "^2.1.29",
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": "2ff303719dd914f0beeee873b285466e3c8eadf5"
34
+ "gitHead": "ae6bb276e5139b7924bb81e4235d0745a59057b8"
35
35
  }