This commit is contained in:
2022-01-18 15:53:49 +01:00
parent fc1dd9da03
commit 298c8d74f7
4 changed files with 57 additions and 10 deletions
@@ -101,6 +101,7 @@
}
this.$emit('input', value);
this.$emit('update:value', value);
}
}
}
@@ -1,5 +1,5 @@
<template>
<ui-form ref="form" class="editor-page" v-slot="form" @submit="onSubmit" @load="onLoad" :route="route">
<ui-form ref="form" class="editor-page" v-slot="form" @submit="onInternalSubmit" @load="onInternalLoad" :route="route">
<ui-form-header v-model:value="model" :prefix="prefix" :title="title" :disabled="readonly" :is-create="!id" :state="form.state" :can-delete="canDelete" @delete="onInternalDelete" />
<ui-editor :config="editor" v-model="model" :meta="meta" :disabled="readonly" :scope="true">
<template v-slot:below>
@@ -45,6 +45,14 @@
type: Function,
default: null
},
onLoad: {
type: Function,
default: null
},
onSubmit: {
type: Function,
default: null
},
disabled: {
type: [Boolean, Function],
default: false
@@ -71,22 +79,40 @@
methods: {
async onLoad(form)
async onInternalLoad(form)
{
var config = { system: this.$route.query['zero.scope'] == 'system' };
const response = await form.load(() => this.id ? this.api.getById(this.id, undefined, config) : this.api.getEmpty(this.$route.query['zero.flavor'], config));
this.model = response;
if (typeof this.onLoad === 'function')
{
this.model = await this.onLoad({ id: this.id, api: this.api, form, config});
}
else
{
const response = await form.load(() => this.id ? this.api.getById(this.id, undefined, config) : this.api.getEmpty(this.$route.query['zero.flavor'], config));
this.model = response;
}
},
async onSubmit(form)
async onInternalSubmit(form)
{
form.setState('loading');
let isCreate = !this.id;
var config = { system: this.$route.query['zero.scope'] == 'system' };
let response = null;
if (typeof this.onSubmit === 'function')
{
response = await this.onSubmit({ id: this.id, isCreate, config, form, model: this.model });
}
else
{
response = !isCreate ? await this.api.update(this.model, config) : await this.api.create(this.model, config);
}
const response = !isCreate ? await this.api.update(this.model, config) : await this.api.create(this.model, config);
await form.handle(response);
if (response.success)
@@ -13,7 +13,7 @@
name: 'uiLanguagepicker',
props: {
modelValue: {
value: {
type: [String, Array],
default: null
},
@@ -52,7 +52,7 @@
onChange(value)
{
this.$emit('input', value);
this.$emit('update:modelValue', value);
this.$emit('update:value', value);
}
}
}
+22 -2
View File
@@ -1,5 +1,5 @@
import { groupBy as _groupBy } from 'underscore';
import { groupBy as _groupBy, difference as _difference } from 'underscore';
const arrayMoveMutate = (array: any[], from: number, to: number) =>
{
@@ -79,4 +79,24 @@ export function selectorToArray(selector: string): string[]
selector = selector.replace(/\[(\w+)\]/g, '.$1');
selector = selector.replace(/^\./, '');
return selector.split('.');
};
};
/**
* Removes duplicate items from an array
* @returns {any[]} Unique array
*/
export function arrayUnique(array: any[]): any[]
{
return [...new Set(array)];
}
/**
* Returns the different items from two arrays
* @returns {any[]} Difference
*/
export function arrayDifference(array: any[], other: any[]): any[]
{
return _difference(array, other);
}