From 9d58e4c191877968317872a7abc9372b6a49ee81 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Mon, 10 Jan 2022 16:13:59 +0100 Subject: [PATCH] more editor fields --- .../app/components/ui-select-button.vue | 1 - zero.Backoffice.UI/app/core/zeroRuntime.ts | 2 +- zero.Backoffice.UI/app/editor/compile.ts | 20 ++++- zero.Backoffice.UI/app/editor/editor-field.ts | 20 ++++- .../app/editor/editor-types.d.ts | 6 ++ .../app/editor/fields/createFields.ts | 1 + .../app/editor/fields/datePicker.vue | 36 +++++++++ .../fields/editor-field-extensions.d.ts | 15 ++++ .../app/editor/ui-editor-component.vue | 15 ++-- .../app/editor/ui-editor-overlay.vue | 2 +- zero.Backoffice.UI/app/services/overlay.ts | 24 +++++- .../app/styles/Modules/_box.scss | 2 +- zero.Core/Rendering/RazorRenderer.cs | 77 ++++++++++++++++++- 13 files changed, 201 insertions(+), 20 deletions(-) create mode 100644 zero.Backoffice.UI/app/editor/fields/datePicker.vue diff --git a/zero.Backoffice.UI/app/components/ui-select-button.vue b/zero.Backoffice.UI/app/components/ui-select-button.vue index b289c8f2..cfab598b 100644 --- a/zero.Backoffice.UI/app/components/ui-select-button.vue +++ b/zero.Backoffice.UI/app/components/ui-select-button.vue @@ -5,7 +5,6 @@ -
diff --git a/zero.Backoffice.UI/app/core/zeroRuntime.ts b/zero.Backoffice.UI/app/core/zeroRuntime.ts index bdba34d0..bcbfd23b 100644 --- a/zero.Backoffice.UI/app/core/zeroRuntime.ts +++ b/zero.Backoffice.UI/app/core/zeroRuntime.ts @@ -29,7 +29,7 @@ import * as zeroOptions from '../options'; import plugins from '../plugins.generated'; plugins.push( - countryPlugin, applicationPlugin, settingsPlugin, languagePlugin, + editorPlugin, countryPlugin, applicationPlugin, settingsPlugin, languagePlugin, mediaPlugin, spacePlugin, pagePlugin, mailTemplatePlugin, translationPlugin, integrationPlugin, userPlugin ); diff --git a/zero.Backoffice.UI/app/editor/compile.ts b/zero.Backoffice.UI/app/editor/compile.ts index aede6adb..8ab0b945 100644 --- a/zero.Backoffice.UI/app/editor/compile.ts +++ b/zero.Backoffice.UI/app/editor/compile.ts @@ -38,6 +38,15 @@ export interface ZeroCompiledEditorFieldset } +export interface ZeroCompiledEditorChangeEvent +{ + value: any; + oldValue: any; + model: any; + component: Component; +} + + export interface ZeroCompiledEditorField { path: string; @@ -58,6 +67,7 @@ export interface ZeroCompiledEditorField sort: number; columns: number; preview?: ZeroEditorFieldFilterPreview; + onChange: (event: ZeroCompiledEditorChangeEvent) => void; } @@ -128,7 +138,15 @@ export function compileField(zero: Zero, editor: ZeroEditor, field: ZeroEditorFi icon: field.configuration.preview.icon || 'fth-square', selected: field.configuration.preview.selected || (x => !!x), value: field.configuration.preview.value || (x => x ? x : null) - } : null + } : null, + + onChange(event: ZeroCompiledEditorChangeEvent) + { + (field.configuration.changeHandlers || []).forEach(handler => + { + handler(event); + }); + } } as ZeroCompiledEditorField; diff --git a/zero.Backoffice.UI/app/editor/editor-field.ts b/zero.Backoffice.UI/app/editor/editor-field.ts index ccb36acd..b821582c 100644 --- a/zero.Backoffice.UI/app/editor/editor-field.ts +++ b/zero.Backoffice.UI/app/editor/editor-field.ts @@ -96,6 +96,17 @@ export class ZeroEditorFieldImpl implements ZeroEditorField this.options = options; return this; } + + + /** + * The expression argument is called when the value of the field changes + * @param {function} callback - function which is called + */ + onChange(callback: Function): ZeroEditorField + { + this.configuration.changeHandlers.push(callback); + return this; + } } @@ -113,7 +124,8 @@ export function createDefaultFieldConfiguration(): ZeroEditorFieldConfiguration classes: null, horizontal: false, sort: 0, - preview: undefined + preview: undefined, + changeHandlers: [] } as ZeroEditorFieldConfiguration; } @@ -163,7 +175,11 @@ export interface ZeroEditorFieldConfiguration /** * Sort order for fields within the editor canvas **/ - preview?: ZeroEditorFieldFilterPreview + preview?: ZeroEditorFieldFilterPreview, + /** + * Handlers which get called on value change + **/ + changeHandlers?: Array } diff --git a/zero.Backoffice.UI/app/editor/editor-types.d.ts b/zero.Backoffice.UI/app/editor/editor-types.d.ts index 9802dec4..4a45ac4c 100644 --- a/zero.Backoffice.UI/app/editor/editor-types.d.ts +++ b/zero.Backoffice.UI/app/editor/editor-types.d.ts @@ -79,5 +79,11 @@ declare module 'zero/schemas' * @param {T} [options] = Custom options to pass to this editor */ component(component: Component, options?: any): ZeroEditorField; + + /** + * The expression argument is called when the value of the field changes + * @param {function} callback - function which is called + */ + onChange(callback: Function): ZeroEditorField; } } \ No newline at end of file diff --git a/zero.Backoffice.UI/app/editor/fields/createFields.ts b/zero.Backoffice.UI/app/editor/fields/createFields.ts index b673e991..49255bea 100644 --- a/zero.Backoffice.UI/app/editor/fields/createFields.ts +++ b/zero.Backoffice.UI/app/editor/fields/createFields.ts @@ -16,4 +16,5 @@ export default function createFields(app: ZeroPluginOptions): void app.fieldType('checklist', defineAsyncComponent(() => import('./checklist.vue'))); app.fieldType('inputlist', defineAsyncComponent(() => import('./inputlist.vue'))); app.fieldType('nested', defineAsyncComponent(() => import('./nested.vue'))); + app.fieldType('datePicker', defineAsyncComponent(() => import('./datePicker.vue'))); } \ No newline at end of file diff --git a/zero.Backoffice.UI/app/editor/fields/datePicker.vue b/zero.Backoffice.UI/app/editor/fields/datePicker.vue new file mode 100644 index 00000000..61523227 --- /dev/null +++ b/zero.Backoffice.UI/app/editor/fields/datePicker.vue @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/zero.Backoffice.UI/app/editor/fields/editor-field-extensions.d.ts b/zero.Backoffice.UI/app/editor/fields/editor-field-extensions.d.ts index 8765e62f..73bef1a9 100644 --- a/zero.Backoffice.UI/app/editor/fields/editor-field-extensions.d.ts +++ b/zero.Backoffice.UI/app/editor/fields/editor-field-extensions.d.ts @@ -75,9 +75,24 @@ declare module 'zero/schemas' * @param {NestedFieldOptions} options - Custom options */ nested(options: NestedFieldOptions): ZeroEditorField; + + /** + * Create a date picker + * @param {DatePickerFieldOptions} options - Custom options + */ + datePicker(options?: DatePickerFieldOptions): ZeroEditorField; } + export interface DatePickerFieldOptions + { + format?: string; + pickTime?: boolean; + maxDate?: string | Date; + minDate?: string | Date; + amPm?: boolean; + } + export interface ToggleFieldOptions { negative?: boolean | null; diff --git a/zero.Backoffice.UI/app/editor/ui-editor-component.vue b/zero.Backoffice.UI/app/editor/ui-editor-component.vue index 4a817564..98622028 100644 --- a/zero.Backoffice.UI/app/editor/ui-editor-component.vue +++ b/zero.Backoffice.UI/app/editor/ui-editor-component.vue @@ -151,15 +151,12 @@ this.$emit('input', this.value); - // TODO - //if (typeof this.field.configuration.onChange === 'function') - //{ - // this.field.configuration.onChange(value, { - // oldValue, - // model: this.value, - // component: this - // }); - //} + this.field.onChange({ + value: value, + model: this.value, + oldValue, + component: this + }) }, diff --git a/zero.Backoffice.UI/app/editor/ui-editor-overlay.vue b/zero.Backoffice.UI/app/editor/ui-editor-overlay.vue index 97c32a0b..d7e09bc0 100644 --- a/zero.Backoffice.UI/app/editor/ui-editor-overlay.vue +++ b/zero.Backoffice.UI/app/editor/ui-editor-overlay.vue @@ -3,7 +3,7 @@