@dile/crud 0.0.9

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.
Files changed (79) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +5 -0
  3. package/components/action/crud-actions.js +2 -0
  4. package/components/action/crud-delete-action.js +2 -0
  5. package/components/action/crud-single-actions.js +2 -0
  6. package/components/action/src/DileCrudActions.js +181 -0
  7. package/components/action/src/DileCrudDeleteAction.js +18 -0
  8. package/components/action/src/DileCrudSingleActions.js +77 -0
  9. package/components/ajax/ajax.js +2 -0
  10. package/components/ajax/index.js +1 -0
  11. package/components/ajax/src/DileAjax.js +108 -0
  12. package/components/ajax-form/ajax-form.js +2 -0
  13. package/components/ajax-form/index.js +1 -0
  14. package/components/ajax-form/src/DileAjaxForm.js +216 -0
  15. package/components/ajax-select-crud/ajax-select-crud.js +3 -0
  16. package/components/ajax-select-crud/index.js +1 -0
  17. package/components/ajax-select-crud/src/DileAjaxSelectCrud.js +75 -0
  18. package/components/crud/crud-single.js +2 -0
  19. package/components/crud/crud.js +2 -0
  20. package/components/crud/delete-action.js +2 -0
  21. package/components/crud/src/DileCrud.js +352 -0
  22. package/components/detail/crud-detail.js +2 -0
  23. package/components/detail/src/DileCrudDetail.js +166 -0
  24. package/components/insert/crud-insert.js +2 -0
  25. package/components/insert/index.js +1 -0
  26. package/components/insert/src/DileCrudInsert.js +78 -0
  27. package/components/item-delete/crud-item-delete.js +2 -0
  28. package/components/item-delete/index.js +1 -0
  29. package/components/item-delete/src/DileCrudItemDelete.js +106 -0
  30. package/components/list/crud-list-item.js +2 -0
  31. package/components/list/crud-list-pagination-links.js +2 -0
  32. package/components/list/crud-list-service.js +2 -0
  33. package/components/list/crud-list.js +2 -0
  34. package/components/list/crud-select-all.js +2 -0
  35. package/components/list/index.js +5 -0
  36. package/components/list/src/DileCrudList.js +332 -0
  37. package/components/list/src/DileCrudListItem.js +129 -0
  38. package/components/list/src/DileCrudListPaginationLinks.js +89 -0
  39. package/components/list/src/DileCrudListService.js +163 -0
  40. package/components/list/src/DileCrudSelectAll.js +158 -0
  41. package/components/single/crud-single.js +2 -0
  42. package/components/single/index.js +1 -0
  43. package/components/single/src/DileCrudSingle.js +142 -0
  44. package/components/ui/crud-filters-form.js +3 -0
  45. package/components/ui/crud-filters-list-item.js +2 -0
  46. package/components/ui/crud-filters-list.js +2 -0
  47. package/components/ui/crud-filters.js +2 -0
  48. package/components/ui/crud-list-options.js +2 -0
  49. package/components/ui/crud-page-size-select.js +2 -0
  50. package/components/ui/crud-page-size.js +2 -0
  51. package/components/ui/crud-pagination-nav-button.js +2 -0
  52. package/components/ui/crud-sort-form.js +2 -0
  53. package/components/ui/index.js +4 -0
  54. package/components/ui/src/DileCrudFilters.js +62 -0
  55. package/components/ui/src/DileCrudFiltersForm.js +58 -0
  56. package/components/ui/src/DileCrudFiltersList.js +70 -0
  57. package/components/ui/src/DileCrudFiltersListItem.js +28 -0
  58. package/components/ui/src/DileCrudListOptions.js +64 -0
  59. package/components/ui/src/DileCrudPageSize.js +27 -0
  60. package/components/ui/src/DileCrudPageSizeSelect.js +44 -0
  61. package/components/ui/src/DileCrudPaginationNavButton.js +44 -0
  62. package/components/ui/src/DileCrudSortForm.js +105 -0
  63. package/components/update/crud-update.js +2 -0
  64. package/components/update/index.js +1 -0
  65. package/components/update/src/DileCrudUpdate.js +81 -0
  66. package/lib/AxiosInstanceBuilder.js +21 -0
  67. package/lib/CrudConfigBuilder.js +13 -0
  68. package/lib/DileAxios.js +14 -0
  69. package/lib/DileConfig.js +0 -0
  70. package/lib/DileCrudMixin.js +72 -0
  71. package/lib/DileLoading.js +31 -0
  72. package/lib/RequestApiAdapter.js +15 -0
  73. package/lib/ResponseApiAdapter.js +37 -0
  74. package/lib/capitalizeString.js +3 -0
  75. package/lib/deepMerge.js +38 -0
  76. package/lib/defaultConfig.js +67 -0
  77. package/package.json +35 -0
  78. package/styles/crud-styles.js +6 -0
  79. package/styles/form-styles.js +24 -0
@@ -0,0 +1,75 @@
1
+ import { DileAxios } from '../../../lib/DileAxios.js';
2
+ import { DileSelectAjax } from '@dile/ui/components/select';
3
+
4
+ export class DileAjaxSelectCrud extends DileAxios(DileSelectAjax) {
5
+
6
+ static get properties() {
7
+ return {
8
+ maxResults: { type: Number },
9
+ pageParamName: { type: String },
10
+ getSelectResultList: { type: Object },
11
+ };
12
+ }
13
+
14
+ constructor() {
15
+ super();
16
+ }
17
+
18
+ searchValueInitial() {
19
+ let request = this.axiosInstance.get(`${this.endpoint}/${this.value}`);
20
+ request.then((response) => {
21
+ if (response.status == 200) {
22
+ let res = response.data;
23
+ if (res.error) {
24
+ this.registerError(res.data);
25
+ } else {
26
+ this.registerText(res.data);
27
+ }
28
+ } else {
29
+ this.registerError('Bad response code');
30
+ }
31
+ })
32
+ .catch(err => {
33
+ this.registerError(err);
34
+ });
35
+ }
36
+
37
+ loadData() {
38
+ this.loading = true;
39
+ let params = {}
40
+ if (this.pageParamName && this.maxResults) {
41
+ params[this.pageParamName] = this.maxResults;
42
+ }
43
+ params[this.queryStringVariable] = this.keyword;
44
+ let request = this.axiosInstance.get(this.endpoint, { params });
45
+ request.then((response) => {
46
+ if (response.status == 200) {
47
+ let res = response.data;
48
+ if (res.error) {
49
+ this.registerError(res.data);
50
+ } else {
51
+ this.registerData(res);
52
+ }
53
+ } else {
54
+ this.registerError('Bad response code');
55
+ }
56
+ })
57
+ .catch(err => {
58
+ this.registerError(err);
59
+ });
60
+ }
61
+
62
+ registerText(json) {
63
+ this.selectedText = json[this.displayProperty];
64
+ this.loading = false;
65
+ }
66
+
67
+ registerData(json) {
68
+ if(this.getSelectResultList) {
69
+ this.data = this.getSelectResultList(json);
70
+ } else {
71
+ this.data = this.getResultData(json);
72
+ }
73
+ this.updateComplete.then(() => this.loading = false)
74
+ }
75
+ }
@@ -0,0 +1,2 @@
1
+ import { DileCrudSingle } from "./src/DileCrudSingle";
2
+ customElements.define('dile-crud-single', DileCrudSingle);
@@ -0,0 +1,2 @@
1
+ import { DileCrud } from "./src/DileCrud.js";
2
+ customElements.define('dile-crud', DileCrud);
@@ -0,0 +1,2 @@
1
+ import { DileCrudDeleteAction } from "../action/src/DileCrudDeleteAction.js";
2
+ customElements.define('dile-crud-delete-action', DileCrudDeleteAction);
@@ -0,0 +1,352 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import '@dile/ui/components/input/input-search.js';
3
+ import '@dile/ui/components/nav/nav.js';
4
+ import '@dile/ui/components/select/select.js';
5
+ import '@dile/ui/components/modal/modal.js';
6
+ import '@dile/ui/components/modal/modal-help.js';
7
+ import '../../item-delete/crud-item-delete.js';
8
+ import '../../list/crud-list.js';
9
+ import '../../ui/crud-sort-form.js';
10
+ import '../../ui/crud-page-size.js';
11
+ import '../../ui/crud-filters.js';
12
+ import '../../insert/crud-insert.js';
13
+ import '../../update/crud-update.js';
14
+ import '../../action/crud-actions.js';
15
+ import '../../action/crud-delete-action.js';
16
+ import { formStyles } from '../../../styles/form-styles.js';
17
+ import { DileCrudMixin } from '../../../lib/DileCrudMixin.js';
18
+ import { crudStyles } from '../../../styles/crud-styles.js';
19
+ import { addIcon } from '@dile/icons';
20
+
21
+ export class DileCrud extends DileCrudMixin(LitElement) {
22
+ static styles = [
23
+ formStyles,
24
+ crudStyles,
25
+ css`
26
+ :host {
27
+ display: block;
28
+ --dile-nav-padding-y: 0.4rem;
29
+ --dile-nav-padding-x: 0.8rem;
30
+ }
31
+ header {
32
+ display: grid;
33
+ grid-template-columns: 1fr auto;
34
+ column-gap: 1rem;
35
+ row-gap: 0.5rem;
36
+ align-items: center;
37
+ margin-bottom: 0.5rem;
38
+ }
39
+ dile-input-search {
40
+ grid-column-start: 1;
41
+ grid-column-end: 3;
42
+ }
43
+ .actions {
44
+ display: flex;
45
+
46
+ }
47
+ .action-controller {
48
+ margin-right: 0.5rem;
49
+ }
50
+ .action-controller:last-child {
51
+ margin-right: 0;
52
+ }
53
+ .simplecard {
54
+ --dile-card-box-shadow: none;
55
+ --dile-card-border: none;
56
+ margin: 0.7rem;
57
+ }
58
+ .insertButtonContainer {
59
+ display: flex;
60
+ justify-content: flex-end;
61
+ margin-bottom: 0.5rem;
62
+ }
63
+ @media(min-width: 400px) {
64
+ .simplecard {
65
+ --dile-card-border: none;
66
+ margin: 1rem;
67
+ }
68
+ }
69
+ @media(min-width: 500px) {
70
+ .simplecard {
71
+ margin: 1.2rem 0.5rem;
72
+ }
73
+ }
74
+ @media(min-width: 500px) {
75
+ .simplecard {
76
+ margin: 1rem 0rem;
77
+ }
78
+ }
79
+ `
80
+ ];
81
+
82
+ static get properties() {
83
+ return {
84
+ title: { type: String },
85
+ config: { type: Object },
86
+ actionIds: { type: Array },
87
+ keyword: { type: String },
88
+ belongsTo: { type: String },
89
+ relationId: { type: String },
90
+ };
91
+ }
92
+
93
+ constructor() {
94
+ super();
95
+ this.actionIds = [];
96
+ }
97
+
98
+ // GETTERS ELEMENTOS
99
+ get modalInsert() {
100
+ return this.shadowRoot.getElementById('modalInsert');
101
+ }
102
+
103
+ get listElement() {
104
+ return this.shadowRoot.querySelector('dile-crud-list');
105
+ }
106
+ get deleteElement() {
107
+ return this.shadowRoot.getElementById('eldelete');
108
+ }
109
+
110
+ // TEMPLATES
111
+
112
+ render() {
113
+ return html`
114
+ <header>
115
+ ${this.title
116
+ ? html`<h1 class="main-crud-title">${this.title}</h1>`
117
+ : ''
118
+ }
119
+ ${this.config.customization.disableInsert ? '' : this.insertButtomTemplate}
120
+ <dile-input-search @dile-input-search=${this.keywordChanged}></dile-input-search>
121
+ </header>
122
+
123
+ <main>
124
+ ${this.navActionsTemplate}
125
+ <div
126
+ @item-checkbox-changed=${this.itemCheckboxChanged}
127
+ @dile-chip-icon-click=${this.removeFilter}
128
+ @crud-list-all-ids-selected=${this.crudSelectAll}
129
+ >
130
+ ${this.listTemplate}
131
+ </div>
132
+ </main>
133
+
134
+ ${this.config.customization.disableUpdate ? '' : this.updateTemplate}
135
+
136
+ <dile-crud-item-delete
137
+ id="eldelete"
138
+ endpoint="${this.config.endpoint}"
139
+ @delete-success=${this.deleteSuccess}
140
+ ></dile-crud-item-delete>
141
+
142
+ ${this.insertTemplate}
143
+ ${this.updateTemplate}
144
+ `;
145
+ }
146
+
147
+ get insertButtomTemplate() {
148
+ return html`
149
+ <div class="insertButtonContainer">
150
+ <dile-button-icon @click="${this.openInsert}" .icon="${addIcon}">${this.config.labels.insertAction}</dile-button-icon>
151
+ </div>
152
+ `
153
+ }
154
+
155
+ get insertTemplate() {
156
+ return html`
157
+ <dile-modal
158
+ id="modalInsert"
159
+ showCloseIcon
160
+ blocking
161
+ >
162
+ <dile-crud-insert
163
+ title=${this.config.labels.insertWindowTitle}
164
+ endpoint="${this.config.endpoint}"
165
+ .responseAdapter=${this.config.responseAdapter}
166
+ .formTemplate=${this.config.templates.insertForm}
167
+ actionLabel=${this.config.labels.insertAction}
168
+ formIdentifier="${this.config.formIds.insertForm}"
169
+ @crud-insert-success="${this.modalInsertSuccess}"
170
+ belongsTo=${this.belongsTo}
171
+ relationId=${this.relationId}
172
+ ></dile-crud-insert>
173
+ </dile-modal>
174
+ `
175
+ }
176
+
177
+ get listTemplate() {
178
+ return html`
179
+ <dile-crud-list
180
+ .config=${this.config}
181
+ @crud-item-edit=${this.updateRequest}
182
+ @crud-item-delete=${this.itemDeleteRequest}
183
+ @insert-requested=${this.openInsert}
184
+ .actionIds=${this.actionIds}
185
+ belongsTo=${this.belongsTo}
186
+ relationId=${this.relationId}
187
+ ></dile-crud-list>
188
+ `
189
+ }
190
+ get helpTemplate() {
191
+ return html`
192
+ <dile-modal-help
193
+ title="${this.config.labels.helpTitle}"
194
+ label="${this.config.labels.helpButtonLabel}"
195
+ >${this.config.templates.help()}</dile-modal-help>`
196
+ }
197
+
198
+ get navActionsTemplate() {
199
+ return html`
200
+ <dile-nav>
201
+ ${this.config.customization.disableHelp
202
+ ? ''
203
+ : html`<div slot="menu">${this.helpTemplate}</div>`
204
+ }
205
+ <div class="actions" slot="actions">
206
+ ${this.actionsTemplate}
207
+ ${this.config.customization.disableFilter
208
+ ? ''
209
+ : html`
210
+ <dile-crud-filters
211
+ class="action-controller"
212
+ id="elfilters"
213
+ @filters-changed=${this.filtersChanged}
214
+ .filters=${this.config.availableFilters || []}
215
+ ></dile-crud-filters>
216
+ `
217
+ }
218
+ ${this.config.customization.disablePagination
219
+ ? ''
220
+ : html`
221
+ <dile-crud-page-size
222
+ class="action-controller"
223
+ @page-size-changed=${this.pageSizeChanged}
224
+ .pageSizes=${this.config.pageSize.available || [10, 25, 50]}
225
+ pageSize="${this.config.pageSize.initial}"
226
+ ></dile-crud-page-size>
227
+ `
228
+ }
229
+ ${this.config.customization.disableSort
230
+ ? ''
231
+ : html`
232
+ <dile-crud-sort-form
233
+ class="action-controller"
234
+ .sortOptions=${this.config.sort.options || []}
235
+ sortField="${this.config.sort.initialSortField}"
236
+ sortDirection="${this.config.sort.initialSortDirection || 'desc'}"
237
+ @sort-changed=${this.sortFormChanged}
238
+ ></dile-crud-sort-form>
239
+ `
240
+ }
241
+ </div>
242
+ </dile-nav>
243
+ `
244
+ }
245
+
246
+ // BEHAVIOURS
247
+
248
+ openInsert() {
249
+ this.dispatchEvent(new CustomEvent('crud-item-insert', { bubbles: true, composed: true }));
250
+ this.modalInsert.open();
251
+ }
252
+
253
+ insertSaveSuccess() {
254
+ this.refresh();
255
+ }
256
+
257
+ updateRequest(e) {
258
+ this.editItem(e.detail.itemId);
259
+ this.modalUpdate.open();
260
+ }
261
+
262
+ editItem(id) {
263
+ this.updateElement.edit(id);
264
+ }
265
+
266
+ keywordChanged(e) {
267
+ this.setKeyword(e.detail.keyword);
268
+ }
269
+
270
+ setKeyword(keyword) {
271
+ this.listElement.setKeyword(keyword);
272
+ }
273
+
274
+ sortFormChanged(e) {
275
+ this.listElement.setSort(e.detail);
276
+ }
277
+
278
+ pageSizeChanged(e) {
279
+ this.listElement.setPageSize(e.detail.pageSize);
280
+ }
281
+
282
+ itemCheckboxChanged(e) {
283
+ if(e.detail.checked) {
284
+ this.attachActionId(e.detail.itemId);
285
+ } else {
286
+ this.detachActionId(e.detail.itemId);
287
+ }
288
+ }
289
+
290
+ attachActionId(id) {
291
+ if(! this.actionIds.includes(id)) {
292
+ this.actionIds = [
293
+ ...this.actionIds,
294
+ id
295
+ ];
296
+ }
297
+ }
298
+
299
+ detachActionId(id) {
300
+ if(this.actionIds.includes(id)) {
301
+ this.actionIds.splice(this.actionIds.indexOf(id), 1);
302
+ this.count = this.actionIds.length;
303
+ }
304
+ this.actionIds = [...this.actionIds]
305
+ //this.actionsElement.setActionIds(this.actionIds);
306
+ }
307
+
308
+ actionSuccess(e) {
309
+ if (e.detail.action === 'DeleteAction') {
310
+ this.removeActionItems(e.detail.data.delete_elems);
311
+ }
312
+ this.refresh();
313
+ }
314
+
315
+ removeActionItems(idsArray) {
316
+ idsArray.forEach(item => this.detachActionId(item));
317
+ }
318
+
319
+ filtersChanged(e) {
320
+ this.listElement.setFilters(e.detail.filters);
321
+ }
322
+
323
+ removeFilter(e) {
324
+ if(e.detail.name == 'keyword') {
325
+ this.shadowRoot.querySelector('dile-input-search').clear();
326
+ } else {
327
+ this.filtersElement.removeFilter(e.detail.name);
328
+ }
329
+ }
330
+
331
+ crudSelectAll(e) {
332
+ this.actionIds = e.detail.ids;
333
+ }
334
+
335
+ itemDeleteRequest(e) {
336
+ this.deleteElement.delete(e.detail.itemId)
337
+ }
338
+
339
+ // SUCCESS HANDLERS
340
+ modalInsertSuccess() {
341
+ this.modalInsert.close();
342
+ this.refresh();
343
+ }
344
+
345
+ deleteSuccess() {
346
+ this.refresh();
347
+ }
348
+
349
+ refresh() {
350
+ this.listElement.refresh();
351
+ }
352
+ }
@@ -0,0 +1,2 @@
1
+ import { DileCrudDetail } from "./src/DileCrudDetail.js";
2
+ customElements.define('dile-crud-detail', DileCrudDetail);
@@ -0,0 +1,166 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import { formStyles } from '../../../styles/form-styles';
3
+ import { DileLoading, loadingStyles } from '../../../lib/DileLoading.js';
4
+ import '../../ajax/ajax.js';
5
+ import { ResponseApiAdapter } from '../../../lib/ResponseApiAdapter.js';
6
+
7
+ export class DileCrudDetail extends DileLoading(LitElement) {
8
+ static styles = [
9
+ formStyles,
10
+ loadingStyles,
11
+ css`
12
+ :host {
13
+ display: block;
14
+ margin-bottom: 0;
15
+ }
16
+ .detail-data {
17
+ background-color: #f5f5f5;
18
+ padding: 1rem;
19
+ border-top-left-radius: 0.6rem;
20
+ border-top-right-radius: 0.6rem;
21
+
22
+ }
23
+ .detail-data p {
24
+ margin: 0.05rem 0;
25
+ }
26
+ main {
27
+ display: flex;
28
+ flex-direction: row;
29
+ align-items: flex-start;
30
+ --dile-icon-color: #bbb;
31
+ --dile-icon-size: 32px;
32
+ }
33
+ section {
34
+ padding: 1rem 0 0;
35
+ flex-grow: 1;
36
+ }
37
+ .morecontent {
38
+ display: grid;
39
+ grid-template-columns: auto 1fr;
40
+ column-gap: 0.6rem;
41
+ row-gap: 0.25rem;
42
+ padding: 0.25rem 0 0;
43
+ font-size: 0.85rem;
44
+ }
45
+ h1 {
46
+ font-size: 1.5rem;
47
+ margin-bottom: 0.5rem;
48
+ margin-top: 0;
49
+ }
50
+ aside {
51
+ padding: 1rem 0;
52
+ min-width: 32px;
53
+ }
54
+
55
+ @media(min-width : 520px) {
56
+ main {
57
+ --dile-icon-size: 48px;
58
+ }
59
+ }
60
+ @media(min-width : 800px) {
61
+ main {
62
+ --dile-icon-size: 64px;
63
+ }
64
+ h1 {
65
+ font-size: 1.8rem;
66
+ }
67
+ }
68
+ `
69
+ ];
70
+
71
+ static get properties() {
72
+ return {
73
+ endpoint: { type: String },
74
+ element: { type: Object },
75
+ itemDetailTemplate: { type: Object },
76
+ responseAdapter: { type: Object },
77
+ };
78
+ }
79
+
80
+ constructor() {
81
+ super();
82
+ this.responseAdapter = new ResponseApiAdapter();
83
+ }
84
+
85
+ firstUpdated() {
86
+ this.ajaxget = this.shadowRoot.getElementById('ajaxget');
87
+ }
88
+
89
+ updated(changedProperties) {
90
+ if (changedProperties.has('endpoint')) {
91
+ this.refresh();
92
+ }
93
+ }
94
+
95
+ render() {
96
+ return html`
97
+ ${this.ajaxTemplate}
98
+ ${this.loading
99
+ ? this.loadingTemplate
100
+ : this.itemTemplate
101
+ }
102
+ `;
103
+ }
104
+
105
+ get ajaxTemplate() {
106
+ return html`
107
+ <dile-ajax
108
+ id="ajaxget"
109
+ method="get"
110
+ url="${this.endpoint}"
111
+ @ajax-success="${this.doSuccessGet}"
112
+ @ajax-error="${this.doErrorGet}"
113
+ ></dile-ajax>
114
+ `
115
+ }
116
+
117
+ get itemTemplate() {
118
+ return html`
119
+ <div class="detail-data">
120
+ ${this.itemDetailTemplate(this.element)}
121
+ </div>
122
+ `;
123
+ }
124
+
125
+ itemEdit() {
126
+ this.dispatchEvent(new CustomEvent('item-edit', {
127
+ bubbles: true,
128
+ composed: true,
129
+ detail: { itemId: this.element.id },
130
+ }));
131
+ }
132
+
133
+ itemDelete() {
134
+ this.dispatchEvent(new CustomEvent('item-delete', {
135
+ bubbles: true,
136
+ composed: true,
137
+ detail: { itemId: this.element.id },
138
+ }));
139
+ }
140
+
141
+ doSuccessGet(e) {
142
+ this.loading = false;
143
+ this.responseAdapter.setResponse(e.detail);
144
+ this.element = this.responseAdapter.getData();
145
+ this.dispatchEvent(new CustomEvent('crud-item-detail-loaded', {
146
+ bubbles: true,
147
+ composed: true,
148
+ detail: {
149
+ element: this.element,
150
+ previousDetail: e.detail,
151
+ }
152
+ }));
153
+ }
154
+
155
+ doErrorGet(e) {
156
+ this.dispatchEvent(new CustomEvent('crud-item-detail-load-error', {
157
+ bubbles: true,
158
+ composed: true,
159
+ detail: e.detail,
160
+ }));
161
+ }
162
+
163
+ refresh() {
164
+ this.ajaxget.generateRequest();
165
+ }
166
+ }
@@ -0,0 +1,2 @@
1
+ import { DileCrudInsert } from './src/DileCrudInsert';
2
+ customElements.define('dile-crud-insert', DileCrudInsert);
@@ -0,0 +1 @@
1
+ export { DileCrudInsert } from './src/DileCrudInsert.js';
@@ -0,0 +1,78 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import '../../ajax-form/ajax-form.js'
3
+ import { formStyles } from '../../../styles/form-styles.js';
4
+ import { ResponseApiAdapter } from '../../../lib/ResponseApiAdapter.js';
5
+
6
+ export class DileCrudInsert extends LitElement {
7
+ static styles = [
8
+ formStyles,
9
+ css`
10
+
11
+ `
12
+ ];
13
+
14
+ static get properties() {
15
+ return {
16
+ title: { type: String },
17
+ endpoint: { type: String },
18
+ actionLabel: { type: String },
19
+ belongsTo: { type: String },
20
+ relationId: { type: String },
21
+ formTemplate: { type: Object },
22
+ buttonSmall: { type: Boolean },
23
+ responseAdapter: { type: Object},
24
+ formIdentifier: { type: String },
25
+ };
26
+ }
27
+
28
+ constructor() {
29
+ super();
30
+ this.responseAdapter = new ResponseApiAdapter();
31
+ this.actionLabel = 'Insert';
32
+ this.formIdentifier = 'insertform';
33
+ }
34
+
35
+ get formElement() {
36
+ return this.shadowRoot.getElementById(this.formId);
37
+ }
38
+
39
+ render() {
40
+ return html`
41
+ ${this.title
42
+ ? html`<h1>${this.title}</h1>`
43
+ : ''
44
+ }
45
+
46
+ <dile-ajax-form
47
+ operation="insert"
48
+ endpoint="${this.endpoint}"
49
+ actionLabel="${this.actionLabel}"
50
+ @save-success="${this.doSuccessSave}"
51
+ ?buttonSmall="${this.buttonSmall}"
52
+ .responseAdapter="${this.responseAdapter}"
53
+ formIdentifier="${this.formIdentifier}"
54
+ >
55
+ ${this.formTemplate(this.belongsTo, this.relationId)}
56
+ </dile-ajax-form>
57
+ `;
58
+ }
59
+
60
+ doSuccessSave(e) {
61
+ this.dispatchEvent(new CustomEvent('crud-insert-success', {
62
+ bubbles: true,
63
+ composed: true,
64
+ detail: e.detail
65
+ }));
66
+ }
67
+
68
+ setData(data) {
69
+ this.updateComplete.then(() => {
70
+ this.formElement.setData(data);
71
+ });
72
+
73
+ }
74
+
75
+ clearFeedback() {
76
+ this.formElement.clearFeedback();
77
+ }
78
+ }
@@ -0,0 +1,2 @@
1
+ import { DileCrudItemDelete } from "./src/DileCrudItemDelete";
2
+ customElements.define('dile-crud-item-delete', DileCrudItemDelete);
@@ -0,0 +1 @@
1
+ export { DileCrudItemDelete } from "./src/DileCrudItemDelete";