mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-08-29 20:50:13 +08:00
Fix #478 - Add new trigger status check 'onDependencyChange'
- add trigger to email select action
This commit is contained in:
parent
3adb99624d
commit
39881bceb6
3 changed files with 27 additions and 9 deletions
|
@ -146,17 +146,18 @@ export class BaseFieldComponent implements FieldComponentInterface, OnInit, OnDe
|
|||
if (this.field.valueChanges$ && ((this.dependentFields && Object.keys(this.dependentFields).length) || this.dependentAttributes.length)) {
|
||||
this.subs.push(this.field.valueChanges$.pipe(debounceTime(500)).subscribe((data) => {
|
||||
Object.keys(this.dependentFields).forEach(fieldKey => {
|
||||
const dependentField = this.dependentFields[fieldKey];
|
||||
const dependentFieldKey = this.dependentFields[fieldKey];
|
||||
const field = this.record.fields[fieldKey] || null;
|
||||
const dependentField = this.record.fields[dependentFieldKey.field] || null;
|
||||
if (!field) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.field.previousValue != data.value) {
|
||||
const types = dependentField.type ?? [];
|
||||
const types = dependentFieldKey.type ?? [];
|
||||
|
||||
if (types.includes('logic')) {
|
||||
this.logic.runLogic(field, this.originalMode as ViewMode, this.record, 'onValueChange');
|
||||
this.logic.runLogic(field, this.originalMode as ViewMode, this.record, 'onDependencyChange', dependentField);
|
||||
}
|
||||
|
||||
if (types.includes('displayLogic')) {
|
||||
|
|
|
@ -76,4 +76,9 @@ export class EmailPrimarySelectAction extends FieldLogicActionHandler {
|
|||
emailField.formControl.updateValueAndValidity({onlySelf: true, emitEvent: true});
|
||||
}
|
||||
}
|
||||
|
||||
getTriggeringStatus(): string[] {
|
||||
return ['onFieldInitialize'];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -84,15 +84,16 @@ export class FieldLogicManager extends BaseActionManager<FieldLogicActionData> {
|
|||
* @param {object} mode
|
||||
* @param {object} record
|
||||
* @param triggeringStatus
|
||||
* @param dependentField
|
||||
*/
|
||||
runLogic(field: Field, mode: ViewMode, record: Record, triggeringStatus: string = ''): void {
|
||||
runLogic(field: Field, mode: ViewMode, record: Record, triggeringStatus: string = '', dependentField: Field = {} as Field): void {
|
||||
if (!field.logic) {
|
||||
return;
|
||||
}
|
||||
|
||||
const actions = Object.keys(field.logic).map(key => field.logic[key]);
|
||||
|
||||
const modeActions = this.parseModeActions(actions, mode, triggeringStatus);
|
||||
const modeActions = this.parseModeActions(actions, mode, triggeringStatus, dependentField);
|
||||
const context = {
|
||||
record,
|
||||
field,
|
||||
|
@ -147,7 +148,7 @@ export class FieldLogicManager extends BaseActionManager<FieldLogicActionData> {
|
|||
* @param mode
|
||||
* @param triggeringStatus
|
||||
*/
|
||||
protected parseModeActions(declaredActions: Action[], mode: ViewMode, triggeringStatus: string) {
|
||||
protected parseModeActions(declaredActions: Action[], mode: ViewMode, triggeringStatus: string, fieldDependent: Field) {
|
||||
if (!declaredActions) {
|
||||
return [];
|
||||
}
|
||||
|
@ -181,10 +182,21 @@ export class FieldLogicManager extends BaseActionManager<FieldLogicActionData> {
|
|||
|
||||
availableActions[mode].forEach(action => {
|
||||
|
||||
const frontendActionTriggeringStatus = this?.actions[mode][action.key]?.getTriggeringStatus() ?? null;
|
||||
const actionTriggeringStatus = action?.triggeringStatus ?? frontendActionTriggeringStatus ?? defaultTriggeringStatus;
|
||||
const dependentFieldsKeys = Object.keys(action?.params?.activeOnFields ?? {});
|
||||
|
||||
if(triggeringStatus && !actionTriggeringStatus.includes(triggeringStatus)) {
|
||||
const frontendActionTriggeringStatus = this?.actions[mode][action.key]?.getTriggeringStatus() ?? null;
|
||||
|
||||
let actionTriggeringStatus = action?.triggeringStatus ?? frontendActionTriggeringStatus ?? defaultTriggeringStatus;
|
||||
|
||||
if (triggeringStatus && !actionTriggeringStatus.includes(triggeringStatus)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionTriggeringStatus.includes('onValueChange')) {
|
||||
actionTriggeringStatus = ['onAnyLogic'];
|
||||
}
|
||||
|
||||
if (actionTriggeringStatus.includes('onDependencyChange') && !dependentFieldsKeys?.includes(fieldDependent.name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue