82 lines
2.7 KiB
TypeScript
82 lines
2.7 KiB
TypeScript
import { actionAddins } from ".";
|
|
import { IAction, IActionResult, IActionNode, IActionProperty, IField } from "../types/ActionTypes";
|
|
/**
|
|
* アクションの属性定義
|
|
*/
|
|
interface IMailCheckProps {
|
|
field: IField;//チェックするフィールドの対象
|
|
message: string;//エラーメッセージ
|
|
}
|
|
/**
|
|
* メールアドレスチェックアクション
|
|
*/
|
|
export class MailCheckAction implements IAction {
|
|
name: string;
|
|
actionProps: IActionProperty[];
|
|
props: IMailCheckProps;
|
|
constructor() {
|
|
this.name = "メールアドレスチェック";
|
|
this.actionProps = [];
|
|
this.props = {
|
|
field: { code: '' },
|
|
message: '',
|
|
|
|
}
|
|
//アクションを登録する
|
|
this.register();
|
|
}
|
|
/**
|
|
* アクションの実行を呼び出す
|
|
* @param actionNode
|
|
* @param event
|
|
* @returns
|
|
*/
|
|
async process(actionNode: IActionNode, event: any): Promise<IActionResult> {
|
|
let result = {
|
|
canNext: true,
|
|
result: false
|
|
};
|
|
try {
|
|
//属性設定を取得する
|
|
this.actionProps = actionNode.actionProps;
|
|
|
|
const emailAction = this.actionProps.find(obj => obj.props.name === 'emailcheck')
|
|
|
|
if (!('field' in actionNode.ActionValue) && !('message' in actionNode.ActionValue) && !!! emailAction) {
|
|
return result
|
|
}
|
|
|
|
this.props = actionNode.ActionValue as IMailCheckProps;
|
|
//条件式の計算結果を取得
|
|
const record = event.record;
|
|
const value = record[this.props.field.code].value;
|
|
|
|
if (emailAction?.props.modelValue === '厳格') {
|
|
if (!new RegExp('^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$').test(value)) {
|
|
record[this.props.field.code].error = this.props.message;
|
|
}
|
|
} else if (emailAction?.props.modelValue === 'ゆるめ') {
|
|
if (!new RegExp('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$').test(value)) {
|
|
record[this.props.field.code].error = this.props.message;
|
|
}
|
|
} else {
|
|
result = {
|
|
canNext: true,
|
|
result: true
|
|
}
|
|
}
|
|
return result;
|
|
} catch (error) {
|
|
event.error = error;
|
|
console.error(error);
|
|
result.canNext = false;
|
|
return result;
|
|
}
|
|
};
|
|
register(): void {
|
|
actionAddins[this.name] = this;
|
|
}
|
|
|
|
}
|
|
new MailCheckAction();
|