actions.js
2 years ago
getters.js
2 years ago
index.js
2 years ago
mutations.js
2 years ago
state.js
2 years ago
actions.js
47 lines
| 1 | import Constants from '../../../constants'; |
| 2 | |
| 3 | export default { |
| 4 | beforeRunFetch( { getters, rootGetters } ) { |
| 5 | if ( Constants.CHOOSE_ACTION !== getters.processContext ) { |
| 6 | return; |
| 7 | } |
| 8 | const label = rootGetters['messages/label']; |
| 9 | |
| 10 | if ( ! getters.getChecked.length ) { |
| 11 | throw new Error( label( 'empty_checked' ) ); |
| 12 | } |
| 13 | |
| 14 | if ( ! getters.getCurrentAction?.endpoint ) { |
| 15 | throw new Error( label( 'empty_action' ) ); |
| 16 | } |
| 17 | }, |
| 18 | runRowAction( { commit, getters } ) { |
| 19 | commit( 'toggleDoingAction', null, { root: true } ); |
| 20 | commit( 'toggleLoading', 'page' ); |
| 21 | |
| 22 | const onFinish = () => { |
| 23 | commit( 'toggleLoading', 'page' ); |
| 24 | commit( 'toggleDoingAction', null, { root: true } ); |
| 25 | //commit( 'clearProcess' ); |
| 26 | }; |
| 27 | |
| 28 | try { |
| 29 | getters.getActionPromise().finally( onFinish ); |
| 30 | } catch ( error ) { |
| 31 | onFinish(); |
| 32 | } |
| 33 | }, |
| 34 | beforeRowAction( { state } ) { |
| 35 | const { action, payload = [] } = state.currentProcess; |
| 36 | |
| 37 | if ( 'function' !== typeof state.beforeActions[ action ] ) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | const promise = state.beforeActions[ action ] ?? false; |
| 42 | |
| 43 | promise( ...payload ); |
| 44 | |
| 45 | throw new Error(); |
| 46 | }, |
| 47 | }; |