@dile/crud 1.1.2 → 1.1.4

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.
@@ -55,6 +55,7 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
55
55
  static get properties() {
56
56
  return {
57
57
  operation: { type: String },
58
+ method: { type: String },
58
59
  endpoint: { type: String },
59
60
  actionLabel: { type: String },
60
61
  cancelLabel: { type: String },
@@ -166,8 +167,8 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
166
167
  ></dile-ajax>
167
168
  <dile-ajax
168
169
  id="ajaxsave"
169
- method="${this.saveMethod(this.operation)}"
170
- url="${this.endpoint}${this.operation == 'insert' ? '' : `/${this.relatedId}`}"
170
+ method="${this.saveMethod(this.operation, this.method)}"
171
+ url="${this.generateEndpoint(this.operation, this.method, this.relatedId)}"
171
172
  @ajax-success="${this.doSuccessSave}"
172
173
  @ajax-error="${this.doErrorSave}"
173
174
  language="${this.language}"
@@ -264,16 +265,44 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
264
265
 
265
266
  }
266
267
 
267
- saveMethod(operation) {
268
- switch(operation) {
269
- case 'insert':
270
- return 'post';
271
- case 'update':
272
- return 'put';
268
+ saveMethod(operation, method) {
269
+ if(this.operation != '') {
270
+ switch(operation) {
271
+ case 'insert':
272
+ return 'post';
273
+ case 'update':
274
+ return 'put';
275
+ }
276
+ } else if(this.isValidMethod(method)) {
277
+ return method;
273
278
  }
274
279
  throw this.translations.ajax_form_not_supported;
275
280
  }
276
281
 
282
+ isValidMethod(method) {
283
+ if (!method || typeof method !== 'string') {
284
+ return false;
285
+ }
286
+ const validMethods = ['get', 'post', 'put', 'patch', 'delete'];
287
+ return validMethods.includes(method.toLowerCase());
288
+ }
289
+
290
+ generateEndpoint(operation, method, relatedId) {
291
+ if (operation === 'insert') {
292
+ return this.endpoint;
293
+ } else if (operation === 'update') {
294
+ return `${this.endpoint}/${relatedId}`;
295
+ } else if (method) {
296
+ const methodLower = method.toLowerCase();
297
+ if (methodLower === 'post') {
298
+ return this.endpoint;
299
+ } else if (['put', 'patch', 'delete'].includes(methodLower) && relatedId) {
300
+ return `${this.endpoint}/${relatedId}`;
301
+ }
302
+ }
303
+ return this.endpoint;
304
+ }
305
+
277
306
  clearErrors() {
278
307
  this.form.clearErrors();
279
308
  this.feedback.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Components to create a generic crud system based on Web Components and Lit",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "5e351778fe7c3206effd8c3589ba6ef6992d694b"
34
+ "gitHead": "e60b713895058e0b14a9b018a1e6f825846813c4"
35
35
  }