Skip to content

Commit

Permalink
Merge branch 'main' into v15/fix/move-property-editor-ui-picker-modal
Browse files Browse the repository at this point in the history
  • Loading branch information
madsrasmussen authored Sep 24, 2024
2 parents 82f6afb + a0cadc1 commit 2a51d91
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
/**
* Validate this context, all the validators of this context will be validated.
* Notice its a recursive check meaning sub validation contexts also validates their validators.
* @returns succeed {Promise<boolean>} - Returns a promise that resolves to true if the validator succeeded, this depends on the validators and wether forceSucceed is set.
* @returns succeed {Promise<boolean>} - Returns a promise that resolves to true if the validation succeeded.
*/
async validate(): Promise<void> {
// TODO: clear server messages here?, well maybe only if we know we will get new server messages? Do the server messages hook into the system like another validator?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import type { UUIComboboxEvent, UUIComboboxElement } from '@umbraco-cms/backoffi
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UmbMediaTypeDetailRepository, UMB_MEDIA_TYPE_PICKER_MODAL } from '@umbraco-cms/backoffice/media-type';
import { UMB_MODAL_MANAGER_CONTEXT, type UmbModalManagerContext } from '@umbraco-cms/backoffice/modal';
import {
UMB_VALIDATION_EMPTY_LOCALIZATION_KEY,
UmbFormControlMixin,
type UmbFormControlValidatorConfig,
} from '@umbraco-cms/backoffice/validation';

