Skip to content

Commit

Permalink
New ItemSet occurrence gets instantly validated #2333
Browse files Browse the repository at this point in the history
-reverting adding validateOccurrenceOnAdd param

(cherry picked from commit 8eb6bde)
  • Loading branch information
ashklianko authored and alansemenov committed Jan 10, 2022
1 parent f74850c commit 549b6e6
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 88 deletions.
22 changes: 4 additions & 18 deletions src/main/resources/assets/admin/common/js/form/FormItemLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class FormItemLayer {

private lazyRender: boolean = true;

private validateOccurrenceOnAdd: boolean = false;

private formItemLayerFactory: FormItemLayerFactory;

constructor(context: FormContext, layerFactory: FormItemLayerFactory) {
Expand Down Expand Up @@ -115,14 +113,6 @@ export class FormItemLayer {
});
}

setValidateOccurrenceOnAdd(value: boolean): void {
this.validateOccurrenceOnAdd = value;

this.formItemViews.forEach((formItemView: FormItemView) => {
formItemView.setValidateOccurrenceOnAdd(value);
});
}

setLazyRender(value: boolean) {
this.lazyRender = value;
}
Expand Down Expand Up @@ -158,8 +148,7 @@ export class FormItemLayer {
formSet: formItemSet,
parent: <FormSetOccurrenceView>this.parent,
parentDataSet: propertySet,
occurrencesLazyRender: this.lazyRender,
validateOccurrenceOnAdd: this.validateOccurrenceOnAdd
occurrencesLazyRender: this.lazyRender
});
}

Expand All @@ -172,8 +161,7 @@ export class FormItemLayer {
fieldSet: fieldSet,
parent: this.parent,
dataSet: propertySet,
lazyRender: this.lazyRender,
validateOccurrenceOnAdd: this.validateOccurrenceOnAdd
lazyRender: this.lazyRender
});
}

Expand Down Expand Up @@ -203,8 +191,7 @@ export class FormItemLayer {
formSet: formOptionSet,
parent: <FormSetOccurrenceView>this.parent,
parentDataSet: propertySet,
occurrencesLazyRender: this.lazyRender,
validateOccurrenceOnAdd: this.validateOccurrenceOnAdd
occurrencesLazyRender: this.lazyRender
});
}

