import { actionAddins } from "."; import { IAction,IActionResult, IActionNode, IActionProperty, IField, IContext} from "../types/ActionTypes"; /** * アクションの属性定義 */ interface IStrCountCheckProps{ field:IField;//チェックするフィールドの対象 message:string;//エラーメッセージ maxLength:number;// } /** * 正規表現チェックアクション */ export class StrCountCheckAciton implements IAction{ name: string; actionProps: IActionProperty[]; props:IStrCountCheckProps; constructor(){ this.name="文字数チェック"; this.actionProps=[]; this.props={ field:{code:''}, message:'', maxLength:0 } //アクションを登録する this.register(); } /** * アクションの実行を呼び出す * @param actionNode * @param event * @returns */ async process(actionNode:IActionNode,event:any,context:IContext):Promise { let result={ canNext:true, result:false }; try{ //属性設定を取得する this.actionProps=actionNode.actionProps; if (!('field' in actionNode.ActionValue) && !('message' in actionNode.ActionValue) && !('strExpression'in actionNode.ActionValue)) { return result } this.props = actionNode.ActionValue as IStrCountCheckProps; //条件式の計算結果を取得 const record = event.record; const value = record[this.props.field.code].value; const maxLength = this.props.maxLength; if(value === undefined || value === '' ){ return result; }else if(maxLength < value.length){ record[this.props.field.code].error = this.props.message; }else{ record[this.props.field.code].error = null; } 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 StrCountCheckAciton();