interface FieldPickerValue {
alias: string;
Expand All @@ -29,19 +34,44 @@ enum FieldType {
}

@customElement('umb-template-field-dropdown-list')
export class UmbTemplateFieldDropdownListElement extends UmbLitElement {
export class UmbTemplateFieldDropdownListElement extends UmbFormControlMixin<
FieldPickerValue | undefined,
typeof UmbLitElement,
undefined
>(UmbLitElement) {
//
#requiredValidation?: UmbFormControlValidatorConfig;
@property({ type: Boolean })
public get required(): boolean | undefined {
return undefined;
}
public set required(value: boolean | undefined) {
if (value === true) {
this.#requiredValidation ??= this.addValidator(
'valueMissing',
() => this.requiredMessage,
() => !this._value,
);
} else if (this.#requiredValidation) {
this.removeValidator(this.#requiredValidation);
}
}

@property({ type: String })
requiredMessage = UMB_VALIDATION_EMPTY_LOCALIZATION_KEY;

@property({ type: Boolean, attribute: 'exclude-media-type', reflect: true })
public excludeMediaType = false;

private _value: FieldPickerValue | undefined;
@property({ type: Object })
public set value(val: FieldPickerValue | undefined) {
public override set value(val: FieldPickerValue | undefined) {
const oldVal = this._value;
this._value = val;
this.requestUpdate('value', oldVal);
this.dispatchEvent(new UmbChangeEvent());
}
public get value(): FieldPickerValue | undefined {
public override get value(): FieldPickerValue | undefined {
return this._value;
}

Expand Down Expand Up @@ -176,8 +206,8 @@ export class UmbTemplateFieldDropdownListElement extends UmbLitElement {
if (this._type !== FieldType.SYSTEM && !this._unique) return;
return html`
<strong>${this.localize.string(this._uniqueName ?? '')}</strong>
<uui-combobox id="value" value=${ifDefined(this.value?.alias)}>
<uui-combobox-list @change=${this.#onChangeValue}>
<uui-combobox id="value" value=${ifDefined(this.value?.alias)} @change=${this.#onChangeValue}>
<uui-combobox-list>
${repeat(
this._customFields,
(field) => field.alias,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,35 @@ import type { UmbTemplateFieldDropdownListElement } from './components/template-
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import { css, html, customElement, state } from '@umbraco-cms/backoffice/external/lit';
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal';
import type { UUIBooleanInputEvent, UUIInputEvent } from '@umbraco-cms/backoffice/external/uui';
import type { UUIBooleanInputEvent, UUIButtonState, UUIInputEvent } from '@umbraco-cms/backoffice/external/uui';

// import of local components
import './components/template-field-dropdown-list/index.js';
import { UmbValidationContext, umbBindToValidation } from '@umbraco-cms/backoffice/validation';

@customElement('umb-templating-page-field-builder-modal')
export class UmbTemplatingPageFieldBuilderModalElement extends UmbModalBaseElement<
UmbTemplatingPageFieldBuilderModalData,
UmbTemplatingPageFieldBuilderModalValue
> {
private _close() {
#validation = new UmbValidationContext(this);

#close() {
this.modalContext?.reject();
}

private _submit() {
if (!this._field) return;
this.value = { output: getUmbracoFieldSnippet(this._field, this._default, this._recursive) };
this.modalContext?.submit();
async #submit() {
this._submitButtonState = 'waiting';

try {
await this.#validation.validate();
this._submitButtonState = 'success';

this.value = { output: getUmbracoFieldSnippet(this._field!, this._default, this._recursive) };
this.modalContext?.submit();
} catch {
this._submitButtonState = 'failed';
}
}

@state()
Expand All @@ -39,6 +50,9 @@ export class UmbTemplatingPageFieldBuilderModalElement extends UmbModalBaseEleme
@state()
private _recursive: boolean = false;

@state()
private _submitButtonState: UUIButtonState;

/** TODO: Implement "Choose field" */

#onChangeFieldValue(e: Event) {
Expand All @@ -50,12 +64,14 @@ export class UmbTemplatingPageFieldBuilderModalElement extends UmbModalBaseEleme
<umb-body-layout headline=${this.localize.term('template_insert')}>
<uui-box>
<div>
<uui-label for="page-field-value">
<umb-localize key="templateEditor_chooseField">Choose field</umb-localize>
</uui-label>
<umb-template-field-dropdown-list
@change=${this.#onChangeFieldValue}
exclude-media-type></umb-template-field-dropdown-list>
<umb-property-layout orientation="vertical" label=${this.localize.term('templateEditor_chooseField')}>
<umb-template-field-dropdown-list
slot="editor"
required
${umbBindToValidation(this)}
@change=${this.#onChangeFieldValue}
exclude-media-type></umb-template-field-dropdown-list>
</umb-property-layout>
<uui-label for="page-field-default-value">
<umb-localize key="templateEditor_defaultValue">Default value</umb-localize>
Expand Down Expand Up @@ -85,14 +101,15 @@ export class UmbTemplatingPageFieldBuilderModalElement extends UmbModalBaseEleme
</uui-box>
<uui-button
slot="actions"
@click=${this._close}
@click=${this.#close}
look="secondary"
label=${this.localize.term('general_close')}></uui-button>
<uui-button
slot="actions"
@click=${this._submit}
@click=${this.#submit}
color="positive"
look="primary"
.state=${this._submitButtonState}
label=${this.localize.term('general_submit')}></uui-button>
</umb-body-layout>
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import type { UmbChangeEvent } from '@umbraco-cms/backoffice/event';
import type { UmbUiCultureInputElement } from '@umbraco-cms/backoffice/localization';
import { umbBindToValidation } from '@umbraco-cms/backoffice/validation';

@customElement('umb-user-workspace-profile-settings')
export class UmbUserWorkspaceProfileSettingsElement extends UmbLitElement {
Expand Down Expand Up @@ -79,6 +80,7 @@ export class UmbUserWorkspaceProfileSettingsElement extends UmbLitElement {
@change="${this.#onEmailChange}"
required
required-message=${this.localize.term('user_emailRequired')}
${umbBindToValidation(this)}
value=${ifDefined(this._user?.email)}></uui-input>
</umb-property-layout>
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { UmbSubmittableWorkspaceContext } from '@umbraco-cms/backoffice/wor
import { UmbSubmittableWorkspaceContextBase } from '@umbraco-cms/backoffice/workspace';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
import { UmbValidationContext } from '@umbraco-cms/backoffice/validation';

type EntityType = UmbUserDetailModel;

Expand Down Expand Up @@ -40,6 +41,8 @@ export class UmbUserWorkspaceContext
constructor(host: UmbControllerHost) {
super(host, UMB_USER_WORKSPACE_ALIAS);

this.addValidationContext(new UmbValidationContext(this));

this.routes.setRoutes([
{
path: 'edit/:id',
Expand Down

0 comments on commit 2a51d91

Please sign in to comment.