PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 1.1.0
JetFormBuilder — Dynamic Blocks Form Builder v1.1.0
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 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 All 134 releases
jetformbuilder / assets / js / action-localize-helper.js

action-localize-helper.js in JetFormBuilder — Dynamic Blocks Form Builder 1.1.0, at assets/js/action-localize-helper.js

77 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const getLocalized = ( actionType, objectKey = '' ) => {
2 const preparedAction = window.jetFormActionTypes.find( action => actionType === action.id );
3 if ( ! preparedAction ) {
4 return false;
5 }
6 const actionSelfLocalized = window[ preparedAction.self ];
7
8 return ( objectKey && actionSelfLocalized[ objectKey ] ) ? actionSelfLocalized[ objectKey ] : actionSelfLocalized;
9 };
10
11 const getLocalizedWithFunc = ( { actionType = false, source = false },
12 objectKey,
13 ifEmptyReturn = '' ) => {
14
15 let action = false;
16
17 if ( source && source[ objectKey ] ) {
18 action = source[ objectKey ];
19 } else if ( actionType ) {
20 action = ( getLocalized( actionType )[ objectKey ] );
21 }
22
23 if ( ! action ) {
24 return () => ifEmptyReturn;
25 }
26
27 return attr => {
28 if ( attr ) {
29 return ( action[ attr ] ? action[ attr ] : ifEmptyReturn );
30 } else {
31 return action;
32 }
33 };
34 };
35
36 const getActionLabel = ( type ) => {
37 const action = window.jetFormActionTypes.find( el => el.id === type );
38 return action ? action.name : '';
39 };
40
41 const localizedLabel = settings => {
42 return getLocalizedWithFunc( settings, '__labels', '[Empty Label]' );
43 };
44
45 const localizedHelp = settings => {
46 return getLocalizedWithFunc( settings, '__help_messages' );
47 };
48
49 const localizedGatewayAttrs = settings => {
50 return getLocalizedWithFunc( settings, '__gateway_attrs', [] );
51 };
52
53 const localizedMessages = settings => {
54 return getLocalizedWithFunc( settings, '__messages', {} );
55 };
56
57 const getLocalizedFullPack = actionType => {
58 const source = getLocalized( actionType );
59
60 const label = localizedLabel( { source } );
61 const help = localizedHelp( { source } );
62 const messages = localizedMessages( { source } );
63 const gatewayAttrs = localizedGatewayAttrs( { source } );
64
65 return { source, label, help, messages, gatewayAttrs };
66 };
67
68 window.JetFBLocalizeHelper = {
69 getActionLabel,
70 getLocalizedWithFunc,
71 localizedLabel,
72 localizedHelp,
73 localizedGatewayAttrs,
74 localizedMessages,
75 getLocalizedFullPack
76 };
77