lkt-item-crud 2.0.15 → 2.0.17

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.
@@ -100,6 +100,9 @@ declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
100
100
  readData: LktObject;
101
101
  beforeEmitUpdate: Function;
102
102
  notificationType: NotificationType;
103
+ enabledSaveWithoutChanges: boolean;
104
+ redirectOnCreate: string | ((id: number | string) => string);
105
+ redirectOnDrop: string | (() => string);
103
106
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
104
107
  declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
105
108
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-item-crud",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "./dist/build.js",
@@ -23,6 +23,7 @@
23
23
  import { __ } from 'lkt-i18n';
24
24
  import ButtonNav from '../components/ButtonNav.vue';
25
25
  import { openToast } from 'lkt-toast';
26
+ import { useRouter } from 'vue-router';
26
27
 
27
28
  // defineOptions({
28
29
  // inheritAttrs: false
@@ -30,6 +31,8 @@
30
31
 
31
32
  const props = withDefaults(defineProps<ItemCrudConfig>(), getDefaultValues(ItemCrud));
32
33
 
34
+ const router = useRouter();
35
+
33
36
  const slots: SetupContext['slots'] = useSlots();
34
37
 
35
38
  const emit = defineEmits([
@@ -199,11 +202,16 @@
199
202
  }
200
203
  return true;
201
204
  },
202
- doAutoReloadId = (r?: HTTPResponse) => {
205
+ doAutoReloadId = (r?: HTTPResponse, redirect?: string|Function) => {
203
206
  debug('doAutoReloadId -> enter: ', r);
204
207
  if (typeof r !== 'undefined' && r.autoReloadId) {
205
208
  debug('doAutoReloadId -> autoReloadId detected: ', r.autoReloadId);
206
- if (!computedInsideModal.value) {
209
+ if (typeof redirect !== 'undefined') {
210
+ let route = redirect;
211
+ if (typeof redirect === 'function') route = redirect(r.autoReloadId);
212
+ router.push(route);
213
+ }
214
+ else if (!computedInsideModal.value) {
207
215
  debug('doAutoReloadId -> outsideModal');
208
216
  props.readData['id'] = r.autoReloadId;
209
217
  debug('doAutoReloadId -> turning off create mode');
@@ -239,7 +247,7 @@
239
247
  positionX: ToastPositionX.Right,
240
248
  });
241
249
  }
242
- doAutoReloadId(r);
250
+ doAutoReloadId(r, props.redirectOnCreate);
243
251
  debug('onCreate -> beforeEmitCreate');
244
252
  emit('create', r);
245
253
  },
@@ -296,6 +304,12 @@
296
304
  //@ts-ignore
297
305
  closeModal(props.modalConfig.modalName, props.modalConfig.modalKey);
298
306
  }
307
+
308
+ if (typeof props.redirectOnDrop !== 'undefined') {
309
+ let route = props.redirectOnDrop;
310
+ if (typeof props.redirectOnDrop === 'function') route = props.redirectOnDrop();
311
+ router.push(route);
312
+ }
299
313
  },
300
314
  doSave = () => {
301
315
  // @ts-ignore
@@ -351,7 +365,7 @@
351
365
  }),
352
366
  ableToUpdate = computed(() => {
353
367
  if (props.mode !== ItemCrudMode.Update || !canUpdate.value) return false;
354
- if (!dataChanged.value) return false;
368
+ if (!props.enabledSaveWithoutChanges && !dataChanged.value) return false;
355
369
 
356
370
  if (typeof safeUpdateButton.value?.disabled === 'function') return !safeUpdateButton.value.disabled(item.value);
357
371
  if (typeof safeUpdateButton.value?.disabled === 'boolean') return !safeUpdateButton.value.disabled;
@@ -360,7 +374,7 @@
360
374
  }),
361
375
  ableToCreate = computed(() => {
362
376
  if (props.mode !== ItemCrudMode.Create) return false;
363
- if (!dataChanged.value) return false;
377
+ if (!props.enabledSaveWithoutChanges && !dataChanged.value) return false;
364
378
 
365
379
  if (typeof safeCreateButton.value?.disabled === 'function') return !safeCreateButton.value.disabled(item.value);
366
380
  if (typeof safeCreateButton.value?.disabled === 'boolean') return !safeCreateButton.value.disabled;