Expand All @@ -216,8 +203,7 @@ export class FormItemLayer {
formOptionSetOption: formOptionSetOption,
parent: this.parent,
parentDataSet: propertySet,
lazyRender: this.lazyRender,
validateOccurrenceOnAdd: this.validateOccurrenceOnAdd
lazyRender: this.lazyRender
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {Store} from '../store/Store';
export interface CreatedFormItemLayerConfig {
context: FormContext;
lazyRender?: boolean;
validateOccurrenceOnAdd?: boolean;
}

export interface FormItemLayerFactory {
Expand Down Expand Up @@ -34,9 +33,6 @@ export class FormItemLayerFactoryImpl implements FormItemLayerFactory {
if (config.lazyRender != null) {
layer.setLazyRender(config.lazyRender);
}

layer.setValidateOccurrenceOnAdd(!!config.validateOccurrenceOnAdd);

return layer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,4 @@ export abstract class FormItemOccurrenceView
setEnabled(enable: boolean) {
//
}

setValidateOccurrenceOnAdd(value: boolean): void {
//
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,6 @@ export class FormItemOccurrences<V extends FormItemOccurrenceView> {
});
}

setValidateOccurrenceOnAdd(value: boolean): void {
this.occurrenceViews.forEach((view: V) => {
view.setValidateOccurrenceOnAdd(value);
});
}

createNewOccurrenceView(_occurrence: FormItemOccurrence<V>): V {
throw new Error('Must be implemented by inheritor');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ export class FormItemView
//
}

setValidateOccurrenceOnAdd(value: boolean): void {
//
}

doRender(): Q.Promise<boolean> {
return super.doRender().then((rendered) => {
this.addClass('form-item-view');
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/assets/admin/common/js/form/FormView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,4 @@ export class FormView
setEnabled(enable: boolean) {
this.formItemLayer.setEnabled(enable);
}

setValidateOccurrenceOnAdd(value: boolean): void {
this.formItemLayer.setValidateOccurrenceOnAdd(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export class ApplicationConfiguratorDialog

return this.formView.layout().then(() => {
this.addClass('animated');
this.formView.setValidateOccurrenceOnAdd(true);

setTimeout(() => {
ResponsiveManager.fireResizeEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,4 @@ export abstract class FormSetOccurrenceView

return new MoreButton([addAboveAction, addBelowAction, removeAction]);
}

setValidateOccurrenceOnAdd(value: boolean): void {
this.formItemLayer.setValidateOccurrenceOnAdd(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export interface FormSetOccurrencesConfig<V extends FormSetOccurrenceView> {
propertyArray: PropertyArray;

lazyRender?: boolean;

validateOccurrenceOnAdd?: boolean;
}

export class FormSetOccurrences<V extends FormSetOccurrenceView>
Expand All @@ -41,8 +39,6 @@ export class FormSetOccurrences<V extends FormSetOccurrenceView>

private readonly lazyRender: boolean;

private validateOccurrenceOnAdd: boolean;

private layerFactory: FormItemLayerFactory;

private expandRequestedListeners: { (view: FormSetOccurrenceView): void }[] = [];
Expand All @@ -62,13 +58,11 @@ export class FormSetOccurrences<V extends FormSetOccurrenceView>
this.formSet = config.formSet;
this.parent = config.parent;
this.lazyRender = config.lazyRender;
this.validateOccurrenceOnAdd = !!config.validateOccurrenceOnAdd;
}

protected getNewOccurrenceConfig(occurrence: FormSetOccurrence<V>): FormSetOccurrenceViewConfig<V> {
const dataSet: PropertySet = this.getOrPopulateSetFromArray(occurrence.getIndex());
const layer: FormItemLayer = this.layerFactory.createLayer(
{context: this.context, lazyRender: this.lazyRender, validateOccurrenceOnAdd: this.validateOccurrenceOnAdd});
const layer: FormItemLayer = this.layerFactory.createLayer({context: this.context, lazyRender: this.lazyRender});

return {
context: this.context,
Expand All @@ -90,7 +84,7 @@ export class FormSetOccurrences<V extends FormSetOccurrenceView>
}

createNewOccurrenceView(occurrence: FormSetOccurrence<V>): V {
const newOccurrenceView: V = this.createOccurrenceView(this.getNewOccurrenceConfig(occurrence));
const newOccurrenceView = this.createOccurrenceView(this.getNewOccurrenceConfig(occurrence));

newOccurrenceView.onRemoveButtonClicked((event: RemoveButtonClickedEvent<V>) => this.removeOccurrenceView(event.getView()));
newOccurrenceView.onExpandRequested(view => this.notifyExpandRequested(view));
Expand Down Expand Up @@ -136,12 +130,6 @@ export class FormSetOccurrences<V extends FormSetOccurrenceView>
});
}

setValidateOccurrenceOnAdd(value: boolean): void {
super.setValidateOccurrenceOnAdd(value);

this.validateOccurrenceOnAdd = value;
}

moveOccurrence(index: number, destinationIndex: number) {
super.moveOccurrence(index, destinationIndex);
}
Expand Down
28 changes: 7 additions & 21 deletions src/main/resources/assets/admin/common/js/form/set/FormSetView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export interface FormSetViewConfig {
formSet: FormSet;

parent: FormSetOccurrenceView;

validateOccurrenceOnAdd?: boolean
}

export abstract class FormSetView<V extends FormSetOccurrenceView>
Expand Down Expand Up @@ -76,8 +74,6 @@ export abstract class FormSetView<V extends FormSetOccurrenceView>

protected occurrencesLazyRender: boolean;

protected validateOccurrenceOnAdd: boolean;

/**
* The index of child Data being dragged.
*/
Expand All @@ -97,7 +93,6 @@ export abstract class FormSetView<V extends FormSetOccurrenceView>
this.classPrefix = classPrefix;
this.helpText = this.formSet.getHelpText();
this.occurrencesLazyRender = config.occurrencesLazyRender;
this.validateOccurrenceOnAdd = !!config.validateOccurrenceOnAdd;

this.addClass(this.formSet.getPath().getElements().length % 2 ? 'even' : 'odd');
if (this.formSet.getOccurrences().getMaximum() === 1) {
Expand All @@ -121,8 +116,7 @@ export abstract class FormSetView<V extends FormSetOccurrenceView>
formSet: this.formSet,
parent: this.getParent(),
propertyArray: this.getPropertyArray(this.parentDataSet),
lazyRender: this.occurrencesLazyRender,
validateOccurrenceOnAdd: this.validateOccurrenceOnAdd
lazyRender: this.occurrencesLazyRender
});

return this.formItemOccurrences;
Expand Down Expand Up @@ -340,11 +334,6 @@ export abstract class FormSetView<V extends FormSetOccurrenceView>
this.addButton.setEnabled(enable);
}

setValidateOccurrenceOnAdd(value: boolean): void {
this.validateOccurrenceOnAdd = value;
this.formItemOccurrences.setValidateOccurrenceOnAdd(value);
}

onFocus(listener: (event: FocusEvent) => void) {
this.formItemOccurrences.onFocus(listener);
}
Expand Down Expand Up @@ -575,21 +564,18 @@ export abstract class FormSetView<V extends FormSetOccurrenceView>

private makeAddButton(): Button {
const addButton: Button = new Button(i18n('action.add'));

addButton
.setTitle(i18n('button.add', this.formSet.getLabel()))
.addClass('small')
.onClicked(this.addOccurrence.bind(this));

.onClicked(() => {
this.formItemOccurrences
.createAndAddOccurrence(this.formItemOccurrences.countOccurrences())
.then((item: V) => this.expandOccurrenceView(item)
);
});
return addButton;
}

protected addOccurrence(): void {
this.formItemOccurrences
.createAndAddOccurrence(this.formItemOccurrences.countOccurrences(), this.validateOccurrenceOnAdd)
.then((item: V) => this.expandOccurrenceView(item));
}

expandRecursively() {
this.toggleOccurrencesVisibility(true);
this.formItemOccurrences.getOccurrenceViews().forEach((item: V) => this.expandOccurrenceView(item));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ export class FieldSetView
this.formItemLayer.setEnabled(enable);
}

setValidateOccurrenceOnAdd(value: boolean): void {
this.formItemLayer.setValidateOccurrenceOnAdd(value);
}

giveFocus(): boolean {

let focusGiven = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,4 @@ export class FormOptionSetOptionView
}
this.formItemLayer.setEnabled(enable);
}

setValidateOccurrenceOnAdd(value: boolean): void {
this.formItemLayer.setValidateOccurrenceOnAdd(value);
}
}

0 comments on commit 549b6e6

Please sign in to comment.