91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
import { actionAddins } from ".";
|
|
import { IAction, IActionResult, IActionNode, IActionProperty, IField, IContext } from "../types/ActionTypes";
|
|
/**
|
|
* アクションの属性定義
|
|
*/
|
|
interface IMailCheckProps {
|
|
field: IField;//チェックするフィールドの対象
|
|
message: string;//エラーメッセージ
|
|
emailCheck:string;
|
|
}
|
|
/**
|
|
* メールアドレスチェックアクション
|
|
*/
|
|
export class MailCheckAction implements IAction {
|
|
name: string;
|
|
actionProps: IActionProperty[];
|
|
props: IMailCheckProps;
|
|
constructor() {
|
|
this.name = "メールアドレスチェック";
|
|
this.actionProps = [];
|
|
this.props = {
|
|
field: { code: '' },
|
|
message: '',
|
|
emailCheck:''
|
|
}
|
|
//アクションを登録する
|
|
this.register();
|
|
}
|
|
/**
|
|
* アクションの実行を呼び出す
|
|
* @param actionNode
|
|
* @param event
|
|
* @returns
|
|
*/
|
|
async process(actionNode: IActionNode, event: any,context:IContext): Promise<IActionResult> {
|
|
let result = {
|
|
canNext: true,
|
|
result: false
|
|
};
|
|
|
|
try {
|
|
//属性設定を取得する
|
|
this.actionProps = actionNode.actionProps;
|
|
|
|
if (!('field' in actionNode.ActionValue) && !('message' in actionNode.ActionValue) && !('emailCheck' in actionNode.ActionValue)) {
|
|
return result
|
|
}
|
|
this.props = actionNode.ActionValue as IMailCheckProps;
|
|
const record = event.record;
|
|
//対象フィールドの存在チェック
|
|
if(!(this.props.field.code in record)){
|
|
throw new Error(`フィールド[${this.props.field.code}]が見つかりませんでした。`);
|
|
}
|
|
const value = record[this.props.field.code].value;
|
|
|
|
if (this.props.emailCheck === '厳格') {
|
|
if (!/^[a-zA-Z0-9_-¥.]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value)) {
|
|
record[this.props.field.code].error = this.props.message;
|
|
}
|
|
else {
|
|
record[this.props.field.code].error = null;
|
|
result.result=true;
|
|
}
|
|
} else if (this.props.emailCheck === 'ゆるめ') {
|
|
if (!/^[^@]+@[^@]+$/.test(value)) {
|
|
record[this.props.field.code].error = this.props.message;
|
|
}
|
|
else {
|
|
record[this.props.field.code].error = null;
|
|
result.result=true;
|
|
}
|
|
} else {
|
|
result = {
|
|
canNext: true,
|
|
result: true
|
|
}
|
|
}
|
|
return result;
|
|
} catch (error) {
|
|
context.errors.handleError(error,actionNode);
|
|
result.canNext = false;
|
|
return result;
|
|
}
|
|
};
|
|
register(): void {
|
|
actionAddins[this.name] = this;
|
|
}
|
|
|
|
}
|
|
new MailCheckAction();
|