@capillarytech/creatives-library 8.0.136-alpha.4 → 8.0.136-beta.3

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.
Files changed (292) hide show
  1. package/components/BreadCrumbs/index.js +65 -0
  2. package/components/BreadCrumbs/messages.js +13 -0
  3. package/components/CapTagList/index.js +235 -0
  4. package/components/CapTagList/messages.js +45 -0
  5. package/components/Card/_customCard.scss +40 -0
  6. package/components/Card/index.js +78 -0
  7. package/components/Card/tests/__snapshots__/index.test.js.snap +22 -0
  8. package/components/Card/tests/index.test.js +20 -0
  9. package/components/CardGrid/index.js +71 -0
  10. package/components/Ckeditor/index.js +238 -0
  11. package/components/Ckeditor/messages.js +13 -0
  12. package/components/Ckeditor/style.scss +3 -0
  13. package/components/Component/index.js +29 -0
  14. package/components/CustomPopOver/index.js +81 -0
  15. package/components/CustomPopOver/messages.js +17 -0
  16. package/components/DateFilter/index.js +349 -0
  17. package/components/DateFilter/messages.js +57 -0
  18. package/components/DateRange/index.js +114 -0
  19. package/components/DateRange/messages.js +25 -0
  20. package/components/Edmeditor/index.js +65 -0
  21. package/components/Edmeditor/messages.js +13 -0
  22. package/components/EmailPreview/_emailPreview.scss +119 -0
  23. package/components/EmailPreview/assets/images/iPad.svg +10 -0
  24. package/components/EmailPreview/assets/images/mobile.png +0 -0
  25. package/components/EmailPreview/index.js +107 -0
  26. package/components/EmailPreview/messages.js +33 -0
  27. package/components/Footer/index.js +27 -0
  28. package/components/Footer/messages.js +13 -0
  29. package/components/FormBuilder/_formBuilder.scss +83 -0
  30. package/components/FormBuilder/index.js +3279 -0
  31. package/components/FormBuilder/messages.js +61 -0
  32. package/components/Header/index.js +44 -0
  33. package/components/Header/messages.js +29 -0
  34. package/components/ImagePreview/_imagePreview.scss +63 -0
  35. package/components/ImagePreview/index.js +52 -0
  36. package/components/ImagePreview/messages.js +17 -0
  37. package/components/PageHeader/_pageHeader.scss +22 -0
  38. package/components/PageHeader/index.js +37 -0
  39. package/components/PageHeader/messages.js +13 -0
  40. package/components/Pagination/_pagination.scss +5 -0
  41. package/components/Pagination/index.js +49 -0
  42. package/components/PreviewSideBar/_previewsidebar.scss +28 -0
  43. package/components/PreviewSideBar/index.js +152 -0
  44. package/components/PreviewSideBar/messages.js +41 -0
  45. package/components/Sidebar/_sidebar.scss +115 -0
  46. package/components/Sidebar/index.js +214 -0
  47. package/components/Sidebar/messages.js +21 -0
  48. package/components/SlideBox/_slideBox.scss +63 -0
  49. package/components/SlideBox/index.js +47 -0
  50. package/components/SlideBox/tests/index.test.js +103 -0
  51. package/components/SmsEditor/index.js +55 -0
  52. package/components/SmsTest/index.js +117 -0
  53. package/components/SmsTest/messages.js +21 -0
  54. package/components/TemplatePreview/WechatRichmediaTemplatePreview/_wechatRichmediaTemplatePrev.scss +42 -0
  55. package/components/TemplatePreview/WechatRichmediaTemplatePreview/index.js +141 -0
  56. package/components/TemplatePreview/WechatRichmediaTemplatePreview/messages.js +21 -0
  57. package/components/TemplatePreview/_templatePreview.scss +642 -0
  58. package/components/TemplatePreview/assets/images/WECHAT_5x.png +0 -0
  59. package/components/TemplatePreview/assets/images/androidPushMessage.svg +45 -0
  60. package/components/TemplatePreview/assets/images/home-screen-android.svg +21 -0
  61. package/components/TemplatePreview/assets/images/home-screen-ios.svg +16 -0
  62. package/components/TemplatePreview/assets/images/iPhonePushMessage.svg +135 -0
  63. package/components/TemplatePreview/assets/images/mobile.svg +24 -0
  64. package/components/TemplatePreview/assets/images/sms-body.png +0 -0
  65. package/components/TemplatePreview/assets/images/sms-icon.png +0 -0
  66. package/components/TemplatePreview/assets/images/sms_mobile.png +0 -0
  67. package/components/TemplatePreview/assets/images/sms_mobile_android.svg +22 -0
  68. package/components/TemplatePreview/assets/images/sms_mobile_ios.svg +16 -0
  69. package/components/TemplatePreview/assets/images/user-icon.svg +19 -0
  70. package/components/TemplatePreview/assets/images/wechat-mobile.svg +78 -0
  71. package/components/TemplatePreview/assets/images/wechat_mobile_android.svg +20 -0
  72. package/components/TemplatePreview/index.js +617 -0
  73. package/components/TemplatePreview/messages.js +78 -0
  74. package/components/Toastr/index.js +60 -0
  75. package/components/Toastr/messages.js +13 -0
  76. package/components/ToastrMessage/index.js +113 -0
  77. package/components/ToastrMessage/messages.js +17 -0
  78. package/components/TopBar/_topbar.scss +46 -0
  79. package/components/TopBar/assets/images/capillary_logo.png +0 -0
  80. package/components/TopBar/assets/images/old_capillary_logo.png +0 -0
  81. package/components/TopBar/index.js +113 -0
  82. package/components/TopBar/messages.js +29 -0
  83. package/containers/App/actions.js +7 -0
  84. package/containers/App/constants.js +114 -0
  85. package/containers/App/index.js +52 -0
  86. package/containers/App/reducer.js +19 -0
  87. package/containers/App/sagas.js +31 -0
  88. package/containers/App/selectors.js +25 -0
  89. package/containers/App/test/saga.test.js +11 -0
  90. package/containers/Assets/Gallery/_gallery.scss +126 -0
  91. package/containers/Assets/Gallery/actions.js +37 -0
  92. package/containers/Assets/Gallery/constants.js +23 -0
  93. package/containers/Assets/Gallery/index.js +473 -0
  94. package/containers/Assets/Gallery/messages.js +93 -0
  95. package/containers/Assets/Gallery/reducer.js +81 -0
  96. package/containers/Assets/Gallery/sagas.js +80 -0
  97. package/containers/Assets/Gallery/selectors.js +25 -0
  98. package/containers/Assets/Gallery/tests/__snapshots__/reducer.test.js.snap +9 -0
  99. package/containers/Assets/Gallery/tests/actions.test.js +25 -0
  100. package/containers/Assets/Gallery/tests/reducer.test.js +96 -0
  101. package/containers/Assets/Gallery/tests/saga.test.js +157 -0
  102. package/containers/Cap/actions.js +66 -0
  103. package/containers/Cap/constants.js +25 -0
  104. package/containers/Cap/index.js +402 -0
  105. package/containers/Cap/messages.js +75 -0
  106. package/containers/Cap/reducer.js +113 -0
  107. package/containers/Cap/sagas.js +159 -0
  108. package/containers/Cap/selectors.js +75 -0
  109. package/containers/Cap/tests/__snapshots__/index.test.js.snap +2269 -0
  110. package/containers/Cap/tests/index.test.js +22 -0
  111. package/containers/Cap/tests/saga.test.js +284 -0
  112. package/containers/Dashboard/actions.js +15 -0
  113. package/containers/Dashboard/constants.js +7 -0
  114. package/containers/Dashboard/index.js +76 -0
  115. package/containers/Dashboard/messages.js +13 -0
  116. package/containers/Dashboard/reducer.js +21 -0
  117. package/containers/Dashboard/sagas.js +17 -0
  118. package/containers/Dashboard/selectors.js +25 -0
  119. package/containers/Dashboard/test/saga.test.js +9 -0
  120. package/containers/Ebill/_ebill.scss +5 -0
  121. package/containers/Ebill/actions.js +43 -0
  122. package/containers/Ebill/constants.js +20 -0
  123. package/containers/Ebill/index.js +1278 -0
  124. package/containers/Ebill/messages.js +77 -0
  125. package/containers/Ebill/reducer.js +72 -0
  126. package/containers/Ebill/sagas.js +74 -0
  127. package/containers/Ebill/selectors.js +25 -0
  128. package/containers/Ebill/test/saga.test.js +11 -0
  129. package/containers/Email/_email.scss +141 -0
  130. package/containers/Email/actions.js +81 -0
  131. package/containers/Email/constants.js +36 -0
  132. package/containers/Email/index.js +3325 -0
  133. package/containers/Email/messages.js +289 -0
  134. package/containers/Email/reducer.js +142 -0
  135. package/containers/Email/sagas.js +135 -0
  136. package/containers/Email/selectors.js +31 -0
  137. package/containers/Email/test/saga.test.js +671 -0
  138. package/containers/LanguageProvider/actions.js +17 -0
  139. package/containers/LanguageProvider/constants.js +8 -0
  140. package/containers/LanguageProvider/index.js +80 -0
  141. package/containers/LanguageProvider/reducer.js +30 -0
  142. package/containers/LanguageProvider/selectors.js +20 -0
  143. package/containers/LanguageProvider/tests/actions.test.js +19 -0
  144. package/containers/LanguageProvider/tests/index.test.js +78 -0
  145. package/containers/LanguageProvider/tests/reducer.test.js +20 -0
  146. package/containers/LanguageProvider/tests/selectors.test.js +15 -0
  147. package/containers/Line/Create/_lineCreate.scss +54 -0
  148. package/containers/Line/Create/actions.js +90 -0
  149. package/containers/Line/Create/constants.js +39 -0
  150. package/containers/Line/Create/index.js +836 -0
  151. package/containers/Line/Create/messages.js +189 -0
  152. package/containers/Line/Create/reducer.js +99 -0
  153. package/containers/Line/Create/sagas.js +121 -0
  154. package/containers/Line/Create/selectors.js +36 -0
  155. package/containers/Line/Create/tests/saga.test.js +202 -0
  156. package/containers/Line/Edit/_lineEdit.scss +35 -0
  157. package/containers/Line/Edit/actions.js +79 -0
  158. package/containers/Line/Edit/constants.js +27 -0
  159. package/containers/Line/Edit/index.js +1050 -0
  160. package/containers/Line/Edit/messages.js +177 -0
  161. package/containers/Line/Edit/reducer.js +83 -0
  162. package/containers/Line/Edit/sagas.js +80 -0
  163. package/containers/Line/Edit/selectors.js +29 -0
  164. package/containers/Line/Edit/test/saga.test.js +160 -0
  165. package/containers/Login/assets/images/capillary_logo.png +0 -0
  166. package/containers/Login/components/LoginForm/index.js +62 -0
  167. package/containers/Login/components/LoginForm/messages.js +33 -0
  168. package/containers/Login/index.js +130 -0
  169. package/containers/Login/messages.js +25 -0
  170. package/containers/Login/selectors.js +25 -0
  171. package/containers/MobilePush/Create/_mobilePushCreate.scss +39 -0
  172. package/containers/MobilePush/Create/actions.js +46 -0
  173. package/containers/MobilePush/Create/constants.js +23 -0
  174. package/containers/MobilePush/Create/index.js +2303 -0
  175. package/containers/MobilePush/Create/messages.js +269 -0
  176. package/containers/MobilePush/Create/reducer.js +70 -0
  177. package/containers/MobilePush/Create/sagas.js +74 -0
  178. package/containers/MobilePush/Create/selectors.js +28 -0
  179. package/containers/MobilePush/Create/test/saga.test.js +19 -0
  180. package/containers/MobilePush/Edit/_mobilePushCreate.scss +39 -0
  181. package/containers/MobilePush/Edit/actions.js +91 -0
  182. package/containers/MobilePush/Edit/constants.js +35 -0
  183. package/containers/MobilePush/Edit/index.js +2601 -0
  184. package/containers/MobilePush/Edit/messages.js +266 -0
  185. package/containers/MobilePush/Edit/reducer.js +112 -0
  186. package/containers/MobilePush/Edit/sagas.js +126 -0
  187. package/containers/MobilePush/Edit/selectors.js +29 -0
  188. package/containers/MobilePush/Edit/tests/saga.test.js +255 -0
  189. package/containers/NotFoundPage/index.js +25 -0
  190. package/containers/NotFoundPage/messages.js +13 -0
  191. package/containers/NotFoundPage/tests/index.test.js +17 -0
  192. package/containers/Sms/Create/_smsCreate.scss +42 -0
  193. package/containers/Sms/Create/actions.js +27 -0
  194. package/containers/Sms/Create/constants.js +16 -0
  195. package/containers/Sms/Create/index.js +1488 -0
  196. package/containers/Sms/Create/messages.js +109 -0
  197. package/containers/Sms/Create/reducer.js +41 -0
  198. package/containers/Sms/Create/sagas.js +40 -0
  199. package/containers/Sms/Create/selectors.js +28 -0
  200. package/containers/Sms/Create/test/saga.test.js +11 -0
  201. package/containers/Sms/Edit/actions.js +40 -0
  202. package/containers/Sms/Edit/constants.js +17 -0
  203. package/containers/Sms/Edit/index.js +1472 -0
  204. package/containers/Sms/Edit/messages.js +105 -0
  205. package/containers/Sms/Edit/reducer.js +50 -0
  206. package/containers/Sms/Edit/sagas.js +60 -0
  207. package/containers/Sms/Edit/selectors.js +32 -0
  208. package/containers/Sms/Edit/test/saga.test.js +13 -0
  209. package/containers/TagList/_tagList.scss +8 -0
  210. package/containers/TagList/actions.js +15 -0
  211. package/containers/TagList/constants.js +32 -0
  212. package/containers/TagList/index.js +236 -0
  213. package/containers/TagList/messages.js +13 -0
  214. package/containers/TagList/reducer.js +23 -0
  215. package/containers/TagList/sagas.js +11 -0
  216. package/containers/TagList/selectors.js +25 -0
  217. package/containers/Templates/_templates.scss +333 -0
  218. package/containers/Templates/actions.js +103 -0
  219. package/containers/Templates/constants.js +60 -0
  220. package/containers/Templates/index.js +1756 -0
  221. package/containers/Templates/messages.js +337 -0
  222. package/containers/Templates/reducer.js +142 -0
  223. package/containers/Templates/sagas.js +163 -0
  224. package/containers/Templates/selectors.js +28 -0
  225. package/containers/Templates/test/saga.test.js +241 -0
  226. package/containers/WeChat/MapTemplates/_mapTemplates.scss +8 -0
  227. package/containers/WeChat/MapTemplates/actions.js +52 -0
  228. package/containers/WeChat/MapTemplates/constants.js +28 -0
  229. package/containers/WeChat/MapTemplates/index.js +1610 -0
  230. package/containers/WeChat/MapTemplates/messages.js +157 -0
  231. package/containers/WeChat/MapTemplates/reducer.js +74 -0
  232. package/containers/WeChat/MapTemplates/sagas.js +84 -0
  233. package/containers/WeChat/MapTemplates/selectors.js +25 -0
  234. package/containers/WeChat/MapTemplates/test/saga.test.js +155 -0
  235. package/containers/WeChat/RichmediaTemplates/Create/_createRichmedia.scss +57 -0
  236. package/containers/WeChat/RichmediaTemplates/Create/actions.js +36 -0
  237. package/containers/WeChat/RichmediaTemplates/Create/constants.js +15 -0
  238. package/containers/WeChat/RichmediaTemplates/Create/index.js +1071 -0
  239. package/containers/WeChat/RichmediaTemplates/Create/messages.js +165 -0
  240. package/containers/WeChat/RichmediaTemplates/Create/reducer.js +60 -0
  241. package/containers/WeChat/RichmediaTemplates/Create/richmediaschema.js +497 -0
  242. package/containers/WeChat/RichmediaTemplates/Create/sagas.js +51 -0
  243. package/containers/WeChat/RichmediaTemplates/Create/selectors.js +37 -0
  244. package/containers/WeChat/RichmediaTemplates/Create/test/saga.test.js +13 -0
  245. package/containers/WeChat/RichmediaTemplates/Edit/actions.js +20 -0
  246. package/containers/WeChat/RichmediaTemplates/Edit/constants.js +10 -0
  247. package/containers/WeChat/RichmediaTemplates/Edit/index.js +136 -0
  248. package/containers/WeChat/RichmediaTemplates/Edit/messages.js +13 -0
  249. package/containers/WeChat/RichmediaTemplates/Edit/reducer.js +28 -0
  250. package/containers/WeChat/RichmediaTemplates/Edit/sagas.js +36 -0
  251. package/containers/WeChat/RichmediaTemplates/Edit/selectors.js +30 -0
  252. package/containers/WeChat/RichmediaTemplates/Edit/test/saga.test.js +12 -0
  253. package/containers/WeChat/RichmediaTemplates/View/actions.js +15 -0
  254. package/containers/WeChat/RichmediaTemplates/View/constants.js +7 -0
  255. package/containers/WeChat/RichmediaTemplates/View/index.js +47 -0
  256. package/containers/WeChat/RichmediaTemplates/View/messages.js +21 -0
  257. package/containers/WeChat/RichmediaTemplates/View/reducer.js +23 -0
  258. package/containers/WeChat/RichmediaTemplates/View/sagas.js +11 -0
  259. package/containers/WeChat/RichmediaTemplates/View/selectors.js +25 -0
  260. package/index.js +2 -4
  261. package/package.json +1 -1
  262. package/routes.js +202 -136
  263. package/services/getSchema.js +1 -1
  264. package/services/localStorageApi.js +0 -1
  265. package/tests/i18n.test.js +1 -1
  266. package/utils/asyncInjectors.js +78 -0
  267. package/utils/authWrapper.js +1 -1
  268. package/utils/callNativeEvent.js +16 -0
  269. package/utils/checkStore.js +21 -0
  270. package/utils/common.js +2 -2
  271. package/utils/customAuthWrapper.js +62 -0
  272. package/utils/customConnectedAuthWrapper.js +26 -0
  273. package/utils/tagValidations.js +1 -1
  274. package/utils/tests/checkStore.test.js +1 -1
  275. package/utils/tests/customAuth.test.js +1 -1
  276. package/utils/transformerUtils.js +195 -1
  277. package/v2Components/CapTagList/index.js +14 -9
  278. package/v2Components/Carousel/style.scss +1 -1
  279. package/v2Components/EmailMobilePreview/index.js +2 -2
  280. package/v2Components/FormBuilder/index.js +2 -2
  281. package/v2Components/TemplatePreview/index.js +1 -2
  282. package/v2Containers/Cap/tests/saga.test.js +1 -1
  283. package/v2Containers/Email/index.js +1 -1
  284. package/v2Containers/FTP/index.js +1 -1
  285. package/v2Containers/Line/Container/Text/index.js +6 -6
  286. package/v2Containers/Sms/Create/index.js +2 -2
  287. package/v2Containers/Sms/Edit/index.js +1 -1
  288. package/v2Containers/TagList/index.js +1 -1
  289. package/v2Containers/TagList/utils.js +1 -1
  290. package/v2Containers/Templates/index.js +1 -1
  291. package/v2Containers/Templates/sagas.js +1 -1
  292. package/constants/unified.js +0 -189
