@capillarytech/creatives-library 8.0.136 → 8.0.137-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants/unified.js +189 -0
- package/package.json +1 -1
- package/services/getSchema.js +1 -1
- package/services/localStorageApi.js +1 -0
- package/tests/i18n.test.js +1 -1
- package/utils/common.js +2 -2
- package/utils/tagValidations.js +1 -1
- package/utils/tests/checkStore.test.js +1 -1
- package/utils/tests/customAuth.test.js +1 -1
- package/utils/transformerUtils.js +1 -1
- package/v2Components/CapTagList/index.js +9 -14
- package/v2Components/Carousel/style.scss +1 -1
- package/v2Components/EmailMobilePreview/index.js +2 -2
- package/v2Components/FormBuilder/index.js +2 -2
- package/v2Components/TemplatePreview/index.js +2 -1
- package/v2Containers/Cap/tests/saga.test.js +1 -1
- package/v2Containers/Email/index.js +1 -1
- package/v2Containers/FTP/index.js +1 -1
- package/v2Containers/Line/Container/Text/index.js +1 -1
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +0 -1
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +271 -0
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +189 -0
- package/v2Containers/MobilePushNew/index.scss +0 -7
- package/v2Containers/Sms/Create/index.js +2 -2
- package/v2Containers/Sms/Edit/index.js +1 -1
- package/v2Containers/TagList/index.js +1 -1
- package/v2Containers/TagList/utils.js +1 -1
- package/v2Containers/Templates/index.js +1 -1
- package/v2Containers/Templates/sagas.js +1 -1
- package/components/BreadCrumbs/index.js +0 -65
- package/components/BreadCrumbs/messages.js +0 -13
- package/components/CapTagList/index.js +0 -235
- package/components/CapTagList/messages.js +0 -45
- package/components/Card/_customCard.scss +0 -40
- package/components/Card/index.js +0 -78
- package/components/Card/tests/__snapshots__/index.test.js.snap +0 -22
- package/components/Card/tests/index.test.js +0 -20
- package/components/CardGrid/index.js +0 -71
- package/components/Ckeditor/index.js +0 -238
- package/components/Ckeditor/messages.js +0 -13
- package/components/Ckeditor/style.scss +0 -3
- package/components/Component/index.js +0 -29
- package/components/CustomPopOver/index.js +0 -81
- package/components/CustomPopOver/messages.js +0 -17
- package/components/DateFilter/index.js +0 -349
- package/components/DateFilter/messages.js +0 -57
- package/components/DateRange/index.js +0 -114
- package/components/DateRange/messages.js +0 -25
- package/components/Edmeditor/index.js +0 -65
- package/components/Edmeditor/messages.js +0 -13
- package/components/EmailPreview/_emailPreview.scss +0 -119
- package/components/EmailPreview/assets/images/iPad.svg +0 -10
- package/components/EmailPreview/assets/images/mobile.png +0 -0
- package/components/EmailPreview/index.js +0 -107
- package/components/EmailPreview/messages.js +0 -33
- package/components/Footer/index.js +0 -27
- package/components/Footer/messages.js +0 -13
- package/components/FormBuilder/_formBuilder.scss +0 -83
- package/components/FormBuilder/index.js +0 -3279
- package/components/FormBuilder/messages.js +0 -61
- package/components/Header/index.js +0 -44
- package/components/Header/messages.js +0 -29
- package/components/ImagePreview/_imagePreview.scss +0 -63
- package/components/ImagePreview/index.js +0 -52
- package/components/ImagePreview/messages.js +0 -17
- package/components/PageHeader/_pageHeader.scss +0 -22
- package/components/PageHeader/index.js +0 -37
- package/components/PageHeader/messages.js +0 -13
- package/components/Pagination/_pagination.scss +0 -5
- package/components/Pagination/index.js +0 -49
- package/components/PreviewSideBar/_previewsidebar.scss +0 -28
- package/components/PreviewSideBar/index.js +0 -152
- package/components/PreviewSideBar/messages.js +0 -41
- package/components/Sidebar/_sidebar.scss +0 -115
- package/components/Sidebar/index.js +0 -214
- package/components/Sidebar/messages.js +0 -21
- package/components/SlideBox/_slideBox.scss +0 -63
- package/components/SlideBox/index.js +0 -47
- package/components/SlideBox/tests/index.test.js +0 -103
- package/components/SmsEditor/index.js +0 -55
- package/components/SmsTest/index.js +0 -117
- package/components/SmsTest/messages.js +0 -21
- package/components/TemplatePreview/WechatRichmediaTemplatePreview/_wechatRichmediaTemplatePrev.scss +0 -42
- package/components/TemplatePreview/WechatRichmediaTemplatePreview/index.js +0 -141
- package/components/TemplatePreview/WechatRichmediaTemplatePreview/messages.js +0 -21
- package/components/TemplatePreview/_templatePreview.scss +0 -642
- package/components/TemplatePreview/assets/images/WECHAT_5x.png +0 -0
- package/components/TemplatePreview/assets/images/androidPushMessage.svg +0 -45
- package/components/TemplatePreview/assets/images/home-screen-android.svg +0 -21
- package/components/TemplatePreview/assets/images/home-screen-ios.svg +0 -16
- package/components/TemplatePreview/assets/images/iPhonePushMessage.svg +0 -135
- package/components/TemplatePreview/assets/images/mobile.svg +0 -24
- package/components/TemplatePreview/assets/images/sms-body.png +0 -0
- package/components/TemplatePreview/assets/images/sms-icon.png +0 -0
- package/components/TemplatePreview/assets/images/sms_mobile.png +0 -0
- package/components/TemplatePreview/assets/images/sms_mobile_android.svg +0 -22
- package/components/TemplatePreview/assets/images/sms_mobile_ios.svg +0 -16
- package/components/TemplatePreview/assets/images/user-icon.svg +0 -19
- package/components/TemplatePreview/assets/images/wechat-mobile.svg +0 -78
- package/components/TemplatePreview/assets/images/wechat_mobile_android.svg +0 -20
- package/components/TemplatePreview/index.js +0 -617
- package/components/TemplatePreview/messages.js +0 -78
- package/components/Toastr/index.js +0 -60
- package/components/Toastr/messages.js +0 -13
- package/components/ToastrMessage/index.js +0 -113
- package/components/ToastrMessage/messages.js +0 -17
- package/components/TopBar/_topbar.scss +0 -46
- package/components/TopBar/assets/images/capillary_logo.png +0 -0
- package/components/TopBar/assets/images/old_capillary_logo.png +0 -0
- package/components/TopBar/index.js +0 -113
- package/components/TopBar/messages.js +0 -29
- package/containers/App/actions.js +0 -7
- package/containers/App/constants.js +0 -114
- package/containers/App/index.js +0 -52
- package/containers/App/reducer.js +0 -19
- package/containers/App/sagas.js +0 -31
- package/containers/App/selectors.js +0 -25
- package/containers/App/test/saga.test.js +0 -11
- package/containers/Assets/Gallery/_gallery.scss +0 -126
- package/containers/Assets/Gallery/actions.js +0 -37
- package/containers/Assets/Gallery/constants.js +0 -23
- package/containers/Assets/Gallery/index.js +0 -473
- package/containers/Assets/Gallery/messages.js +0 -93
- package/containers/Assets/Gallery/reducer.js +0 -81
- package/containers/Assets/Gallery/sagas.js +0 -80
- package/containers/Assets/Gallery/selectors.js +0 -25
- package/containers/Assets/Gallery/tests/__snapshots__/reducer.test.js.snap +0 -9
- package/containers/Assets/Gallery/tests/actions.test.js +0 -25
- package/containers/Assets/Gallery/tests/reducer.test.js +0 -96
- package/containers/Assets/Gallery/tests/saga.test.js +0 -157
- package/containers/Cap/actions.js +0 -66
- package/containers/Cap/constants.js +0 -25
- package/containers/Cap/index.js +0 -402
- package/containers/Cap/messages.js +0 -75
- package/containers/Cap/reducer.js +0 -113
- package/containers/Cap/sagas.js +0 -159
- package/containers/Cap/selectors.js +0 -75
- package/containers/Cap/tests/__snapshots__/index.test.js.snap +0 -2269
- package/containers/Cap/tests/index.test.js +0 -22
- package/containers/Cap/tests/saga.test.js +0 -284
- package/containers/Dashboard/actions.js +0 -15
- package/containers/Dashboard/constants.js +0 -7
- package/containers/Dashboard/index.js +0 -76
- package/containers/Dashboard/messages.js +0 -13
- package/containers/Dashboard/reducer.js +0 -21
- package/containers/Dashboard/sagas.js +0 -17
- package/containers/Dashboard/selectors.js +0 -25
- package/containers/Dashboard/test/saga.test.js +0 -9
- package/containers/Ebill/_ebill.scss +0 -5
- package/containers/Ebill/actions.js +0 -43
- package/containers/Ebill/constants.js +0 -20
- package/containers/Ebill/index.js +0 -1278
- package/containers/Ebill/messages.js +0 -77
- package/containers/Ebill/reducer.js +0 -72
- package/containers/Ebill/sagas.js +0 -74
- package/containers/Ebill/selectors.js +0 -25
- package/containers/Ebill/test/saga.test.js +0 -11
- package/containers/Email/_email.scss +0 -141
- package/containers/Email/actions.js +0 -81
- package/containers/Email/constants.js +0 -36
- package/containers/Email/index.js +0 -3325
- package/containers/Email/messages.js +0 -289
- package/containers/Email/reducer.js +0 -142
- package/containers/Email/sagas.js +0 -135
- package/containers/Email/selectors.js +0 -31
- package/containers/Email/test/saga.test.js +0 -671
- package/containers/LanguageProvider/actions.js +0 -17
- package/containers/LanguageProvider/constants.js +0 -8
- package/containers/LanguageProvider/index.js +0 -80
- package/containers/LanguageProvider/reducer.js +0 -30
- package/containers/LanguageProvider/selectors.js +0 -20
- package/containers/LanguageProvider/tests/actions.test.js +0 -19
- package/containers/LanguageProvider/tests/index.test.js +0 -78
- package/containers/LanguageProvider/tests/reducer.test.js +0 -20
- package/containers/LanguageProvider/tests/selectors.test.js +0 -15
- package/containers/Line/Create/_lineCreate.scss +0 -54
- package/containers/Line/Create/actions.js +0 -90
- package/containers/Line/Create/constants.js +0 -39
- package/containers/Line/Create/index.js +0 -836
- package/containers/Line/Create/messages.js +0 -189
- package/containers/Line/Create/reducer.js +0 -99
- package/containers/Line/Create/sagas.js +0 -121
- package/containers/Line/Create/selectors.js +0 -36
- package/containers/Line/Create/tests/saga.test.js +0 -202
- package/containers/Line/Edit/_lineEdit.scss +0 -35
- package/containers/Line/Edit/actions.js +0 -79
- package/containers/Line/Edit/constants.js +0 -27
- package/containers/Line/Edit/index.js +0 -1050
- package/containers/Line/Edit/messages.js +0 -177
- package/containers/Line/Edit/reducer.js +0 -83
- package/containers/Line/Edit/sagas.js +0 -80
- package/containers/Line/Edit/selectors.js +0 -29
- package/containers/Line/Edit/test/saga.test.js +0 -160
- package/containers/Login/assets/images/capillary_logo.png +0 -0
- package/containers/Login/components/LoginForm/index.js +0 -62
- package/containers/Login/components/LoginForm/messages.js +0 -33
- package/containers/Login/index.js +0 -130
- package/containers/Login/messages.js +0 -25
- package/containers/Login/selectors.js +0 -25
- package/containers/MobilePush/Create/_mobilePushCreate.scss +0 -39
- package/containers/MobilePush/Create/actions.js +0 -46
- package/containers/MobilePush/Create/constants.js +0 -23
- package/containers/MobilePush/Create/index.js +0 -2303
- package/containers/MobilePush/Create/messages.js +0 -269
- package/containers/MobilePush/Create/reducer.js +0 -70
- package/containers/MobilePush/Create/sagas.js +0 -74
- package/containers/MobilePush/Create/selectors.js +0 -28
- package/containers/MobilePush/Create/test/saga.test.js +0 -19
- package/containers/MobilePush/Edit/_mobilePushCreate.scss +0 -39
- package/containers/MobilePush/Edit/actions.js +0 -91
- package/containers/MobilePush/Edit/constants.js +0 -35
- package/containers/MobilePush/Edit/index.js +0 -2601
- package/containers/MobilePush/Edit/messages.js +0 -266
- package/containers/MobilePush/Edit/reducer.js +0 -112
- package/containers/MobilePush/Edit/sagas.js +0 -126
- package/containers/MobilePush/Edit/selectors.js +0 -29
- package/containers/MobilePush/Edit/tests/saga.test.js +0 -255
- package/containers/NotFoundPage/index.js +0 -25
- package/containers/NotFoundPage/messages.js +0 -13
- package/containers/NotFoundPage/tests/index.test.js +0 -17
- package/containers/Sms/Create/_smsCreate.scss +0 -42
- package/containers/Sms/Create/actions.js +0 -27
- package/containers/Sms/Create/constants.js +0 -16
- package/containers/Sms/Create/index.js +0 -1488
- package/containers/Sms/Create/messages.js +0 -109
- package/containers/Sms/Create/reducer.js +0 -41
- package/containers/Sms/Create/sagas.js +0 -40
- package/containers/Sms/Create/selectors.js +0 -28
- package/containers/Sms/Create/test/saga.test.js +0 -11
- package/containers/Sms/Edit/actions.js +0 -40
- package/containers/Sms/Edit/constants.js +0 -17
- package/containers/Sms/Edit/index.js +0 -1472
- package/containers/Sms/Edit/messages.js +0 -105
- package/containers/Sms/Edit/reducer.js +0 -50
- package/containers/Sms/Edit/sagas.js +0 -60
- package/containers/Sms/Edit/selectors.js +0 -32
- package/containers/Sms/Edit/test/saga.test.js +0 -13
- package/containers/TagList/_tagList.scss +0 -8
- package/containers/TagList/actions.js +0 -15
- package/containers/TagList/constants.js +0 -32
- package/containers/TagList/index.js +0 -236
- package/containers/TagList/messages.js +0 -13
- package/containers/TagList/reducer.js +0 -23
- package/containers/TagList/sagas.js +0 -11
- package/containers/TagList/selectors.js +0 -25
- package/containers/Templates/_templates.scss +0 -333
- package/containers/Templates/actions.js +0 -103
- package/containers/Templates/constants.js +0 -60
- package/containers/Templates/index.js +0 -1756
- package/containers/Templates/messages.js +0 -337
- package/containers/Templates/reducer.js +0 -142
- package/containers/Templates/sagas.js +0 -163
- package/containers/Templates/selectors.js +0 -28
- package/containers/Templates/test/saga.test.js +0 -241
- package/containers/WeChat/MapTemplates/_mapTemplates.scss +0 -8
- package/containers/WeChat/MapTemplates/actions.js +0 -52
- package/containers/WeChat/MapTemplates/constants.js +0 -28
- package/containers/WeChat/MapTemplates/index.js +0 -1610
- package/containers/WeChat/MapTemplates/messages.js +0 -157
- package/containers/WeChat/MapTemplates/reducer.js +0 -74
- package/containers/WeChat/MapTemplates/sagas.js +0 -84
- package/containers/WeChat/MapTemplates/selectors.js +0 -25
- package/containers/WeChat/MapTemplates/test/saga.test.js +0 -155
- package/containers/WeChat/RichmediaTemplates/Create/_createRichmedia.scss +0 -57
- package/containers/WeChat/RichmediaTemplates/Create/actions.js +0 -36
- package/containers/WeChat/RichmediaTemplates/Create/constants.js +0 -15
- package/containers/WeChat/RichmediaTemplates/Create/index.js +0 -1071
- package/containers/WeChat/RichmediaTemplates/Create/messages.js +0 -165
- package/containers/WeChat/RichmediaTemplates/Create/reducer.js +0 -60
- package/containers/WeChat/RichmediaTemplates/Create/richmediaschema.js +0 -497
- package/containers/WeChat/RichmediaTemplates/Create/sagas.js +0 -51
- package/containers/WeChat/RichmediaTemplates/Create/selectors.js +0 -37
- package/containers/WeChat/RichmediaTemplates/Create/test/saga.test.js +0 -13
- package/containers/WeChat/RichmediaTemplates/Edit/actions.js +0 -20
- package/containers/WeChat/RichmediaTemplates/Edit/constants.js +0 -10
- package/containers/WeChat/RichmediaTemplates/Edit/index.js +0 -136
- package/containers/WeChat/RichmediaTemplates/Edit/messages.js +0 -13
- package/containers/WeChat/RichmediaTemplates/Edit/reducer.js +0 -28
- package/containers/WeChat/RichmediaTemplates/Edit/sagas.js +0 -36
- package/containers/WeChat/RichmediaTemplates/Edit/selectors.js +0 -30
- package/containers/WeChat/RichmediaTemplates/Edit/test/saga.test.js +0 -12
- package/containers/WeChat/RichmediaTemplates/View/actions.js +0 -15
- package/containers/WeChat/RichmediaTemplates/View/constants.js +0 -7
- package/containers/WeChat/RichmediaTemplates/View/index.js +0 -47
- package/containers/WeChat/RichmediaTemplates/View/messages.js +0 -21
- package/containers/WeChat/RichmediaTemplates/View/reducer.js +0 -23
- package/containers/WeChat/RichmediaTemplates/View/sagas.js +0 -11
- package/containers/WeChat/RichmediaTemplates/View/selectors.js +0 -25
- package/utils/asyncInjectors.js +0 -78
- package/utils/callNativeEvent.js +0 -16
- package/utils/checkStore.js +0 -21
- package/utils/customAuthWrapper.js +0 -62
- package/utils/customConnectedAuthWrapper.js +0 -26
- package/utils/jed.js +0 -1497
- package/utils/smsCharCount.js +0 -351
|
@@ -1,3279 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* FormBuilder
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import PropTypes from 'prop-types';
|
|
9
|
-
|
|
10
|
-
import React from 'react';
|
|
11
|
-
import { Label } from 'semantic-ui-react';
|
|
12
|
-
import _ from 'lodash';
|
|
13
|
-
import { injectIntl, intlShape, FormattedMessage } from 'react-intl';
|
|
14
|
-
import { Tabs, Row, Col, Table, Modal, notification} from 'antd';
|
|
15
|
-
import { CapButton, CapInput, CapPopover, CapTextArea, CapCheckbox, CapRadio, CapRadioGroup, CapSelect, CapTable, CapColumn} from '@capillarytech/cap-react-ui-library';
|
|
16
|
-
import TemplatePreview from '../../components/TemplatePreview';
|
|
17
|
-
// import { CapCheckbox } from '@capillarytech/cap-react-ui-library/basic/checkbox';
|
|
18
|
-
import TagList from '../../containers/TagList';
|
|
19
|
-
import SmsEditor from '../SmsEditor';
|
|
20
|
-
import SlideBox from '../SlideBox';
|
|
21
|
-
import CardGrid from '../CardGrid';
|
|
22
|
-
import CKEditor from "../../components/Ckeditor/";
|
|
23
|
-
import EDMEditor from "../../components/Edmeditor";
|
|
24
|
-
import CustomPopOver from '../../components/CustomPopOver';
|
|
25
|
-
import './_formBuilder.scss';
|
|
26
|
-
import {updateCharCount, checkUnicode} from "../../utils/smsCharCountV2";
|
|
27
|
-
import globalMessages from '../../v2Containers/Cap/messages';
|
|
28
|
-
import messages from './messages';
|
|
29
|
-
import { createQueryString } from '../../utils/common';
|
|
30
|
-
const TabPane = Tabs.TabPane;
|
|
31
|
-
const {Column} = Table;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const tagsTypes = {
|
|
35
|
-
MISSING_TAGS: 'missingTags',
|
|
36
|
-
UNSUPPORTED_TAGS: 'unsupportedTags',
|
|
37
|
-
};
|
|
38
|
-
const errorMessageForTags = {
|
|
39
|
-
UNSUPPORTED_TAG_ERROR: 'unsupportedTagsError',
|
|
40
|
-
MISSING_TAG_ERROR: 'missingTagsError',
|
|
41
|
-
GENERIC_VALIDATION_ERROR: 'genericValidationError',
|
|
42
|
-
};
|
|
43
|
-
// import styled from 'styled-components';
|
|
44
|
-
|
|
45
|
-
// import { FormattedMessage } from 'react-intl';
|
|
46
|
-
// import messages from './messages';
|
|
47
|
-
|
|
48
|
-
class FormBuilder extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
49
|
-
constructor(props) {
|
|
50
|
-
super(props);
|
|
51
|
-
this.state = {
|
|
52
|
-
formData: {},
|
|
53
|
-
errorData: {},
|
|
54
|
-
currentTab: 1,
|
|
55
|
-
currentLangTab: 'en',
|
|
56
|
-
usingTabContainer: false,
|
|
57
|
-
tabCount: 1,
|
|
58
|
-
tabKey: '',
|
|
59
|
-
isFormValid: false,
|
|
60
|
-
checkValidation: false,
|
|
61
|
-
showModal: false,
|
|
62
|
-
modal: {},
|
|
63
|
-
currentEvent: {},
|
|
64
|
-
currentEventData: {},
|
|
65
|
-
popoverVisible: false,
|
|
66
|
-
customPopoverVisible: false,
|
|
67
|
-
};
|
|
68
|
-
this.renderForm = this.renderForm.bind(this);
|
|
69
|
-
this.updateFormData = this.updateFormData.bind(this);
|
|
70
|
-
this.callChildEvent = this.callChildEvent.bind(this);
|
|
71
|
-
this.renderColLabelSection = this.renderColLabelSection.bind(this);
|
|
72
|
-
this.renderMultiColSection = this.renderMultiColSection.bind(this);
|
|
73
|
-
this.renderSection = this.renderSection.bind(this);
|
|
74
|
-
this.renderContainer = this.renderContainer.bind(this);
|
|
75
|
-
this.renderParentSection = this.renderParentSection.bind(this);
|
|
76
|
-
this.initializeStandAloneSections = this.initializeStandAloneSections.bind(this);
|
|
77
|
-
this.initializeMultiColSection = this.initializeMultiColSection.bind(this);
|
|
78
|
-
this.initializeParentSection = this.initializeParentSection.bind(this);
|
|
79
|
-
this.initializeColLabelSection = this.initializeColLabelSection.bind(this);
|
|
80
|
-
this.initializeContainers = this.initializeContainers.bind(this);
|
|
81
|
-
this.cloneVersionData = this.cloneVersionData.bind(this);
|
|
82
|
-
this.markFinalTabVersion = this.markFinalTabVersion.bind(this);
|
|
83
|
-
this.duplicateVersion = this.duplicateVersion.bind(this);
|
|
84
|
-
this.deleteVersion = this.deleteVersion.bind(this);
|
|
85
|
-
this.renameVersion = this.renameVersion.bind(this);
|
|
86
|
-
this.resetState = this.resetState.bind(this);
|
|
87
|
-
this.onEdit = this.onEdit.bind(this);
|
|
88
|
-
this.changeVersionName = this.changeVersionName.bind(this);
|
|
89
|
-
this.hasClass = this.hasClass.bind(this);
|
|
90
|
-
this.validateForm = this.validateForm.bind(this);
|
|
91
|
-
this.indexOfEnd = this.indexOfEnd.bind(this);
|
|
92
|
-
this.saveForm = this.saveForm.bind(this);
|
|
93
|
-
this.initializeEditErrorData = this.initializeEditErrorData.bind(this);
|
|
94
|
-
this.checkIfSupportedTag = this.checkIfSupportedTag.bind(this);
|
|
95
|
-
this.transformInjectedTags = this.transformInjectedTags.bind(this);
|
|
96
|
-
this.handleSetRadioValue = this.handleSetRadioValue.bind(this);
|
|
97
|
-
this.formElements = [];
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
componentWillMount() {
|
|
101
|
-
this.setState({usingTabContainer: this.props.usingTabContainer ? this.props.usingTabContainer : false});
|
|
102
|
-
if (this.props.formData && (this.props.isEdit || (!this.props.isEdit && !_.isEmpty(this.props.formData)))) {
|
|
103
|
-
this.setState({formData: this.props.formData}, () => {
|
|
104
|
-
// if (!this.props.isNewVersionFlow) {
|
|
105
|
-
this.initialiseForm(this.props.schema, false, true);
|
|
106
|
-
// }
|
|
107
|
-
});
|
|
108
|
-
} else {
|
|
109
|
-
this.initialiseForm(this.props.schema, true);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
componentWillReceiveProps(nextProps) {
|
|
114
|
-
const type = this.props.location.query.type;
|
|
115
|
-
if (this.state.usingTabContainer && nextProps.tabCount !== this.props.tabCount) {
|
|
116
|
-
this.setState({tabCount: nextProps.tabCount});
|
|
117
|
-
}
|
|
118
|
-
if (nextProps.startValidation && nextProps.startValidation !== false && this.props.startValidation !== nextProps.startValidation) {
|
|
119
|
-
this.setState({checkValidation: true});
|
|
120
|
-
const ifValid = this.validateForm(null, null, null, true);
|
|
121
|
-
|
|
122
|
-
if (ifValid) {
|
|
123
|
-
this.saveForm(true);
|
|
124
|
-
} else {
|
|
125
|
-
this.props.stopValidation();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// if (nextProps.saveForm && this.props.saveForm !== nextProps.saveForm) {
|
|
129
|
-
// this.saveForm(saveForm);
|
|
130
|
-
// }
|
|
131
|
-
if (nextProps.isEdit) {
|
|
132
|
-
if (!_.isEqual(nextProps.formData, this.state.formData) && !_.isEmpty(nextProps.formData)) {
|
|
133
|
-
if (type === 'embedded') { //TODO: has to be checked and changed.
|
|
134
|
-
this.setState({checkValidation: true, formData: nextProps.formData}, () => {
|
|
135
|
-
this.validateForm();
|
|
136
|
-
});
|
|
137
|
-
// this.setState({formData: nextProps.formData}, () => {
|
|
138
|
-
// this.validateForm();
|
|
139
|
-
// });
|
|
140
|
-
}
|
|
141
|
-
//TODO change this structure
|
|
142
|
-
if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'WECHAT') {
|
|
143
|
-
this.setState({formData: nextProps.formData});
|
|
144
|
-
} else if ( !_.isEmpty(nextProps.formData) && !_.isEqual(this.state.formData, nextProps.formData) && this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'MOBILEPUSH') {
|
|
145
|
-
this.setState({formData: nextProps.formData, tabCount: nextProps.tabCount});
|
|
146
|
-
// this.resetTabKeys(nextProps.formData, nextProps.tabCount);
|
|
147
|
-
} else if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'EMAIL') {
|
|
148
|
-
this.setState({formData: nextProps.formData});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (this.state.usingTabContainer && this.state.tabKey === '') {
|
|
152
|
-
//this.setState({formData: nextProps.formData});
|
|
153
|
-
if (nextProps.isNewVersionFlow && !_.isEqual(this.state.tabKey, nextProps.tabKey)) {
|
|
154
|
-
this.setState({tabKey: nextProps.tabKey});
|
|
155
|
-
} else if (!nextProps.isNewVersionFlow) {
|
|
156
|
-
this.resetTabKeys(nextProps.formData, nextProps.tabCount);
|
|
157
|
-
}
|
|
158
|
-
this.initializeEditErrorData(nextProps.formData, nextProps.tabCount);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (_.isEmpty(this.props.formData) && !_.isEmpty(nextProps.formData)) {
|
|
162
|
-
if (this.state.usingTabContainer) {
|
|
163
|
-
this.resetTabKeys(nextProps.formData, nextProps.tabCount);
|
|
164
|
-
}
|
|
165
|
-
this.initializeEditErrorData(nextProps.formData, nextProps.tabCount);
|
|
166
|
-
}
|
|
167
|
-
if (!_.isEmpty(this.props.formData) && this.props.formData !== this.state.formData && _.isEmpty(this.state.formData) && this.state.usingTabContainer) {
|
|
168
|
-
this.resetTabKeys(this.props.formData, nextProps.tabCount);
|
|
169
|
-
}
|
|
170
|
-
if ( this.state.usingTabContainer && nextProps.formData && !_.isEmpty(nextProps.formData) && _.isEmpty(this.props.formData) && nextProps.tabCount && this.state.tabCount !== nextProps.tabCount) {
|
|
171
|
-
this.setState({ formData: nextProps.formData, tabCount: nextProps.tabCount }, () => {
|
|
172
|
-
this.initializeEditErrorData(nextProps.formData, nextProps.tabCount);
|
|
173
|
-
if (this.state.usingTabContainer) {
|
|
174
|
-
this.resetTabKeys(nextProps.formData, nextProps.tabCount);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
if (nextProps.tabCount > 1) {
|
|
178
|
-
this.setState({usingTabContainer: true});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
// if (nextProps.currentTab) {
|
|
182
|
-
// this.setState({currentTab: nextProps.currentTab});
|
|
183
|
-
// }
|
|
184
|
-
} else if (!_.isEmpty(nextProps.formData) &&
|
|
185
|
-
( !this.state.usingTabContainer || (this.state.usingTabContainer && nextProps.tabKey !== ''))
|
|
186
|
-
&& !_.isEqual(nextProps.formData, this.state.formData) &&
|
|
187
|
-
!_.isEqual(nextProps.formData, this.props.formData)) {
|
|
188
|
-
this.setState({formData: nextProps.formData, tabKey: nextProps.tabKey}, () => {
|
|
189
|
-
this.validateForm();
|
|
190
|
-
});
|
|
191
|
-
//this.resetTabKeys(nextProps.formData, nextProps.tabCount);
|
|
192
|
-
} else if ((_.isEmpty(this.props.formData) || !this.props.formData) && _.isEmpty(this.state.formData)) {
|
|
193
|
-
this.initialiseForm(nextProps.schema, true);
|
|
194
|
-
} else if (_.isEmpty(this.props.formData) && !_.isEmpty(nextProps.formData)) {
|
|
195
|
-
this.setState({formData: nextProps.formData});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
let currentLangTab = _.cloneDeep(this.state.currentLangTab);
|
|
199
|
-
if (nextProps.isNewVersionFlow && nextProps.formData[`${this.state.currentTab - 1}`] && nextProps.formData[`${this.state.currentTab - 1}`].activeTab) {
|
|
200
|
-
currentLangTab = nextProps.formData[`${this.state.currentTab - 1}`].activeTab;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (nextProps.isNewVersionFlow && nextProps.currentTab && nextProps.currentTab !== this.props.currentTab) {
|
|
204
|
-
this.setState({currentTab: nextProps.currentTab});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (!_.isEmpty(nextProps.formData) && !_.isEqual(this.state.formData, nextProps.formData)) {
|
|
208
|
-
if (nextProps.isNewVersionFlow) {
|
|
209
|
-
const nextPropsFormData = nextProps.formData[nextProps.currentTab - 1];
|
|
210
|
-
const nextPropsTabKey = nextPropsFormData && nextPropsFormData.tabKey;
|
|
211
|
-
const tabKey = (this.state.tabKey !== nextPropsTabKey) ? nextPropsTabKey: this.state.tabKey;
|
|
212
|
-
|
|
213
|
-
this.setState({tabKey});
|
|
214
|
-
}
|
|
215
|
-
this.setState({formData: nextProps.formData, currentLangTab}, () => {
|
|
216
|
-
if (nextProps.isNewVersionFlow && !this.state.formData[this.state.currentTab - 1][this.state.formData[this.state.currentTab - 1].activeTab].tabKey) {
|
|
217
|
-
this.resetTabKeys(nextProps.formData, nextProps.tabCount, false, true);
|
|
218
|
-
}
|
|
219
|
-
if (type === 'embedded' || (this.props?.schema?.channel || "").toUpperCase() === 'EMAIL') {
|
|
220
|
-
this.validateForm();
|
|
221
|
-
}
|
|
222
|
-
if ((this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'MOBILEPUSH')) {
|
|
223
|
-
this.validateForm();
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (!_.isEqual(nextProps.schema, this.props.schema)) {
|
|
230
|
-
this.setState({ isFormValid: (this.props.isEdit ? this.props.isEdit : true) }, () => {
|
|
231
|
-
if (!this.props.isEdit || (this.props.isEdit && !_.isEmpty(nextProps.formData))) {
|
|
232
|
-
let resetTabKeys = (this.state.formData.tabKey === undefined);
|
|
233
|
-
if ((this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'MOBILEPUSH')) {
|
|
234
|
-
resetTabKeys = false;
|
|
235
|
-
}
|
|
236
|
-
if (this.props.isNewVersionFlow) {
|
|
237
|
-
resetTabKeys = false;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
this.initialiseForm(nextProps.schema, false, resetTabKeys);
|
|
241
|
-
this.validateForm();
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
if (!_.isEqual(nextProps.checkValidation, this.props.checkValidation)) {
|
|
246
|
-
this.setState({ checkValidation: nextProps.checkValidation });
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (this.props.currentTab !== nextProps.currentTab && nextProps.currentTab) {
|
|
250
|
-
this.setState({currentTab: nextProps.currentTab});
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (!_.isEmpty(nextProps.injectedTags) && !_.isEqual(nextProps.injectedTags, this.props.injectedTags)) {
|
|
254
|
-
this.validateForm(nextProps.tags, nextProps.injectedTags);
|
|
255
|
-
}
|
|
256
|
-
if (!_.isEmpty(nextProps.tags) && !_.isEqual(nextProps.tags, this.props.tags)) {
|
|
257
|
-
this.validateForm(nextProps.tags, nextProps.injectedTags);
|
|
258
|
-
}
|
|
259
|
-
if (!_.isEqual(nextProps.showModal, this.props.showModal)) {
|
|
260
|
-
this.setState({showModal: nextProps.showModal});
|
|
261
|
-
}
|
|
262
|
-
if (nextProps.modal && (!_.isEqual(nextProps.modal, this.props.modal) || _.isEmpty(this.state.modal))) {
|
|
263
|
-
this.setState({modal: nextProps.modal});
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
onEdit() {
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
getModal = () => {
|
|
272
|
-
let modal;
|
|
273
|
-
if (this.state.modal) {
|
|
274
|
-
if (this.state.modal.type === 'confirm') {
|
|
275
|
-
modal = (<Modal
|
|
276
|
-
visible={this.state.showModal}
|
|
277
|
-
title={this.state.modal.title}
|
|
278
|
-
onOk={this.handleOk}
|
|
279
|
-
onCancel={this.handleCancel}
|
|
280
|
-
footer={[
|
|
281
|
-
<CapButton key="back" onClick={this.handleCancel}><FormattedMessage {...messages.cancel} /></CapButton>,
|
|
282
|
-
<CapButton key="submit" type="primary" id={this.state.modal.id} onClick={this.handleOk}>
|
|
283
|
-
<FormattedMessage {...messages.yes} />
|
|
284
|
-
</CapButton>,
|
|
285
|
-
]}
|
|
286
|
-
>
|
|
287
|
-
{this.state.modal.body}
|
|
288
|
-
</Modal>);
|
|
289
|
-
} else if (this.state.modal.type === "info") {
|
|
290
|
-
modal = (<Modal
|
|
291
|
-
visible={this.state.showModal}
|
|
292
|
-
title={this.state.modal.title}
|
|
293
|
-
onOk={this.handleOk}
|
|
294
|
-
onCancel={this.handleCancel}
|
|
295
|
-
footer={[
|
|
296
|
-
<CapButton key="back" onClick={this.handleCancel}><FormattedMessage {...messages.ok} /></CapButton>,
|
|
297
|
-
]}
|
|
298
|
-
>
|
|
299
|
-
{this.state.modal.body}
|
|
300
|
-
</Modal>);
|
|
301
|
-
} else if (this.state.modal.type === "action") {
|
|
302
|
-
modal = (<Modal
|
|
303
|
-
visible={this.state.showModal}
|
|
304
|
-
title={this.state.modal.title}
|
|
305
|
-
onOk={this.handleOk}
|
|
306
|
-
onCancel={this.handleCancel}
|
|
307
|
-
footer={[
|
|
308
|
-
]}
|
|
309
|
-
afterClose={this.handleCloseModal}
|
|
310
|
-
>
|
|
311
|
-
{this.state.modal.jsx}
|
|
312
|
-
</Modal>);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return modal;
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
openNotificationWithIcon = (type, message) => {
|
|
319
|
-
const dur = (type === 'error' || type === 'warning') ? null : 5;
|
|
320
|
-
notification[type]({
|
|
321
|
-
message: (`${type.toUpperCase()} ! ! ! `),
|
|
322
|
-
description: message, //'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
|
|
323
|
-
duration: dur,
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
handleCloseModal = () => {
|
|
328
|
-
const event = this.state.currentEvent;
|
|
329
|
-
if (!_.isEmpty(this.state.currentEvent)) {
|
|
330
|
-
switch (event) {
|
|
331
|
-
case "addLanguage":
|
|
332
|
-
this.updateFormData(this.state.currentEventData, this.state.currentEventVal, this.state.currentEvent);
|
|
333
|
-
break;
|
|
334
|
-
default:
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
handleVisibleChange = (popoverVisible) => {
|
|
341
|
-
this.setState({ popoverVisible });
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
handleCustomPopoverVisibleChange = (customPopoverVisible) => {
|
|
345
|
-
this.setState({ customPopoverVisible });
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
resetTabKeys(form, count, changeDefaultTab, setFormTabKey) {
|
|
349
|
-
const tabCount = count || this.state.tabCount;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const formData = _.cloneDeep(form);
|
|
353
|
-
let baseIndex = 0;
|
|
354
|
-
for (let idx = 0; idx < tabCount; idx += 1) {
|
|
355
|
-
if (this.props.isNewVersionFlow && formData[idx].selectedLanguages.length > 0) {
|
|
356
|
-
for (let langIndex = 0; langIndex < formData[idx].selectedLanguages.length; langIndex += 1 ) {
|
|
357
|
-
const id = _.uniqueId();
|
|
358
|
-
if (formData[idx][formData[idx].selectedLanguages[langIndex]]) {
|
|
359
|
-
if (!formData[idx][formData[idx].selectedLanguages[langIndex]].tabKey) {
|
|
360
|
-
formData[idx][formData[idx].selectedLanguages[langIndex]].tabKey = id;
|
|
361
|
-
}
|
|
362
|
-
if (formData[idx].base) {
|
|
363
|
-
formData.base[formData.base.selectedLanguages[langIndex]].tabKey = id;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
if (setFormTabKey) {
|
|
368
|
-
if (!formData[idx].activeTab) {
|
|
369
|
-
const baseLanguage = this.props.baseLanguage;
|
|
370
|
-
|
|
371
|
-
formData[idx].tabKey = formData[idx][baseLanguage].tabKey;
|
|
372
|
-
} else {
|
|
373
|
-
formData[idx].tabKey = formData[idx][formData[idx].activeTab].tabKey;
|
|
374
|
-
}
|
|
375
|
-
if (formData[idx].base) {
|
|
376
|
-
if (!formData.base.activeTab) {
|
|
377
|
-
const baseLanguage = this.props.baseLanguage;
|
|
378
|
-
formData.base.tabKey = formData.base[baseLanguage].tabKey;
|
|
379
|
-
} else {
|
|
380
|
-
formData.base.tabKey = formData.base[formData[idx].activeTab].tabKey;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
if (formData[idx].base && formData.base.activeTab) {
|
|
386
|
-
// if (!formData.base.tabKey) {
|
|
387
|
-
|
|
388
|
-
formData.base.tabKey = formData[idx][formData[idx].activeTab].tabKey;
|
|
389
|
-
//}
|
|
390
|
-
baseIndex = idx;
|
|
391
|
-
}
|
|
392
|
-
} else if (formData[idx]) {
|
|
393
|
-
if (!formData[idx].tabKey) {
|
|
394
|
-
formData[idx].tabKey = _.uniqueId();
|
|
395
|
-
}
|
|
396
|
-
if (formData[idx].base) {
|
|
397
|
-
formData.base = formData[idx];
|
|
398
|
-
baseIndex = idx;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
if ((formData.base && formData.base.tabKey && formData.base.tabKey !== '' && !changeDefaultTab) || (formData.base && this.state.tabKey !== formData.base.tabKey)) {
|
|
404
|
-
if (this.state.currentTab === 1 && !this.props.isNewVersionFlow) {
|
|
405
|
-
this.setState({tabKey: formData.base.tabKey});
|
|
406
|
-
} else if (this.props.isNewVersionFlow && this.state.tabKey !== formData[this.state.currentTab - 1].tabKey) {
|
|
407
|
-
this.setState({tabKey: formData[this.state.currentTab - 1].tabKey});
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
if (setFormTabKey) {
|
|
411
|
-
this.setState({tabKey: formData.base.tabKey});
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (changeDefaultTab) {
|
|
416
|
-
this.setState({formData}, () => {
|
|
417
|
-
this.props.onChange(formData, this.state.tabCount);
|
|
418
|
-
this.validateForm();
|
|
419
|
-
});
|
|
420
|
-
} else {
|
|
421
|
-
this.setState({formData, currentTab: baseIndex + 1}, () => {
|
|
422
|
-
this.props.onChange(formData, this.state.tabCount);
|
|
423
|
-
this.validateForm();
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/* eslint-disable */
|
|
429
|
-
validateForm(tags, injectedTags, isSave, showMessages) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
let isValid = true;
|
|
433
|
-
const type = (this.props.location && this.props.location.query.type) ? this.props.location.query.type : 'full';
|
|
434
|
-
const currentModule = (this.props.location && this.props.location.query.module) ? this.props.location.query.module : 'default';
|
|
435
|
-
const errorData = _.cloneDeep(this.state.errorData);
|
|
436
|
-
if (this.props.schema.channel === 'SMS') {
|
|
437
|
-
|
|
438
|
-
for (let count = 0; count < this.state.tabCount; count += 1) {
|
|
439
|
-
if (_.isEmpty(errorData[count])) {
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
const index = count + 1;
|
|
443
|
-
if (!this.state.formData[count]) {
|
|
444
|
-
continue;
|
|
445
|
-
}
|
|
446
|
-
const content = this.state.formData[count][`sms-editor${index > 1 ? index : ''}`];
|
|
447
|
-
const unicodeCheck = this.state.formData[count][`unicode-validity${index > 1 ? index : ''}`];
|
|
448
|
-
const ifUnicode = content && content !== '' ? checkUnicode(content) : false;
|
|
449
|
-
|
|
450
|
-
const tagValidationResponse = this.validateTags(content, tags, injectedTags);
|
|
451
|
-
|
|
452
|
-
if (tagValidationResponse.valid) {
|
|
453
|
-
errorData[count][`sms-editor${index > 1 ? index : ''}`] = false;
|
|
454
|
-
} else {
|
|
455
|
-
const { MISSING_TAG_ERROR, UNSUPPORTED_TAG_ERROR, GENERIC_VALIDATION_ERROR } = errorMessageForTags;
|
|
456
|
-
const { missingTags, unsupportedTags} = tagValidationResponse;
|
|
457
|
-
errorData[count][`sms-editor${index > 1 ? index : ''}`] = missingTags && missingTags.length ? MISSING_TAG_ERROR : ( unsupportedTags && unsupportedTags.length ? UNSUPPORTED_TAG_ERROR : GENERIC_VALIDATION_ERROR);
|
|
458
|
-
isValid = false;
|
|
459
|
-
}
|
|
460
|
-
if(content !== '' && (ifUnicode && !unicodeCheck)) {
|
|
461
|
-
errorData[count][`unicode-validity${index > 1 ? index : ''}`] = true;
|
|
462
|
-
isValid = false;
|
|
463
|
-
} else if (content === '') {
|
|
464
|
-
|
|
465
|
-
errorData[count][`sms-editor${index > 1 ? index : ''}`] = errorMessageForTags.GENERIC_VALIDATION_ERROR;
|
|
466
|
-
isValid = false;
|
|
467
|
-
} else {
|
|
468
|
-
errorData[count][`unicode-validity${index > 1 ? index : ''}`] = false;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
if(type !== 'embedded' && (!this.state.formData['template-name'] || this.state.formData['template-name'] === '')) {
|
|
472
|
-
errorData['template-name'] = true;
|
|
473
|
-
isValid = false;
|
|
474
|
-
} else {
|
|
475
|
-
errorData['template-name'] = false;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
//validation for LINE
|
|
480
|
-
if (this.props.schema.channel === 'LINE') {
|
|
481
|
-
|
|
482
|
-
if (this.state.formData['0']['message-editor'] !== undefined ) {
|
|
483
|
-
const content = this.state.formData['0']['message-editor'];
|
|
484
|
-
|
|
485
|
-
const tagValidationResponse = this.validateTags(content, tags, injectedTags);
|
|
486
|
-
|
|
487
|
-
if (tagValidationResponse.valid) {
|
|
488
|
-
_.set(errorData, `['0']['message-editor']`, false);
|
|
489
|
-
} else {
|
|
490
|
-
|
|
491
|
-
_.set(errorData, `['0']['message-editor']`, true);
|
|
492
|
-
isValid = false;
|
|
493
|
-
}
|
|
494
|
-
if (content.trim() === '') {
|
|
495
|
-
|
|
496
|
-
_.set(errorData, `['0']['message-editor']`, true);
|
|
497
|
-
isValid = false;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
if ( (this.state.formData['0'].image !== undefined) && (this.state.formData['0'].imagePreview !== undefined)){
|
|
502
|
-
const imgContentLength = this.state.formData['0'].image.length;
|
|
503
|
-
const imgContentLengthPreview = this.state.formData['0'].imagePreview.length;
|
|
504
|
-
if ( (imgContentLength < 1) && (imgContentLengthPreview < 1) ) {
|
|
505
|
-
|
|
506
|
-
_.set(errorData, `['0'].image`, true);
|
|
507
|
-
_.set(errorData, `['0'].imagePreview`, true);
|
|
508
|
-
isValid = false;
|
|
509
|
-
}else{
|
|
510
|
-
_.set(errorData, `['0'].image`, false);
|
|
511
|
-
_.set(errorData, `['0'].imagePreview`, false);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
if(type !== 'embedded' && (!this.state.formData['template-name'] || this.state.formData['template-name'] === '')) {
|
|
515
|
-
_.set(errorData, `['template-name']`, true);
|
|
516
|
-
isValid = false;
|
|
517
|
-
} else {
|
|
518
|
-
_.set(errorData, `['template-name']`, false);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'WECHAT') {
|
|
523
|
-
|
|
524
|
-
_.forEach(this.state.formData, (val, index) => {
|
|
525
|
-
|
|
526
|
-
if (index.indexOf('template') > -1 && this.state.formData[index] !== undefined) {
|
|
527
|
-
const content = this.state.formData[index];
|
|
528
|
-
if (content.trim() === '') {
|
|
529
|
-
errorData[index] = true;
|
|
530
|
-
isValid = false;
|
|
531
|
-
} else {
|
|
532
|
-
const tagValidationResponse = this.validateTags(content, tags, injectedTags);
|
|
533
|
-
|
|
534
|
-
if (tagValidationResponse.valid) {
|
|
535
|
-
errorData[index] = false;
|
|
536
|
-
} else {
|
|
537
|
-
errorData[index] = true;
|
|
538
|
-
isValid = false;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
} else if (index === 'wechat-template') {
|
|
542
|
-
const content = this.state.formData[index];
|
|
543
|
-
if (content.trim() === '') {
|
|
544
|
-
errorData[index] = true;
|
|
545
|
-
isValid = false;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
}
|
|
551
|
-
if(this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === "MOBILEPUSH"){
|
|
552
|
-
let androidValid = true, iosValid = true;
|
|
553
|
-
let isOnlyAndroid = false, isOnlyIos = false;
|
|
554
|
-
|
|
555
|
-
const androidData = {};
|
|
556
|
-
for(let data in this.state.formData[0]){
|
|
557
|
-
if(!!this.state.formData[0][data] && data !== "tabKey" && data !== "base"){
|
|
558
|
-
androidData[data] = this.state.formData[0][data];
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
if(_.isEmpty(androidData)){
|
|
562
|
-
isOnlyIos = true;
|
|
563
|
-
}
|
|
564
|
-
const iosData = {};
|
|
565
|
-
for(let data in this.state.formData[1]){
|
|
566
|
-
if(!!this.state.formData[1][data] && data !== "tabKey" && data !== "base"){
|
|
567
|
-
iosData[data] = this.state.formData[1][data];
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
if(_.isEmpty(iosData)){
|
|
571
|
-
isOnlyAndroid = true;
|
|
572
|
-
}
|
|
573
|
-
_.forEach(this.state.formData, (tab, index) => {
|
|
574
|
-
let isCurrentTabValid = true;
|
|
575
|
-
let skipValidation = false;
|
|
576
|
-
if (type.toLowerCase() === 'embedded' && ((isOnlyAndroid && parseInt(index) === 1) || (isOnlyIos && parseInt(index) === 0))) {
|
|
577
|
-
skipValidation = true;
|
|
578
|
-
}
|
|
579
|
-
if (!isNaN(index) && tab && !skipValidation) {
|
|
580
|
-
const selector = index > 0 ? `${Number(index) + 1}` : '';
|
|
581
|
-
let message = tab[`message-editor${selector}`];
|
|
582
|
-
|
|
583
|
-
message = message.trim();
|
|
584
|
-
|
|
585
|
-
if (errorData[parseInt(index)]) {
|
|
586
|
-
if (message === "") {
|
|
587
|
-
errorData[parseInt(index)][`message-editor${selector}`] = true;
|
|
588
|
-
isValid = false;
|
|
589
|
-
isCurrentTabValid = false;
|
|
590
|
-
} else {
|
|
591
|
-
errorData[parseInt(index)][`message-editor${selector}`] = false;
|
|
592
|
-
const tagValidationResponse = this.validateTags(message, tags, injectedTags);
|
|
593
|
-
|
|
594
|
-
if (tagValidationResponse.valid) {
|
|
595
|
-
errorData[parseInt(index)][`message-editor${selector}`] = false;
|
|
596
|
-
} else {
|
|
597
|
-
errorData[parseInt(index)][`message-editor${selector}`] = true;
|
|
598
|
-
isValid = false;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
const title = tab[`message-title${selector}`].trim();
|
|
604
|
-
if (title === "") {
|
|
605
|
-
errorData[parseInt(index)][`message-title${selector}`] = true;
|
|
606
|
-
isValid = false;
|
|
607
|
-
isCurrentTabValid = false;
|
|
608
|
-
} else {
|
|
609
|
-
errorData[parseInt(index)][`message-title${selector}`] = false;
|
|
610
|
-
const tagValidationResponse = this.validateTags(title, tags, injectedTags);
|
|
611
|
-
|
|
612
|
-
if (tagValidationResponse.valid) {
|
|
613
|
-
errorData[parseInt(index)][`message-title${selector}`] = false;
|
|
614
|
-
} else {
|
|
615
|
-
errorData[parseInt(index)][`message-title${selector}`] = true;
|
|
616
|
-
isValid = false;
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
// if(tab['primary-cta-link'].trim() === ""){
|
|
621
|
-
// errorData[parseInt(index)][`primary-cta-link`] = true;
|
|
622
|
-
// isValid = false;
|
|
623
|
-
// }else {
|
|
624
|
-
// errorData[parseInt(index)]['primary-cta-link'] = false;
|
|
625
|
-
// }
|
|
626
|
-
if(tab['cta-deeplink-select'] === ""){
|
|
627
|
-
errorData[parseInt(index)][`cta-deeplink-select`] = true;
|
|
628
|
-
isValid = false;
|
|
629
|
-
isCurrentTabValid = false;
|
|
630
|
-
}else {
|
|
631
|
-
errorData[parseInt(index)]['cta-deeplink-select'] = false;
|
|
632
|
-
}
|
|
633
|
-
if(tab['cta-deeplink2-select'] === ""){
|
|
634
|
-
errorData[parseInt(index)][`cta-deeplink2-select`] = true;
|
|
635
|
-
isValid = false;
|
|
636
|
-
isCurrentTabValid = false;
|
|
637
|
-
}else {
|
|
638
|
-
errorData[parseInt(index)]['cta-deeplink2-select'] = false;
|
|
639
|
-
}
|
|
640
|
-
// }
|
|
641
|
-
if(tab[`cta-deeplink-text`] === ""){
|
|
642
|
-
errorData[parseInt(index)][`cta-deeplink-text`] = true;
|
|
643
|
-
isValid = false;
|
|
644
|
-
isCurrentTabValid = false;
|
|
645
|
-
}else {
|
|
646
|
-
errorData[parseInt(index)]['cta-deeplink-text'] = false;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
if(tab['cta-deeplink2-text'] === ""){
|
|
650
|
-
errorData[parseInt(index)][`cta-deeplink2-text`] = true;
|
|
651
|
-
isValid = false;
|
|
652
|
-
isCurrentTabValid = false;
|
|
653
|
-
}else {
|
|
654
|
-
errorData[parseInt(index)]['cta-deeplink2-text'] = false;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
if(tab['secondary-cta-0-link'] === ""){
|
|
659
|
-
errorData[parseInt(index)][`secondary-cta-0-link`] = true;
|
|
660
|
-
isValid = false;
|
|
661
|
-
isCurrentTabValid = false;
|
|
662
|
-
}else {
|
|
663
|
-
errorData[parseInt(index)]['secondary-cta-0-link'] = false;
|
|
664
|
-
}
|
|
665
|
-
if(tab['secondary-cta-0-label'] === ""){
|
|
666
|
-
errorData[parseInt(index)][`secondary-cta-0-label`] = true;
|
|
667
|
-
isValid = false;
|
|
668
|
-
isCurrentTabValid = false;
|
|
669
|
-
}else {
|
|
670
|
-
errorData[parseInt(index)]['secondary-cta-0-label'] = false;
|
|
671
|
-
}
|
|
672
|
-
if(tab['cta-deeplink-secondary-cta-0-text'] === ""){
|
|
673
|
-
errorData[parseInt(index)][`cta-deeplink-secondary-cta-0-text`] = true;
|
|
674
|
-
isValid = false;
|
|
675
|
-
isCurrentTabValid = false;
|
|
676
|
-
}else {
|
|
677
|
-
errorData[parseInt(index)]['cta-deeplink-secondary-cta-0-text'] = false;
|
|
678
|
-
}
|
|
679
|
-
if(tab['cta-deeplink-secondary-cta-0-select'] === ""){
|
|
680
|
-
errorData[parseInt(index)][`cta-deeplink-secondary-cta-0-select`] = true;
|
|
681
|
-
isValid = false;
|
|
682
|
-
isCurrentTabValid = false;
|
|
683
|
-
}else {
|
|
684
|
-
errorData[parseInt(index)]['cta-deeplink-secondary-cta-0-select'] = false;
|
|
685
|
-
}
|
|
686
|
-
if(tab['secondary-cta-1-label'] === ""){
|
|
687
|
-
errorData[parseInt(index)][`secondary-cta-1-label`] = true;
|
|
688
|
-
isValid = false;
|
|
689
|
-
isCurrentTabValid = false;
|
|
690
|
-
}else {
|
|
691
|
-
errorData[parseInt(index)]['secondary-cta-1-label'] = false;
|
|
692
|
-
}
|
|
693
|
-
if(tab['cta-deeplink-secondary-cta-1-text'] === ""){
|
|
694
|
-
errorData[parseInt(index)][`cta-deeplink-secondary-cta-1-text`] = true;
|
|
695
|
-
isValid = false;
|
|
696
|
-
isCurrentTabValid = false;
|
|
697
|
-
}else {
|
|
698
|
-
errorData[parseInt(index)]['cta-deeplink-secondary-cta-1-text'] = false;
|
|
699
|
-
}
|
|
700
|
-
if(tab['cta-deeplink-secondary-cta-1-select'] === ""){
|
|
701
|
-
errorData[parseInt(index)][`cta-deeplink-secondary-cta-1-select`] = true;
|
|
702
|
-
isValid = false;
|
|
703
|
-
isCurrentTabValid = false;
|
|
704
|
-
}else {
|
|
705
|
-
errorData[parseInt(index)]['cta-deeplink-secondary-cta-1-select'] = false;
|
|
706
|
-
}
|
|
707
|
-
if(tab['cta-deeplink-secondary-cta-1-text2'] === ""){
|
|
708
|
-
errorData[parseInt(index)][`cta-deeplink-secondary-cta-1-text2`] = true;
|
|
709
|
-
isValid = false;
|
|
710
|
-
isCurrentTabValid = false;
|
|
711
|
-
}else {
|
|
712
|
-
errorData[parseInt(index)]['cta-deeplink-secondary-cta-1-text2'] = false;
|
|
713
|
-
}
|
|
714
|
-
if(tab['cta-deeplink-secondary-cta-1-select2'] === ""){
|
|
715
|
-
errorData[parseInt(index)][`cta-deeplink-secondary-cta-1-select2`] = true;
|
|
716
|
-
isValid = false;
|
|
717
|
-
isCurrentTabValid = false;
|
|
718
|
-
}else {
|
|
719
|
-
errorData[parseInt(index)]['cta-deeplink-secondary-cta-1-select2'] = false;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
if(typeof tab['image'] !== 'undefined' && tab['image'] === ""){
|
|
723
|
-
errorData[parseInt(index)]['image'] = true;
|
|
724
|
-
isValid = false;
|
|
725
|
-
isCurrentTabValid = false;
|
|
726
|
-
}else{
|
|
727
|
-
errorData[parseInt(index)]['image'] = false;
|
|
728
|
-
}
|
|
729
|
-
_.forEach(Object.keys(tab), (key) => {
|
|
730
|
-
if (key.indexOf('custom-value') > -1) {
|
|
731
|
-
if (tab[key] === "") {
|
|
732
|
-
errorData[parseInt(index)][key] = true;
|
|
733
|
-
isValid = false;
|
|
734
|
-
isCurrentTabValid = false;
|
|
735
|
-
}else {
|
|
736
|
-
errorData[parseInt(index)][key] = false;
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
if(index == 0){
|
|
743
|
-
androidValid = isCurrentTabValid;
|
|
744
|
-
} else if(index == 1){
|
|
745
|
-
iosValid = isCurrentTabValid;
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
if(type !== 'embedded' && (!this.state.formData['template-name'] || this.state.formData['template-name'] === '')) {
|
|
749
|
-
errorData['template-name'] = true;
|
|
750
|
-
isValid = false;
|
|
751
|
-
androidValid = false;
|
|
752
|
-
iosValid = false
|
|
753
|
-
} else {
|
|
754
|
-
errorData['template-name'] = false;
|
|
755
|
-
}
|
|
756
|
-
if(isSave && (androidValid || iosValid)){
|
|
757
|
-
const modal = this.state.modal;
|
|
758
|
-
const androidData = {};
|
|
759
|
-
|
|
760
|
-
for(let data in this.state.formData[0]){
|
|
761
|
-
if(!!this.state.formData[0][data] && data !== "tabKey" && data !== "base"){
|
|
762
|
-
androidData[data] = this.state.formData[0][data];
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
if(_.isEmpty(androidData) && this.state.currentTab === 2){
|
|
766
|
-
this.setState({androidValid, iosValid}, () => {
|
|
767
|
-
this.props.setModalContent('ios');
|
|
768
|
-
});
|
|
769
|
-
// modal.body = "Android template is not configured. Save without Android template";
|
|
770
|
-
// modal.id = "ios";
|
|
771
|
-
// modal.type = 'confirm';
|
|
772
|
-
return;
|
|
773
|
-
}
|
|
774
|
-
const iosData = {};
|
|
775
|
-
for(let data in this.state.formData[1]){
|
|
776
|
-
if(!!this.state.formData[1][data] && data !== "tabKey"){
|
|
777
|
-
iosData[data] = this.state.formData[1][data];
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
if(_.isEmpty(iosData) && this.state.currentTab === 1){
|
|
781
|
-
this.setState({androidValid, iosValid}, () => {
|
|
782
|
-
this.props.setModalContent('android');
|
|
783
|
-
});
|
|
784
|
-
// modal.body = "IOS template is not configured, Save without IOS template";
|
|
785
|
-
// modal.id = 'android';
|
|
786
|
-
// modal.type = 'confirm';
|
|
787
|
-
// this.setState({modal, showModal: true, androidValid, iosValid});
|
|
788
|
-
return;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
if (!androidValid || !iosValid) {
|
|
792
|
-
this.setState({androidValid, iosValid});
|
|
793
|
-
}
|
|
794
|
-
if (isOnlyAndroid && androidValid) {
|
|
795
|
-
isValid = isValid && true;
|
|
796
|
-
} else if (isOnlyIos && iosValid) {
|
|
797
|
-
isValid = isValid && true;
|
|
798
|
-
} else if (!isOnlyIos && !isOnlyAndroid && androidValid && iosValid) {
|
|
799
|
-
isValid = isValid && true;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
// Form Data Validation for Email Channel
|
|
804
|
-
if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === "EMAIL") {
|
|
805
|
-
// Validating Email By iterating all elements of FormBuilder
|
|
806
|
-
_.forEach(this.state.formData, (data, index) => {
|
|
807
|
-
|
|
808
|
-
if (!this.state.formData["template-subject"] && type.toLowerCase() === 'embedded' && (currentModule.toLowerCase() === 'loyalty' || currentModule.toLowerCase() === 'dvs' || currentModule.toLowerCase() === 'timeline' || currentModule.toLowerCase() === 'library')) {
|
|
809
|
-
errorData["template-subject"] = true;
|
|
810
|
-
isValid = false;
|
|
811
|
-
}
|
|
812
|
-
// Check if template subject present in form data from Loyalty, DVS, Timeline
|
|
813
|
-
if (index === 'template-subject' && type.toLowerCase() === 'embedded' && (currentModule.toLowerCase() === 'loyalty' || currentModule.toLowerCase() === 'dvs' || currentModule.toLowerCase() === 'timeline' || currentModule.toLowerCase() === 'library')) {
|
|
814
|
-
if (data.trim() === '') {
|
|
815
|
-
errorData[index] = true;
|
|
816
|
-
isValid = false;
|
|
817
|
-
} else {
|
|
818
|
-
errorData[index] = false;
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
// Check if Template name present in full mode
|
|
823
|
-
if(type !== 'embedded' && index === 'template-name' && data === '') {
|
|
824
|
-
errorData[index] = true;
|
|
825
|
-
isValid = false;
|
|
826
|
-
} else if(type !== 'embedded' && index === 'template-name' && data !== '') {
|
|
827
|
-
errorData[index] = false;
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
// Check formData if selected version present or not
|
|
831
|
-
if(index === 'template-version' && data === '') {
|
|
832
|
-
errorData[index] = true;
|
|
833
|
-
isValid = false;
|
|
834
|
-
} else if(index === 'template-version' && data !== '') {
|
|
835
|
-
errorData[index] = false;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
// Check error for the versions
|
|
839
|
-
if (!isNaN(index) || index === 'base') {
|
|
840
|
-
if (errorData[index] === undefined) {
|
|
841
|
-
errorData[index] = {};
|
|
842
|
-
}
|
|
843
|
-
let errorString = "";
|
|
844
|
-
for (var i = 0; i < data.selectedLanguages.length; i+= 1) {
|
|
845
|
-
const currentLang = data.selectedLanguages[i];
|
|
846
|
-
const content = (data[currentLang] || {})['template-content'];
|
|
847
|
-
const tagValidationResponse = this.validateTags(content, tags, injectedTags);
|
|
848
|
-
if (errorData[index][currentLang] === undefined) {
|
|
849
|
-
errorData[index][currentLang] = {};
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
if (tagValidationResponse.valid) {
|
|
853
|
-
errorData[index][currentLang]['template-content'] = false;
|
|
854
|
-
} else {
|
|
855
|
-
errorData[index][currentLang]['template-content'] = true;
|
|
856
|
-
isValid = false;
|
|
857
|
-
if (showMessages && !isNaN(index)) {
|
|
858
|
-
if (tagValidationResponse.missingTags.length > 0 || tagValidationResponse.unsupportedTags.length > 0) {
|
|
859
|
-
errorString += `${this.props.intl.formatMessage(messages.contentNotValidLanguage)} ${currentLang}\n`;
|
|
860
|
-
}
|
|
861
|
-
if (tagValidationResponse.missingTags.length > 0) {
|
|
862
|
-
errorString += `${this.props.intl.formatMessage(messages.missingTags)} ${tagValidationResponse.missingTags.toString()}\n`;
|
|
863
|
-
}
|
|
864
|
-
if (tagValidationResponse.unsupportedTags.length > 0) {
|
|
865
|
-
errorString += `${this.props.intl.formatMessage(messages.unsupportedTags)} ${tagValidationResponse.unsupportedTags.toString()}\n`;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
if (errorString !== "") {
|
|
871
|
-
this.openNotificationWithIcon('error', errorString);
|
|
872
|
-
}
|
|
873
|
-
_.forEach(errorData[index], (versionData, key) => {
|
|
874
|
-
if (data.selectedLanguages.indexOf(key) === -1) {
|
|
875
|
-
delete errorData[index][key];
|
|
876
|
-
}
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
});
|
|
880
|
-
// for (let count = 0; count < this.state.tabCount; count += 1) {
|
|
881
|
-
// const index = count + 1;
|
|
882
|
-
// // const content = this.state.formData[count][`template-content${index > 1 ? index : ''}`];
|
|
883
|
-
// // const tagValidationResponse = this.validateTags(content, tags, injectedTags);
|
|
884
|
-
// //
|
|
885
|
-
// // if (tagValidationResponse.valid) {
|
|
886
|
-
// // errorData[count][`template-content${index > 1 ? index : ''}`] = false;
|
|
887
|
-
// // } else {
|
|
888
|
-
// // errorData[count][`template-content${index > 1 ? index : ''}`] = true;
|
|
889
|
-
// // isValid = false;
|
|
890
|
-
// // }
|
|
891
|
-
// }
|
|
892
|
-
// if (type.toLowerCase() === 'embedded' && (currentModule.toLowerCase() === 'loyalty' || currentModule.toLowerCase() === 'dvs' || currentModule.toLowerCase() === 'timeline')) {
|
|
893
|
-
// if (this.state.formData['template-subject'] && this.state.formData['template-subject'].trim() === '') {
|
|
894
|
-
// errorData['template-subject'] = true;
|
|
895
|
-
// isValid = false;
|
|
896
|
-
// }
|
|
897
|
-
// }
|
|
898
|
-
// if(type !== 'embedded' && (!this.state.formData['template-name'] || this.state.formData['template-name'] === '')) {
|
|
899
|
-
// errorData['template-name'] = true;
|
|
900
|
-
// isValid = false;
|
|
901
|
-
// } else {
|
|
902
|
-
// errorData['template-name'] = false;
|
|
903
|
-
// }
|
|
904
|
-
}
|
|
905
|
-
this.setState({isFormValid : isValid, errorData});
|
|
906
|
-
|
|
907
|
-
this.props.onFormValidityChange(isValid);
|
|
908
|
-
return isValid;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
indexOfEnd(targetString, string) {
|
|
912
|
-
var io = targetString.indexOf(string);
|
|
913
|
-
return io == -1 ? -1 : io + string.length;
|
|
914
|
-
}
|
|
915
|
-
continueSaveForm = (id) => {
|
|
916
|
-
|
|
917
|
-
};
|
|
918
|
-
saveForm(saveForm) {
|
|
919
|
-
if (this.props.isNewVersionFlow && !saveForm) {
|
|
920
|
-
this.props.getValidationData();
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
if (this.state.isFormValid) {
|
|
924
|
-
this.props.onSubmit(this.state.formData);
|
|
925
|
-
} else {
|
|
926
|
-
this.setState({checkValidation: true});
|
|
927
|
-
this.validateForm(null, null, true);
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
transformInjectedTags(tags) {
|
|
932
|
-
_.forEach(tags, (tag) => {
|
|
933
|
-
const temp = tag;
|
|
934
|
-
let subKey = '';
|
|
935
|
-
Object.keys(tag).map( (k) => {
|
|
936
|
-
if (k.indexOf("subtags") !== -1) {
|
|
937
|
-
subKey = k;
|
|
938
|
-
}
|
|
939
|
-
return true;
|
|
940
|
-
});
|
|
941
|
-
if (subKey !== '') {
|
|
942
|
-
temp['tag-header'] = true;
|
|
943
|
-
if (subKey !== 'subtags') {
|
|
944
|
-
temp.subtags = _.cloneDeep(temp[subKey]);
|
|
945
|
-
delete temp[subKey];
|
|
946
|
-
}
|
|
947
|
-
temp.subtags = this.transformInjectedTags(temp.subtags);
|
|
948
|
-
}
|
|
949
|
-
});
|
|
950
|
-
return tags;
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
checkIfSupportedTag(checkingTag, injectedTags) {
|
|
954
|
-
let result = false;
|
|
955
|
-
_.forEach(injectedTags, (tag, key) => {
|
|
956
|
-
if (tag.subtags) {
|
|
957
|
-
if (this.checkIfSupportedTag(checkingTag, tag.subtags)) {
|
|
958
|
-
result = true;
|
|
959
|
-
}
|
|
960
|
-
} else if (checkingTag === key) {
|
|
961
|
-
result = true;
|
|
962
|
-
}
|
|
963
|
-
});
|
|
964
|
-
|
|
965
|
-
return result;
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
skipTags(tag) {
|
|
969
|
-
const regexGroups = ["dynamic_expiry_date_after_\\d+_days.FORMAT_\\d", "unsubscribe\\(#[a-zA-Z\\d]{6}\\)","Link_to_[a-zA-z]","SURVEY.*.TOKEN"];
|
|
970
|
-
|
|
971
|
-
//const regexGroups = [];
|
|
972
|
-
let skipped = false;
|
|
973
|
-
_.forEach(regexGroups, (group) => {
|
|
974
|
-
//const groupRegex = /dynamic_expiry_date_after_\(\d+\)_days.FORMAT_\d/g;
|
|
975
|
-
const groupRegex = new RegExp(group, "g");
|
|
976
|
-
let match = groupRegex.exec(tag);
|
|
977
|
-
if (match !== null ) {
|
|
978
|
-
skipped = true;
|
|
979
|
-
return true;
|
|
980
|
-
}
|
|
981
|
-
return true;
|
|
982
|
-
});
|
|
983
|
-
return skipped;
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
validateTags(content, tagsParam, injectedTagsParams) {
|
|
987
|
-
const type = (this.props.location && this.props.location.query.type) ? this.props.location.query.type : 'full';
|
|
988
|
-
let currentModule = this.props.location.query.module ? this.props.location.query.module : 'default';
|
|
989
|
-
if (this.props.tagModule) {
|
|
990
|
-
currentModule = this.props.tagModule;
|
|
991
|
-
}
|
|
992
|
-
const tags = tagsParam ? tagsParam : this.props.tags;
|
|
993
|
-
const injectedTags = this.transformInjectedTags(injectedTagsParams ? injectedTagsParams : this.props.injectedTags);
|
|
994
|
-
const excludedTags = ['user_id_b64', 'outbox_id_b64'];
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
const response = {};
|
|
998
|
-
response.valid = true;
|
|
999
|
-
response.missingTags = [];
|
|
1000
|
-
response.unsupportedTags = [];
|
|
1001
|
-
_.forEach(tags, (tag) => {
|
|
1002
|
-
_.forEach(tag.definition.supportedModules, (module) => {
|
|
1003
|
-
if (module.mandatory && (currentModule === module.context)) {
|
|
1004
|
-
if (content.indexOf(`{{${tag.definition.value}}}`) === -1) {
|
|
1005
|
-
response.valid = false;
|
|
1006
|
-
response.missingTags.push(tag.definition.value);
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
});
|
|
1010
|
-
});
|
|
1011
|
-
const regex = /{{[(A-Z\w\(\)@!#$%^&*~.,/\\]+}}/g;
|
|
1012
|
-
let match = regex.exec(content);
|
|
1013
|
-
while (match !== null) {
|
|
1014
|
-
const tagValue = match[0].substring(this.indexOfEnd(match[0], '{{'), match[0].indexOf('}}'));
|
|
1015
|
-
match = regex.exec(content);
|
|
1016
|
-
let ifSupported = false;
|
|
1017
|
-
_.forEach(tags, (tag) => {
|
|
1018
|
-
if (tag.definition.value === tagValue) {
|
|
1019
|
-
ifSupported = true;
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1022
|
-
const ifSkipped = this.skipTags(tagValue);
|
|
1023
|
-
if (ifSkipped) {
|
|
1024
|
-
ifSupported = true;
|
|
1025
|
-
let isUnsubscribeSkipped = tagValue.indexOf("unsubscribe") != -1 ;
|
|
1026
|
-
if (isUnsubscribeSkipped) {
|
|
1027
|
-
const missingTagIndex = response.missingTags.indexOf("unsubscribe");
|
|
1028
|
-
if(missingTagIndex != -1) { //skip regex tags for mandatory tags also
|
|
1029
|
-
response.missingTags.splice(missingTagIndex, 1);
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
ifSupported = ifSupported || this.checkIfSupportedTag(tagValue, injectedTags);
|
|
1034
|
-
if (!ifSupported) {
|
|
1035
|
-
response.unsupportedTags.push(tagValue);
|
|
1036
|
-
response.valid = false;
|
|
1037
|
-
}
|
|
1038
|
-
if (response.unsupportedTags.length == 0 && response.missingTags.length == 0 ) {
|
|
1039
|
-
response.valid = true;
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
return response;
|
|
1043
|
-
}
|
|
1044
|
-
/* eslint-enable */
|
|
1045
|
-
initializeParentSection(section, formDataObj, isContainer, index, ifError) {
|
|
1046
|
-
let formData = formDataObj;
|
|
1047
|
-
_.forEach(section.childSections, (childSection) => {
|
|
1048
|
-
if (childSection.type === 'col-label') {
|
|
1049
|
-
formData = this.initializeColLabelSection(childSection, formData, isContainer, index, ifError);
|
|
1050
|
-
} else if (childSection.type === 'multicols') {
|
|
1051
|
-
formData = this.initializeMultiColSection(childSection, formData, isContainer, index, ifError);
|
|
1052
|
-
} else {
|
|
1053
|
-
formData = this.initializeParentSection(childSection, formData, isContainer, index, ifError);
|
|
1054
|
-
}
|
|
1055
|
-
});
|
|
1056
|
-
return formData;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
initializeEditErrorData(formData, tabCount) {
|
|
1060
|
-
const errorData = {};
|
|
1061
|
-
for (let idx = 0; idx < tabCount; idx += 1 ) {
|
|
1062
|
-
_.forEach(formData[0], (val, key) => {
|
|
1063
|
-
if (!errorData[idx]) {
|
|
1064
|
-
errorData[idx] = {};
|
|
1065
|
-
}
|
|
1066
|
-
if (key === 'tabKey' || key === 'base' || key === 'selectedLanguages') {
|
|
1067
|
-
return true;
|
|
1068
|
-
}
|
|
1069
|
-
if (this.props.isNewVersionFlow && formData[0].selectedLanguages.indexOf(key) > -1) {
|
|
1070
|
-
_.forEach(formData[0].selectedLanguages, (lang) => {
|
|
1071
|
-
if (errorData[idx] === undefined) {
|
|
1072
|
-
errorData[idx] = {};
|
|
1073
|
-
}
|
|
1074
|
-
if (errorData[idx][lang] === undefined) {
|
|
1075
|
-
errorData[idx][lang] = {};
|
|
1076
|
-
}
|
|
1077
|
-
errorData[idx][lang]['template-content'] = false;
|
|
1078
|
-
});
|
|
1079
|
-
} else {
|
|
1080
|
-
errorData[idx][key] = false;
|
|
1081
|
-
}
|
|
1082
|
-
return true;
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
this.setState({errorData});
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
initializeMultiColSection(section, formDataObj, isContainer, index, ifError) {
|
|
1089
|
-
const formData = _.cloneDeep(formDataObj);
|
|
1090
|
-
const newFormData = {};
|
|
1091
|
-
newFormData[index] = {};
|
|
1092
|
-
_.forEach(section.inputFields, (inputField) => {
|
|
1093
|
-
_.forEach(inputField.cols, (col) => {
|
|
1094
|
-
if (isContainer && !formData[index]) {
|
|
1095
|
-
formData[index] = {};
|
|
1096
|
-
}
|
|
1097
|
-
if (isContainer && this.props.isNewVersionFlow) {
|
|
1098
|
-
// if (formData[index] && formData[index].selectedLanguages && formData[index].selectedLanguages.length > 0) {
|
|
1099
|
-
// for (let i = 0; i < formData[index].selectedLanguages.length; i += 1 ) {
|
|
1100
|
-
// formData[index][formData[index].selectedLanguages[i]] = {};
|
|
1101
|
-
// }
|
|
1102
|
-
// } else {
|
|
1103
|
-
// formData[index][`${this.props.baseLanguage ? this.props.baseLanguage : 'en'}`] = {};
|
|
1104
|
-
// }
|
|
1105
|
-
_.forEach(this.props.supportedLanguages, (language) => {
|
|
1106
|
-
if (!formData[index][language.iso_code] && this.props.baseLanguage === language.iso_code) {
|
|
1107
|
-
formData[index][language.iso_code] = {};
|
|
1108
|
-
}
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
|
-
// if (!ifError && (col.id.indexOf('template-label-') === -1 && col.id.indexOf('tagList-') === -1)) {
|
|
1112
|
-
// this.formElements.push(col.id);
|
|
1113
|
-
// }
|
|
1114
|
-
if (!col.onlyDisplay && !ifError) {
|
|
1115
|
-
if (col.id.indexOf('tagList-') === -1) {
|
|
1116
|
-
this.formElements.push(col.id);
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
if (!this.props.isNewVersionFlow) {
|
|
1120
|
-
if (isContainer && formData[index][col.id] === undefined) {
|
|
1121
|
-
if (ifError) {
|
|
1122
|
-
formData[index][col.id] = false;
|
|
1123
|
-
} else if (isContainer && formData[index][col.id] === undefined && col.value) {
|
|
1124
|
-
formData[index][col.id] = col.value;
|
|
1125
|
-
} else {
|
|
1126
|
-
formData[index][col.id] = '';
|
|
1127
|
-
}
|
|
1128
|
-
} else if (!isContainer && ifError && formData[col.id] === undefined) {
|
|
1129
|
-
formData[col.id] = false;
|
|
1130
|
-
} else if (!isContainer && !ifError && formData[col.id] === undefined) {
|
|
1131
|
-
formData[col.id] = '';
|
|
1132
|
-
}
|
|
1133
|
-
} else if (!(col.id.indexOf('template-content') > -1 && col.id !== 'template-content')) {
|
|
1134
|
-
if (isContainer && formData[index] && formData[index][this.props.baseLanguage] && formData[index][this.props.baseLanguage][col.id] === undefined) {
|
|
1135
|
-
if (ifError) {
|
|
1136
|
-
formData[index][this.props.baseLanguage][col.id] = false;
|
|
1137
|
-
} else if (isContainer && formData[index][this.props.baseLanguage][col.id] === undefined && col.value) {
|
|
1138
|
-
formData[index][this.props.baseLanguage][col.id] = col.value;
|
|
1139
|
-
} else {
|
|
1140
|
-
formData[index][this.props.baseLanguage][col.id] = '';
|
|
1141
|
-
}
|
|
1142
|
-
} else if (!isContainer && ifError && formData[col.id] === undefined) {
|
|
1143
|
-
formData[col.id] = false;
|
|
1144
|
-
} else if (!isContainer && !ifError && formData[col.id] === undefined) {
|
|
1145
|
-
formData[col.id] = '';
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
if (col.type === 'checkbox') {
|
|
1150
|
-
if (isContainer) {
|
|
1151
|
-
formData[index][col.id] = false;
|
|
1152
|
-
} else if (!isContainer && formData[col.id] === undefined) {
|
|
1153
|
-
formData[col.id] = false;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
});
|
|
1157
|
-
});
|
|
1158
|
-
return formData;
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
initializeColLabelSection(section, formDataObj, isContainer, index, ifError) {
|
|
1162
|
-
const formData = formDataObj;
|
|
1163
|
-
_.forEach(section.inputFields, (inputField) => {
|
|
1164
|
-
if (isContainer && !formData[index]) {
|
|
1165
|
-
formData[index] = {};
|
|
1166
|
-
}
|
|
1167
|
-
if (!ifError && (inputField.id.indexOf('template-label-') === -1 && inputField.id.indexOf('tagList-') === -1)) {
|
|
1168
|
-
this.formElements.push(inputField.id);
|
|
1169
|
-
}
|
|
1170
|
-
if (!inputField.onlyDisplay) {
|
|
1171
|
-
if (isContainer && !this.props.isNewVersionFlow && formData[index][inputField.id] === undefined) {
|
|
1172
|
-
if (ifError) {
|
|
1173
|
-
formData[index][inputField.id] = false;
|
|
1174
|
-
} else {
|
|
1175
|
-
formData[index][inputField.id] = '';
|
|
1176
|
-
}
|
|
1177
|
-
} else if (isContainer && this.props.isNewVersionFlow && formData[index][this.props.baseLanguage][inputField.id] === undefined) {
|
|
1178
|
-
if (ifError) {
|
|
1179
|
-
formData[index][this.props.baseLanguage][inputField.id] = false;
|
|
1180
|
-
} else {
|
|
1181
|
-
formData[index][this.props.baseLanguage][inputField.id] = '';
|
|
1182
|
-
}
|
|
1183
|
-
} else if (!isContainer && ifError && this.state.formData[inputField.id] === undefined) {
|
|
1184
|
-
formData[inputField.id] = false;
|
|
1185
|
-
} else if (!isContainer && !ifError && this.state.formData[inputField.id] === undefined) {
|
|
1186
|
-
formData[inputField.id] = '';
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
if (inputField.type === 'checkbox') {
|
|
1190
|
-
if (isContainer) {
|
|
1191
|
-
formData[index][inputField.id] = false;
|
|
1192
|
-
} else {
|
|
1193
|
-
formData[inputField.id] = false;
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
});
|
|
1197
|
-
return formData;
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
initializeStandAloneSections(schema, formDataObj, ifError) {
|
|
1201
|
-
let formData = _.cloneDeep(formDataObj);
|
|
1202
|
-
if (schema.standalone) {
|
|
1203
|
-
_.forEach(schema.standalone.sections, (section) => {
|
|
1204
|
-
if (section) {
|
|
1205
|
-
if (section.type === 'multicols') {
|
|
1206
|
-
formData = this.initializeMultiColSection(section, formData, false, -1, ifError);
|
|
1207
|
-
} else if (section.type === 'col-label') {
|
|
1208
|
-
formData = this.initializeColLabelSection(section, formData, false, -1, ifError);
|
|
1209
|
-
} else if (section.type === 'parent') {
|
|
1210
|
-
formData = this.initializeParentSection(section, formData, false, -1, ifError);
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
|
-
return formData;
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
initializeContainers(schema, formDataObj, ifError) {
|
|
1219
|
-
let formData = _.cloneDeep(formDataObj);
|
|
1220
|
-
if (this.props.isNewVersionFlow) {
|
|
1221
|
-
_.forEach(schema.containers, (val, index) => {
|
|
1222
|
-
if (val.type === 'tabs') {
|
|
1223
|
-
this.setState({usingTabContainer: true});
|
|
1224
|
-
_.forEach(val.panes, (pane, paneIndex) => {
|
|
1225
|
-
_.forEach(pane.sections, (section) => {
|
|
1226
|
-
if (section.type === 'multicols') {
|
|
1227
|
-
formData = this.initializeMultiColSection(section, formData, true, index, ifError, paneIndex);
|
|
1228
|
-
} else if (section.type === 'col-label') {
|
|
1229
|
-
formData = this.initializeColLabelSection(section, formData, true, index, ifError);
|
|
1230
|
-
} else if (section.type === 'parent') {
|
|
1231
|
-
formData = this.initializeParentSection(section, formData, true, index, ifError);
|
|
1232
|
-
}
|
|
1233
|
-
});
|
|
1234
|
-
});
|
|
1235
|
-
if (ifError) {
|
|
1236
|
-
formData[val.id] = false;
|
|
1237
|
-
}
|
|
1238
|
-
formData[val.id] = '';
|
|
1239
|
-
}
|
|
1240
|
-
if (val.type === 'checkbox') {
|
|
1241
|
-
formData[val.id] = false;
|
|
1242
|
-
}
|
|
1243
|
-
});
|
|
1244
|
-
} else {
|
|
1245
|
-
_.forEach(schema.containers, (val) => {
|
|
1246
|
-
if (val.type === 'tabs') {
|
|
1247
|
-
this.setState({usingTabContainer: true});
|
|
1248
|
-
_.forEach(val.panes, (pane, index) => {
|
|
1249
|
-
_.forEach(pane.sections, (section) => {
|
|
1250
|
-
if (section.type === 'multicols') {
|
|
1251
|
-
formData = this.initializeMultiColSection(section, formData, true, index, ifError);
|
|
1252
|
-
} else if (section.type === 'col-label') {
|
|
1253
|
-
formData = this.initializeColLabelSection(section, formData, true, index, ifError);
|
|
1254
|
-
} else if (section.type === 'parent') {
|
|
1255
|
-
formData = this.initializeParentSection(section, formData, true, index, ifError);
|
|
1256
|
-
}
|
|
1257
|
-
});
|
|
1258
|
-
});
|
|
1259
|
-
if (ifError) {
|
|
1260
|
-
formData[val.id] = false;
|
|
1261
|
-
}
|
|
1262
|
-
formData[val.id] = '';
|
|
1263
|
-
}
|
|
1264
|
-
if (val.type === 'checkbox') {
|
|
1265
|
-
formData[val.id] = false;
|
|
1266
|
-
}
|
|
1267
|
-
});
|
|
1268
|
-
}
|
|
1269
|
-
return formData;
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
initialiseForm(schema, makeFormEmpty, resetTabKeys) {
|
|
1273
|
-
let formData = makeFormEmpty ? {} : _.cloneDeep(this.state.formData);
|
|
1274
|
-
let errorData = {};
|
|
1275
|
-
this.formElements = [];
|
|
1276
|
-
if (_.isEmpty(schema)) {
|
|
1277
|
-
return;
|
|
1278
|
-
}
|
|
1279
|
-
errorData = this.initializeStandAloneSections(schema, errorData, true);
|
|
1280
|
-
formData = this.initializeStandAloneSections(schema, formData);
|
|
1281
|
-
formData = this.initializeContainers(schema, formData);
|
|
1282
|
-
errorData = this.initializeContainers(schema, errorData, true);
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
if (!this.props.isEdit) {
|
|
1286
|
-
if (!formData[0]) {
|
|
1287
|
-
formData[0] = {};
|
|
1288
|
-
}
|
|
1289
|
-
if (!errorData[0]) {
|
|
1290
|
-
errorData[0] = {};
|
|
1291
|
-
}
|
|
1292
|
-
formData[0].base = true;
|
|
1293
|
-
formData[0].tabKey = formData[0].tabKey ? formData[0].tabKey : _.uniqueId();
|
|
1294
|
-
errorData.base = errorData[0];
|
|
1295
|
-
formData.base = formData[0];
|
|
1296
|
-
if (this.state.currentTab === 1) {
|
|
1297
|
-
this.setState({tabKey: formData.base.tabKey});
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
const tempFormData = _.cloneDeep(formData);
|
|
1301
|
-
if (!this.props.isNewVersionFlow) {
|
|
1302
|
-
_.forEach(formData, (element, key) => {
|
|
1303
|
-
if (typeof element !== 'object' && this.formElements.indexOf(key) === -1) {
|
|
1304
|
-
delete tempFormData[key];
|
|
1305
|
-
} else if (typeof element === "object") {
|
|
1306
|
-
_.forEach(element, (innerElement, innerKey) => {
|
|
1307
|
-
if (innerKey !== "tabKey" && innerKey !== "base" && innerKey !== 'name' && innerKey !== 'imagePreview' && this.formElements.indexOf(innerKey) === -1) {
|
|
1308
|
-
delete tempFormData[key][innerKey];
|
|
1309
|
-
}
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
formData = _.cloneDeep(tempFormData);
|
|
1315
|
-
this.setState({formData, errorData}, () => {
|
|
1316
|
-
this.validateForm();
|
|
1317
|
-
if (this.props.isSchemaChanged || resetTabKeys) {
|
|
1318
|
-
this.resetTabKeys(this.state.formData, this.props.tabCount, true);
|
|
1319
|
-
}
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
cloneVersionData(ifError) {
|
|
1324
|
-
if (this.state.tabCount === 0) {
|
|
1325
|
-
this.initialiseForm(this.props.schema, true);
|
|
1326
|
-
return;
|
|
1327
|
-
}
|
|
1328
|
-
let formData = {};
|
|
1329
|
-
if (ifError) {
|
|
1330
|
-
formData = Object.assign({}, this.state.errorData);
|
|
1331
|
-
} else {
|
|
1332
|
-
formData = Object.assign({}, this.state.formData);
|
|
1333
|
-
}
|
|
1334
|
-
let newTabIndex = 0;
|
|
1335
|
-
if (ifError) {
|
|
1336
|
-
newTabIndex = this.state.tabCount - 1;
|
|
1337
|
-
} else {
|
|
1338
|
-
newTabIndex = this.state.tabCount;
|
|
1339
|
-
}
|
|
1340
|
-
formData[newTabIndex] = {};
|
|
1341
|
-
|
|
1342
|
-
const newTabCount = newTabIndex + 1;
|
|
1343
|
-
_.forEach(formData[0], (val, key) => {
|
|
1344
|
-
if (key === 'base') {
|
|
1345
|
-
return true;
|
|
1346
|
-
}
|
|
1347
|
-
if (key === 'tabKey') {
|
|
1348
|
-
return true;
|
|
1349
|
-
}
|
|
1350
|
-
if (typeof val === 'string') {
|
|
1351
|
-
if (ifError) {
|
|
1352
|
-
formData[newTabIndex][`${key}${newTabCount}`] = false;
|
|
1353
|
-
} else if (this.props.isNewVersionFlow) {
|
|
1354
|
-
if (key.indexOf('activeTab') > -1) {
|
|
1355
|
-
formData[newTabIndex][`${key}`] = this.props.baseLanguage;
|
|
1356
|
-
} else {
|
|
1357
|
-
formData[newTabIndex][`${key}${newTabCount}`] = '';
|
|
1358
|
-
}
|
|
1359
|
-
} else {
|
|
1360
|
-
formData[newTabIndex][`${key}${newTabCount}`] = '';
|
|
1361
|
-
}
|
|
1362
|
-
} else if (typeof val === 'boolean') {
|
|
1363
|
-
formData[newTabIndex][`${key}${newTabCount}`] = false;
|
|
1364
|
-
} else if (typeof val === 'object') {
|
|
1365
|
-
if (this.props.isNewVersionFlow) {
|
|
1366
|
-
if (key.indexOf('selectedLanguages') > -1) {
|
|
1367
|
-
formData[newTabIndex][key] = [this.props.baseLanguage];
|
|
1368
|
-
} else if (key === this.props.baseLanguage) {
|
|
1369
|
-
formData[newTabIndex][key] = {};
|
|
1370
|
-
_.forEach(val, (subVal, index) => {
|
|
1371
|
-
// if (subVal === 'is_drag_drop' || subVal === 'lang_id' || subVal === 'iso_code' === 'language') {
|
|
1372
|
-
//
|
|
1373
|
-
// formData[newTabIndex][key][index] = formData[0][this.props.baseLanguage][subVal];
|
|
1374
|
-
// } else {
|
|
1375
|
-
if (index === 'tabKey') {
|
|
1376
|
-
formData[newTabIndex][key][index] = _.uniqueId();
|
|
1377
|
-
} else if (index === 'template-content') {
|
|
1378
|
-
formData[newTabIndex][key][index] = "";
|
|
1379
|
-
} else {
|
|
1380
|
-
formData[newTabIndex][key][index] = _.cloneDeep(formData[0][key][index]);
|
|
1381
|
-
}
|
|
1382
|
-
// }
|
|
1383
|
-
});
|
|
1384
|
-
}
|
|
1385
|
-
} else {
|
|
1386
|
-
formData[newTabIndex][key] = {};
|
|
1387
|
-
_.forEach(val, (subVal, index) => {
|
|
1388
|
-
formData[newTabIndex][key][index] = '';
|
|
1389
|
-
});
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
return true;
|
|
1393
|
-
});
|
|
1394
|
-
let id = (this.props.isNewVersionFlow && formData[newTabIndex][this.props.baseLanguage].tabKey) ? formData[newTabIndex][this.props.baseLanguage].tabKey : _.uniqueId();
|
|
1395
|
-
|
|
1396
|
-
if (!ifError) {
|
|
1397
|
-
let validId = false;
|
|
1398
|
-
while (!validId) {
|
|
1399
|
-
validId = true;
|
|
1400
|
-
for (let idx = 0; idx < this.state.tabCount; idx += 1) {
|
|
1401
|
-
if (id === formData[idx].tabKey) {
|
|
1402
|
-
validId = false;
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
if (validId) {
|
|
1406
|
-
break;
|
|
1407
|
-
}
|
|
1408
|
-
id = _.uniqueId();
|
|
1409
|
-
}
|
|
1410
|
-
formData[newTabIndex].tabKey = id;
|
|
1411
|
-
}
|
|
1412
|
-
// if (!this.props.isEdit) {
|
|
1413
|
-
if (ifError) {
|
|
1414
|
-
this.setState({errorData: formData});
|
|
1415
|
-
} else {
|
|
1416
|
-
this.props.onChange(formData, newTabCount, newTabIndex + 1);
|
|
1417
|
-
|
|
1418
|
-
this.setState({tabCount: newTabCount, formData, currentTab: newTabIndex + 1, tabKey: id}, () => {
|
|
1419
|
-
this.cloneVersionData(true);
|
|
1420
|
-
});
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
changeVersionName(data) {
|
|
1425
|
-
const formData = _.cloneDeep(this.state.formData);
|
|
1426
|
-
if (formData[this.state.currentTab - 1]) {
|
|
1427
|
-
formData[this.state.currentTab - 1].name = data;
|
|
1428
|
-
this.setState({formData});
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
markFinalTabVersion() {
|
|
1433
|
-
const formData = _.cloneDeep(this.state.formData);
|
|
1434
|
-
if (this.state.usingTabContainer) {
|
|
1435
|
-
for (let count = 0; count < this.state.tabCount; count += 1) {
|
|
1436
|
-
if (parseInt(this.state.currentTab - 1, 10) !== count) {
|
|
1437
|
-
formData[count].base = false;
|
|
1438
|
-
} else {
|
|
1439
|
-
formData[count].base = true;
|
|
1440
|
-
formData.base = formData[count];
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
this.setState({formData});
|
|
1444
|
-
|
|
1445
|
-
this.props.onChange(formData, this.state.tabCount);
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
resetState(isEdit, usingTabContainer) {
|
|
1450
|
-
this.setState({
|
|
1451
|
-
formData: {},
|
|
1452
|
-
currentTab: 1,
|
|
1453
|
-
usingTabContainer: usingTabContainer || false,
|
|
1454
|
-
tabCount: 1,
|
|
1455
|
-
errorData: {},
|
|
1456
|
-
tabKey: '',
|
|
1457
|
-
}, () => {
|
|
1458
|
-
if (!isEdit) {
|
|
1459
|
-
this.initialiseForm(this.props.schema, true);
|
|
1460
|
-
}
|
|
1461
|
-
});
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
duplicateVersion(ifError, currentTab) {
|
|
1465
|
-
let formData = {};
|
|
1466
|
-
let tabCount = 0;
|
|
1467
|
-
if (ifError) {
|
|
1468
|
-
formData = _.cloneDeep(this.state.errorData);
|
|
1469
|
-
tabCount = this.state.tabCount - 1;
|
|
1470
|
-
} else {
|
|
1471
|
-
formData = _.cloneDeep(this.state.formData);
|
|
1472
|
-
tabCount = this.state.tabCount;
|
|
1473
|
-
}
|
|
1474
|
-
const newTabCount = tabCount + 1;
|
|
1475
|
-
_.forEach(formData[0], (val, key) => {
|
|
1476
|
-
if (!formData[tabCount]) {
|
|
1477
|
-
formData[tabCount] = {};
|
|
1478
|
-
}
|
|
1479
|
-
if (key === 'base') {
|
|
1480
|
-
formData[tabCount].base = false;
|
|
1481
|
-
return true;
|
|
1482
|
-
}
|
|
1483
|
-
if (key === 'tabKey') {
|
|
1484
|
-
let validId = false;
|
|
1485
|
-
let id = _.uniqueId();
|
|
1486
|
-
while (!validId) {
|
|
1487
|
-
validId = true;
|
|
1488
|
-
for (let idx = 0; idx < this.state.tabCount; idx += 1) {
|
|
1489
|
-
if (id === formData[idx].tabKey) {
|
|
1490
|
-
validId = false;
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
if (validId) {
|
|
1494
|
-
break;
|
|
1495
|
-
}
|
|
1496
|
-
id = _.uniqueId();
|
|
1497
|
-
}
|
|
1498
|
-
formData[tabCount].tabKey = id;
|
|
1499
|
-
return true;
|
|
1500
|
-
}
|
|
1501
|
-
const tempTab = ifError ? currentTab : this.state.currentTab;
|
|
1502
|
-
if (typeof val === 'string') {
|
|
1503
|
-
if (this.props.isNewVersionFlow) {
|
|
1504
|
-
formData[tabCount][`${key}`] = formData[tempTab - 1][`${key}`];
|
|
1505
|
-
} else {
|
|
1506
|
-
formData[tabCount][`${key}${newTabCount}`] = formData[tempTab - 1][`${key}${parseInt(tempTab, 10) === 1 ? '' : tempTab}`];
|
|
1507
|
-
}
|
|
1508
|
-
} else if (typeof val === 'boolean') {
|
|
1509
|
-
if (this.props.isNewVersionFlow) {
|
|
1510
|
-
formData[tabCount][`${key}`] = formData[tempTab - 1][`${key}`];
|
|
1511
|
-
} else {
|
|
1512
|
-
formData[tabCount][`${key}${newTabCount}`] = formData[tempTab - 1][`${key}${parseInt(tempTab, 10) === 1 ? '' : tempTab}`];
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
return true;
|
|
1516
|
-
});
|
|
1517
|
-
if (ifError) {
|
|
1518
|
-
this.setState({errorData: formData});
|
|
1519
|
-
} else {
|
|
1520
|
-
const tempTab = ifError ? currentTab : this.state.currentTab;
|
|
1521
|
-
const version = `${this.props.intl.formatMessage(messages.version)} ${this.state.currentTab}`;
|
|
1522
|
-
formData[tabCount].name = `${this.props?.intl?.formatMessage(globalMessages.copyOf)} ${formData[tempTab - 1].name ? formData[tempTab - 1].name : version}`;
|
|
1523
|
-
formData[tabCount].base = false;
|
|
1524
|
-
const initialTab = this.state.currentTab;
|
|
1525
|
-
this.setState({formData, tabCount: tabCount + 1, currentTab: tabCount + 1, tabKey: formData[tabCount].tabKey}, () => {
|
|
1526
|
-
this.duplicateVersion(true, initialTab);
|
|
1527
|
-
});
|
|
1528
|
-
|
|
1529
|
-
this.props.onChange(formData, tabCount + 1, tabCount + 1);
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
deleteVersion(ifError, currentTab) {
|
|
1534
|
-
if (!ifError && this.state.tabCount === 1) {
|
|
1535
|
-
return;
|
|
1536
|
-
}
|
|
1537
|
-
let formData = {};
|
|
1538
|
-
let finalCurrentTab = 0;
|
|
1539
|
-
let tabCount = 0;
|
|
1540
|
-
if (ifError) {
|
|
1541
|
-
formData = _.cloneDeep(this.state.errorData);
|
|
1542
|
-
tabCount = this.state.tabCount + 1;
|
|
1543
|
-
finalCurrentTab = currentTab;
|
|
1544
|
-
} else {
|
|
1545
|
-
formData = _.cloneDeep(this.state.formData);
|
|
1546
|
-
tabCount = this.state.tabCount;
|
|
1547
|
-
finalCurrentTab = this.state.currentTab;
|
|
1548
|
-
}
|
|
1549
|
-
// delete formData[this.state.currentTab - 1];
|
|
1550
|
-
let finalActiveTabKey = '';
|
|
1551
|
-
if (tabCount > 1 && currentTab !== tabCount) {
|
|
1552
|
-
finalActiveTabKey = formData[currentTab].tabKey;
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1555
|
-
if (tabCount > 1 && currentTab === tabCount) {
|
|
1556
|
-
finalActiveTabKey = formData[currentTab - 2].tabKey;
|
|
1557
|
-
finalCurrentTab = currentTab - 1;
|
|
1558
|
-
}
|
|
1559
|
-
// if (this.state.tabCount > 1 && this.state.currentTab === 1) {
|
|
1560
|
-
// finalActiveTabKey = this.state.formData[1].tabKey;
|
|
1561
|
-
// }
|
|
1562
|
-
if (tabCount === 1) {
|
|
1563
|
-
finalActiveTabKey = '';
|
|
1564
|
-
}
|
|
1565
|
-
const initialFormData = _.cloneDeep(formData[0]);
|
|
1566
|
-
for (let count = currentTab - 1; count < tabCount - 1; count += 1) {
|
|
1567
|
-
delete formData[count];
|
|
1568
|
-
_.forEach(initialFormData, (val, key) => {
|
|
1569
|
-
if (!formData[count]) {
|
|
1570
|
-
formData[count] = {};
|
|
1571
|
-
}
|
|
1572
|
-
if (key === 'base') {
|
|
1573
|
-
formData[count].base = formData[count + 1].base ? formData[count + 1].base : false;
|
|
1574
|
-
return true;
|
|
1575
|
-
}
|
|
1576
|
-
if (key === 'tabKey') {
|
|
1577
|
-
formData[count].tabKey = formData[count + 1].tabKey;
|
|
1578
|
-
return true;
|
|
1579
|
-
}
|
|
1580
|
-
formData[count][`${key}${count === 0 ? '' : count + 1}`] = formData[count + 1][`${key}${count + 2}`];
|
|
1581
|
-
return true;
|
|
1582
|
-
});
|
|
1583
|
-
}
|
|
1584
|
-
delete formData[tabCount - 1];
|
|
1585
|
-
if (ifError) {
|
|
1586
|
-
this.setState({errorData: formData});
|
|
1587
|
-
} else {
|
|
1588
|
-
const initialTab = currentTab;
|
|
1589
|
-
if (this.props.isNewVersionFlow) {
|
|
1590
|
-
formData['template-version-options'].splice(`${currentTab - 1}`, 1);
|
|
1591
|
-
formData['template-version'] = formData['template-version-options'][0].value;
|
|
1592
|
-
}
|
|
1593
|
-
this.setState({formData, tabCount: tabCount - 1, tabKey: finalActiveTabKey, currentTab: finalCurrentTab}, () => {
|
|
1594
|
-
this.deleteVersion(true, initialTab);
|
|
1595
|
-
});
|
|
1596
|
-
|
|
1597
|
-
this.props.onChange(formData, tabCount - 1);
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
deleteLanguage = () => {
|
|
1602
|
-
if (this.state.formData[`${this.state.currentTab - 1}`].activeTab !== this.props.baseLanguage) {
|
|
1603
|
-
const formData = _.cloneDeep(this.state.formData);
|
|
1604
|
-
const currentTab = `${this.state.currentTab - 1}`;
|
|
1605
|
-
const currentLang = formData[`${this.state.currentTab - 1}`].activeTab;
|
|
1606
|
-
const deleteLanguageIndex = formData[currentTab].selectedLanguages.indexOf(currentLang);
|
|
1607
|
-
const baseLangTabKey = formData[currentTab][this.props.baseLanguage].tabKey;
|
|
1608
|
-
|
|
1609
|
-
delete formData[currentTab][currentLang];
|
|
1610
|
-
formData[currentTab].activeTab = this.props.baseLanguage;
|
|
1611
|
-
formData[currentTab].selectedLanguages.splice(deleteLanguageIndex, 1);
|
|
1612
|
-
formData[currentTab].tabKey = baseLangTabKey;
|
|
1613
|
-
if (formData[currentTab].base) {
|
|
1614
|
-
delete formData.base[currentLang];
|
|
1615
|
-
delete formData.base.selectedLanguages.splice(deleteLanguageIndex, 1);
|
|
1616
|
-
formData.base.tabKey = baseLangTabKey;
|
|
1617
|
-
formData.base.activeTab = this.props.baseLanguage;
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
this.setState({formData, currentLangTab: this.props.baseLanguage, tabKey: baseLangTabKey}, () => {
|
|
1621
|
-
this.state.currentEvent.call(this.props.parent, formData, deleteLanguageIndex);
|
|
1622
|
-
this.setState({currentEvent: {}, currentEventData: {}});
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
};
|
|
1626
|
-
|
|
1627
|
-
renameVersion(currentTab) {
|
|
1628
|
-
document.getElementById(`tab-header${currentTab > 1 ? currentTab : ''}`).contentEditable = "true";
|
|
1629
|
-
document.getElementById(`tab-header${currentTab > 1 ? currentTab : ''}`).focus();
|
|
1630
|
-
}
|
|
1631
|
-
|
|
1632
|
-
updateFormData(data, val, event) {
|
|
1633
|
-
const formData = _.cloneDeep(this.state.formData);
|
|
1634
|
-
|
|
1635
|
-
const tabIndex = this.state.currentTab - 1;
|
|
1636
|
-
let currentTab = _.cloneDeep(this.state.currentTab);
|
|
1637
|
-
|
|
1638
|
-
if (this.state.usingTabContainer && !val.standalone) {
|
|
1639
|
-
const data1 = data;
|
|
1640
|
-
if (event === "addLanguage") {
|
|
1641
|
-
const addLanguageType = this.props.addLanguageType;
|
|
1642
|
-
if (addLanguageType === '') {
|
|
1643
|
-
return;
|
|
1644
|
-
}
|
|
1645
|
-
const currentLang = formData[tabIndex].activeTab;
|
|
1646
|
-
let baseTab = _.cloneDeep(formData[tabIndex][currentLang]);
|
|
1647
|
-
let id = _.uniqueId();
|
|
1648
|
-
let validId = false;
|
|
1649
|
-
switch (addLanguageType) {
|
|
1650
|
-
case "upload":
|
|
1651
|
-
baseTab = _.cloneDeep(formData[tabIndex][currentLang]);
|
|
1652
|
-
|
|
1653
|
-
baseTab.iso_code = data.iso_code;
|
|
1654
|
-
baseTab.lang_id = data.lang_id;
|
|
1655
|
-
baseTab.language = data.language;
|
|
1656
|
-
while (!validId) {
|
|
1657
|
-
validId = true;
|
|
1658
|
-
for (let idx = 0; idx < formData[tabIndex].selectedLanguages.length; idx += 1) {
|
|
1659
|
-
if (!formData[tabIndex]) {
|
|
1660
|
-
continue;
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
if (id === formData[tabIndex][formData[tabIndex].selectedLanguages[idx]].tabKey) {
|
|
1664
|
-
validId = false;
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
if (validId) {
|
|
1668
|
-
break;
|
|
1669
|
-
}
|
|
1670
|
-
id = _.uniqueId();
|
|
1671
|
-
}
|
|
1672
|
-
baseTab.tabKey = id;
|
|
1673
|
-
//formData[tabIndex].selectedLanguages.push(data.iso_code);
|
|
1674
|
-
formData[tabIndex][data.iso_code] = baseTab;
|
|
1675
|
-
|
|
1676
|
-
formData[tabIndex].activeTab = data.iso_code;
|
|
1677
|
-
formData[tabIndex].tabKey = baseTab.tabKey;
|
|
1678
|
-
break;
|
|
1679
|
-
case "copyPrimaryLanguage":
|
|
1680
|
-
case "useEditor":
|
|
1681
|
-
baseTab = _.cloneDeep(formData[tabIndex][this.props.baseLanguage]);
|
|
1682
|
-
|
|
1683
|
-
//baseTab['template-content'] = '';
|
|
1684
|
-
baseTab.iso_code = data.iso_code;
|
|
1685
|
-
baseTab.lang_id = data.lang_id;
|
|
1686
|
-
baseTab.language = data.language;
|
|
1687
|
-
validId = false;
|
|
1688
|
-
while (!validId) {
|
|
1689
|
-
validId = true;
|
|
1690
|
-
for (let idx = 0; idx < formData[tabIndex].selectedLanguages.length; idx += 1) {
|
|
1691
|
-
if (!formData[idx]) {
|
|
1692
|
-
continue;
|
|
1693
|
-
}
|
|
1694
|
-
if (id === formData[tabIndex][formData[tabIndex].selectedLanguages[idx]].tabKey) {
|
|
1695
|
-
validId = false;
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
if (validId) {
|
|
1699
|
-
break;
|
|
1700
|
-
}
|
|
1701
|
-
id = _.uniqueId();
|
|
1702
|
-
}
|
|
1703
|
-
baseTab.tabKey = id;
|
|
1704
|
-
formData[tabIndex].selectedLanguages.push(data.iso_code);
|
|
1705
|
-
formData[tabIndex][data.iso_code] = baseTab;
|
|
1706
|
-
|
|
1707
|
-
formData[tabIndex].activeTab = data.iso_code;
|
|
1708
|
-
formData[tabIndex].tabKey = baseTab.tabKey;
|
|
1709
|
-
break;
|
|
1710
|
-
case '':
|
|
1711
|
-
return;
|
|
1712
|
-
default:
|
|
1713
|
-
break;
|
|
1714
|
-
}
|
|
1715
|
-
const that = this;
|
|
1716
|
-
setTimeout(() => {
|
|
1717
|
-
that.setState({tabKey: baseTab.tabKey});
|
|
1718
|
-
}, 0);
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
if (!this.props.isNewVersionFlow) {
|
|
1722
|
-
formData[tabIndex][val.id] = data1;
|
|
1723
|
-
} else if (this.props.isNewVersionFlow && event !== "addLanguage" && event !== "onContentChange") {
|
|
1724
|
-
formData[tabIndex][this.props.baseLanguage][val.id] = data1;
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
if (formData[tabIndex].base) {
|
|
1728
|
-
if (!this.props.isNewVersionFlow) {
|
|
1729
|
-
formData.base[val.id] = data1;
|
|
1730
|
-
} else {
|
|
1731
|
-
formData.base[data1.iso_code] = formData[tabIndex][data1.iso_code];
|
|
1732
|
-
formData.base.tabKey = formData[tabIndex].tabKey;
|
|
1733
|
-
formData.base.activeTab = formData[tabIndex].activeTab;
|
|
1734
|
-
formData.base.selectedLanguages = formData[tabIndex].selectedLanguages;
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
} else {
|
|
1738
|
-
formData[val.id] = data;
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
if (this.props.isNewVersionFlow) {
|
|
1742
|
-
if (event === 'onSelect' && data === 'New Version') {
|
|
1743
|
-
this.callChildEvent(data, val, 'addVersion', event);
|
|
1744
|
-
} else if (event === 'onSelect' && data !== 'New Version') {
|
|
1745
|
-
currentTab = _.findIndex(this.state.formData['template-version-options'], { key: data}) + 1;
|
|
1746
|
-
this.setState({currentTab, tabKey: formData[`${currentTab - 1}`].tabKey}, () => {
|
|
1747
|
-
val.injectedEvents[event].call(this, this.state.formData['template-version-options'][currentTab - 1].key, formData, val);
|
|
1748
|
-
});
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1751
|
-
if (event === 'onContentChange') {
|
|
1752
|
-
|
|
1753
|
-
// formData[`${this.state.currentTab - 1}`][formData[`${this.state.currentTab - 1}`].activeTab]['template-content'] = data.editor.getData();
|
|
1754
|
-
// if (formData[`${this.state.currentTab - 1}`].tabKey === formData.base.tabKey) {
|
|
1755
|
-
// formData.base[formData[`${this.state.currentTab - 1}`].activeTab][`template-content`] = data.editor.getData();
|
|
1756
|
-
//}
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
this.setState({formData}, () => {
|
|
1762
|
-
this.validateForm();
|
|
1763
|
-
});
|
|
1764
|
-
if (event && val.injectedEvents[event]) {
|
|
1765
|
-
if (event === "onRowClick") {
|
|
1766
|
-
val.injectedEvents[event].call(this, data);
|
|
1767
|
-
} else if (this.props.isNewVersionFlow && event !== 'onSelect') {
|
|
1768
|
-
if (event === 'addLanguage') {
|
|
1769
|
-
val.injectedEvents[event].call(this, data, formData, val);
|
|
1770
|
-
this.setState({currentEventVal: {}, currentEvent: {}, currentEventData: {}});
|
|
1771
|
-
} else {
|
|
1772
|
-
val.injectedEvents[event].call(this, true, formData, val);
|
|
1773
|
-
}
|
|
1774
|
-
} else if (!this.props.isNewVersionFlow) {
|
|
1775
|
-
val.injectedEvents[event].call(this, true, formData, val);
|
|
1776
|
-
}
|
|
1777
|
-
} else if (val.injectedEvents && val.injectedEvents.onChange) {
|
|
1778
|
-
val.injectedEvents.onChange.call(this, true, formData, val);
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
if (!((event === 'onSelect' && data === 'New Version') || event === 'onContentChange')) {
|
|
1782
|
-
this.props.onChange(formData, this.state.tabCount, currentTab);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
hasClass(element, className) {
|
|
1788
|
-
return (` ${element.className} `).indexOf(` ${className} `) > -1;
|
|
1789
|
-
}
|
|
1790
|
-
allowAddSecondaryCta = (val) => {
|
|
1791
|
-
if (val.fieldsCount > 0) {
|
|
1792
|
-
const errorData = _.cloneDeep(this.state.errorData);
|
|
1793
|
-
_.forEach(Object.keys(errorData), (key) => {
|
|
1794
|
-
if (typeof errorData[key] !== "object") {
|
|
1795
|
-
errorData[key] = false;
|
|
1796
|
-
} else {
|
|
1797
|
-
_.forEach(Object.keys(errorData[key]), (innerKey) => {
|
|
1798
|
-
errorData[key][innerKey] = false;
|
|
1799
|
-
});
|
|
1800
|
-
}
|
|
1801
|
-
});
|
|
1802
|
-
if (this.state.formData[this.state.currentTab - 1][`secondary-cta-${val.fieldsCount - 1}-label`] === "") {
|
|
1803
|
-
errorData[this.state.currentTab - 1][`secondary-cta-${val.fieldsCount - 1}-label`] = true;
|
|
1804
|
-
this.setState({errorData, checkValidation: true, isFormValid: false});
|
|
1805
|
-
return false;
|
|
1806
|
-
}
|
|
1807
|
-
if (this.state.formData[this.state.currentTab - 1][`cta-deeplink-secondary-cta-${val.fieldsCount - 1}`] === "") {
|
|
1808
|
-
errorData[this.state.currentTab - 1][`cta-deeplink-secondary-cta-${val.fieldsCount - 1}`] = true;
|
|
1809
|
-
this.setState({errorData, checkValidation: true, isFormValid: false});
|
|
1810
|
-
return false;
|
|
1811
|
-
}
|
|
1812
|
-
if (this.state.formData[this.state.currentTab - 1][`cta-deeplink-secondary-cta-${val.fieldsCount - 1}-select`] === "") {
|
|
1813
|
-
errorData[this.state.currentTab - 1][`cta-deeplink-secondary-cta--${val.fieldsCount - 1}-select`] = true;
|
|
1814
|
-
this.setState({errorData, checkValidation: true, isFormValid: false});
|
|
1815
|
-
return false;
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
return true;
|
|
1819
|
-
};
|
|
1820
|
-
callChildEvent(data, val, event) {
|
|
1821
|
-
if (!event) {
|
|
1822
|
-
return;
|
|
1823
|
-
}
|
|
1824
|
-
const tab = this.state.tabCount;
|
|
1825
|
-
// const parent = this._reactInternalInstance._currentElement._owner._instance;
|
|
1826
|
-
if (event === 'onTabChange') {
|
|
1827
|
-
const that = this;
|
|
1828
|
-
this.setState({tabKey: `${data}`});
|
|
1829
|
-
setTimeout(() => {
|
|
1830
|
-
if (this.props.isNewVersionFlow) {
|
|
1831
|
-
const formData = _.cloneDeep(this.state.formData);
|
|
1832
|
-
let activeTabIndex = '1';
|
|
1833
|
-
const elems = document.getElementsByClassName("ant-tabs-tab");
|
|
1834
|
-
|
|
1835
|
-
for (let i = 0; i < elems.length; i += 1) {
|
|
1836
|
-
if (elems.item(i).classList.contains("ant-tabs-tab-active")) {
|
|
1837
|
-
activeTabIndex = i + 1;
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
|
|
1841
|
-
formData[(this.state.currentTab - 1)].activeTab = formData[(this.state.currentTab - 1)].selectedLanguages[activeTabIndex - 1];
|
|
1842
|
-
formData[(this.state.currentTab - 1)].tabKey = `${data}`;
|
|
1843
|
-
if (formData[(this.state.currentTab - 1)].base) {
|
|
1844
|
-
formData.base.activeTab = formData[(this.state.currentTab - 1)].selectedLanguages[activeTabIndex - 1];
|
|
1845
|
-
formData.base.tabKey = `${data}`;
|
|
1846
|
-
}
|
|
1847
|
-
|
|
1848
|
-
const formDataActiveKey = formData[(this.state.currentTab - 1)][formData[(this.state.currentTab - 1)].activeTab];
|
|
1849
|
-
const formDataTabKey = formDataActiveKey && formDataActiveKey.tabKey;
|
|
1850
|
-
that.setState({formData, currentLangTab: formData[(this.state.currentTab - 1)].activeTab, tabKey: formDataTabKey}, () => {
|
|
1851
|
-
val.injectedEvents[event].call(that.props.parent, this.state.currentTab, formData);
|
|
1852
|
-
});
|
|
1853
|
-
} else {
|
|
1854
|
-
let activeTabIndex = '1';
|
|
1855
|
-
const elems = document.getElementsByClassName("ant-tabs-tab");
|
|
1856
|
-
|
|
1857
|
-
for (let i = 0; i < elems.length; i += 1) {
|
|
1858
|
-
if (elems.item(i).classList.contains("ant-tabs-tab-active")) {
|
|
1859
|
-
activeTabIndex = i + 1;
|
|
1860
|
-
}
|
|
1861
|
-
}
|
|
1862
|
-
|
|
1863
|
-
that.setState({currentTab: activeTabIndex});
|
|
1864
|
-
val.injectedEvents[event].call(that.props.parent, activeTabIndex);
|
|
1865
|
-
}
|
|
1866
|
-
}, 0);
|
|
1867
|
-
return;
|
|
1868
|
-
} else if (event === 'addVersion') {
|
|
1869
|
-
this.cloneVersionData();
|
|
1870
|
-
this.setState({ popoverVisible: false });
|
|
1871
|
-
const that = this;
|
|
1872
|
-
setTimeout(() => {
|
|
1873
|
-
val.injectedEvents[event].call(that.props.parent, tab);
|
|
1874
|
-
}, 0);
|
|
1875
|
-
return;
|
|
1876
|
-
} else if (event === 'onTagSelect') {
|
|
1877
|
-
val.injectedEvents[event].call(this.props.parent, data, this.state.currentTab, val);
|
|
1878
|
-
return;
|
|
1879
|
-
} else if (event === 'markFinalVersion' || event === 'duplicateVersion' || event === 'deleteVersion' || event === 'renameVersion') {
|
|
1880
|
-
this.setState({ popoverVisible: false });
|
|
1881
|
-
if ((event !== 'deleteVersion' && !this.props.isNewVersionFlow) || ((event === 'deleteVersion') && this.props.schema.channel.toUpperCase() === 'EMAIL')) {
|
|
1882
|
-
val.injectedEvents[event].call(this.props.parent, data, this.state.currentTab);
|
|
1883
|
-
} else {
|
|
1884
|
-
this.setState({currentEvent: val.injectedEvents[event], currentEventData: data});
|
|
1885
|
-
}
|
|
1886
|
-
if (event === 'markFinalVersion') {
|
|
1887
|
-
this.markFinalTabVersion();
|
|
1888
|
-
if (this.props.isNewVersionFlow) {
|
|
1889
|
-
val.injectedEvents[event].call(this.props.parent, data, this.state.currentTab);
|
|
1890
|
-
}
|
|
1891
|
-
} else if (event === 'duplicateVersion') {
|
|
1892
|
-
if (this.props.schema.channel.toUpperCase() === 'EMAIL') {
|
|
1893
|
-
const formData = _.cloneDeep(this.state.formData);
|
|
1894
|
-
formData[this.state.tabCount] = _.cloneDeep(formData[`${this.state.currentTab - 1}`]);
|
|
1895
|
-
_.forEach(formData[this.state.tabCount].selectedLanguages, (lang) => {
|
|
1896
|
-
const tmptabData = formData[this.state.tabCount][lang];
|
|
1897
|
-
_.forEach(formData[this.state.tabCount][lang], (tabData, index) => {
|
|
1898
|
-
if (index === 'tabKey') {
|
|
1899
|
-
tmptabData.tabKey = _.uniqueId();
|
|
1900
|
-
}
|
|
1901
|
-
});
|
|
1902
|
-
});
|
|
1903
|
-
formData[this.state.tabCount].tabKey = formData[this.state.tabCount][formData[this.state.tabCount].activeTab].tabKey;
|
|
1904
|
-
|
|
1905
|
-
this.setState({formData, tabKey: formData[this.state.tabCount].tabKey}, () => {
|
|
1906
|
-
val.injectedEvents[event].call(this.props.parent, formData, this.state.currentTab);
|
|
1907
|
-
});
|
|
1908
|
-
} else {
|
|
1909
|
-
this.duplicateVersion();
|
|
1910
|
-
}
|
|
1911
|
-
} else if (event === 'deleteVersion') {
|
|
1912
|
-
if (this.props.schema.channel.toUpperCase() === 'EMAIL') {
|
|
1913
|
-
// this.deleteVersion(false, this.state.currentTab);
|
|
1914
|
-
this.setState({currentEvent: val.injectedEvents[event], currentEventData: data }, () => {
|
|
1915
|
-
this.props.setModalContent('delete-version');
|
|
1916
|
-
});
|
|
1917
|
-
} else {
|
|
1918
|
-
this.handleConfirmations();
|
|
1919
|
-
}
|
|
1920
|
-
} else if (event === 'renameVersion') {
|
|
1921
|
-
this.renameVersion(this.state.currentTab);
|
|
1922
|
-
}
|
|
1923
|
-
return;
|
|
1924
|
-
} else if (event === 'discardValues') {
|
|
1925
|
-
val.injectedEvents[event].call(this.props.parent, data);
|
|
1926
|
-
if (this.props.isEdit) {
|
|
1927
|
-
this.resetState(true, this.state.usingTabContainer);
|
|
1928
|
-
} else {
|
|
1929
|
-
this.resetState(false, this.state.usingTabContainer);
|
|
1930
|
-
}
|
|
1931
|
-
return;
|
|
1932
|
-
} else if (event === 'onChange') {
|
|
1933
|
-
if (val.id === 'tab-header') {
|
|
1934
|
-
val.injectedEvents[event].call(this.props.parent, data, this.state.currentTab);
|
|
1935
|
-
this.changeVersionName(data);
|
|
1936
|
-
}
|
|
1937
|
-
return;
|
|
1938
|
-
} else if (event === "addSecondaryCta") {
|
|
1939
|
-
if (!this.allowAddSecondaryCta(val)) {
|
|
1940
|
-
return;
|
|
1941
|
-
}
|
|
1942
|
-
} else if (event === "onContentChange") {
|
|
1943
|
-
val.injectedEvents[event].call(this.props.parent, data, val.id);
|
|
1944
|
-
return;
|
|
1945
|
-
} else if (event === 'deleteLanguage') {
|
|
1946
|
-
this.setState({currentEvent: val.injectedEvents[event], currentEventData: data }, () => {
|
|
1947
|
-
this.props.setModalContent('delete-language');
|
|
1948
|
-
});
|
|
1949
|
-
// const modalContent = {
|
|
1950
|
-
// title: "Alert",
|
|
1951
|
-
// body: "Do you really want to delete this language?",
|
|
1952
|
-
// type: 'confirm',
|
|
1953
|
-
// id: 'email-language-delete-modal',
|
|
1954
|
-
// };
|
|
1955
|
-
// debugger;
|
|
1956
|
-
// if (this.state.formData[`${this.state.currentTab - 1}`].activeTab === this.props.baseLanguage) {
|
|
1957
|
-
//
|
|
1958
|
-
// } else {
|
|
1959
|
-
// const formData = _.cloneDeep(this.state.formData);
|
|
1960
|
-
// const currentTab = `${this.state.currentTab - 1}`;
|
|
1961
|
-
// const currentLang = formData[`${this.state.currentTab - 1}`].activeTab;
|
|
1962
|
-
// const deleteLanguageIndex = formData[currentTab].selectedLanguages.indexOf(currentLang);
|
|
1963
|
-
//
|
|
1964
|
-
// delete formData[currentTab][currentLang];
|
|
1965
|
-
// formData[currentTab].activeTab = this.props.baseLanguage;
|
|
1966
|
-
// formData[currentTab].selectedLanguages.splice(deleteLanguageIndex, 1);
|
|
1967
|
-
//
|
|
1968
|
-
// this.setState({formData, currentLangTab: this.props.baseLanguage}, () => {
|
|
1969
|
-
// val.injectedEvents[event].call(this.props.parent, formData, deleteLanguageIndex);
|
|
1970
|
-
// });
|
|
1971
|
-
// }
|
|
1972
|
-
return;
|
|
1973
|
-
}
|
|
1974
|
-
|
|
1975
|
-
// val.injectedEvents[event].call(this.props.parent, data);
|
|
1976
|
-
val.injectedEvents[event].call(this.props.parent, data, val.id);
|
|
1977
|
-
}
|
|
1978
|
-
openFileDialog = (e, parentID) => {
|
|
1979
|
-
document.querySelector(`#${parentID} #fileName`).click();
|
|
1980
|
-
};
|
|
1981
|
-
handleOk = (ev) => {
|
|
1982
|
-
const id = ev.target.id;
|
|
1983
|
-
|
|
1984
|
-
this.setState({showModal: false});
|
|
1985
|
-
if (id === "android" && this.state.androidValid) {
|
|
1986
|
-
this.props.onSubmit(this.state.formData);
|
|
1987
|
-
} else if (id === "ios" && this.state.iosValid) {
|
|
1988
|
-
this.props.onSubmit(this.state.formData);
|
|
1989
|
-
} else if (id === "sms-version-modal") {
|
|
1990
|
-
this.state.currentEvent.call(this.props.parent, this.state.currentEventData, this.state.currentTab);
|
|
1991
|
-
this.setState({currentEvent: {}, currentEventData: {}});
|
|
1992
|
-
this.deleteVersion(false, this.state.currentTab);
|
|
1993
|
-
} else if (id === 'template-back-confirm-modal') {
|
|
1994
|
-
const type = this.props.location.query.type;
|
|
1995
|
-
const response = {
|
|
1996
|
-
action: 'moveToTemplates',
|
|
1997
|
-
value: 'ok',
|
|
1998
|
-
};
|
|
1999
|
-
this.props.iframeParent.postMessage(JSON.stringify(response), '*');
|
|
2000
|
-
const isLanguageSupport = this.props.location.query.isLanguageSupport || false;
|
|
2001
|
-
const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
|
|
2002
|
-
const module = this.props.location.query.module ? this.props.location.query.module : 'default';
|
|
2003
|
-
this.props.router.push({
|
|
2004
|
-
pathname: `/${(this.props.schema.channel || '').toLowerCase()}/`,
|
|
2005
|
-
search: createQueryString(type === 'embedded' ? {type: 'embedded', module, isLanguageSupport, isEdmSupport} : {module, isLanguageSupport, isEdmSupport})})
|
|
2006
|
-
} else if (id === "email-language-delete-modal") {
|
|
2007
|
-
this.deleteLanguage();
|
|
2008
|
-
this.props.handleCancelModal();
|
|
2009
|
-
// this.setState({currentEvent: {}, currentEventData: {}});
|
|
2010
|
-
} else if (id === 'email-version-delete-modal') {
|
|
2011
|
-
this.deleteVersion(false, this.state.currentTab);
|
|
2012
|
-
} else if ( id === 'template-delete-confirm-modal') {
|
|
2013
|
-
this.props.handleDelete(this.props.modal);
|
|
2014
|
-
}
|
|
2015
|
-
};
|
|
2016
|
-
handleCancel = (ev) => {
|
|
2017
|
-
const id = ev.target.id;
|
|
2018
|
-
this.setState({showModal: false});
|
|
2019
|
-
if (id === 'template-back-confirm-modal') {
|
|
2020
|
-
const response = {
|
|
2021
|
-
action: 'moveToTemplate',
|
|
2022
|
-
value: 'cancel',
|
|
2023
|
-
};
|
|
2024
|
-
this.props.iframeParent.postMessage(JSON.stringify(response), '*');
|
|
2025
|
-
}
|
|
2026
|
-
if (this.props.handleCancelModal) {
|
|
2027
|
-
this.props.handleCancelModal();
|
|
2028
|
-
}
|
|
2029
|
-
};
|
|
2030
|
-
handleConfirmations = () => {
|
|
2031
|
-
this.setState({showModal: true});
|
|
2032
|
-
};
|
|
2033
|
-
|
|
2034
|
-
handleSetRadioValue = (formData, currentTab, val) => {
|
|
2035
|
-
if (formData[currentTab - 1] && formData[currentTab - 1][val.id] && formData[currentTab - 1][val.id] !== "") {
|
|
2036
|
-
return formData[currentTab - 1][val.id];
|
|
2037
|
-
} else if (formData[val.id]) {
|
|
2038
|
-
return formData[val.id];
|
|
2039
|
-
}
|
|
2040
|
-
return val.value;
|
|
2041
|
-
}
|
|
2042
|
-
uploadImages = (e, {files}, val) => {
|
|
2043
|
-
e.preventDefault();
|
|
2044
|
-
const _URL = window.URL || window.webkitURL;
|
|
2045
|
-
const file = files[0];
|
|
2046
|
-
if (val.supportedExtensions) {
|
|
2047
|
-
const allowedExtensions = /(\.bmp|\.jpeg|\.png|\.gif|\.avif|\.jpg)$/i;
|
|
2048
|
-
if (!allowedExtensions.exec(file.name)) {
|
|
2049
|
-
this.callChildEvent({file, type: 'wrong file'}, val, val.submitAction);
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
const img = new Image();
|
|
2053
|
-
img.src = _URL.createObjectURL(file);
|
|
2054
|
-
img.onload = () => {
|
|
2055
|
-
const fileParams = {
|
|
2056
|
-
width: img.width,
|
|
2057
|
-
height: img.height,
|
|
2058
|
-
error: file.size / (1e+6) > 5,
|
|
2059
|
-
};
|
|
2060
|
-
this.callChildEvent({file, type: 'image', fileParams}, val, val.submitAction);
|
|
2061
|
-
};
|
|
2062
|
-
const event = e;
|
|
2063
|
-
event.target.value = null;
|
|
2064
|
-
};
|
|
2065
|
-
|
|
2066
|
-
findBaseTab = () => {
|
|
2067
|
-
const activeTabKey = this.state.formData && this.state.formData.base ? this.state.formData.base.tabKey : -1;
|
|
2068
|
-
const formData = _.cloneDeep(this.state.formData);
|
|
2069
|
-
let baseTab = 0;
|
|
2070
|
-
for (let i = 0; i < this.state.tabCount; i += 1) {
|
|
2071
|
-
if (formData[i] && formData[i].tabKey === activeTabKey) {
|
|
2072
|
-
baseTab = i;
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
|
|
2076
|
-
return baseTab;
|
|
2077
|
-
};
|
|
2078
|
-
|
|
2079
|
-
handleOnHoverItem = (isHovering, id) => {
|
|
2080
|
-
if (isHovering) {
|
|
2081
|
-
this.setState({hoveredItem: id});
|
|
2082
|
-
} else {
|
|
2083
|
-
this.setState({hoveredItem: ''});
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
|
|
2087
|
-
handleOnItemClick = (isClicked, id) => {
|
|
2088
|
-
this.setState({clickedItem: id});
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
|
-
populateTemplatesList(data) {
|
|
2092
|
-
if (!data) {
|
|
2093
|
-
return [];
|
|
2094
|
-
}
|
|
2095
|
-
const items = [];
|
|
2096
|
-
data.map( (template) => {
|
|
2097
|
-
//
|
|
2098
|
-
const temp = {};
|
|
2099
|
-
temp.id = template._id;
|
|
2100
|
-
if ((this.props.schema.channel || '').toLowerCase() === 'email') {
|
|
2101
|
-
//
|
|
2102
|
-
const imgSrc = template && template.versions && template.versions.base ? template.versions.base.preview_http_url : '';
|
|
2103
|
-
const content = <img src={imgSrc || ''} alt="" />;
|
|
2104
|
-
|
|
2105
|
-
temp.content = (
|
|
2106
|
-
<div
|
|
2107
|
-
className="sms-template-content">
|
|
2108
|
-
<div className={`sms-text ${this.state.clickedItem === template._id ? 'sms-text-blurred' : ''}`}>
|
|
2109
|
-
{content}
|
|
2110
|
-
</div>
|
|
2111
|
-
{/*template._id === this.state.clickedItem ? <CapButton onClick={(e) => this.handleEditClick(e, template._id)} className="edit-button" type="secondary">{type === 'embedded' ? this.props.intl.formatMessage(messages.selectButton) : this.props.intl.formatMessage(messages.editButton)}</CapButton> : ''*/}
|
|
2112
|
-
{/*template._id === this.state.clickedItem ? <CapButton onClick={() => this.handlePreviewClick(template)} className="preview-button" type="cancel">{this.props.intl.formatMessage(messages.previewButton)}</CapButton> : ''*/}
|
|
2113
|
-
</div>);
|
|
2114
|
-
}
|
|
2115
|
-
// temp.footer = (
|
|
2116
|
-
// <div className="footer-container">
|
|
2117
|
-
// <div className="card-title">
|
|
2118
|
-
// <span className="template-name" style={{ fontWeight: `${this.props.schema.channel.toLowerCase() === 'wechat' ? '400' : '600'}` }}>
|
|
2119
|
-
// { template && template.versions && template.versions.history && template.versions.history.length > 1 && this.props.schema.channel.toLowerCase() !== 'mobilepush' && <i style={{fontSize: '16px', margin: '0 8px 0 0', verticalAlign: 'middle'}} className="material-icons">filter_none</i>}
|
|
2120
|
-
// {template.name}
|
|
2121
|
-
// </span>
|
|
2122
|
-
// </div>
|
|
2123
|
-
// </div>
|
|
2124
|
-
// );
|
|
2125
|
-
items.push(temp);
|
|
2126
|
-
return true;
|
|
2127
|
-
});
|
|
2128
|
-
return items;
|
|
2129
|
-
}
|
|
2130
|
-
|
|
2131
|
-
handleAddLanguageFlow(data, val, event) {
|
|
2132
|
-
this.setState({currentEventData: data, currentEventVal: val, currentEvent: event, customPopoverVisible: false}, () => {
|
|
2133
|
-
this.props.setModalContent('add-language', data);
|
|
2134
|
-
});
|
|
2135
|
-
}
|
|
2136
|
-
|
|
2137
|
-
getMissingOrUnsupportedTagsName = (content = '', type) => {
|
|
2138
|
-
const { MISSING_TAGS, UNSUPPORTED_TAGS} = tagsTypes;
|
|
2139
|
-
const tagValidationResponse = this.validateTags(content);
|
|
2140
|
-
if (type && (type === MISSING_TAGS || type === UNSUPPORTED_TAGS)) {
|
|
2141
|
-
return tagValidationResponse[type].join(', ').toString();
|
|
2142
|
-
}
|
|
2143
|
-
return null;
|
|
2144
|
-
|
|
2145
|
-
};
|
|
2146
|
-
|
|
2147
|
-
renderTextAreaContent = (styling, columns, val, isVersionEnable, rows, cols, offset = 0) => {
|
|
2148
|
-
const { checkValidation, errorData, currentTab, formData } = this.state;
|
|
2149
|
-
const { MISSING_TAGS, UNSUPPORTED_TAGS } = tagsTypes;
|
|
2150
|
-
const errorType = (isVersionEnable ? errorData[`${currentTab - 1}`][val.id] : errorData[val.id]);
|
|
2151
|
-
const ifError = checkValidation && errorType;
|
|
2152
|
-
const messageContent = isVersionEnable ? formData[`${currentTab - 1}`][val.id] : formData[val.id];
|
|
2153
|
-
const { MISSING_TAG_ERROR, UNSUPPORTED_TAG_ERROR } = errorMessageForTags;
|
|
2154
|
-
let errorMessage = false;
|
|
2155
|
-
const { formatMessage } = this.props.intl;
|
|
2156
|
-
switch (errorType) {
|
|
2157
|
-
case MISSING_TAG_ERROR:
|
|
2158
|
-
errorMessage = formatMessage(messages.missingTagsValidationError, {missingTags: this.getMissingOrUnsupportedTagsName(messageContent, MISSING_TAGS)});
|
|
2159
|
-
break;
|
|
2160
|
-
case UNSUPPORTED_TAG_ERROR:
|
|
2161
|
-
errorMessage = formatMessage(messages.unsupportedTagsValidationError, {unsupportedTags: this.getMissingOrUnsupportedTagsName(messageContent, UNSUPPORTED_TAGS)});
|
|
2162
|
-
break;
|
|
2163
|
-
case true:
|
|
2164
|
-
errorMessage = formatMessage(messages.genericTagsValidationError);
|
|
2165
|
-
break;
|
|
2166
|
-
default:
|
|
2167
|
-
break;
|
|
2168
|
-
}
|
|
2169
|
-
if (styling === 'semantic') {
|
|
2170
|
-
columns.push(
|
|
2171
|
-
<Col key="input" span={val.width} offset={offset}>
|
|
2172
|
-
<CapTextArea
|
|
2173
|
-
id={val.id}
|
|
2174
|
-
className={`${ifError ? 'error' : ''}`}
|
|
2175
|
-
placeholder={val.placeholder ? val.placeholder : ''}
|
|
2176
|
-
errorMessage={errorMessage}
|
|
2177
|
-
autosize={val.autosize ? val.autosizeParams : false}
|
|
2178
|
-
onChange={(e) => this.updateFormData(e.target.value, val)}
|
|
2179
|
-
style={val.style ? val.style : {}}
|
|
2180
|
-
defaultValue={messageContent || ''}
|
|
2181
|
-
value={messageContent || ''}
|
|
2182
|
-
rows={rows}
|
|
2183
|
-
disabled={val.disabled}
|
|
2184
|
-
cols={cols}
|
|
2185
|
-
/>
|
|
2186
|
-
</Col>
|
|
2187
|
-
);
|
|
2188
|
-
}
|
|
2189
|
-
};
|
|
2190
|
-
|
|
2191
|
-
renderColLabelSection(section, childIndex) {
|
|
2192
|
-
// const schema = this.props.schema
|
|
2193
|
-
const fields = [];
|
|
2194
|
-
_.forEach(section.inputFields, (val) => {
|
|
2195
|
-
const row = [];
|
|
2196
|
-
const columns = [];
|
|
2197
|
-
const type = val.type;
|
|
2198
|
-
const styling = val.styling;
|
|
2199
|
-
if (!this.props.isNewVersionFlow && !val.standalone && !val.onlyDisplay && this.props.usingTabContainer && !this.state.formData[`${this.state.currentTab - 1}`]) {
|
|
2200
|
-
return true;
|
|
2201
|
-
}
|
|
2202
|
-
if (!val.onlyDisplay && !val.standalone && (!this.state.formData[`${this.state.currentTab - 1}`] || (!this.state.formData[`${this.state.currentTab - 1}`][val.id] && this.state.formData[`${this.state.currentTab - 1}`][val.id] === null))) {
|
|
2203
|
-
return true;
|
|
2204
|
-
}
|
|
2205
|
-
if (!val.onlyDisplay && !val.standalone && (!this.state.errorData[`${this.state.currentTab - 1}`] || (!this.state.errorData[`${this.state.currentTab - 1}`][val.id] && this.state.errorData[`${this.state.currentTab - 1}`][val.id] === null))) {
|
|
2206
|
-
return true;
|
|
2207
|
-
}
|
|
2208
|
-
//
|
|
2209
|
-
columns.push(
|
|
2210
|
-
<Col key="label" span={4}>
|
|
2211
|
-
<Label style={val.labelStyle ? val.labelStyle : {}}>{val.label}</Label>
|
|
2212
|
-
</Col>
|
|
2213
|
-
);
|
|
2214
|
-
let ifError = false;
|
|
2215
|
-
const isVersionEnable = (this.state.usingTabContainer && !val.standalone);
|
|
2216
|
-
if (val.primitive) {
|
|
2217
|
-
if (val.id === "mark-final-version-label") {
|
|
2218
|
-
const baseTab = this.findBaseTab();
|
|
2219
|
-
if ((baseTab + 1) === childIndex) {
|
|
2220
|
-
return true;
|
|
2221
|
-
}
|
|
2222
|
-
}
|
|
2223
|
-
columns.push(
|
|
2224
|
-
<Col key={val.id} span={val.width}>
|
|
2225
|
-
{this.renderPrimitiveElement(val, childIndex)}
|
|
2226
|
-
</Col>
|
|
2227
|
-
);
|
|
2228
|
-
return true;
|
|
2229
|
-
}
|
|
2230
|
-
let content = "";
|
|
2231
|
-
let charList = {};
|
|
2232
|
-
switch (type) {
|
|
2233
|
-
case "input":
|
|
2234
|
-
if (styling === 'semantic') {
|
|
2235
|
-
ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
|
|
2236
|
-
|
|
2237
|
-
columns.push(
|
|
2238
|
-
<Col key={val.id} span={val.width}>
|
|
2239
|
-
<CapInput
|
|
2240
|
-
id={val.id}
|
|
2241
|
-
errorMessage={val.errorMessage ? val.errorMessage : ''}
|
|
2242
|
-
className={`input-primary chart-name-input${ifError ? ' error' : ''}`}
|
|
2243
|
-
// fluid={val.fluid}
|
|
2244
|
-
style={val?.style ? {
|
|
2245
|
-
...val?.style,
|
|
2246
|
-
display: ((this.props?.location?.query?.module).toLowerCase() === 'dvs') ? 'block' : val?.style?.display
|
|
2247
|
-
} : {}}
|
|
2248
|
-
placeholder={val.placeholder}
|
|
2249
|
-
onChange={(e) => this.updateFormData(e.target.value, val)}
|
|
2250
|
-
defaultValue={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
|
|
2251
|
-
value={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
|
|
2252
|
-
disabled={val.disabled}
|
|
2253
|
-
/>
|
|
2254
|
-
</Col>
|
|
2255
|
-
);
|
|
2256
|
-
}
|
|
2257
|
-
break;
|
|
2258
|
-
case "SmsEditor":
|
|
2259
|
-
columns.push(
|
|
2260
|
-
<Col span={5} key="input">
|
|
2261
|
-
<SmsEditor
|
|
2262
|
-
id={val.id}
|
|
2263
|
-
content={this.state.formData[val.id]}
|
|
2264
|
-
onDataChange={(data) => this.updateFormData(data.value, val)}
|
|
2265
|
-
/>
|
|
2266
|
-
</Col>
|
|
2267
|
-
);
|
|
2268
|
-
break;
|
|
2269
|
-
case "textarea":
|
|
2270
|
-
const rows = 20;
|
|
2271
|
-
const cols = 20;
|
|
2272
|
-
this.renderTextAreaContent(styling, columns, val, isVersionEnable, rows, cols);
|
|
2273
|
-
break;
|
|
2274
|
-
case "contentPreview":
|
|
2275
|
-
content = isVersionEnable ? this.state.formData[this.state.currentTab - 1]['sms-editor'] : this.state.formData['sms-editor'];
|
|
2276
|
-
charList = updateCharCount(content).char_list;
|
|
2277
|
-
columns.push(<CapColumn id={val.id} className={"preview-chars"} span={val.width}>
|
|
2278
|
-
{charList.map((char) => char)}
|
|
2279
|
-
</CapColumn>);
|
|
2280
|
-
break;
|
|
2281
|
-
case "checkbox":
|
|
2282
|
-
ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
|
|
2283
|
-
if (styling === 'semantic') {
|
|
2284
|
-
columns.push(
|
|
2285
|
-
<Col key="input" span={val.width} offset={val.offset}>
|
|
2286
|
-
<CapCheckbox
|
|
2287
|
-
className={`${ifError ? 'error' : ''}`}
|
|
2288
|
-
errorMessage={val.errorMessage ? val.errorMessage : ''}
|
|
2289
|
-
style={val.style ? val.style : {}}
|
|
2290
|
-
onChange={(e) => this.updateFormData(e, val)}
|
|
2291
|
-
checked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
|
|
2292
|
-
defaultChecked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
|
|
2293
|
-
disabled={val.disabled}
|
|
2294
|
-
/>
|
|
2295
|
-
</Col>
|
|
2296
|
-
);
|
|
2297
|
-
}
|
|
2298
|
-
break;
|
|
2299
|
-
case "tag-list":
|
|
2300
|
-
columns.push(
|
|
2301
|
-
<Col key={`input-${val.id}`} span={10} offset={val.offset}>
|
|
2302
|
-
<TagList
|
|
2303
|
-
key={`input-${val.id}`}
|
|
2304
|
-
moduleFilterEnabled={this.props.location && this.props.location.query && this.props.location.query.type !== 'embedded'}
|
|
2305
|
-
label={val.label ? val.label : ''}
|
|
2306
|
-
onTagSelect={(data) => this.callChildEvent(data, val, 'onTagSelect')}
|
|
2307
|
-
onContextChange={this.props.onContextChange}
|
|
2308
|
-
location={this.props.location}
|
|
2309
|
-
tags={this.props.tags ? this.props.tags : []}
|
|
2310
|
-
injectedTags={this.props.injectedTags ? this.props.injectedTags : {}}
|
|
2311
|
-
className={val.className ? val.className : ''}
|
|
2312
|
-
id={val.id}
|
|
2313
|
-
userLocale={this.props.userLocale}
|
|
2314
|
-
/>
|
|
2315
|
-
</Col>
|
|
2316
|
-
);
|
|
2317
|
-
break;
|
|
2318
|
-
case "tabs":
|
|
2319
|
-
columns.push(
|
|
2320
|
-
<Col key="input" span={10}>
|
|
2321
|
-
<TagList
|
|
2322
|
-
onTagSelect={(data) => this.callChildEvent(data, val, 'onTagSelect')}
|
|
2323
|
-
/>
|
|
2324
|
-
</Col>
|
|
2325
|
-
);
|
|
2326
|
-
break;
|
|
2327
|
-
case "sms-preview": {
|
|
2328
|
-
if (this.state.usingTabContainer && !this.state.formData[`${this.state.currentTab - 1}`]) {
|
|
2329
|
-
return true;
|
|
2330
|
-
}
|
|
2331
|
-
content = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][`sms-editor${this.state.currentTab > 1 ? this.state.currentTab : ''}`] : this.state.formData[val.id];
|
|
2332
|
-
const unicodeEnabled = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][`unicode-validity${this.state.currentTab > 1 ? this.state.currentTab : ''}`] : this.state.formData['unicode-validity'];
|
|
2333
|
-
columns.push(
|
|
2334
|
-
<Col key="input" span={10}>
|
|
2335
|
-
<TemplatePreview
|
|
2336
|
-
channel={val.channel ? val.channel : 'SMS'}
|
|
2337
|
-
content={content}
|
|
2338
|
-
charCounterEnabled={val.charCounterEnabled}
|
|
2339
|
-
unicodeEnabled={unicodeEnabled}
|
|
2340
|
-
>
|
|
2341
|
-
</TemplatePreview>
|
|
2342
|
-
</Col>
|
|
2343
|
-
);
|
|
2344
|
-
break;
|
|
2345
|
-
}
|
|
2346
|
-
case "popover":
|
|
2347
|
-
columns.push(
|
|
2348
|
-
<CapPopover
|
|
2349
|
-
trigger={val.trigger}
|
|
2350
|
-
placement={val.placement}
|
|
2351
|
-
visible={this.state.popoverVisible && (this.props.isNewVersionFlow || this.state.currentTab === childIndex || !childIndex)}
|
|
2352
|
-
onVisibleChange={this.handleVisibleChange}
|
|
2353
|
-
content={
|
|
2354
|
-
_.forEach(val.content.sections, (contentSection) => {
|
|
2355
|
-
this.renderSection(contentSection);
|
|
2356
|
-
})
|
|
2357
|
-
}
|
|
2358
|
-
>
|
|
2359
|
-
{
|
|
2360
|
-
_.forEach(val.value.sections, (popoverSection) => {
|
|
2361
|
-
this.renderSection(popoverSection);
|
|
2362
|
-
})
|
|
2363
|
-
}
|
|
2364
|
-
</CapPopover>
|
|
2365
|
-
);
|
|
2366
|
-
break;
|
|
2367
|
-
case "select": {
|
|
2368
|
-
const options = (this.state.formData[`${val.id}-options`]) ? (this.state.formData[`${val.id}-options`]) : val.options;
|
|
2369
|
-
columns.push(
|
|
2370
|
-
<Col style={val.colStyle ? val.colStyle : {}} span={val.width}>
|
|
2371
|
-
<CapSelect
|
|
2372
|
-
id={val.id}
|
|
2373
|
-
placeholder={val.placeholder ? val.placeholder : ''}
|
|
2374
|
-
options={options}
|
|
2375
|
-
style={val.style ? val.style : {}}
|
|
2376
|
-
onSelect={(data) => this.updateFormData(data, val, 'onSelect')}
|
|
2377
|
-
value={(this.state.formData[val.id] && this.state.formData[val.id] !== '' ? this.state.formData[val.id] : undefined)}
|
|
2378
|
-
disabled={val.disabled}
|
|
2379
|
-
/>
|
|
2380
|
-
</Col>
|
|
2381
|
-
);
|
|
2382
|
-
}
|
|
2383
|
-
break;
|
|
2384
|
-
case "ckeditor":
|
|
2385
|
-
|
|
2386
|
-
columns.push(
|
|
2387
|
-
<Col style={val.colStyle ? val.colStyle : {}} span={val.width}>
|
|
2388
|
-
<CKEditor
|
|
2389
|
-
id={val.id}
|
|
2390
|
-
content={(this.state.formData[`${this.state.currentTab - 1}`][val.id] ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : '')}
|
|
2391
|
-
events={val.events}
|
|
2392
|
-
getEditorInstanse={val.getEditorInstanse}
|
|
2393
|
-
// this.callChildEvent(data, val, 'addVersion', event);
|
|
2394
|
-
handleContentChange={(event) => this.callChildEvent(event, val, 'onContentChange')}
|
|
2395
|
-
/>
|
|
2396
|
-
</Col>
|
|
2397
|
-
);
|
|
2398
|
-
break;
|
|
2399
|
-
case "edmeditor": {
|
|
2400
|
-
// if (!this.state.formData[`${this.state.currentTab - 1}`]) {
|
|
2401
|
-
// return true;
|
|
2402
|
-
// }
|
|
2403
|
-
let langTab = 1;
|
|
2404
|
-
if (val.id.match(/edmeditor/g)) {
|
|
2405
|
-
if (val.length > 9 && val.id.charAt(9)) {
|
|
2406
|
-
langTab = val.id.charAt(9);
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
const edmSrc = this.state.formData[`${this.state.currentTab - 1}`][this.state.currentLangTab][`edmeditor${langTab > 1 ? langTab : ''}src`];
|
|
2410
|
-
|
|
2411
|
-
if (!edmSrc) {
|
|
2412
|
-
return false;
|
|
2413
|
-
}
|
|
2414
|
-
|
|
2415
|
-
columns.push(
|
|
2416
|
-
<Col style={val.colStyle ? val.colStyle : {}} span={val.width}>
|
|
2417
|
-
<EDMEditor
|
|
2418
|
-
id={val.id}
|
|
2419
|
-
getEditorInstanse={this.getEditorInstanse}
|
|
2420
|
-
edmSrc={edmSrc}
|
|
2421
|
-
/>
|
|
2422
|
-
</Col>
|
|
2423
|
-
);
|
|
2424
|
-
}
|
|
2425
|
-
break;
|
|
2426
|
-
default:
|
|
2427
|
-
break;
|
|
2428
|
-
}
|
|
2429
|
-
row.push(
|
|
2430
|
-
<Row>
|
|
2431
|
-
{
|
|
2432
|
-
_.forEach(columns, (value) => {
|
|
2433
|
-
if (value) {
|
|
2434
|
-
return value;
|
|
2435
|
-
}
|
|
2436
|
-
return value;
|
|
2437
|
-
})
|
|
2438
|
-
}
|
|
2439
|
-
</Row>
|
|
2440
|
-
);
|
|
2441
|
-
|
|
2442
|
-
fields.push(row);
|
|
2443
|
-
return true;
|
|
2444
|
-
});
|
|
2445
|
-
_.forEach(section.actionFields, (val) => {
|
|
2446
|
-
const row = [];
|
|
2447
|
-
const columns = [];
|
|
2448
|
-
const type = val.type;
|
|
2449
|
-
const styling = val.styling;
|
|
2450
|
-
switch (type) {
|
|
2451
|
-
case "button":
|
|
2452
|
-
if (styling === 'semantic' && val.metaType === 'submit-button') {
|
|
2453
|
-
columns.push(
|
|
2454
|
-
<Col>
|
|
2455
|
-
<CapButton
|
|
2456
|
-
onClick={(data) => val.id === 'save-button' ? this.saveForm() : this.callChildEvent(data, val, val.submitAction)}>
|
|
2457
|
-
{val.value}
|
|
2458
|
-
</CapButton>
|
|
2459
|
-
</Col>
|
|
2460
|
-
);
|
|
2461
|
-
}
|
|
2462
|
-
break;
|
|
2463
|
-
default:
|
|
2464
|
-
break;
|
|
2465
|
-
}
|
|
2466
|
-
row.push(columns);
|
|
2467
|
-
fields.push(row);
|
|
2468
|
-
});
|
|
2469
|
-
return fields;
|
|
2470
|
-
}
|
|
2471
|
-
|
|
2472
|
-
renderParentSection(section, childIndex) {
|
|
2473
|
-
const cols = [];
|
|
2474
|
-
section.childSections.map( (childSection) => {
|
|
2475
|
-
const renderedChildSection = this.renderSection(childSection, childIndex);
|
|
2476
|
-
cols.push(<Col style={childSection.colStyle ? childSection.colStyle : {}}offset={childSection.offset} span={childSection.width}>{renderedChildSection}</Col>);
|
|
2477
|
-
return true;
|
|
2478
|
-
});
|
|
2479
|
-
const row = (<Row style={section.rowStyle ? section.rowStyle : {}}>
|
|
2480
|
-
{
|
|
2481
|
-
_.forEach(cols, (value) => {
|
|
2482
|
-
if (value) {
|
|
2483
|
-
return value;
|
|
2484
|
-
}
|
|
2485
|
-
return value;
|
|
2486
|
-
})
|
|
2487
|
-
}
|
|
2488
|
-
</Row>);
|
|
2489
|
-
return row;
|
|
2490
|
-
}
|
|
2491
|
-
|
|
2492
|
-
renderSection(section, childIndex) {
|
|
2493
|
-
switch (section.type) {
|
|
2494
|
-
case "col-label":
|
|
2495
|
-
return this.renderColLabelSection(section, childIndex);
|
|
2496
|
-
case "multicols":
|
|
2497
|
-
return this.renderMultiColSection(section, childIndex);
|
|
2498
|
-
case "parent":
|
|
2499
|
-
return this.renderParentSection(section, childIndex);
|
|
2500
|
-
default:
|
|
2501
|
-
break;
|
|
2502
|
-
}
|
|
2503
|
-
return null;
|
|
2504
|
-
}
|
|
2505
|
-
|
|
2506
|
-
renderPrimitiveElement(val, childIndex) {
|
|
2507
|
-
const type = val.type;
|
|
2508
|
-
const tabName = this.state.formData[childIndex - 1] && this.state.formData[childIndex - 1].name ? this.state.formData[childIndex - 1].name : `${val.value} ${childIndex}`;
|
|
2509
|
-
let value = val.dynamicTab ? tabName : val.value;
|
|
2510
|
-
switch (type) {
|
|
2511
|
-
case "span":
|
|
2512
|
-
return <span id={`${val.id}${childIndex > 1 ? childIndex : ''}`}>{val.dynamicTab ? tabName : val.value}</span>;
|
|
2513
|
-
case "div":
|
|
2514
|
-
if (this.state.formData[`${this.state.currentTab - 1}`] && this.state.formData[`${this.state.currentTab - 1}`][val.id] && this.state.formData[`${this.state.currentTab - 1}`][val.id].trim() !== "") {
|
|
2515
|
-
value = this.state.formData[`${this.state.currentTab - 1}`][val.id];
|
|
2516
|
-
}
|
|
2517
|
-
return (<div
|
|
2518
|
-
className={val.className ? val.className : ''}
|
|
2519
|
-
id={`${val.id}${childIndex > 1 ? childIndex : ''}`}
|
|
2520
|
-
onClick={(data) => this.callChildEvent(data, val, val.submitAction)}
|
|
2521
|
-
style={val.style ? val.style : {}}
|
|
2522
|
-
onInput={(e) => { e.stopPropagation(); this.callChildEvent(e.target.textContent, val, 'onChange'); }}
|
|
2523
|
-
>{value}</div>);
|
|
2524
|
-
default:
|
|
2525
|
-
return '';
|
|
2526
|
-
}
|
|
2527
|
-
}
|
|
2528
|
-
|
|
2529
|
-
renderMultiColSection(section, childIndex) {
|
|
2530
|
-
const fields = [];
|
|
2531
|
-
let contentSections = [];
|
|
2532
|
-
let popoverSections = [];
|
|
2533
|
-
const self = this;
|
|
2534
|
-
_.forEach(section.inputFields, (field) => {
|
|
2535
|
-
const columns = [];
|
|
2536
|
-
_.forEach(field.cols, (val) => {
|
|
2537
|
-
const type = val.type;
|
|
2538
|
-
const styling = val.styling;
|
|
2539
|
-
const isVersionEnable = (this.state.usingTabContainer && !val.standalone);
|
|
2540
|
-
|
|
2541
|
-
if (!this.props.isNewVersionFlow && !val.standalone && !val.onlyDisplay && isVersionEnable && !this.state.formData[`${this.state.currentTab - 1}`]) {
|
|
2542
|
-
return true;
|
|
2543
|
-
}
|
|
2544
|
-
if (!val.standalone && !val.onlyDisplay &&
|
|
2545
|
-
(!this.state.formData[`${this.state.currentTab - 1}`] ||
|
|
2546
|
-
(!this.props.isNewVersionFlow && !this.state.formData[`${this.state.currentTab - 1}`] &&
|
|
2547
|
-
this.state.errorData[`${this.state.currentTab - 1}`][val.id] === null)) &&
|
|
2548
|
-
(this.props.isNewVersionFlow && !this.state.formData[`${this.state.currentTab - 1}`] &&
|
|
2549
|
-
this.state.errorData[`${this.state.currentTab - 1}`] && this.state.errorData[`${this.state.currentTab - 1}`][val.id] === null)) {
|
|
2550
|
-
return true;
|
|
2551
|
-
}
|
|
2552
|
-
if (!val.onlyDisplay && !val.standalone &&
|
|
2553
|
-
(!this.props.isNewVersionFlow && (!this.state.errorData[`${this.state.currentTab - 1}`] ||
|
|
2554
|
-
(!this.state.errorData[`${this.state.currentTab - 1}`] &&
|
|
2555
|
-
this.state.errorData[`${this.state.currentTab - 1}`][val.id] === null)))) {
|
|
2556
|
-
return true;
|
|
2557
|
-
}
|
|
2558
|
-
|
|
2559
|
-
let ifError = false;
|
|
2560
|
-
if (val.primitive) {
|
|
2561
|
-
if (val.id === "mark-final-version-label") {
|
|
2562
|
-
const baseTab = this.findBaseTab();
|
|
2563
|
-
if ((baseTab + 1) === childIndex) {
|
|
2564
|
-
return true;
|
|
2565
|
-
}
|
|
2566
|
-
}
|
|
2567
|
-
columns.push(
|
|
2568
|
-
<Col style={val.colStyle ? val.colStyle : {}} offset={val.offset} key={val.id} span={val.width}>
|
|
2569
|
-
{this.renderPrimitiveElement(val, childIndex)}
|
|
2570
|
-
</Col>
|
|
2571
|
-
);
|
|
2572
|
-
return true;
|
|
2573
|
-
}
|
|
2574
|
-
|
|
2575
|
-
switch (type) {
|
|
2576
|
-
case "input":
|
|
2577
|
-
ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
|
|
2578
|
-
|
|
2579
|
-
if (styling === 'semantic') {
|
|
2580
|
-
columns.push(
|
|
2581
|
-
<Col key={val.id} span={val.width}>
|
|
2582
|
-
<CapInput
|
|
2583
|
-
id={val.id}
|
|
2584
|
-
errorMessage={val.errorMessage ? val.errorMessage : ''}
|
|
2585
|
-
className={`input-primary chart-name-input${ifError ? ' error' : ''}`}
|
|
2586
|
-
// fluid={val.fluid}
|
|
2587
|
-
style={val?.style ? {
|
|
2588
|
-
...val?.style,
|
|
2589
|
-
display: ((this.props?.location?.query?.module).toLowerCase() === 'dvs') ? 'block' : val?.style?.display
|
|
2590
|
-
} : {}}
|
|
2591
|
-
placeholder={val.placeholder}
|
|
2592
|
-
onChange={(e) => this.updateFormData(e.target.value, val)}
|
|
2593
|
-
value={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
|
|
2594
|
-
defaultValue={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
|
|
2595
|
-
disabled={val.disabled}
|
|
2596
|
-
/>
|
|
2597
|
-
</Col>
|
|
2598
|
-
);
|
|
2599
|
-
}
|
|
2600
|
-
break;
|
|
2601
|
-
case "SmsEditor":
|
|
2602
|
-
columns.push(
|
|
2603
|
-
<Col span={5} key="input">
|
|
2604
|
-
<SmsEditor
|
|
2605
|
-
id={val.id}
|
|
2606
|
-
content={this.state.formData[val.id]}
|
|
2607
|
-
onDataChange={(data) => this.updateFormData(data.value, val)}
|
|
2608
|
-
/>
|
|
2609
|
-
</Col>
|
|
2610
|
-
);
|
|
2611
|
-
break;
|
|
2612
|
-
case "textarea":
|
|
2613
|
-
const rows = 10;
|
|
2614
|
-
const cols = 2;
|
|
2615
|
-
this.renderTextAreaContent(styling, columns, val, isVersionEnable, rows, cols, val.offset);
|
|
2616
|
-
break;
|
|
2617
|
-
case "checkbox":
|
|
2618
|
-
ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
|
|
2619
|
-
if (styling === 'semantic') {
|
|
2620
|
-
columns.push(
|
|
2621
|
-
<Col key="input" span={val.width} offset={val.offset}>
|
|
2622
|
-
<CapCheckbox
|
|
2623
|
-
className={`${ifError ? 'error' : ''}`}
|
|
2624
|
-
errorMessage={val.errorMessage ? val.errorMessage : ''}
|
|
2625
|
-
onChange={(e) => this.updateFormData(e.target.checked, val)}
|
|
2626
|
-
checked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
|
|
2627
|
-
defaultChecked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
|
|
2628
|
-
style={val.style ? val.style : {}}
|
|
2629
|
-
disabled={val.disabled}
|
|
2630
|
-
>
|
|
2631
|
-
{val.label}
|
|
2632
|
-
</CapCheckbox>
|
|
2633
|
-
</Col>
|
|
2634
|
-
);
|
|
2635
|
-
}
|
|
2636
|
-
break;
|
|
2637
|
-
case "radio":
|
|
2638
|
-
ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
|
|
2639
|
-
if (styling === 'semantic') {
|
|
2640
|
-
columns.push(
|
|
2641
|
-
<Col key={`input-${val.id}`} span={val.width} offset={val.offset}>
|
|
2642
|
-
<CapRadio
|
|
2643
|
-
className={`${ifError ? 'error' : ''}`}
|
|
2644
|
-
errorMessage={val.errorMessage ? val.errorMessage : ''}
|
|
2645
|
-
onChange={(e) => this.updateFormData(e.target.checked, val)}
|
|
2646
|
-
checked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
|
|
2647
|
-
defaultChecked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
|
|
2648
|
-
style={val.style ? val.style : {}}
|
|
2649
|
-
>
|
|
2650
|
-
{val.label}
|
|
2651
|
-
</CapRadio>
|
|
2652
|
-
</Col>
|
|
2653
|
-
);
|
|
2654
|
-
}
|
|
2655
|
-
break;
|
|
2656
|
-
case 'radioGroup':
|
|
2657
|
-
ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
|
|
2658
|
-
if (styling === 'semantic') {
|
|
2659
|
-
columns.push(
|
|
2660
|
-
<Col key={`input-${val.id}`} span={val.width} offset={val.offset}>
|
|
2661
|
-
<CapRadioGroup
|
|
2662
|
-
key={`${val.id}-radio-group`}
|
|
2663
|
-
className={`${ifError ? 'error' : ''}`}
|
|
2664
|
-
errorMessage={val.errorMessage ? val.errorMessage : ''}
|
|
2665
|
-
onChange={(e) => this.updateFormData(e.target.value, val)}
|
|
2666
|
-
style={val.style ? val.style : {}}
|
|
2667
|
-
value={this.handleSetRadioValue(this.state.formData, self.state.currentTab, val)}
|
|
2668
|
-
name={val.name ? val.name : `${val.id}-name`}
|
|
2669
|
-
options={val.options}
|
|
2670
|
-
disabled={val.disabled}
|
|
2671
|
-
>
|
|
2672
|
-
</CapRadioGroup>
|
|
2673
|
-
{/*{ifError ?*/}
|
|
2674
|
-
{/*<div className="error"> {val.errorMessage}</div>*/}
|
|
2675
|
-
{/*:*/}
|
|
2676
|
-
{/*""*/}
|
|
2677
|
-
{/*}*/}
|
|
2678
|
-
</Col>
|
|
2679
|
-
);
|
|
2680
|
-
}
|
|
2681
|
-
break;
|
|
2682
|
-
case 'image':
|
|
2683
|
-
ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
|
|
2684
|
-
columns.push(
|
|
2685
|
-
<Col key={`input-${val.id}${self.state.currentTab - 1}`} style={val.style} span={val.width} offset={val.offset}>
|
|
2686
|
-
<div>
|
|
2687
|
-
<div className={`image-container ${ifError ? 'error' : ''}`}>
|
|
2688
|
-
{self.state && !!self.state.formData[`${self.state.currentTab - 1}`].image ?
|
|
2689
|
-
<img src={self.state.formData[`${self.state.currentTab - 1}`].image} alt={val.alt} style={val.style}/>
|
|
2690
|
-
:
|
|
2691
|
-
<div style={{width: "100%", textAlign: "center"}}><span className="image-placeholder">{val.placeholder}</span></div>
|
|
2692
|
-
}
|
|
2693
|
-
</div>
|
|
2694
|
-
{ifError && <span className="error">{val.errorMessage}</span>}
|
|
2695
|
-
</div>
|
|
2696
|
-
</Col>
|
|
2697
|
-
);
|
|
2698
|
-
break;
|
|
2699
|
-
case 'upload':
|
|
2700
|
-
columns.push(
|
|
2701
|
-
<Col span={val.width} offset={val.offset} style={val.style}>
|
|
2702
|
-
<form encType="multipart/form-data" id={val.id}>
|
|
2703
|
-
<input key={val.id} style={{ display: 'none'}} id="fileName" type="file" onChange={(e) => this.uploadImages(e, {files: e.target.files}, val)} accept={val.supportedExtensions ? val.supportedExtensions : "image/*"} />
|
|
2704
|
-
<CapButton disabled={val.disabled ? val.disabled : false} type="secondary" onClick={(e) => this.openFileDialog(e, val.id)} style={{float: 'right'}}>
|
|
2705
|
-
{val.label}
|
|
2706
|
-
</CapButton>
|
|
2707
|
-
</form>
|
|
2708
|
-
</Col>
|
|
2709
|
-
);
|
|
2710
|
-
break;
|
|
2711
|
-
case "table":
|
|
2712
|
-
columns.push(
|
|
2713
|
-
<CapTable dataSource={self.props.iosCtasData} loading={self.props.iosCtasData ? !self.props.iosCtasData.length : true} onRowClick={(row) => this.updateFormData(row, val, "onRowClick" )} pagination={val.pagination}>
|
|
2714
|
-
{_.map(val.columns, (col) => <Column {...col}/>)}
|
|
2715
|
-
</CapTable>
|
|
2716
|
-
);
|
|
2717
|
-
break;
|
|
2718
|
-
case "tag-list":
|
|
2719
|
-
columns.push(
|
|
2720
|
-
<Col key={`input-${val.id}`} offset={val.offset} span={val.width ? val.width : ''} style={val.style ? val.style : {marginBottom: '16px'}}>
|
|
2721
|
-
<TagList
|
|
2722
|
-
key={`input-${val.id}`}
|
|
2723
|
-
moduleFilterEnabled={this.props.location && this.props.location.query && this.props.location.query.type !== 'embedded'}
|
|
2724
|
-
label={val.label ? val.label : ''}
|
|
2725
|
-
onTagSelect={(data) => this.callChildEvent(data, val, 'onTagSelect')}
|
|
2726
|
-
onContextChange={this.props.onContextChange}
|
|
2727
|
-
location={this.props.location}
|
|
2728
|
-
tags={this.props.tags ? this.props.tags : []}
|
|
2729
|
-
injectedTags={this.props.injectedTags ? this.props.injectedTags : {}}
|
|
2730
|
-
className={val.className ? val.className : ''}
|
|
2731
|
-
id={val.id}
|
|
2732
|
-
userLocale={this.props.userLocale}
|
|
2733
|
-
/>
|
|
2734
|
-
</Col>
|
|
2735
|
-
);
|
|
2736
|
-
break;
|
|
2737
|
-
case "button":
|
|
2738
|
-
if (styling === 'semantic' && val.metaType === 'submit-button') {
|
|
2739
|
-
columns.push(
|
|
2740
|
-
<Col style={val.colStyle ? val.colStyle : {}} span={val.width} offset={val.offset}>
|
|
2741
|
-
<CapButton
|
|
2742
|
-
type={val.buttonType}
|
|
2743
|
-
icon={val.icon}
|
|
2744
|
-
disabled={val.disabled ? val.disabled : false}
|
|
2745
|
-
onClick={(data) => val.id === 'save-button' ? this.saveForm() : this.callChildEvent(data, val, val.submitAction)}>
|
|
2746
|
-
{val.value}
|
|
2747
|
-
</CapButton>
|
|
2748
|
-
</Col>
|
|
2749
|
-
);
|
|
2750
|
-
}
|
|
2751
|
-
break;
|
|
2752
|
-
|
|
2753
|
-
case "sms-preview": {
|
|
2754
|
-
let content = "";
|
|
2755
|
-
if (this.state.usingTabContainer && !this.state.formData[`${this.state.currentTab - 1}`]) {
|
|
2756
|
-
return true;
|
|
2757
|
-
}
|
|
2758
|
-
content = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][`sms-editor${this.state.currentTab > 1 ? this.state.currentTab : ''}`] : this.state.formData[val.id];
|
|
2759
|
-
const unicodeEnabled = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][`unicode-validity${this.state.currentTab > 1 ? this.state.currentTab : ''}`] : this.state.formData['unicode-validity'];
|
|
2760
|
-
columns.push(
|
|
2761
|
-
<Col key="input" span={23} offset={1}>
|
|
2762
|
-
<TemplatePreview
|
|
2763
|
-
key={val.id}
|
|
2764
|
-
style={val.customStyling ? val.customStyling : {}}
|
|
2765
|
-
channel={val.channel ? val.channel : 'SMS'}
|
|
2766
|
-
content={content}
|
|
2767
|
-
charCounterEnabled={val.charCounterEnabled}
|
|
2768
|
-
unicodeEnabled={unicodeEnabled}
|
|
2769
|
-
>
|
|
2770
|
-
</TemplatePreview>
|
|
2771
|
-
</Col>
|
|
2772
|
-
);
|
|
2773
|
-
}
|
|
2774
|
-
break;
|
|
2775
|
-
case "line-preview": {
|
|
2776
|
-
const content = {
|
|
2777
|
-
bodyText: isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][`message-editor${this.state.currentTab > 1 ? this.state.currentTab : ''}`] : this.state.formData[val.id],
|
|
2778
|
-
bodyImage: this.state.formData[`${this.state.currentTab - 1}`].imagePreview,
|
|
2779
|
-
};
|
|
2780
|
-
if (!this.state.formData[`${this.state.currentTab - 1}`]) {
|
|
2781
|
-
return true;
|
|
2782
|
-
}
|
|
2783
|
-
|
|
2784
|
-
columns.push(
|
|
2785
|
-
<Col key="input" span={23} offset={1}>
|
|
2786
|
-
<TemplatePreview
|
|
2787
|
-
key={val.id}
|
|
2788
|
-
style={val.customStyling ? val.customStyling : {}}
|
|
2789
|
-
channel={val.channel}
|
|
2790
|
-
content={content}
|
|
2791
|
-
>
|
|
2792
|
-
</TemplatePreview>
|
|
2793
|
-
</Col>
|
|
2794
|
-
);
|
|
2795
|
-
}
|
|
2796
|
-
break;
|
|
2797
|
-
case "mobile-push-preview":
|
|
2798
|
-
if (!this.state.formData[`${this.state.currentTab - 1}`]) {
|
|
2799
|
-
return true;
|
|
2800
|
-
}
|
|
2801
|
-
columns.push(
|
|
2802
|
-
<Col key="input" span={23} offset={1}>
|
|
2803
|
-
<TemplatePreview
|
|
2804
|
-
key={val.id}
|
|
2805
|
-
device={val.device ? val.device : 'android'}
|
|
2806
|
-
style={val.customStyling ? val.customStyling : {}}
|
|
2807
|
-
channel={val.channel}
|
|
2808
|
-
content={{
|
|
2809
|
-
header: this.state.formData[`${this.state.currentTab - 1}`][val.content.title],
|
|
2810
|
-
bodyText: this.state.formData[`${this.state.currentTab - 1}`][val.content.message],
|
|
2811
|
-
bodyImage: this.state.formData[`${this.state.currentTab - 1}`].image,
|
|
2812
|
-
actions: [
|
|
2813
|
-
{label: this.state.formData[`${this.state.currentTab - 1}`][val.content.secondaryCta1]},
|
|
2814
|
-
{label: this.state.formData[`${this.state.currentTab - 1}`][val.content.secondaryCta2]},
|
|
2815
|
-
],
|
|
2816
|
-
appName: val.content.appName,
|
|
2817
|
-
}}
|
|
2818
|
-
>
|
|
2819
|
-
</TemplatePreview>
|
|
2820
|
-
</Col>
|
|
2821
|
-
);
|
|
2822
|
-
break;
|
|
2823
|
-
case "popover":
|
|
2824
|
-
contentSections = val.content.sections.map( (contentSection) => {
|
|
2825
|
-
const result = this.renderSection(contentSection, childIndex);
|
|
2826
|
-
return result;
|
|
2827
|
-
});
|
|
2828
|
-
popoverSections = val.value.sections.map( (popoverSection) => {
|
|
2829
|
-
const result = this.renderSection(popoverSection, childIndex);
|
|
2830
|
-
return result;
|
|
2831
|
-
});
|
|
2832
|
-
columns.push(
|
|
2833
|
-
<Col style={val.colStyle ? val.colStyle : {}} span={val.width} offset={val.offset}>
|
|
2834
|
-
<CapPopover
|
|
2835
|
-
trigger={val.trigger}
|
|
2836
|
-
placement={val.placement}
|
|
2837
|
-
visible={this.state.popoverVisible && (this.props.isNewVersionFlow || this.state.currentTab === childIndex || !childIndex)}
|
|
2838
|
-
onVisibleChange={this.handleVisibleChange}
|
|
2839
|
-
content={
|
|
2840
|
-
_.forEach(contentSections, (contentSection) => {
|
|
2841
|
-
if (contentSection) {
|
|
2842
|
-
return contentSection;
|
|
2843
|
-
}
|
|
2844
|
-
return contentSection;
|
|
2845
|
-
})
|
|
2846
|
-
}
|
|
2847
|
-
>
|
|
2848
|
-
{
|
|
2849
|
-
_.forEach(popoverSections, (popoverSection) => {
|
|
2850
|
-
if (popoverSection) {
|
|
2851
|
-
return popoverSection;
|
|
2852
|
-
}
|
|
2853
|
-
return popoverSection;
|
|
2854
|
-
})
|
|
2855
|
-
}
|
|
2856
|
-
</CapPopover>
|
|
2857
|
-
</Col>
|
|
2858
|
-
);
|
|
2859
|
-
break;
|
|
2860
|
-
|
|
2861
|
-
case "icon":
|
|
2862
|
-
if (val.id === "base-version-icon") {
|
|
2863
|
-
const baseTab = this.findBaseTab();
|
|
2864
|
-
if ((baseTab + 1) !== childIndex) {
|
|
2865
|
-
return true;
|
|
2866
|
-
}
|
|
2867
|
-
}
|
|
2868
|
-
columns.push(
|
|
2869
|
-
<Col
|
|
2870
|
-
key={`icon-${val.id}`}
|
|
2871
|
-
id={val.id}
|
|
2872
|
-
offset={val.offset}
|
|
2873
|
-
span={val.width ? val.width : 1}
|
|
2874
|
-
onClick={(data) => this.callChildEvent(data, val, val.submitAction)}
|
|
2875
|
-
className={val.className ? val.className : ''}
|
|
2876
|
-
style={val.colStyle ? val.colStyle : {}}
|
|
2877
|
-
>
|
|
2878
|
-
<i style={val.style ? val.style : {}} className="material-icons">{val.value ? val.value : ''}</i>
|
|
2879
|
-
</Col>
|
|
2880
|
-
);
|
|
2881
|
-
break;
|
|
2882
|
-
case "select": {
|
|
2883
|
-
ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
|
|
2884
|
-
const options = (this.state.formData[`${val.id}-options`]) ? (this.state.formData[`${val.id}-options`]) : val.options;
|
|
2885
|
-
columns.push(
|
|
2886
|
-
<Col style={val.colStyle ? val.colStyle : {}} span={val.width}>
|
|
2887
|
-
<CapSelect
|
|
2888
|
-
id={val.id}
|
|
2889
|
-
options={options}
|
|
2890
|
-
placeholder={val.placeholder ? val.placeholder : ''}
|
|
2891
|
-
style={val.style ? val.style : {}}
|
|
2892
|
-
onSelect={(data) => this.updateFormData(data, val, 'onSelect')}
|
|
2893
|
-
value={isVersionEnable ? this.state.formData[this.state.currentTab - 1][val.id] : this.state.formData[val.id]}
|
|
2894
|
-
disabled={val.disabled}
|
|
2895
|
-
/>
|
|
2896
|
-
{ifError && val.errorMessage &&
|
|
2897
|
-
<span className={'error'}>{val.errorMessage}</span>
|
|
2898
|
-
}
|
|
2899
|
-
</Col>
|
|
2900
|
-
);
|
|
2901
|
-
}
|
|
2902
|
-
break;
|
|
2903
|
-
case "ckeditor": {
|
|
2904
|
-
if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toLowerCase() === 'wechat' ) {
|
|
2905
|
-
const content = !_.isEmpty(this.state.formData) && this.state.formData['content-value'] ? this.state.formData['content-value'] : '';
|
|
2906
|
-
columns.push(
|
|
2907
|
-
<CKEditor
|
|
2908
|
-
id={val.id}
|
|
2909
|
-
content={content}
|
|
2910
|
-
events={val.events}
|
|
2911
|
-
getEditorInstanse={(evt, id) => val.injectedEvents.getEditorInstanse.call(this, evt, id)}
|
|
2912
|
-
handleContentChange={(event) => this.callChildEvent(event, val, 'onContentChange')}
|
|
2913
|
-
channel="wechat"
|
|
2914
|
-
onFocusOut={(event) => this.callChildEvent(event, val, 'onFocusOut')}
|
|
2915
|
-
onFocusIn={(event) => this.callChildEvent(event, val, 'onFocusIn')}
|
|
2916
|
-
/> );
|
|
2917
|
-
} else {
|
|
2918
|
-
if (_.isEmpty(this.state.formData[`${this.state.currentTab - 1}`])) {
|
|
2919
|
-
return true;
|
|
2920
|
-
}
|
|
2921
|
-
let langIndex = 0;
|
|
2922
|
-
if (val.id.indexOf('template-content') > -1 && val.id !== 'template-content') {
|
|
2923
|
-
langIndex = parseInt(val.id.replace('template-content', ''), 10) - 1;
|
|
2924
|
-
}
|
|
2925
|
-
|
|
2926
|
-
const currentLang = ((!_.isEmpty(this.state.formData) && !_.isEmpty(this.state.formData[`${this.state.currentTab - 1}`]) && !_.isEmpty(this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages) && this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages[langIndex]) ? this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages[langIndex] : this.props.baseLanguage) || 'en';
|
|
2927
|
-
const content = this.state?.formData?.[`${this.state.currentTab - 1}`]?.[currentLang]?.['template-content'] || "";
|
|
2928
|
-
|
|
2929
|
-
if (this.state.formData[`${this.state.currentTab - 1}`][currentLang].is_drag_drop) {
|
|
2930
|
-
// content = "";
|
|
2931
|
-
}
|
|
2932
|
-
columns.push(
|
|
2933
|
-
<Col style={val.colStyle ? val.colStyle : {}} span={val.width}>
|
|
2934
|
-
<CKEditor
|
|
2935
|
-
id={val.id}
|
|
2936
|
-
content={content}
|
|
2937
|
-
events={val.events}
|
|
2938
|
-
getEditorInstanse={(evt, id) => val.injectedEvents.getEditorInstanse.call(this, evt, id)}
|
|
2939
|
-
handleContentChange={(event) => this.callChildEvent(event, val, 'onContentChange')}
|
|
2940
|
-
/>
|
|
2941
|
-
</Col>
|
|
2942
|
-
);
|
|
2943
|
-
}
|
|
2944
|
-
}
|
|
2945
|
-
break;
|
|
2946
|
-
case "edmeditor": {
|
|
2947
|
-
// if (!this.state.formData[`${this.state.currentTab - 1}`]) {
|
|
2948
|
-
// return true;
|
|
2949
|
-
// }
|
|
2950
|
-
let langTab = 1;
|
|
2951
|
-
if (val.id.match(/edmeditor/g)) {
|
|
2952
|
-
if (val.id.length > 9 && val.id.charAt(9)) {
|
|
2953
|
-
langTab = val.id.charAt(9);
|
|
2954
|
-
}
|
|
2955
|
-
}
|
|
2956
|
-
const supportedLanguages = (this.state.formData[this.state.currentTab - 1] || {}).selectedLanguages;
|
|
2957
|
-
// let langIndex = 0;
|
|
2958
|
-
// if (val.id.indexOf('edmeditor') > -1 && val.id !== 'edmeditorsrc') {
|
|
2959
|
-
// const test = val.id.replace('src', '');
|
|
2960
|
-
// langIndex = parseInt(test.replace('edmeditor', ''), 10) - 1;
|
|
2961
|
-
// }
|
|
2962
|
-
// const currentLang = (!_.isEmpty(this.state.formData) && !_.isEmpty(this.state.formData[`${this.state.currentTab - 1}`]) && !_.isEmpty(this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages) && this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages[langIndex]) ? this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages[langIndex] : this.props.baseLanguage;
|
|
2963
|
-
const currentLang = supportedLanguages && supportedLanguages[langTab - 1];
|
|
2964
|
-
const edmSrc = this.state.formData[`${this.state.currentTab - 1}`][currentLang] && this.state.formData[`${this.state.currentTab - 1}`][currentLang][`edmeditor${this.state.currentTab > 1 ? this.state.currentTab : ''}src`];
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
if (!edmSrc) {
|
|
2968
|
-
return false;
|
|
2969
|
-
}
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
columns.push(
|
|
2973
|
-
<Col style={val.colStyle ? val.colStyle : {}} span={val.width}>
|
|
2974
|
-
<EDMEditor
|
|
2975
|
-
id={val.id}
|
|
2976
|
-
getEditorInstanse={this.getEditorInstanse}
|
|
2977
|
-
edmSrc={edmSrc}
|
|
2978
|
-
/>
|
|
2979
|
-
</Col>
|
|
2980
|
-
);
|
|
2981
|
-
}
|
|
2982
|
-
break;
|
|
2983
|
-
case "customPopover": {
|
|
2984
|
-
if (!this.state.formData[`${this.state.currentTab - 1}`]) {
|
|
2985
|
-
return true;
|
|
2986
|
-
}
|
|
2987
|
-
columns.push(
|
|
2988
|
-
<Col style={val.colStyle ? val.colStyle : {}} span={val.width}>
|
|
2989
|
-
<CustomPopOver
|
|
2990
|
-
id={val.id}
|
|
2991
|
-
popOverList={this.props.supportedLanguages}
|
|
2992
|
-
excludeList={this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages}
|
|
2993
|
-
handlePopOverClick={(data) => this.handleAddLanguageFlow(data, val, "addLanguage")}
|
|
2994
|
-
visible={this.state.customPopoverVisible}
|
|
2995
|
-
onVisibleChange={this.handleCustomPopoverVisibleChange}
|
|
2996
|
-
/>
|
|
2997
|
-
</Col>
|
|
2998
|
-
);
|
|
2999
|
-
}
|
|
3000
|
-
break;
|
|
3001
|
-
default:
|
|
3002
|
-
break;
|
|
3003
|
-
}
|
|
3004
|
-
return true;
|
|
3005
|
-
});
|
|
3006
|
-
const row = (
|
|
3007
|
-
<Row style={field.rowStyle ? field.rowStyle : {}} className={field.rowClassName ? field.rowClassName : ''}>
|
|
3008
|
-
{
|
|
3009
|
-
_.forEach(columns, (value) => {
|
|
3010
|
-
if (value) {
|
|
3011
|
-
return value;
|
|
3012
|
-
}
|
|
3013
|
-
return value;
|
|
3014
|
-
})
|
|
3015
|
-
}
|
|
3016
|
-
</Row>
|
|
3017
|
-
);
|
|
3018
|
-
fields.push(row);
|
|
3019
|
-
});
|
|
3020
|
-
|
|
3021
|
-
_.forEach(section.actionFields, (field) => {
|
|
3022
|
-
const columns = [];
|
|
3023
|
-
_.forEach(field.cols, (val) => {
|
|
3024
|
-
const type = val.type;
|
|
3025
|
-
const styling = val.styling;
|
|
3026
|
-
switch (type) {
|
|
3027
|
-
case "button":
|
|
3028
|
-
if (styling === 'semantic' && val.metaType === 'submit-button') {
|
|
3029
|
-
columns.push(
|
|
3030
|
-
<Col span={3}>
|
|
3031
|
-
<CapButton
|
|
3032
|
-
type={val.buttonType}
|
|
3033
|
-
icon={val.icon}
|
|
3034
|
-
disabled={val.disabled ? val.disabled : false}
|
|
3035
|
-
onClick={(data) => val.id === 'save-button' ? this.saveForm() : this.callChildEvent(data, val, val.submitAction)}>
|
|
3036
|
-
{val.value}
|
|
3037
|
-
</CapButton>
|
|
3038
|
-
</Col>
|
|
3039
|
-
);
|
|
3040
|
-
}
|
|
3041
|
-
break;
|
|
3042
|
-
default:
|
|
3043
|
-
break;
|
|
3044
|
-
}
|
|
3045
|
-
});
|
|
3046
|
-
const row = (
|
|
3047
|
-
<Row>
|
|
3048
|
-
{
|
|
3049
|
-
_.forEach(columns, (value) => {
|
|
3050
|
-
if (value) {
|
|
3051
|
-
return value;
|
|
3052
|
-
}
|
|
3053
|
-
return value;
|
|
3054
|
-
})
|
|
3055
|
-
}
|
|
3056
|
-
</Row>
|
|
3057
|
-
);
|
|
3058
|
-
fields.push(row);
|
|
3059
|
-
});
|
|
3060
|
-
return fields;
|
|
3061
|
-
}
|
|
3062
|
-
|
|
3063
|
-
renderContainer(container) {
|
|
3064
|
-
const containerType = container.type;
|
|
3065
|
-
const renderedPanes = [];
|
|
3066
|
-
let renderedSections = [];
|
|
3067
|
-
let renderedContentSections = [];
|
|
3068
|
-
let paneIndex = 1;
|
|
3069
|
-
let panes = [];
|
|
3070
|
-
let result = [];
|
|
3071
|
-
let extraActionSections = [];
|
|
3072
|
-
let activeTabKey;
|
|
3073
|
-
let paneTabKey;
|
|
3074
|
-
let stateTabKey = '';
|
|
3075
|
-
switch (containerType) {
|
|
3076
|
-
case "tabs":
|
|
3077
|
-
panes = container.panes;
|
|
3078
|
-
_.forEach(panes, (pane, index) => {
|
|
3079
|
-
renderedSections = pane.sections.map((section) => {
|
|
3080
|
-
result = this.renderSection(section, paneIndex);
|
|
3081
|
-
return result;
|
|
3082
|
-
});
|
|
3083
|
-
|
|
3084
|
-
const sectionHeadeers = pane.sectionsHeaders ? pane.sectionsHeaders : container.tabContent && container.tabContent.sections;
|
|
3085
|
-
renderedContentSections = sectionHeadeers.map( (tabContentSection) => {
|
|
3086
|
-
result = this.renderSection(tabContentSection, paneIndex);
|
|
3087
|
-
return result;
|
|
3088
|
-
});
|
|
3089
|
-
// let newTabKey = `${_.uniqueId()}`;
|
|
3090
|
-
if (!this.state.formData[this.state.currentTab - 1]) {
|
|
3091
|
-
return;
|
|
3092
|
-
}
|
|
3093
|
-
activeTabKey = this.state.formData.tabKey;
|
|
3094
|
-
if (this.props.isNewVersionFlow) {
|
|
3095
|
-
activeTabKey = this.state.tabKey;
|
|
3096
|
-
}
|
|
3097
|
-
paneTabKey = this.state.formData[paneIndex - 1] && this.state.formData[paneIndex - 1].tabKey;
|
|
3098
|
-
if (this.props.isNewVersionFlow) {
|
|
3099
|
-
const currentLang = this.state.formData[this.state.currentTab - 1].selectedLanguages[index];
|
|
3100
|
-
paneTabKey = this.state.formData[this.state.currentTab - 1] && this.state.formData[this.state.currentTab - 1][currentLang] && this.state.formData[this.state.currentTab - 1][currentLang].tabKey;
|
|
3101
|
-
}
|
|
3102
|
-
|
|
3103
|
-
renderedPanes.push(
|
|
3104
|
-
<TabPane
|
|
3105
|
-
forceRender
|
|
3106
|
-
tab={
|
|
3107
|
-
<div className="form-tab-header" onInput={(e) => e.stopPropagation()}>
|
|
3108
|
-
{
|
|
3109
|
-
_.forEach(renderedContentSections, (value) => {
|
|
3110
|
-
if (value) {
|
|
3111
|
-
return value;
|
|
3112
|
-
}
|
|
3113
|
-
return value;
|
|
3114
|
-
})
|
|
3115
|
-
}
|
|
3116
|
-
</div>
|
|
3117
|
-
}
|
|
3118
|
-
key={paneTabKey && paneTabKey !== '' ? `${paneTabKey}` : index}>
|
|
3119
|
-
{
|
|
3120
|
-
_.forEach(renderedSections, (value) => {
|
|
3121
|
-
if (value) {
|
|
3122
|
-
return value;
|
|
3123
|
-
}
|
|
3124
|
-
return value;
|
|
3125
|
-
})
|
|
3126
|
-
}
|
|
3127
|
-
</TabPane>);
|
|
3128
|
-
paneIndex += 1;
|
|
3129
|
-
});
|
|
3130
|
-
extraActionSections = container.tabBarExtraContent && container.tabBarExtraContent.sections ? container.tabBarExtraContent.sections.map((section) => {
|
|
3131
|
-
result = this.renderSection(section);
|
|
3132
|
-
return result;
|
|
3133
|
-
}) : {};
|
|
3134
|
-
stateTabKey = this.state.tabKey;
|
|
3135
|
-
if (stateTabKey && stateTabKey !== '') {
|
|
3136
|
-
activeTabKey = stateTabKey;
|
|
3137
|
-
}
|
|
3138
|
-
return (
|
|
3139
|
-
<Tabs
|
|
3140
|
-
className={`cap-tabs-${container.id}`}
|
|
3141
|
-
activeKey={activeTabKey && activeTabKey !== '' ? `${activeTabKey}` : '1'}
|
|
3142
|
-
defaultActiveKey={activeTabKey && activeTabKey !== '' ? `${activeTabKey}` : '1'}
|
|
3143
|
-
onChange={(data, e) => { this.callChildEvent(data, container, 'onTabChange', e); }}
|
|
3144
|
-
onEdit={(data, e) => this.onEdit(data, e)}
|
|
3145
|
-
style={{width: '100%'}}
|
|
3146
|
-
tabBarExtraContent={
|
|
3147
|
-
!_.isEmpty(extraActionSections) && _.forEach(extraActionSections, (value) => {
|
|
3148
|
-
if (value) {
|
|
3149
|
-
return value;
|
|
3150
|
-
}
|
|
3151
|
-
return value;
|
|
3152
|
-
})
|
|
3153
|
-
}>
|
|
3154
|
-
{
|
|
3155
|
-
_.forEach(renderedPanes, (value) => {
|
|
3156
|
-
if (value) {
|
|
3157
|
-
return value;
|
|
3158
|
-
}
|
|
3159
|
-
return value;
|
|
3160
|
-
})
|
|
3161
|
-
}
|
|
3162
|
-
</Tabs>
|
|
3163
|
-
);
|
|
3164
|
-
|
|
3165
|
-
default:
|
|
3166
|
-
break;
|
|
3167
|
-
}
|
|
3168
|
-
return null;
|
|
3169
|
-
}
|
|
3170
|
-
|
|
3171
|
-
renderForm() {
|
|
3172
|
-
const schema = this.props.schema;
|
|
3173
|
-
const allElements = [];
|
|
3174
|
-
let renderedStandAloneSections;
|
|
3175
|
-
let renderedContainers;
|
|
3176
|
-
if (schema.standalone) {
|
|
3177
|
-
const sections = schema.standalone.sections;
|
|
3178
|
-
renderedStandAloneSections = sections.map((section) => {
|
|
3179
|
-
const result = this.renderSection(section);
|
|
3180
|
-
return result;
|
|
3181
|
-
});
|
|
3182
|
-
allElements.push(renderedStandAloneSections);
|
|
3183
|
-
}
|
|
3184
|
-
if (schema.containers) {
|
|
3185
|
-
renderedContainers = schema.containers.map((container) => {
|
|
3186
|
-
if (container.isActive === undefined || (container.isActive)) {
|
|
3187
|
-
const result = this.renderContainer(container);
|
|
3188
|
-
return result;
|
|
3189
|
-
}
|
|
3190
|
-
return null;
|
|
3191
|
-
});
|
|
3192
|
-
|
|
3193
|
-
allElements.push(renderedContainers);
|
|
3194
|
-
}
|
|
3195
|
-
const modal = this.getModal();
|
|
3196
|
-
allElements.push(modal);
|
|
3197
|
-
return allElements;
|
|
3198
|
-
}
|
|
3199
|
-
|
|
3200
|
-
render() {
|
|
3201
|
-
const cmsTemplateSelectionContent = (
|
|
3202
|
-
<CardGrid
|
|
3203
|
-
className={""}
|
|
3204
|
-
listItem={this.populateTemplatesList(this.props.cmsTemplates)}
|
|
3205
|
-
// filterContent={filterContent}
|
|
3206
|
-
onHoverItem={this.handleOnHoverItem}
|
|
3207
|
-
onItemClick={this.props.handleEdmDefaultTemplateSelection}
|
|
3208
|
-
colNumber={2}
|
|
3209
|
-
>
|
|
3210
|
-
</CardGrid>
|
|
3211
|
-
);
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
return (
|
|
3215
|
-
<Row>
|
|
3216
|
-
{
|
|
3217
|
-
this.props.schema ? this.renderForm() : ''
|
|
3218
|
-
}
|
|
3219
|
-
<SlideBox
|
|
3220
|
-
header={(<h3>{this.props.intl.formatMessage(messages.layoutSelection)}</h3>)}
|
|
3221
|
-
width={60}
|
|
3222
|
-
content={cmsTemplateSelectionContent}
|
|
3223
|
-
show={this.props.showEdmEmailTemplates}
|
|
3224
|
-
handleClose={this.props.toggleEdmEmailTemplateSelection}
|
|
3225
|
-
loadingText={this.props.intl.formatMessage(messages.loadingEDMTemplates)}
|
|
3226
|
-
isLoading={this.props.getCmsTemplatesInProgress}
|
|
3227
|
-
/>
|
|
3228
|
-
</Row>
|
|
3229
|
-
);
|
|
3230
|
-
}
|
|
3231
|
-
}
|
|
3232
|
-
|
|
3233
|
-
FormBuilder.defaultProps = {
|
|
3234
|
-
isNewVersionFlow: false,
|
|
3235
|
-
userLocale: localStorage.getItem('jlocale') || 'en',
|
|
3236
|
-
};
|
|
3237
|
-
|
|
3238
|
-
FormBuilder.propTypes = {
|
|
3239
|
-
schema: PropTypes.object.isRequired,
|
|
3240
|
-
onSubmit: PropTypes.func,
|
|
3241
|
-
formData: PropTypes.object,
|
|
3242
|
-
onChange: PropTypes.func,
|
|
3243
|
-
isEdit: PropTypes.bool,
|
|
3244
|
-
usingTabContainer: PropTypes.bool,
|
|
3245
|
-
parent: PropTypes.object,
|
|
3246
|
-
iframeParent: PropTypes.object,
|
|
3247
|
-
location: PropTypes.object,
|
|
3248
|
-
tags: PropTypes.array,
|
|
3249
|
-
injectedTags: PropTypes.object,
|
|
3250
|
-
onFormValidityChange: PropTypes.func,
|
|
3251
|
-
checkValidation: PropTypes.bool,
|
|
3252
|
-
onContextChange: PropTypes.func,
|
|
3253
|
-
tabCount: PropTypes.number,
|
|
3254
|
-
isSchemaChanged: PropTypes.bool,
|
|
3255
|
-
modal: PropTypes.object,
|
|
3256
|
-
isNewVersionFlow: PropTypes.bool,
|
|
3257
|
-
baseLanguage: PropTypes.string,
|
|
3258
|
-
supportedLanguages: PropTypes.array,
|
|
3259
|
-
router: PropTypes.object,
|
|
3260
|
-
currentTab: PropTypes.number,
|
|
3261
|
-
showModal: PropTypes.bool,
|
|
3262
|
-
handleCancelModal: PropTypes.func,
|
|
3263
|
-
cmsTemplates: PropTypes.array,
|
|
3264
|
-
getCmsTemplatesInProgress: PropTypes.bool,
|
|
3265
|
-
showEdmEmailTemplates: PropTypes.bool,
|
|
3266
|
-
toggleEdmEmailTemplateSelection: PropTypes.func,
|
|
3267
|
-
handleEdmDefaultTemplateSelection: PropTypes.func,
|
|
3268
|
-
userLocale: PropTypes.string,
|
|
3269
|
-
setModalContent: PropTypes.func,
|
|
3270
|
-
addLanguageType: PropTypes.string,
|
|
3271
|
-
getValidationData: PropTypes.func,
|
|
3272
|
-
startValidation: PropTypes.bool,
|
|
3273
|
-
// saveForm: PropTypes.bool,
|
|
3274
|
-
stopValidation: PropTypes.func,
|
|
3275
|
-
handleDelete: PropTypes.func,
|
|
3276
|
-
intl: intlShape.isRequired,
|
|
3277
|
-
};
|
|
3278
|
-
|
|
3279
|
-
export default injectIntl(FormBuilder);
|