@dile/crud 1.4.0 → 1.5.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.
@@ -0,0 +1,2 @@
1
+ import { DileFileUploaderForm } from './src/DileFileUploaderForm.js';
2
+ customElements.define('dile-file-uploader-form', DileFileUploaderForm);
@@ -0,0 +1,2 @@
1
+ import { DileFileUploader } from './src/DileFileUploader.js';
2
+ customElements.define('dile-file-uploader', DileFileUploader);
@@ -0,0 +1,2 @@
1
+ export { DileFileUploaderForm } from './src/DileFileUploaderForm.js';
2
+ export { DileFileUploader } from './src/DileFileUploader.js';
@@ -0,0 +1,69 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import '../../ajax-form/ajax-form.js';
3
+ import '../file-uploader-form.js';
4
+ import { ResponseApiAdapter } from '../../../lib/ResponseApiAdapter.js';
5
+ import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
6
+
7
+ export class DileFileUploader extends DileI18nMixin(LitElement) {
8
+ static styles = [
9
+ css`
10
+ :host {
11
+ display: block;
12
+ }
13
+ `
14
+ ];
15
+
16
+ static get properties() {
17
+ return {
18
+ endpoint: { type: String },
19
+ selectFileLabel: { type: String },
20
+ saveLabel: { type: String },
21
+ allowedExtensions: { type: Array },
22
+ responseAdapter: { type: Object },
23
+ };
24
+ }
25
+
26
+ constructor() {
27
+ super();
28
+ this.responseAdapter = new ResponseApiAdapter();
29
+ this.allowedExtensions = ['*'];
30
+ }
31
+
32
+ render() {
33
+ return html`
34
+ <dile-ajax-form
35
+ id="elform"
36
+ operation="insert"
37
+ endpoint=${this.endpoint}
38
+ actionLabel="${this.saveLabelComputed(this.saveLabel, this.translations)}"
39
+ sendDataAsFormData
40
+ language="${this.language}"
41
+ @save-success=${this.fileSaveSuccess}
42
+ .responseAdapter=${this.responseAdapter}
43
+ >
44
+ <dile-file-uploader-form
45
+ id="form"
46
+ label="${this.selectLabelComputed(this.selectFileLabel, this.translations)}"
47
+ .allowedExtensions=${this.allowedExtensions}
48
+ .translations=${this.translations}
49
+ ></dile-file-uploader-form>
50
+ </dile-ajax-form>
51
+ `;
52
+ }
53
+
54
+ selectLabelComputed(label, translations) {
55
+ return label ? label : translations?.select_file_label ? translations.select_file_label : 'Select a file';
56
+ }
57
+
58
+ saveLabelComputed(label, translations) {
59
+ return label ? label : translations?.save_file_label ? translations.save_file_label : 'Save file';
60
+ }
61
+
62
+ fileSaveSuccess(e) {
63
+ this.dispatchEvent(new CustomEvent('file-uploaded', {
64
+ bubbles: true,
65
+ composed: true,
66
+ detail: e.detail
67
+ }));
68
+ }
69
+ }
@@ -0,0 +1,39 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import { DileForm } from '@dile/ui/mixins/form/index.js'
3
+ import '@dile/ui/components/drop-file/drop-file.js';
4
+
5
+ export class DileFileUploaderForm extends DileForm(LitElement) {
6
+ static styles = [
7
+ css`
8
+ :host {
9
+ display: block;
10
+ }
11
+ dile-drop-file {
12
+ margin-bottom: 0;
13
+ }
14
+ `
15
+ ];
16
+
17
+ static get properties() {
18
+ return {
19
+ label: { type: String },
20
+ allowedExtensions: { type: Array },
21
+ translations: { type: Object },
22
+ };
23
+ }
24
+
25
+ render() {
26
+ return html`
27
+ <dile-drop-file
28
+ name="file"
29
+ label="${this.label}"
30
+ id="dropfile"
31
+ .allowedExtensions=${this.allowedExtensions}
32
+ dropLabel="${this.translations.file_drop}"
33
+ buttonLabel="${this.translations.select_file}"
34
+ selectedFileLabel="${this.translations.selected_file}"
35
+ extensionErrorMessage="${this.translations.extension_allowed}"
36
+ ></dile-drop-file>
37
+ `;
38
+ }
39
+ }
@@ -60,7 +60,8 @@ export class DileCrudInsert extends DileI18nMixin(LitElement) {
60
60
  operation="insert"
61
61
  endpoint="${this.endpoint}"
62
62
  actionLabel="${this.actionLabelComputed(this.actionLabel, this.translations)}"
63
- @save-success="${this.doSuccessSave}"
63
+ @save-success=${this.doSuccessSave}
64
+ @save-error=${this.doSuccessError}
64
65
  ?buttonSmall="${this.buttonSmall}"
65
66
  .responseAdapter="${this.responseAdapter}"
66
67
  formIdentifier="${this.formIdentifier}"
@@ -81,6 +82,14 @@ export class DileCrudInsert extends DileI18nMixin(LitElement) {
81
82
  }));
82
83
  }
83
84
 
85
+ doSuccessError(e) {
86
+ this.dispatchEvent(new CustomEvent('crud-insert-error', {
87
+ bubbles: true,
88
+ composed: true,
89
+ detail: e.detail
90
+ }));
91
+ }
92
+
84
93
  setData(data) {
85
94
  this.updateComplete.then(() => {
86
95
  this.formElement.setData(data);
package/lib/i18n/en.js CHANGED
@@ -46,6 +46,8 @@ export const translations = {
46
46
  element_actions: "Element actions",
47
47
  select_image: "Select an image",
48
48
  save_image: "Save image",
49
+ select_file_label: "Select a file",
50
+ save_file_label: "Save file",
49
51
  file_drop: "Drop here your file",
50
52
  select_file: "Select file",
51
53
  selected_file: "Selected file",
package/lib/i18n/es.js CHANGED
@@ -46,6 +46,8 @@ export const translations = {
46
46
  element_actions: "Acciones en este ítem",
47
47
  select_image: "Selecciona una imagen",
48
48
  save_image: "Salvar la imagen",
49
+ select_file_label: "Selecciona un archivo",
50
+ save_file_label: "Guardar archivo",
49
51
  file_drop: "Suelta aquí el archivo",
50
52
  select_file: "Seleccionar archivo",
51
53
  selected_file: "Archivo seleccionado",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
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.com/",
26
26
  "dependencies": {
27
- "@dile/ui": "^2.17.1",
27
+ "@dile/ui": "^2.18.0",
28
28
  "axios": "^1.13.0",
29
29
  "lit": "^2.7.0 || ^3.0.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "cc0d45df6cd51bb13578c937ab4bdb3065330f6b"
34
+ "gitHead": "8fb4049d780b8cbd0b8a74296fd9983d499f9d4d"
35
35
  }