BaseAction.js
45 lines
| 1 | import Tools from '../../tools'; |
| 2 | |
| 3 | function BaseAction( props = null ) { |
| 4 | this.initData( props ); |
| 5 | } |
| 6 | |
| 7 | BaseAction.prototype.initData = function ( props ) { |
| 8 | this.id = props?.id ?? Tools.getRandomID(); |
| 9 | this.settings = props?.settings ?? {}; |
| 10 | this.type = props?.type ?? 'send_email'; |
| 11 | this.conditions = props?.conditions ?? []; |
| 12 | this.events = props?.events ?? []; |
| 13 | |
| 14 | Object.defineProperty( this, 'selfSettings', { |
| 15 | get: () => { |
| 16 | return this.settings.hasOwnProperty( this.type ?? '' ) |
| 17 | ? this.settings[ this.type ] |
| 18 | : {}; |
| 19 | }, |
| 20 | set: value => { |
| 21 | if ( this.settings.hasOwnProperty( this.type ?? '' ) ) { |
| 22 | this.settings[ this.type ] = {}; |
| 23 | } |
| 24 | |
| 25 | this.settings[ this.type ] = { |
| 26 | ...this.settings[ this.type ], |
| 27 | ...value, |
| 28 | }; |
| 29 | }, |
| 30 | } ); |
| 31 | |
| 32 | Object.defineProperty( this, 'index', { |
| 33 | get: () => { |
| 34 | return props?.index ?? 0; |
| 35 | }, |
| 36 | } ); |
| 37 | }; |
| 38 | |
| 39 | BaseAction.prototype.resetID = function () { |
| 40 | this.id = Tools.getRandomID(); |
| 41 | }; |
| 42 | |
| 43 | export default BaseAction; |
| 44 | |
| 45 |