@@ -0,0 +1,1472 @@
1
+ /*jshint loopfunc:true */
2
+ /*
3
+ *
4
+ * Create
5
+ *
6
+ */
7
+
8
+ import PropTypes from 'prop-types';
9
+
10
+ import React from 'react';
11
+ import { connect } from 'react-redux';
12
+ import { Row, Col, Spin } from 'antd';
13
+ import { injectIntl, intlShape } from 'react-intl';
14
+ import { createStructuredSelector } from 'reselect';
15
+ import _ from 'lodash';
16
+ import { bindActionCreators, compose } from 'redux';
17
+ import { makeSelectEdit, makeSelectEditResponse, makeSelectTemplateDetailsResponse } from './selectors';
18
+ import { makeSelectMetaEntities, setInjectedTags } from '../../Cap/selectors';
19
+ import { UserIsAuthenticated } from '../../../utils/authWrapper';
20
+ import FormBuilder from '../../../components/FormBuilder';
21
+ import * as actions from './actions';
22
+ import {checkUnicode, updateCharCount} from '../../../utils/smsCharCountV2';
23
+ import '../Create/_smsCreate.scss';
24
+ import messages from './messages';
25
+ import * as globalActions from '../../../containers/Cap/actions';
26
+ import {getMessageObject} from '../../../utils/messageUtils';
27
+ import injectSaga from '../../../utils/injectSaga';
28
+ import injectReducer from '../../../utils/injectReducer';
29
+ import reducer from './reducer';
30
+ import { editSmsSaga } from './sagas';
31
+ import { createQueryString } from '../../../utils/common';
32
+ export class Edit extends React.Component { // eslint-disable-line react/prefer-stateless-function
33
+ constructor(props) {
34
+ super(props);
35
+ this.state = {
36
+ formData: {},
37
+ tabCount: 1,
38
+ schema: {},
39
+ currentTab: 1,
40
+ editData: {},
41
+ loading: false,
42
+ isFormValid: true,
43
+ injectedTags: {},
44
+ showModal: false,
45
+ modalContent: {title: this.props.intl.formatMessage(messages.alertMessage), body: this.props.intl.formatMessage(messages.deleteVersion), type: 'confirm', id: 'sms-version-modal'},
46
+ };
47
+ this.saveFormData = this.saveFormData.bind(this);
48
+ this.onFormDataChange = this.onFormDataChange.bind(this);
49
+ this.onTemplateNameChange = this.onTemplateNameChange.bind(this);
50
+ this.onTemplateContentChange = this.onTemplateContentChange.bind(this);
51
+ this.handleFrameTasks = this.handleFrameTasks.bind(this);
52
+ this.getFormData = this.getFormData.bind(this);
53
+ this.validateContent = this.validateContent.bind(this);
54
+ this.onTagSelect = this.onTagSelect.bind(this);
55
+ this.insertAtCursor = this.insertAtCursor.bind(this);
56
+ this.addVersion = this.addVersion.bind(this);
57
+ this.onTabChange = this.onTabChange.bind(this);
58
+ this.setEditState = this.setEditState.bind(this);
59
+ this.discardValues = this.discardValues.bind(this);
60
+ this.resetSchema = this.resetSchema.bind(this);
61
+ this.cloneColLabel = this.cloneColLabel.bind(this);
62
+ this.cloneMultiCol = this.cloneMultiCol.bind(this);
63
+ this.cloneParent = this.cloneParent.bind(this);
64
+ this.markFinalVersion = this.markFinalVersion.bind(this);
65
+ this.deleteVersion = this.deleteVersion.bind(this);
66
+ this.duplicateVersion = this.duplicateVersion.bind(this);
67
+ this.renameVersion = this.renameVersion.bind(this);
68
+ this.onVersionNameChange = this.onVersionNameChange.bind(this);
69
+ this.validateFormData = this.validateFormData.bind(this);
70
+ this.getCurrentWindow = this.getCurrentWindow.bind(this);
71
+ this.removeStandAlone = this.removeStandAlone.bind(this);
72
+ this.startTemplateCreation = this.startTemplateCreation.bind(this);
73
+ this.startLoading = this.startLoading.bind(this);
74
+ this.moveToTemplates = this.moveToTemplates.bind(this);
75
+ this.cancelTemplate = this.cancelTemplate.bind(this);
76
+ this.injectEvents = this.injectEvents.bind(this);
77
+ this.injectSections = this.injectSections.bind(this);
78
+ this.injectContainer = this.injectContainer.bind(this);
79
+ this.injectParentSection = this.injectParentSection.bind(this);
80
+ this.injectColLabelSection = this.injectColLabelSection.bind(this);
81
+ this.injectMultiColSection = this.injectMultiColSection.bind(this);
82
+ this.getMappedEvent = this.getMappedEvent.bind(this);
83
+ this.setFormValidity = this.setFormValidity.bind(this);
84
+ this.showNext = this.showNext.bind(this);
85
+ this.injectMessages = this.injectMessages.bind(this);
86
+ }
87
+
88
+ componentWillMount() {
89
+
90
+ const query = {
91
+ layout: 'SMS',
92
+ type: 'LAYOUT',
93
+ };
94
+ this.props.globalActions.fetchSchemaForEntity(query);
95
+ }
96
+ componentDidMount() {
97
+ if (this.props.location.query && this.props.location.query.module === 'library') {
98
+ if (this.props.params && this.props.params.id) {
99
+ this.props.actions.getTemplateDetails(this.props.params.id);
100
+ } else {
101
+ this.props.actions.setTemplateDetails(this.props.templateData);
102
+ }
103
+ } else {
104
+ this.props.actions.getTemplateDetails(this.props.params.id);
105
+ }
106
+ const type = this.props.location.query.type;
107
+ // const module = this.props.location.query.module;
108
+ // const name = this.props.route.name;
109
+ window.addEventListener("message", this.handleFrameTasks);
110
+ if (type === 'embedded') {
111
+ const response = {
112
+ action: 'startTemplateCreation',
113
+ window: 'edit',
114
+ };
115
+ // if (name !== "view" && module.toLowerCase() === "timeline") {
116
+ // return;
117
+ // }
118
+ parent.postMessage(JSON.stringify(response), '*');
119
+ }
120
+ }
121
+
122
+ componentWillReceiveProps(nextProps) {
123
+ if (nextProps.location.query.module === 'library' && nextProps.isGetFormData) {
124
+ nextProps.getFormSubscriptionData(this.getFormData());
125
+ }
126
+ if ( nextProps.location.query.module === 'library' && nextProps.subscriptionTemplateDetails && nextProps.subscriptionTemplateDetails.name && _.isEmpty(this.state.editData) && !_.isEmpty(this.state.schema)) {
127
+ this.setEditState(nextProps.subscriptionTemplateDetails);
128
+ }
129
+ if (nextProps.templateDetails && nextProps.templateDetails.name && _.isEmpty(this.state.editData) && !_.isEmpty(this.state.schema)) {
130
+ this.setEditState(nextProps.templateDetails);
131
+ }
132
+ if (nextProps.metaEntities && nextProps.metaEntities.layouts && nextProps.metaEntities.layouts.length > 0 && _.isEmpty(this.state.schema)) {
133
+ this.setState({schema: nextProps.metaEntities.layouts[0].definition}, () => {
134
+ this.injectEvents(nextProps.metaEntities.layouts[0].definition);
135
+ });
136
+ if (this.props.location.query.module !== 'library' || (this.props.location.query.module === 'library' && this.props.getDefaultTags)) {
137
+ const query = {
138
+ layout: 'SMS',
139
+ type: 'TAG',
140
+ context: this.props.location.query.type === 'embedded' ? this.props.location.query.module : 'default',
141
+ embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
142
+ };
143
+ if (this.props.getDefaultTags) {
144
+ query.context = this.props.getDefaultTags;
145
+ }
146
+ this.props.globalActions.fetchSchemaForEntity(query);
147
+ if (this.props.location.query.type === 'embedded') {
148
+ this.showNext();
149
+ }
150
+ }
151
+ }
152
+ if (nextProps.Edit.editResponse && nextProps.Edit.editResponse.templateId) {
153
+
154
+ this.resetSchema();
155
+ this.setState({
156
+ formData: {},
157
+ tabCount: 1,
158
+ currentTab: 1,
159
+ editData: {},
160
+ });
161
+ const message = getMessageObject('success', 'SMS Template Edited Successfully', true);
162
+ this.props.globalActions.addMessageToQueue(message);
163
+ this.props.actions.clearEditResponse();
164
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
165
+ const type = this.props.location.query.type;
166
+ this.props.router.push({
167
+ pathname: `/sms/`,
168
+ search : createQueryString(type === 'embedded' ? {type: 'embedded', module} : {module})
169
+ });
170
+ }
171
+
172
+ if (nextProps.Edit.editTemplateError && !_.isEqual(nextProps.Edit.editTemplateError, this.props.Edit.editTemplateError)) {
173
+ const message = getMessageObject('error', (nextProps.Edit.editTemplateErrorMessage && nextProps.Edit.editTemplateErrorMessage !== '') ? nextProps.Edit.editTemplateErrorMessage : this.props.intl.formatMessage(messages.somethingWentWrong), true);
174
+ this.props.globalActions.addMessageToQueue(message);
175
+ }
176
+ }
177
+
178
+ componentWillUnmount() {
179
+ window.removeEventListener("message", this.handleFrameTasks);
180
+ }
181
+
182
+ onTemplateNameChange(name) {
183
+
184
+ }
185
+
186
+ onTemplateContentChange(content) {
187
+
188
+ }
189
+
190
+ onFormDataChange(formData, tabCount, currentTab) {
191
+
192
+ this.setState({formData, tabCount, currentTab});
193
+ if (currentTab) {
194
+ this.setState({currentTab});
195
+ }
196
+ }
197
+
198
+ onVersionNameChange(data, versionIndex) {
199
+
200
+ }
201
+
202
+ onTagSelect(data, currentTab) {
203
+
204
+ const editorId = currentTab > 1 ? `sms-editor${currentTab}` : 'sms-editor';
205
+ this.insertAtCursor(document.getElementById(editorId), `{{${data}}}`, currentTab);
206
+ document.getElementById(editorId).focus();
207
+ }
208
+
209
+ onTabChange(data) {
210
+
211
+ this.setState({currentTab: data});
212
+ }
213
+
214
+ setEditState(data) {
215
+ const that = this;
216
+ const tabCount = data.versions.history.length;
217
+ const formData = {};
218
+ formData['template-name'] = data.name;
219
+ const type = this.props.location.query.type;
220
+ let ifBase = false;
221
+ let currentTab = 1;
222
+ for (let count = 0; count < tabCount; count += 1) {
223
+ formData[count] = _.cloneDeep(data.versions.base);
224
+ if (data.versions && data.versions.history && data.versions.history[count] && data.versions.history[count].base) {
225
+ if (!formData[count]) {
226
+ formData[count] = {};
227
+ }
228
+ formData[count].base = true;
229
+ ifBase = true;
230
+ currentTab = count + 1;
231
+ }
232
+ if (type === 'embedded' || count > 0) {
233
+ setTimeout( () => {
234
+
235
+ if (type === 'embedded') {
236
+ that.removeStandAlone();
237
+ } else {
238
+ that.addVersion(count, tabCount);
239
+ }
240
+ }, 0 );
241
+ }
242
+ }
243
+ if (!ifBase) {
244
+ if (!formData[0]) {
245
+ formData[0] = {};
246
+ }
247
+ formData[0].base = true;
248
+ }
249
+ formData.base = data.versions.base;
250
+
251
+ this.setState({tabCount, formData, editData: data, currentTab}, () => {
252
+ });
253
+ }
254
+
255
+ setFormValidity(isFormValid) {
256
+ this.setState({isFormValid});
257
+ }
258
+
259
+ getFormData(e, value) {
260
+
261
+ const formData = _.cloneDeep(this.state.formData);
262
+ let baseData = {};
263
+ let versionIdx;
264
+ _.forEach(formData, (val, idx) => {
265
+
266
+ if (val.base && idx !== 'base') {
267
+ baseData = val;
268
+ versionIdx = idx;
269
+ }
270
+ });
271
+ baseData['sms-editor'] = baseData[`sms-editor${versionIdx > 0 ? versionIdx : ''}`];
272
+ if (versionIdx !== "0") {
273
+ delete baseData[`sms-editor${versionIdx > 0 ? versionIdx : ''}`];
274
+ }
275
+ const result = {};
276
+ result.base = baseData;
277
+ const msgObj = updateCharCount(baseData['sms-editor']);
278
+ result.base.msg_count = msgObj.msgCount;
279
+
280
+ const response = {
281
+ action: "getFormData",
282
+ value: result,
283
+ postAction: value || 'next',
284
+ validity: this.state.isFormValid,
285
+ };
286
+ this.setState({checkValidation: true});
287
+
288
+ if (e) {
289
+ e.source.postMessage(JSON.stringify(response), e.origin);
290
+ }
291
+ return response;
292
+ }
293
+
294
+ getCurrentWindow(e) {
295
+
296
+ const response = {
297
+ action: e.action,
298
+ value: 'edit',
299
+ direction: e.value,
300
+ };
301
+ parent.postMessage(JSON.stringify(response), '*');
302
+ }
303
+
304
+ getMappedEvent(id, event) {
305
+ const map = {
306
+ "template-name": {
307
+ onChange: this.onTemplateNameChange,
308
+ },
309
+ "discard-button": {
310
+ discardValues: this.discardValues,
311
+ },
312
+ "cancel-button": {
313
+ cancelTemplate: this.cancelTemplate,
314
+ },
315
+ "save-button": {
316
+ saveFormData: this.saveFormData,
317
+ },
318
+ "sms-editor": {
319
+ onChange: this.onTemplateContentChange,
320
+ },
321
+ "tagList": {
322
+ onTagSelect: this.onTagSelect,
323
+ },
324
+ "unicode-validity": {
325
+ onChange: this.onTemplateNameChange,
326
+ },
327
+ "add-version-button": {
328
+ addVersion: this.addVersion,
329
+ },
330
+ "tab-header": {
331
+ onChange: this.onVersionNameChange,
332
+ },
333
+ "tab-options-popover": {
334
+ onTabOptionSelect: this.onTabOptionSelect,
335
+ },
336
+ "mark-final-version-label": {
337
+ markFinalVersion: this.markFinalVersion,
338
+ },
339
+ "duplicate-version-label": {
340
+ duplicateVersion: this.duplicateVersion,
341
+ },
342
+ "rename-version-label": {
343
+ renameVersion: this.renameVersion,
344
+ },
345
+ "delete-version-label": {
346
+ deleteVersion: this.deleteVersion,
347
+ },
348
+ "pane": {
349
+ onTabChange: this.onTabChange,
350
+ },
351
+ };
352
+ return map[id][event];
353
+ }
354
+
355
+ handleOnTagsContextChange = (data) => {
356
+
357
+ const query = {
358
+ layout: 'SMS',
359
+ type: 'TAG',
360
+ context: (data || '').toLowerCase() === 'all' ? 'default' : (data || '').toLowerCase(),
361
+ embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
362
+ };
363
+ this.props.globalActions.fetchSchemaForEntity(query);
364
+ }
365
+
366
+ showNext() {
367
+ const response = {
368
+ action: "showNext",
369
+ value: true,
370
+ };
371
+ parent.postMessage(JSON.stringify(response), '*');
372
+ }
373
+
374
+ startTemplateCreation(data) {
375
+
376
+ if (data.edit) {
377
+ const ifUnicode = checkUnicode(data.content);
378
+
379
+ const content = data.content;
380
+ const tempData = {
381
+ 'sms-editor': content,
382
+ 'unicode-validity': ifUnicode,
383
+ 'base': true,
384
+ };
385
+ const formData = {};
386
+ formData[0] = tempData;
387
+ formData.base = tempData;
388
+ this.setState({formData, loading: false, injectedTags: data.tags});
389
+ } else {
390
+ this.setState({injectedTags: data.tags});
391
+ }
392
+ this.props.globalActions.setInjectedTags(data.tags);
393
+ }
394
+
395
+ startLoading(ifEdit) {
396
+
397
+ if (ifEdit) {
398
+ this.setState({loading: true});
399
+ }
400
+ }
401
+
402
+ moveToTemplates() {
403
+
404
+ const modalContent = {
405
+ title: this.props.intl.formatMessage(messages.alertMessage),
406
+ body: this.props.intl.formatMessage(messages.goBackConfirmation),
407
+ type: 'confirm',
408
+ id: 'template-back-confirm-modal',
409
+ show: true,
410
+ };
411
+ this.setState({modalContent, showModal: true});
412
+ // const type = this.props.location.query.type;
413
+ // this.props.router.push({
414
+ // pathname: `/sms/`,
415
+ // query: type === 'embedded' ? {type: 'embedded', module} : {module},
416
+ // });
417
+ }
418
+
419
+ discardValues() {
420
+
421
+ this.resetSchema();
422
+ this.setState({
423
+ formData: {},
424
+ tabCount: 1,
425
+ currentTab: 1,
426
+ editData: {},
427
+ }, () => {
428
+ this.setEditState(this.props.Edit.templateDetails);
429
+ });
430
+ }
431
+
432
+ resetSchema() {
433
+ //const schema =
434
+ // {
435
+ // standalone: {
436
+ // sections: [
437
+ // {
438
+ // type: "multicols",
439
+ // inputFields: [
440
+ // {
441
+ // cols: [
442
+ // {
443
+ // id: "template-name",
444
+ // placeholder: "Enter template name",
445
+ // type: "input", //Resembles component to be used
446
+ // metaType: "text",
447
+ // datatype: "string",
448
+ // required: true,
449
+ // fluid: true,
450
+ // style: {
451
+ // fontSize: '20px',
452
+ // fontFamily: 'proxima-nova,sans-serif',
453
+ // fontStyle: 'normal',
454
+ // fontWeight: 600,
455
+ // marginBottom: '16px',
456
+ // },
457
+ // styling: "semantic",
458
+ // order: 1,
459
+ // width: 9,
460
+ // // offSet: 10,
461
+ // customComponent: false,
462
+ // standalone: true,
463
+ // supportedEvents: {
464
+ // onChange: this.onTemplateNameChange,
465
+ // },
466
+ // },
467
+ // {
468
+ // id: "discard-button",
469
+ // width: 3,
470
+ // offset: 8,
471
+ // metaType: "submit-button",
472
+ // colStyle: {
473
+ // // marginLeft: '47.833%',
474
+ // textAlign: 'right',
475
+ // paddingRight: '12px',
476
+ // },
477
+ // type: "button",
478
+ // buttonType: "cancel",
479
+ // value: "Discard",
480
+ // customComponent: false,
481
+ // standalone: true,
482
+ // styling: "semantic",
483
+ // order: 3,
484
+ // fluid: false,
485
+ // submitAction: "discardValues",
486
+ // supportedEvents: {
487
+ // discardValues: this.discardValues,
488
+ // },
489
+ // },
490
+ // {
491
+ // id: "cancel-button",
492
+ // width: 2,
493
+ // // offset: 11,
494
+ // metaType: "submit-button",
495
+ // colStyle: {
496
+ // textAlign: 'right',
497
+ // width: '9%',
498
+ // },
499
+ // type: "button",
500
+ // buttonType: "cancel",
501
+ // value: "Cancel",
502
+ // customComponent: false,
503
+ // standalone: true,
504
+ // styling: "semantic",
505
+ // order: 3,
506
+ // fluid: false,
507
+ // submitAction: "cancelTemplate",
508
+ // supportedEvents: {
509
+ // cancelTemplate: this.cancelTemplate,
510
+ // },
511
+ // },
512
+ // {
513
+ // id: "save-button",
514
+ // width: 2,
515
+ // metaType: "submit-button",
516
+ // colStyle: {
517
+ // textAlign: 'right',
518
+ // width: '7%',
519
+ // },
520
+ // type: "button",
521
+ // buttonType: "primary",
522
+ // value: "Save",
523
+ // customComponent: false,
524
+ // styling: "semantic",
525
+ // order: 3,
526
+ // fluid: false,
527
+ // standalone: true,
528
+ // submitAction: "saveFormData",
529
+ // supportedEvents: {
530
+ // saveFormData: this.saveFormData,
531
+ // },
532
+ // },
533
+ // ],
534
+ // },
535
+ // ],
536
+ // actionFields: [],
537
+ // },
538
+ // ],
539
+ // },
540
+ // containers: [
541
+ // {
542
+ // panes: [
543
+ // {
544
+ // sections: [
545
+ // {
546
+ // type: "parent",
547
+ // width: 16,
548
+ // rowStyle: {
549
+ // height: '100%',
550
+ // },
551
+ // childSections: [
552
+ // {
553
+ // colStyle: {
554
+ // paddingTop: '16px',
555
+ // borderRight: '1px solid #d9d9d9',
556
+ // height: '100%',
557
+ // },
558
+ // width: 16,
559
+ // type: "parent",
560
+ // childSections: [
561
+ // {
562
+ // type: "col-label",
563
+ // inputFields: [
564
+ // {
565
+ // id: "sms-editor",
566
+ // label: "Message",
567
+ // labelStyle: {
568
+ // backgroundColor: 'white',
569
+ // textAlign: 'left',
570
+ // color: '#333333',
571
+ // lineHeight: '24px',
572
+ // fontSize: '16px',
573
+ // fontWeight: '600',
574
+ // fontFamily: 'proxima-nova, sans-serif',
575
+ // fontStyle: 'normal',
576
+ // },
577
+ // style: {
578
+ // textAlign: 'left',
579
+ // color: '#333333',
580
+ // fontFamily: 'Open-Sans',
581
+ // lineHeight: '24px',
582
+ // fontSize: '14px',
583
+ // },
584
+ // type: "textarea",
585
+ // metaType: "text",
586
+ // datatype: "string",
587
+ // required: true,
588
+ // placeholder: "Please input sms template content.",
589
+ // fluid: false,
590
+ // styling: "semantic",
591
+ // onlyDisplay: false,
592
+ // width: 18,
593
+ // autosize: true,
594
+ // autosizeParams: {
595
+ // minRows: 3,
596
+ // },
597
+ // order: 2,
598
+ // customComponent: true,
599
+ // supportedEvents: {
600
+ // onChange: this.onTemplateContentChange,
601
+ // },
602
+ // },
603
+ // ],
604
+ // actionFields: [
605
+ // ],
606
+ // },
607
+ // {
608
+ // type: "multicols",
609
+ // inputFields: [
610
+ // {
611
+ // cols: [
612
+ // {
613
+ // offset: 19,
614
+ // id: "tagList",
615
+ // label: "Tags",
616
+ // type: "tag-list", //Resembles component to be used
617
+ // metaType: "List",
618
+ // datatype: "select",
619
+ // required: true,
620
+ // fluid: true,
621
+ // onlyDisplay: true,
622
+ // styling: "semantic",
623
+ // order: 1,
624
+ // customComponent: true,
625
+ // supportedEvents: {
626
+ // onTagSelect: this.onTagSelect,
627
+ // },
628
+ // },
629
+ // ],
630
+ // },
631
+ // {
632
+ // cols: [
633
+ // {
634
+ // id: "unicode-validity",
635
+ // label: "Allow Unicode characters?",
636
+ // labelStyle: {
637
+ // backgroundColor: "white",
638
+ // },
639
+ // style: {
640
+ // textAlign: 'left',
641
+ // color: '#262626',
642
+ // fontFamily: 'Open-Sans',
643
+ // lineHeight: '24px',
644
+ // fontSize: '14px',
645
+ // },
646
+ // type: "checkbox", //Resembles component to be used
647
+ // metaType: "text",
648
+ // datatype: "boolean",
649
+ // required: true,
650
+ // fluid: true,
651
+ // styling: "semantic",
652
+ // order: 1,
653
+ // width: 10,
654
+ // offset: 4,
655
+ // onlyDisplay: false,
656
+ // customComponent: false,
657
+ // supportedEvents: {
658
+ // onChange: this.onTemplateNameChange,
659
+ // },
660
+ // },
661
+ // ],
662
+ // },
663
+ // ],
664
+ // actionFields: [],
665
+ // },
666
+ // ],
667
+ // },
668
+ // {
669
+ // width: 6,
670
+ // type: "multicols",
671
+ // offset: 1,
672
+ // colStyle: {
673
+ // paddingTop: '16px',
674
+ // },
675
+ // inputFields: [
676
+ // {
677
+ // cols: [
678
+ // {
679
+ // id: "sms-preview",
680
+ // type: "sms-preview", //Resembles component to be used
681
+ // customComponent: true,
682
+ // customStyling: { padding: '0' },
683
+ // metaType: "preview",
684
+ // required: true,
685
+ // fluid: true,
686
+ // styling: "semantic",
687
+ // order: 1,
688
+ // width: 5,
689
+ // onlyDisplay: true,
690
+ // offset: 7,
691
+ // channel: 'SMS',
692
+ // supportedEvents: {
693
+ // onChange: this.onTemplateNameChange,
694
+ // },
695
+ // },
696
+ // ],
697
+ // },
698
+ // ],
699
+ // },
700
+ // ],
701
+ // },
702
+ // ],
703
+ // },
704
+ // ],
705
+ // type: "tabs",
706
+ // defaultPanes: 1,
707
+ // additionalPanes: 0,
708
+ // id: "pane",
709
+ // tabBarExtraContent: {
710
+ // sections: [
711
+ // {
712
+ // type: "multicols",
713
+ // actionFields: [
714
+ // {
715
+ // cols: [
716
+ // {
717
+ // id: "add-version-button",
718
+ // metaType: "submit-button",
719
+ // type: "button",
720
+ // buttonType: "cancel",
721
+ // icon: "plus-circle-o",
722
+ // value: "New Version",
723
+ // customComponent: false,
724
+ // onlyDisplay: true,
725
+ // styling: "semantic",
726
+ // order: 3,
727
+ // fluid: false,
728
+ // submitAction: "addVersion",
729
+ // supportedEvents: {
730
+ // addVersion: this.addVersion,
731
+ // },
732
+ // },
733
+ // ],
734
+ // },
735
+ // ],
736
+ // inputFields: [],
737
+ // },
738
+ // ],
739
+ // },
740
+ // tabContent: {
741
+ // sections: [
742
+ // {
743
+ // type: "multicols",
744
+ // inputFields: [
745
+ // {
746
+ // rowStyle: {
747
+ // display: "flex",
748
+ // flex: 1,
749
+ // },
750
+ // cols: [
751
+ // {
752
+ // id: "tab-header",
753
+ // metaType: "label",
754
+ // value: "Version",
755
+ // primitive: true,
756
+ // dynamicTab: true,
757
+ // type: "div",
758
+ // width: 5,
759
+ // offset: 0,
760
+ // onlyDisplay: true,
761
+ // colStyle: {
762
+ // flex: 1,
763
+ // },
764
+ // supportedEvents: {
765
+ // onChange: this.onVersionNameChange,
766
+ // },
767
+ // },
768
+ // {
769
+ // id: "tab-options-popover",
770
+ // metaType: "display",
771
+ // colStyle: {
772
+ // flex: 0,
773
+ // },
774
+ // type: "popover",
775
+ // customComponent: false,
776
+ // styling: "semantic",
777
+ // order: 3,
778
+ // fluid: false,
779
+ // onlyDisplay: true,
780
+ // submitAction: "onTabOptionSelect",
781
+ // supportedEvents: {
782
+ // onTabOptionSelect: this.onTabOptionSelect,
783
+ // },
784
+ // content: {
785
+ // sections: [
786
+ // {
787
+ // type: "multicols",
788
+ // inputFields: [
789
+ // {
790
+ // cols: [
791
+ // {
792
+ // id: "mark-final-version-label",
793
+ // metaType: "label",
794
+ // type: "div",
795
+ // primitive: true,
796
+ // value: "Mark as Final",
797
+ // onlyDisplay: true,
798
+ // customComponent: false,
799
+ // order: 3,
800
+ // fluid: false,
801
+ // submitAction: "markFinalVersion",
802
+ // supportedEvents: {
803
+ // markFinalVersion: this.markFinalVersion,
804
+ // },
805
+ // },
806
+ // ],
807
+ // },
808
+ // {
809
+ // cols: [
810
+ // {
811
+ // id: "duplicate-version-label",
812
+ // metaType: "label",
813
+ // type: "div",
814
+ // primitive: true,
815
+ // value: "Duplicate",
816
+ // onlyDisplay: true,
817
+ // customComponent: false,
818
+ // order: 3,
819
+ // fluid: false,
820
+ // submitAction: "duplicateVersion",
821
+ // supportedEvents: {
822
+ // duplicateVersion: this.duplicateVersion,
823
+ // },
824
+ // },
825
+ // ],
826
+ // },
827
+ // {
828
+ // cols: [
829
+ // {
830
+ // id: "rename-version-label",
831
+ // metaType: "label",
832
+ // type: "div",
833
+ // primitive: true,
834
+ // value: "Rename",
835
+ // onlyDisplay: true,
836
+ // customComponent: false,
837
+ // order: 3,
838
+ // fluid: false,
839
+ // submitAction: "renameVersion",
840
+ // supportedEvents: {
841
+ // renameVersion: this.renameVersion,
842
+ // },
843
+ // },
844
+ // ],
845
+ // },
846
+ // {
847
+ // cols: [
848
+ // {
849
+ // id: "delete-version-label",
850
+ // metaType: "label",
851
+ // type: "div",
852
+ // primitive: true,
853
+ // value: "Delete",
854
+ // onlyDisplay: true,
855
+ // customComponent: false,
856
+ // order: 3,
857
+ // fluid: false,
858
+ // submitAction: "deleteVersion",
859
+ // supportedEvents: {
860
+ // deleteVersion: this.deleteVersion,
861
+ // },
862
+ // },
863
+ // ],
864
+ // },
865
+ // ],
866
+ // actionFields: [],
867
+ // },
868
+ // ],
869
+ // },
870
+ // value: {
871
+ // sections: [
872
+ // {
873
+ // type: "multicols",
874
+ // inputFields: [
875
+ // {
876
+ // cols: [
877
+ // {
878
+ // id: "tab-option-icon",
879
+ // metaType: "display",
880
+ // type: "icon",
881
+ // onlyDisplay: true,
882
+ // primitive: false,
883
+ // value: "&#xE313;",
884
+ // customComponent: false,
885
+ // order: 3,
886
+ // fluid: false,
887
+ // },
888
+ // ],
889
+ // },
890
+ // ],
891
+ // actionFields: [],
892
+ // },
893
+ // ],
894
+ // },
895
+ // trigger: "click",
896
+ // placement: "bottomRight",
897
+ // },
898
+ // ],
899
+ // },
900
+ // ],
901
+ // actionFields: [],
902
+ // },
903
+ // ],
904
+ // },
905
+ // label: "Version",
906
+ // supportedEvents: {
907
+ // onTabChange: this.onTabChange,
908
+ // },
909
+ // },
910
+ // ],
911
+ // channel: "SMS",
912
+ // module: "Campaigns",
913
+ // };
914
+ this.setState({ schema: this.props.metaEntities.layouts[0].definition });
915
+ }
916
+
917
+ validateFormData(formData) {
918
+ const tabCount = this.state.tabCount;
919
+ let isValid = true;
920
+ for (let cnt = 0; cnt < tabCount; cnt += 1) {
921
+ const index = cnt + 1;
922
+ if (formData[cnt]) {
923
+ const text = formData[cnt][`sms-editor${index > 1 ? index : ''}`];
924
+ if (text.indexOf('{{optout}}') === -1) {
925
+ isValid = false;
926
+ }
927
+ }
928
+ }
929
+ if (isValid) {
930
+
931
+ return true;
932
+ }
933
+
934
+ return false;
935
+ }
936
+
937
+ injectEvents(schema) {
938
+
939
+ const temp = schema;
940
+ temp.standalone.sections = this.injectSections(temp.standalone.sections);
941
+ _.forEach(temp.containers, (container) => {
942
+ let tempContainer = container;
943
+ tempContainer = this.injectContainer(tempContainer);
944
+ return tempContainer;
945
+ });
946
+ this.setState({schema});
947
+ return schema;
948
+ }
949
+
950
+ injectContainer(container) {
951
+ const temp = container;
952
+ if (temp.type === 'tabs') {
953
+ temp.tabContent.sections = this.injectSections(temp.tabContent.sections);
954
+ temp.tabBarExtraContent.sections = this.injectSections(temp.tabBarExtraContent.sections);
955
+ temp.tabContent.sections = this.injectSections(temp.tabContent.sections);
956
+ temp.injectedEvents = {};
957
+ _.forEach(temp.supportedEvents, (event) => {
958
+ temp.injectedEvents[event] = this.getMappedEvent(temp.id, event);
959
+ });
960
+ _.forEach(temp.panes, (pane) => {
961
+ const tempPane = pane;
962
+ tempPane.sections = this.injectSections(tempPane.sections);
963
+ });
964
+ }
965
+ return temp;
966
+ }
967
+
968
+ injectMultiColSection(section) {
969
+ _.forEach(section.inputFields, (inputField) => {
970
+ _.forEach(inputField.cols, (col) => {
971
+ let temp = col;
972
+ if (temp.type === 'popover') {
973
+ temp.content.sections = this.injectSections(temp.content.sections);
974
+ temp.value.sections = this.injectSections(temp.value.sections);
975
+ return true;
976
+ }
977
+ temp.injectedEvents = {};
978
+ _.forEach(col.supportedEvents, (event) => {
979
+ temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
980
+ });
981
+
982
+ temp = this.injectMessages(temp);
983
+ return true;
984
+ });
985
+ });
986
+ _.forEach(section.actionFields, (actionField) => {
987
+ _.forEach(actionField.cols, (col) => {
988
+ let temp = col;
989
+ if (temp.type === 'popover') {
990
+ temp.content.sections = this.injectSections(temp.content.sections);
991
+ temp.value.sections = this.injectSections(temp.value.sections);
992
+ return true;
993
+ }
994
+ temp.injectedEvents = {};
995
+ _.forEach(col.supportedEvents, (event) => {
996
+ temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
997
+ });
998
+
999
+ temp = this.injectMessages(temp);
1000
+ return true;
1001
+ });
1002
+ });
1003
+ return section;
1004
+ }
1005
+
1006
+ injectColLabelSection(section) {
1007
+ _.forEach(section.inputFields, (inputField) => {
1008
+ let temp = inputField;
1009
+ if (temp.type === 'popover') {
1010
+ temp.content.sections = this.injectSections(temp.content.sections);
1011
+ temp.value.sections = this.injectSections(temp.value.sections);
1012
+ return true;
1013
+ }
1014
+ temp.injectedEvents = {};
1015
+ _.forEach(inputField.supportedEvents, (event) => {
1016
+ temp.injectedEvents[event] = this.getMappedEvent(inputField.id, event);
1017
+ });
1018
+
1019
+ temp = this.injectMessages(temp);
1020
+ return true;
1021
+ });
1022
+ _.forEach(section.actionFields, (actionField) => {
1023
+ let temp = actionField;
1024
+ if (temp.type === 'popover') {
1025
+ temp.content.sections = this.injectSections(temp.content.sections);
1026
+ temp.value.sections = this.injectSections(temp.value.sections);
1027
+ return true;
1028
+ }
1029
+ temp.injectedEvents = {};
1030
+ _.forEach(actionField.supportedEvents, (event) => {
1031
+ temp.injectedEvents[event] = this.getMappedEvent(actionField.id, event);
1032
+ });
1033
+
1034
+ temp = this.injectMessages(temp);
1035
+ return true;
1036
+ });
1037
+ return section;
1038
+ }
1039
+
1040
+ injectSections(sections) {
1041
+ _.forEach(sections, (section) => {
1042
+ let temp = section;
1043
+ if (temp.type === 'col-label') {
1044
+ temp = this.injectColLabelSection(temp);
1045
+ } else if (section.type === 'multicols') {
1046
+ temp = this.injectMultiColSection(temp);
1047
+ } else if (section.type === 'parent') {
1048
+ temp = this.injectSections(temp.childSections);
1049
+ }
1050
+ });
1051
+ return sections;
1052
+ }
1053
+
1054
+ injectParentSection(section) {
1055
+ _.forEach(section.childSections, (childSection) => {
1056
+ let temp = childSection;
1057
+ if (temp.type === 'col-label') {
1058
+ temp = this.injectColLabelSection(temp);
1059
+ } else if (section.type === 'multicols') {
1060
+ temp = this.injectMultiColSection(temp);
1061
+ } else if (section.type === 'parent') {
1062
+ temp = this.injectParentSection(temp);
1063
+ }
1064
+ });
1065
+ return section;
1066
+ }
1067
+
1068
+ injectMessages(elem) {
1069
+ const temp = elem;
1070
+ if (temp.value && messages[temp.value]) {
1071
+ temp.value = this.props.intl.formatMessage(messages[temp.value]);
1072
+ }
1073
+ if (temp.label && messages[temp.label]) {
1074
+ temp.label = this.props.intl.formatMessage(messages[temp.label]);
1075
+ }
1076
+ if (temp.errorMessage && messages[temp.errorMessage]) {
1077
+ temp.errorMessage = this.props.intl.formatMessage(messages[temp.errorMessage]);
1078
+ }
1079
+ if (temp.placeholder && messages[temp.placeholder]) {
1080
+ temp.placeholder = this.props.intl.formatMessage(messages[temp.placeholder]);
1081
+ }
1082
+ return temp;
1083
+ }
1084
+
1085
+ cloneColLabel(sectionObj, tabIndex) {
1086
+ const section = _.cloneDeep(sectionObj);
1087
+ const inputFields = _.forEach(section.inputFields, (inputField) => {
1088
+ const inputF = inputField;
1089
+ inputF.id = `${inputField.id}${tabIndex}`;
1090
+ return inputF;
1091
+ });
1092
+ section.inputFields = inputFields;
1093
+ return section;
1094
+ }
1095
+
1096
+ cloneMultiCol(sectionObj, tabIndex) {
1097
+ const section = _.cloneDeep(sectionObj);
1098
+ const inputFields = _.forEach(section.inputFields, (inputField) => {
1099
+ const inputF = inputField;
1100
+ const cols = _.forEach(inputF.cols, (col) => {
1101
+ const colTemp = col;
1102
+ colTemp.id = `${col.id}${tabIndex}`;
1103
+ return colTemp;
1104
+ });
1105
+ inputF.cols = cols;
1106
+ return inputF;
1107
+ });
1108
+ section.inputFields = inputFields;
1109
+ return section;
1110
+ }
1111
+
1112
+ cloneParent(section, tabIndex) {
1113
+ const parentsect = section;
1114
+ const childSectionsBeforeCloning = parentsect.childSections.slice();
1115
+ const childSections = [];
1116
+ _.forEach(childSectionsBeforeCloning, (childSection) => {
1117
+ let sect = {};
1118
+ if (childSection.type === 'col-label') {
1119
+ sect = this.cloneColLabel(childSection, tabIndex);
1120
+ } else if (childSection.type === 'multicols') {
1121
+ sect = this.cloneMultiCol(childSection, tabIndex);
1122
+ } else if (childSection.type === 'parent') {
1123
+ sect = this.cloneParent(childSection, tabIndex);
1124
+ }
1125
+ childSections.push(sect);
1126
+ return true;
1127
+ });
1128
+ parentsect.childSections = childSections;
1129
+ return _.cloneDeep(parentsect);
1130
+ }
1131
+
1132
+ deleteVersion() {
1133
+ if (this.state.tabCount === 1) {
1134
+ return;
1135
+ }
1136
+ const schema = _.cloneDeep(this.state.schema);
1137
+ schema.containers[0].panes.splice(this.state.tabCount - 1, 1);
1138
+ schema.containers[0].tabBarExtraContent.sections[0].actionFields[0].cols[0].disabled = false;
1139
+ this.setState({schema, tabCount: this.state.tabCount - 1});
1140
+ }
1141
+
1142
+ renameVersion(data, currentTab) {
1143
+
1144
+ }
1145
+
1146
+ markFinalVersion(data, currentTab) {
1147
+ const message = getMessageObject('success', this.props.intl.formatMessage(messages.templateMarkedFinal), true);
1148
+ this.props.globalActions.addMessageToQueue(message);
1149
+
1150
+ }
1151
+
1152
+ duplicateVersion(data, currentTab) {
1153
+
1154
+ this.addVersion(this.state.tabCount);
1155
+ }
1156
+
1157
+ cancelTemplate() {
1158
+ const type = this.props.location.query.type;
1159
+ const module = this.props.location.query.module;
1160
+ this.props.router.push({
1161
+ pathname: `/sms/`,
1162
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
1163
+ });
1164
+ }
1165
+
1166
+ addVersion(data, addNow) {
1167
+
1168
+ let tabIndex = data + 1;
1169
+ const schema = _.cloneDeep(this.state.schema);
1170
+ const containers = schema.containers.slice();
1171
+ const panes = containers[0].panes.slice();
1172
+ if (addNow && data === 1) {
1173
+ for (let idx = 1; idx < addNow; idx += 1) {
1174
+ const sections = [];
1175
+ const firstPane = _.cloneDeep(panes[0]);
1176
+ tabIndex = idx + 1;
1177
+ _.forEach(firstPane.sections, (section) => { // eslint-disable-line no-loop-func
1178
+ let sect = _.cloneDeep(section);
1179
+ if (sect.type === 'col-label') {
1180
+ sect = this.cloneColLabel(sect, tabIndex);
1181
+ } else if (sect.type === 'multicols') {
1182
+ sect = this.cloneMultiCol(sect, tabIndex);
1183
+ } else if (sect.type === 'parent') {
1184
+ sect = this.cloneParent(sect, tabIndex);
1185
+ }
1186
+ sections.push(sect);
1187
+ return true;
1188
+ });
1189
+ firstPane.sections = sections;
1190
+ schema.containers[0].panes.push(firstPane);
1191
+
1192
+ if (tabIndex === 5) {
1193
+ schema.containers[0].tabBarExtraContent.sections[0].actionFields[0].cols[0].disabled = true;
1194
+ }
1195
+ }
1196
+ if (schema) {
1197
+ this.setState({schema});
1198
+ }
1199
+ } else if (!addNow) {
1200
+ const sections = [];
1201
+ const firstPane = _.cloneDeep(panes[0]);
1202
+ _.forEach(firstPane.sections, (section) => {
1203
+ let sect = _.cloneDeep(section);
1204
+ if (sect.type === 'col-label') {
1205
+ sect = this.cloneColLabel(sect, tabIndex);
1206
+ } else if (sect.type === 'multicols') {
1207
+ sect = this.cloneMultiCol(sect, tabIndex);
1208
+ } else if (sect.type === 'parent') {
1209
+ sect = this.cloneParent(sect, tabIndex);
1210
+ }
1211
+ sections.push(sect);
1212
+ return true;
1213
+ });
1214
+ firstPane.sections = sections;
1215
+ schema.containers[0].panes.push(firstPane);
1216
+
1217
+ if (tabIndex === 5) {
1218
+ schema.containers[0].tabBarExtraContent.sections[0].actionFields[0].cols[0].disabled = true;
1219
+ }
1220
+ if (schema) {
1221
+ this.setState({schema});
1222
+ }
1223
+ }
1224
+ }
1225
+
1226
+ insertAtCursor(field, myValue, currentTab) {
1227
+ //IE support
1228
+ const myField = field;
1229
+ if (document.selection) {
1230
+ myField.focus();
1231
+ const sel = document.selection.createRange();
1232
+ sel.text = myValue;
1233
+ } else if (myField.selectionStart || myField.selectionStart === '0') { //MOZILLA and others
1234
+ const startPos = myField.selectionStart;
1235
+ const endPos = myField.selectionEnd;
1236
+ myField.value = myField.value.substring(0, startPos)
1237
+ + myValue
1238
+ + myField.value.substring(endPos, myField.value.length);
1239
+ myField.selectionStart = startPos + myValue.length;
1240
+ myField.selectionEnd = startPos + myValue.length;
1241
+ } else {
1242
+ myField.value += myValue;
1243
+ }
1244
+ const formData = _.cloneDeep(this.state.formData);
1245
+ formData[currentTab - 1][field.id] = myField.value;
1246
+ formData.base[field.id] = myField.value;
1247
+ this.setState({formData});
1248
+ }
1249
+
1250
+ handleFrameTasks = (e) => {
1251
+
1252
+ const type = e.data;
1253
+ if (typeof type === 'object') {
1254
+
1255
+ const action = type.action;
1256
+ switch (action) {
1257
+ case "startTemplateCreation":
1258
+ this.startTemplateCreation(type.value);
1259
+ break;
1260
+ case "startLoading":
1261
+ this.startLoading(type.edit);
1262
+ break;
1263
+ case "getCurrentWindow":
1264
+ this.getCurrentWindow(type);
1265
+ break;
1266
+ case "getFormData":
1267
+ this.getFormData(e, type.value);
1268
+ break;
1269
+ default:
1270
+ break;
1271
+ }
1272
+ }
1273
+ switch (type) {
1274
+ case "getFormData":
1275
+ this.getFormData(e);
1276
+ break;
1277
+ case "startTemplateCreation":
1278
+
1279
+ //this.getFormData(e);
1280
+ break;
1281
+ case "moveToTemplates":
1282
+
1283
+ this.moveToTemplates();
1284
+ break;
1285
+ case "validateContent":
1286
+
1287
+ this.validateContent(e);
1288
+ break;
1289
+ default:
1290
+ break;
1291
+ }
1292
+ }
1293
+
1294
+ removeStandAlone() {
1295
+ let formData = _.cloneDeep(this.state.formData);
1296
+
1297
+ let baseFormData = {};
1298
+ const oldBaseKeys = formData[0];
1299
+ let baseIndex = -1;
1300
+ let basePane = {};
1301
+ for (let idx = 0; idx < this.state.tabCount; idx += 1 ) {
1302
+ if (!formData[idx].base) {
1303
+ delete formData[idx];
1304
+ } else {
1305
+ baseFormData = formData[idx];
1306
+ baseIndex = idx;
1307
+ }
1308
+ }
1309
+ formData = {};
1310
+ formData[0] = {};
1311
+ _.forEach(oldBaseKeys, (val, key) => {
1312
+ if (key === 'tabKey') {
1313
+ formData[0].tabKey = baseFormData.tabKey;
1314
+ } else if (key === 'base') {
1315
+ formData[0].base = baseFormData.base;
1316
+ } else if (key === 'unicode-validity') {
1317
+ formData[0]['unicode-validity'] = false;
1318
+ } else {
1319
+ formData[0][key] = baseFormData[`${key}${baseIndex + 1 > 1 ? baseIndex + 1 : ''}`];
1320
+ }
1321
+ });
1322
+ formData.base = formData[0];
1323
+ const schema = _.cloneDeep(this.state.schema);
1324
+ delete schema.standalone;
1325
+ schema.standalone = {};
1326
+ schema.standalone.sections = [];
1327
+ _.forEach(schema.containers, (container) => {
1328
+ const temp = container;
1329
+ if (temp.type === 'tabs') {
1330
+ temp.tabBarExtraContent = {};
1331
+ temp.tabBarExtraContent.sections = [];
1332
+ basePane = _.cloneDeep(temp.panes[0]);
1333
+ temp.tabContent = {};
1334
+ temp.tabContent.sections = [];
1335
+ temp.panes = [];
1336
+ temp.panes.push(basePane);
1337
+ }
1338
+ });
1339
+
1340
+ this.setState({ schema, formData, tabCount: 1, tabKey: formData.base.tabKey, currentTab: 1 });
1341
+ }
1342
+
1343
+ validateContent = (e) => {
1344
+
1345
+ const response = {
1346
+ action: "validateContent",
1347
+ value: this.state.isFormValid,
1348
+ };
1349
+ // if (content.indexOf('{{optout}}') === -1) {
1350
+ // const message = getMessageObject('error', 'Template data is not valid', true);
1351
+ // this.props.globalActions.addMessageToQueue(message);
1352
+ // response.value = 'invalid';
1353
+ // }
1354
+
1355
+ e.source.postMessage(JSON.stringify(response), e.origin);
1356
+ }
1357
+
1358
+ handleCancelModal = () => {
1359
+ this.setState({showModal: false});
1360
+ }
1361
+
1362
+ saveFormData(formData) {
1363
+ //Logic to save in db etc
1364
+
1365
+ const obj = _.cloneDeep(this.state.editData);
1366
+ obj.versions = {
1367
+ base: {},
1368
+ history: [],
1369
+ };
1370
+ for (let index = 0; index < this.state.tabCount; index += 1 ) {
1371
+ obj.versions.history.push(formData[index]);
1372
+ }
1373
+ obj.name = formData['template-name'];
1374
+ obj.versions.base = formData.base;
1375
+
1376
+ this.props.actions.editTemplate(obj);
1377
+ }
1378
+ render() {
1379
+ const schema = this.state.schema;
1380
+ let tipText = this.props.Edit && ("getTemplateDetailsInProgress" in this.props.Edit && this.props.Edit.getTemplateDetailsInProgress) ? this.props.intl.formatMessage(messages.getTemplateDetailsLoader) : '';
1381
+ tipText = this.props.Edit && ("editTemplateInProgress" in this.props.Edit && this.props.Edit.editTemplateInProgress) ? this.props.intl.formatMessage(messages.saveTemplateLoader) : '';
1382
+ const spinning = this.state.loading || (this.props.Edit && (("getTemplateDetailsInProgress" in this.props.Edit && this.props.Edit.getTemplateDetailsInProgress) || ("editTemplateInProgress" in this.props.Edit && this.props.Edit.editTemplateInProgress)));
1383
+ let tags = this.props.metaEntities && this.props.metaEntities.tags && this.props.metaEntities.tags.standard ? this.props.metaEntities.tags.standard : [];
1384
+ if (this.props.location.query.type === 'embedded' && this.props.location.query.module === 'library' && !this.props.getDefaultTags) {
1385
+ tags = this.props.supportedTags;
1386
+ }
1387
+ return (
1388
+ <div>
1389
+ <Spin tip={tipText} spinning={spinning}>
1390
+ {/*<Row style={{marginBottom: '16px', marginLeft: '-40px'}}>
1391
+ <Col offset={1}>
1392
+ <Breadcrumb>
1393
+ <Breadcrumb.Item>Campaigns</Breadcrumb.Item>
1394
+ <Breadcrumb.Item>Creatives</Breadcrumb.Item>
1395
+ <Breadcrumb.Item>SMS</Breadcrumb.Item>
1396
+ </Breadcrumb>
1397
+ </Col>
1398
+ </Row>*/}
1399
+ <Row>
1400
+ <Col>
1401
+ <FormBuilder
1402
+ schema={schema}
1403
+ onSubmit={this.saveFormData}
1404
+ onChange={this.onFormDataChange}
1405
+ formData={this.state.formData}
1406
+ tabCount={this.state.tabCount}
1407
+ currentTab={this.state.currentTab}
1408
+ parent={this}
1409
+ iframeParent={parent}
1410
+ location={this.props.location}
1411
+ isEdit
1412
+ showModal={this.state.showModal}
1413
+ modal={this.state.modalContent}
1414
+ tags={tags}
1415
+ tagModule={this.props.getDefaultTags}
1416
+ injectedTags={this.props.injectedTags ? this.props.injectedTags : {}}
1417
+ onFormValidityChange={this.setFormValidity}
1418
+ usingTabContainer
1419
+ checkValidation={this.state.checkValidation}
1420
+ onContextChange={this.handleOnTagsContextChange}
1421
+ handleCancelModal={this.handleCancelModal}
1422
+ router={this.props.router}
1423
+ />
1424
+ </Col>
1425
+ </Row>
1426
+ </Spin>
1427
+ </div>
1428
+ );
1429
+ }
1430
+ }
1431
+
1432
+ Edit.propTypes = {
1433
+ actions: PropTypes.object.isRequired,
1434
+ Edit: PropTypes.object,
1435
+ params: PropTypes.object,
1436
+ router: PropTypes.object,
1437
+ location: PropTypes.object,
1438
+ globalActions: PropTypes.object,
1439
+ metaEntities: PropTypes.object,
1440
+ intl: intlShape.isRequired,
1441
+ templateData: PropTypes.object,
1442
+ supportedTags: PropTypes.array,
1443
+ getDefaultTags: PropTypes.string,
1444
+ // route: PropTypes.object,
1445
+ injectedTags: PropTypes.object,
1446
+ };
1447
+
1448
+ const mapStateToProps = createStructuredSelector({
1449
+ Edit: makeSelectEdit(),
1450
+ editResponse: makeSelectEditResponse(),
1451
+ templateDetails: makeSelectTemplateDetailsResponse(),
1452
+ metaEntities: makeSelectMetaEntities(),
1453
+ injectedTags: setInjectedTags(),
1454
+ });
1455
+
1456
+ function mapDispatchToProps(dispatch) {
1457
+ return {
1458
+ actions: bindActionCreators(actions, dispatch),
1459
+ globalActions: bindActionCreators(globalActions, dispatch),
1460
+ };
1461
+ }
1462
+
1463
+ const withConnect = connect(mapStateToProps, mapDispatchToProps);
1464
+ const withReducer = injectReducer({ key: 'edit', reducer });
1465
+ const withEditSmsSaga = injectSaga({ key: 'edit', saga: editSmsSaga });
1466
+
1467
+ export default compose(
1468
+ UserIsAuthenticated,
1469
+ withEditSmsSaga,
1470
+ withReducer,
1471
+ withConnect,
1472
+ )(injectIntl(Edit));