PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.2
JetFormBuilder — Dynamic Blocks Form Builder v3.1.2
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / assets / src / admin-vuex-package / store / modules / view / actions.js
jetformbuilder / assets / src / admin-vuex-package / store / modules / view Last commit date
actions.js 2 years ago index.js 2 years ago
actions.js
127 lines
1 window.jfbEventBus = window.jfbEventBus || new Vue( {} );
2 const { apiFetch } = wp;
3
4 const getActionFromRecord = ( record, slug ) => {
5 return record.actions.value.find( action => slug === action.value );
6 };
7
8 const apiOptions = getters => {
9 const { action, payload } = getters.currentProcess;
10 const [ checked ] = payload;
11
12 let actionEndpoint = getters.getAction( action );
13
14 if ( !actionEndpoint ) {
15 const record = payload[ 3 ] ?? {};
16
17 actionEndpoint = getActionFromRecord( record, action );
18 }
19
20 const options = getters.fetchListOptions( actionEndpoint?.endpoint );
21
22 return {
23 ...options,
24 ...getters.apiOptions,
25 data: {
26 checked,
27 ...getters.apiData,
28 },
29 };
30 };
31
32 export default {
33 fetchPage( { commit, getters, dispatch } ) {
34 commit( 'toggleLoading', 'page' );
35 const url = getters.receiveEndpoint;
36
37 dispatch( 'fetch', getters.fetchListOptions( url ) ).then( response => {
38 dispatch( 'updateList', response );
39 dispatch( 'updateQueryState' );
40
41 // clear checked rows
42 commit( 'unChooseHead' );
43 commit( 'setChecked', [] );
44 } ).finally( () => {
45 commit( 'toggleLoading', 'page' );
46 } );
47 },
48 fetchPageWithFilters( { commit, getters, dispatch, state } ) {
49 commit( 'toggleLoading', 'page' );
50 dispatch( 'updateQueryState', 1 );
51 const url = getters.receiveEndpoint;
52
53 dispatch( 'fetch', getters.fetchListOptions( url ) ).then( response => {
54 dispatch( 'updateList', response );
55 jfbEventBus.reactiveCounter++;
56 } ).catch( response => {
57 if ( !response?.hasOwnProperty?.( 'code' ) ) {
58 return;
59 }
60 switch ( response.code ) {
61 case 'not_found':
62 dispatch( 'updateList', { list: [], total: 0 } );
63 break;
64 }
65 } ).finally( response => {
66 commit( 'toggleLoading', 'page' );
67 } );
68 },
69 updateList( { commit, getters, dispatch, state }, response ) {
70 commit( 'setList', response.list );
71
72 if ( getters.queryState ) {
73 commit( 'setTotal', response?.total ?? getters.queryState.total );
74 }
75
76 if ( response.list.length > getters.getLimit ) {
77 commit( 'setLimit', response.list.length );
78 }
79
80 commit( 'setOffset', 0 );
81 },
82 fetch( { commit, getters }, options ) {
83 return new Promise( ( resolve, reject ) => {
84 apiFetch( options ).then( resolve ).catch( error => {
85 jfbEventBus.$CXNotice.add( {
86 message: error.message,
87 type: 'error',
88 duration: 4000,
89 } );
90
91 reject( error );
92 } ).finally( reject );
93 } );
94 },
95 apiFetch( { getters, dispatch } ) {
96 dispatch( 'beforeRunFetch' );
97
98 return apiFetch( apiOptions( getters ) );
99 },
100 maybeFetchFilters( props, endpoint ) {
101 const { commit, getters, rootGetters } = props;
102
103 if ( getters.hasFilters || rootGetters.isDoing ) {
104 return;
105 }
106
107 commit( 'toggleDoingAction', null, { root: true } );
108
109 apiFetch( endpoint ).then( response => {
110 commit( 'setFilters', response.filters );
111 jfbEventBus.reactiveCounter++;
112 } ).finally( () => {
113 commit( 'toggleDoingAction', null, { root: true } );
114 } );
115 },
116 activeAll( { commit, getters } ) {
117 const idsList = getters.list.map( row => (
118 row?.choose?.value
119 ) );
120
121 commit( 'setChecked', idsList );
122 },
123 clearFiltersWithFetch( { commit, dispatch }, replaceMap ) {
124 commit( 'clearSelectedFilters', replaceMap );
125 dispatch( 'fetchPageWithFilters' );
126 },
127 };