@capillarytech/creatives-library 0.1.14 → 0.1.16

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.
@@ -940,6 +940,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
940
940
 
941
941
  skipTags(tag) {
942
942
  const regexGroups = ["dynamic_expiry_date_after_\\d+_days.FORMAT_\\d", "user_id_b64", "outbox_id_b64", "unsubscribe\\(#[a-zA-Z\\d]{6}\\)","Link_to_[a-zA-z]"];
943
+
943
944
  //const regexGroups = [];
944
945
  let skipped = false;
945
946
  _.forEach(regexGroups, (group) => {
@@ -60,6 +60,12 @@
60
60
  left: 30%;
61
61
  width: 30%;
62
62
  }
63
+
64
+ img{
65
+ width: 100%;
66
+ object-fit: cover; // try contain
67
+ height: 100%;
68
+ }
63
69
  }
64
70
 
65
71
  .overlay {
@@ -105,3 +111,16 @@
105
111
  }
106
112
  }
107
113
  }
114
+
115
+ #slidebox-content{
116
+ img{
117
+ display: block;
118
+ max-width: 100%;
119
+ margin: 0 auto;
120
+ }
121
+ }
122
+
123
+ #slidebox-container{
124
+ left: 40vw !important;
125
+ width: 60vw !important;
126
+ }
@@ -69,6 +69,7 @@ export class Gallery extends React.Component { // eslint-disable-line react/pref
69
69
  }
70
70
 
71
71
  componentWillReceiveProps(nextProps) {
72
+ console.log("nextProps", nextProps);
72
73
  if ( !_.isEqual(nextProps.Gallery.uploadAssetSuccess, this.props.Gallery.uploadAssetSuccess) && nextProps.Gallery.uploadAssetSuccess) {
73
74
  if (this.props.location.query.type === 'embedded' && nextProps.Gallery.uploadedAssetData) {
74
75
  console.log('Post on will receive props');
@@ -106,19 +107,27 @@ export class Gallery extends React.Component { // eslint-disable-line react/pref
106
107
  const message = getMessageObject('error', this.props.intl.formatMessage(messages.assetDeleteFailed), true);
107
108
  this.props.globalActions.addMessageToQueue(message);
108
109
  }
110
+ if ( nextProps.Gallery.itemDeleted || !nextProps.Gallery.assetUploading) {
111
+ const params = {
112
+ name: this.state.searchText,
113
+ sortBy: 'Most Recent',
114
+ };
115
+ this.getAllAssets({params}, true);
116
+ }
109
117
  }
110
118
 
111
119
  componentWillUnmount() {
112
120
  window.removeEventListener("message", this.handleGallery, false);
113
121
  }
114
122
 
115
- getAllAssets = ({params, getNextPage, resetPage}) => {
123
+ getAllAssets = ({params, getNextPage, resetPage}, isReRender = false) => {
116
124
  let queryParams = params;
117
125
  let page = this.state.page;
118
- if (!this.props.Gallery.fetchingAllAssets && (resetPage || (page === 1 && this.state.totalCount === 0) || page <= (this.state.totalCount / this.state.perPageLimit))) {
126
+ if (!this.props.Gallery.fetchingAllAssets && ((resetPage || (page === 1 && this.state.totalCount === 0) || page <= (this.state.totalCount / this.state.perPageLimit)) || isReRender )) {
119
127
  if (getNextPage) {
120
128
  page += 1;
121
129
  }
130
+
122
131
  let totalCount = this.state.totalCount;
123
132
  if (resetPage) {
124
133
  page = 1;
@@ -226,17 +235,19 @@ export class Gallery extends React.Component { // eslint-disable-line react/pref
226
235
  uploadImages(e, {files}) {
227
236
  e.preventDefault();
228
237
  const _URL = window.URL || window.webkitURL;
229
- const file = files[0];
230
- const img = new Image();
231
- const that = this;
232
- img.src = _URL.createObjectURL(file);
233
- img.onload = function () {
234
- const fileParams = {
235
- width: this.width,
236
- height: this.height,
238
+ //const file = files[0];
239
+ for (let file in files){
240
+ const img = new Image();
241
+ const that = this;
242
+ img.src = _URL.createObjectURL(files[file]);
243
+ img.onload = function () {
244
+ const fileParams = {
245
+ width: this.width,
246
+ height: this.height,
247
+ };
248
+ that.props.actions.uploadAsset(files[file], 'image', fileParams);
237
249
  };
238
- that.props.actions.uploadAsset(file, 'image', fileParams);
239
- };
250
+ }
240
251
  }
241
252
 
242
253
  prepareData() {
@@ -300,7 +311,7 @@ export class Gallery extends React.Component { // eslint-disable-line react/pref
300
311
  <img style={{maxWidth: '100%', maxHeight: '100%'}} src={this.state.selectedAsset.metaInfo.secure_file_path ? this.state.selectedAsset.metaInfo.secure_file_path : this.state.selectedAsset.metaInfo.public_url} alt={this.state.selectedAsset.name} />
301
312
  </div>
302
313
  </div>
303
- <a href={this.state.selectedAsset.metaInfo.public_url} target="_blank" style={{ position: 'fixed', right: '24px', bottom: '17vh' }} ><i className="material-icons" style={{ color: '#2E89DF', cursor: 'pointer' }}>fullscreen</i></a>
314
+ <a href={this.state.selectedAsset.metaInfo.public_url} target="_blank" style={{ position: 'fixed', right: '55px', bottom: '18vh' }} ><i className="material-icons" style={{ color: '#2E89DF', cursor: 'pointer' }}>fullscreen</i></a>
304
315
  </div>
305
316
  <div style={{ fontSize: '14px', color: '#333333', lineHeight: '24px', fontFamily: 'OpenSans', textAlign: 'center', paddingTop: '10px'}}>
306
317
  <p style={{marginBottom: '0px'}}><span><FormattedMessage {...messages.dimensions} />: </span> <span>{`${this.state.selectedAsset.metaInfo.width}X${this.state.selectedAsset.metaInfo.height} px`}</span></p>
@@ -357,7 +368,7 @@ export class Gallery extends React.Component { // eslint-disable-line react/pref
357
368
  );
358
369
  const actionComponents = (
359
370
  <form encType="multipart/form-data" id="myForm">
360
- <input style={{ display: 'none'}} id="fileName" type="file" onChange={(e) => this.uploadImages(e, {files: e.target.files})} accept="image/*" />
371
+ <input style={{ display: 'none'}} id="fileName" type="file" onChange={(e) => this.uploadImages(e, {files: e.target.files})} accept="image/*" multiple/>
361
372
  <CapButton type={this.props.location.query.type !== 'embedded' ? 'primary' : 'secondary'} onClick={(e) => this.openFileDialog(e)} style={{float: 'right'}}>
362
373
  <FormattedMessage {...messages.upload} />
363
374
  </CapButton>
@@ -367,7 +378,7 @@ export class Gallery extends React.Component { // eslint-disable-line react/pref
367
378
 
368
379
  return (
369
380
  <div>
370
- <Spin spinning={this.props.Gallery.assetUploading || this.props.Gallery.fetchingAllAssets}>
381
+ {/*<Spin spinning={this.props.Gallery.assetUploading || this.props.Gallery.fetchingAllAssets}>*/}
371
382
  <Helmet
372
383
  title="Gallery"
373
384
  />
@@ -410,19 +421,21 @@ export class Gallery extends React.Component { // eslint-disable-line react/pref
410
421
  </div>
411
422
  </div>
412
423
  </div> :
413
- <Pagination onPageChange={() => { this.getAllAssets({getNextPage: true}); }} paginationSelector="pagination-container">
414
- <CardGrid
415
- listItem={this.prepareData()}
416
- filterContent={filterContent}
417
- onHoverItem={this.handleOnHoverItem}
418
- onItemClick={this.handleOnHoverItem}
419
- colNumber={this.props.location.query.type === 'embedded' ? 2 : 4}
420
- enablePagination
421
- />
422
- </Pagination>
424
+ <Spin spinning={this.props.Gallery.assetUploading || this.props.Gallery.fetchingAllAssets}>
425
+ <Pagination onPageChange={() => { this.getAllAssets({getNextPage: true}); }} paginationSelector="pagination-container">
426
+ <CardGrid
427
+ listItem={this.prepareData()}
428
+ filterContent={filterContent}
429
+ onHoverItem={this.handleOnHoverItem}
430
+ onItemClick={this.handleOnHoverItem}
431
+ colNumber={this.props.location.query.type === 'embedded' ? 2 : 4}
432
+ enablePagination
433
+ />
434
+ </Pagination>
435
+ </Spin>
423
436
  }
424
437
  {this.state.showImagePreviewModal && this.renderAssetPreviewModal()}
425
- </Spin>
438
+ {/*</Spin>*/}
426
439
  </div>
427
440
  );
428
441
  }
@@ -50,14 +50,14 @@ function galleryReducer(state = initialState, action) {
50
50
  case types.DELETE_ASSET_REQUEST:
51
51
  return state
52
52
  .set('deletingAsset', true)
53
- .set('assetDeleteError', false);
53
+ .set('assetDeleteError', false).set("itemDeleted", false);
54
54
  case types.DELETE_ASSET_SUCCESS:
55
55
  return state
56
- .set('deletingAsset', false);
56
+ .set('deletingAsset', false).set("itemDeleted", true);
57
57
  case types.DELETE_ASSET_FAILURE:
58
58
  return state
59
59
  .set('deletingAsset', false)
60
- .set('assetDeleteError', true);
60
+ .set('assetDeleteError', true).set("itemDeleted", false);
61
61
  case types.GET_USER_LIST_REQUEST:
62
62
  return state
63
63
  .set('fetchingUserList', true)
@@ -24,7 +24,7 @@ export function* uploadAsset(file, assetType, fileParams) {
24
24
  export function* deleteAssetById(assetId, assetType) {
25
25
  try {
26
26
  const result = yield call(Api.deleteAssetById, assetId, assetType);
27
- console.log(result);
27
+ console.log({"delete Asset Id": result});
28
28
  yield put({ type: types.DELETE_ASSET_SUCCESS, data: result.response });
29
29
  } catch (error) {
30
30
  yield put({ type: types.DELETE_ASSET_FAILURE, error });
@@ -765,7 +765,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
765
765
  const newSchema = this.injectEvents(nextProps.metaEntities.layouts[0].definition);
766
766
  console.log('Schema test 1 ', newSchema);
767
767
  this.setState({schema: newSchema});
768
- if (this.props.location.query.module !== 'library') {
768
+ if (this.props.location.query.module !== 'library' || (this.props.location.query.module === 'library' && this.props.getDefaultTags)) {
769
769
  const query = {
770
770
  layout: 'EMAIL',
771
771
  type: 'TAG',
@@ -3247,6 +3247,7 @@ Email.propTypes = {
3247
3247
  isGetFormData: PropTypes.bool,
3248
3248
  getFormSubscriptionData: PropTypes.func,
3249
3249
  supportedTags: PropTypes.array,
3250
+ getDefaultTags: PropTypes.bool,
3250
3251
  };
3251
3252
 
3252
3253
  const mapStateToProps = createStructuredSelector({
@@ -147,7 +147,7 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
147
147
  if (nextProps.metaEntities && nextProps.metaEntities.layouts && nextProps.metaEntities.layouts.length > 0 && _.isEmpty(this.state.schema)) {
148
148
  console.log('final schema is**', nextProps.metaEntities.layouts[0].definition);
149
149
  this.injectEvents(nextProps.metaEntities.layouts[0].definition);
150
- if (this.props.location.query.module !== 'library') {
150
+ if (this.props.location.query.module !== 'library' || (this.props.location.query.module === 'library' && this.props.getDefaultTags)) {
151
151
  const query = {
152
152
  layout: 'SMS',
153
153
  type: 'TAG',
@@ -239,6 +239,9 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
239
239
  }
240
240
  const result = {};
241
241
  result.base = baseData;
242
+ const msgObj = charCount.updateCharCount(baseData['sms-editor']);
243
+ result.base.msg_count = msgObj.msgCount;
244
+ console.log("Message Count", msgObj.msgCount);
242
245
  const response = {
243
246
  action: "getFormData",
244
247
  value: result,
@@ -1459,6 +1462,7 @@ Create.propTypes = {
1459
1462
  metaEntities: PropTypes.object,
1460
1463
  intl: intlShape.isRequired,
1461
1464
  supportedTags: PropTypes.array,
1465
+ getDefaultTags: PropTypes.bool,
1462
1466
  };
1463
1467
 
1464
1468
  const mapStateToProps = createStructuredSelector({
@@ -89,7 +89,11 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
89
89
  }
90
90
  componentDidMount() {
91
91
  if (this.props.location.query && this.props.location.query.module === 'library') {
92
- this.props.actions.setTemplateDetails(this.props.templateData);
92
+ if (this.props.params.id) {
93
+ this.props.actions.getTemplateDetails(this.props.params.id);
94
+ } else {
95
+ this.props.actions.setTemplateDetails(this.props.templateData);
96
+ }
93
97
  } else {
94
98
  this.props.actions.getTemplateDetails(this.props.params.id);
95
99
  }
@@ -123,7 +127,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
123
127
  this.setState({schema: nextProps.metaEntities.layouts[0].definition}, () => {
124
128
  this.injectEvents(nextProps.metaEntities.layouts[0].definition);
125
129
  });
126
- if (this.props.location.query.module !== 'library') {
130
+ if (this.props.location.query.module !== 'library' || (this.props.location.query.module === 'library' && this.props.getDefaultTags)) {
127
131
  const query = {
128
132
  layout: 'SMS',
129
133
  type: 'TAG',
@@ -279,6 +283,9 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
279
283
  }
280
284
  const result = {};
281
285
  result.base = baseData;
286
+ const msgObj = charCount.updateCharCount(baseData['sms-editor']);
287
+ result.base.msg_count = msgObj.msgCount;
288
+ console.log("Message Count", msgObj.msgCount);
282
289
  const response = {
283
290
  action: "getFormData",
284
291
  value: result,
@@ -1438,6 +1445,7 @@ Edit.propTypes = {
1438
1445
  intl: intlShape.isRequired,
1439
1446
  templateData: PropTypes.object,
1440
1447
  supportedTags: PropTypes.array,
1448
+ getDefaultTags: PropTypes.bool,
1441
1449
  // route: PropTypes.object,
1442
1450
  };
1443
1451
 
@@ -64,6 +64,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
64
64
  showHtmlPreview: false,
65
65
  device: 'desktop',
66
66
  searchedTemplates: false,
67
+ defaultAccount: true,
67
68
  };
68
69
  this.handleOnHoverItem = this.handleOnHoverItem.bind(this);
69
70
  this.handleOnItemClick = this.handleOnItemClick.bind(this);
@@ -159,12 +160,14 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
159
160
  if (nextProps.route.name.toLowerCase() === 'sms') {
160
161
  channel = 'Sms';
161
162
  } else if (nextProps.route.name.toLowerCase() === 'wechat') {
163
+ this.setState({defaultAccount: true});
162
164
  channel = 'wechat';
163
165
  nextProps.actions.getWeCrmAccounts();
164
166
  } else if (nextProps.route.name.toLowerCase() === 'email') {
165
167
  channel = 'Email';
166
168
  // this.props.actions.getEdmDefaultTemplates();
167
169
  } else if (nextProps.route.name.toLowerCase() === "mobilepush") {
170
+ this.setState({defaultAccount: true});
168
171
  channel = "mobilepush";
169
172
  nextProps.actions.getWeCrmAccounts(channel);
170
173
  } else if (nextProps.route.name.toLowerCase() === 'ebill') {
@@ -302,12 +305,31 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
302
305
  if (!_.isEmpty(nextProps.Templates.templateDetails) && !_.isEqual(nextProps.Templates.templateDetails, this.props.Templates.templateDetails)) {
303
306
  this.setState({previewTemplate: nextProps.Templates.templateDetails});
304
307
  }
308
+
309
+ if (nextProps.Templates.weCrmAccounts !== undefined && nextProps.Templates.weCrmAccounts.length === 1 && this.state.defaultAccount ) {
310
+ const paramsDefault = {
311
+ name: this.state.searchText,
312
+ sortBy: this.state.sortBy,
313
+ };
314
+ if (this.state.channel.toLowerCase() === 'wechat') {
315
+ paramsDefault.wecrmId = nextProps.Templates.weCrmAccounts[0].configs.wecrm_app_id;
316
+ paramsDefault.wecrmToken = nextProps.Templates.weCrmAccounts[0].configs.wecrm_token;
317
+ nextProps.actions.setWeChatAccount(nextProps.Templates.weCrmAccounts[0]);
318
+ this.setState({defaultAccount: false});
319
+ } else if (this.state.channel.toLowerCase() === 'mobilepush') {
320
+ nextProps.actions.setWeChatAccount(nextProps.Templates.weCrmAccounts[0]);
321
+ paramsDefault.accountId = nextProps.Templates.weCrmAccounts[0].id;
322
+ this.setState({defaultAccount: false});
323
+ }
324
+ this.getAllTemplates({params: paramsDefault}, true);
325
+ }
305
326
  }
306
327
 
307
328
  componentWillUnmount() {
308
329
  console.log('removed listener templates');
309
330
  window.removeEventListener("message", this.handleFrameTasks);
310
331
  this.props.actions.resetTemplateStoreData();
332
+ // this.setState({defaultAccount: false});
311
333
  }
312
334
 
313
335
  onAccountSelect(value, option) {
@@ -978,7 +1000,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
978
1000
  console.log('Data Prepare');
979
1001
  const imgSrc = template && template.versions && template.versions.base ? template.versions.base.preview_http_url : '';
980
1002
  const ifPreviewGenerated = template && template.versions && template.versions.base ? template.versions.base.isPreviewGenerated : 0;
981
- content = <img src={imgSrc || ''} alt={this.props.intl.formatMessage(messages.previewGenerateText)} />;
1003
+ content = <img src={imgSrc || ''} alt={this.props.intl.formatMessage(messages.previewGenerateText)} width="100%" height="100%"/>;
982
1004
  console.log('qwerty template preview', imgSrc, template, ifPreviewGenerated, content);
983
1005
  temp.content = (
984
1006
  <div
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "0.1.14",
4
+ "version": "0.1.16",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -1,351 +0,0 @@
1
- /* eslint-disable */
2
- import Jed from './jed';
3
-
4
- const l10n = {};
5
- const i18n = new Jed(l10n);
6
- let settings;
7
-
8
- function smsCounter(options, chars) {
9
- settings = Object.assign({
10
- smsCount: 160,
11
- }, options);
12
- return updateSmsData(chars); //this.each(function() {
13
- // if (!skipObj) {
14
- // this.keyup(updateSmsData);
15
- // } else {
16
- // updateSmsData();
17
- // }
18
- // });
19
- }
20
-
21
- let updateSmsData = (chars) => {
22
- let skipObj = false;
23
- let msgContent;
24
- if (chars !== undefined && chars !== "" && chars !== false && chars !== true) {
25
- skipObj = true;
26
- }
27
- if (skipObj) {
28
- msgContent = chars;
29
- } else {
30
- // msgContent = $(this).val();
31
- }
32
-
33
- const charset7bit = {
34
- '@': 1,
35
- '$': 1,
36
- "\n": 1,
37
- "\r": 1,
38
- '_': 1,
39
- ' ': 1,
40
- '!': 1,
41
- '"': 1,
42
- '#': 1,
43
- '%': 1,
44
- '&': 1,
45
- "'": 1,
46
- '(': 1,
47
- ')': 1,
48
- '*': 1,
49
- '+': 1,
50
- ',': 1,
51
- '-': 1,
52
- '.': 1,
53
- '/': 1,
54
- '0': 1,
55
- '1': 1,
56
- '2': 1,
57
- '3': 1,
58
- '4': 1,
59
- '5': 1,
60
- '6': 1,
61
- '7': 1,
62
- '8': 1,
63
- '9': 1,
64
- ':': 1,
65
- ';': 1,
66
- '<': 1,
67
- '=': 1,
68
- '>': 1,
69
- '?': 1,
70
- '¡': 1,
71
- 'A': 1,
72
- 'B': 1,
73
- 'C': 1,
74
- 'D': 1,
75
- 'E': 1,
76
- 'F': 1,
77
- 'G': 1,
78
- 'H': 1,
79
- 'I': 1,
80
- 'J': 1,
81
- 'K': 1,
82
- 'L': 1,
83
- 'M': 1,
84
- 'N': 1,
85
- 'O': 1,
86
- 'P': 1,
87
- 'Q': 1,
88
- 'R': 1,
89
- 'S': 1,
90
- 'T': 1,
91
- 'U': 1,
92
- 'V': 1,
93
- 'W': 1,
94
- 'X': 1,
95
- 'Y': 1,
96
- 'Z': 1,
97
- 'a': 1,
98
- 'b': 1,
99
- 'c': 1,
100
- 'd': 1,
101
- 'e': 1,
102
- 'f': 1,
103
- 'g': 1,
104
- 'h': 1,
105
- 'i': 1,
106
- 'j': 1,
107
- 'k': 1,
108
- 'l': 1,
109
- 'm': 1,
110
- 'n': 1,
111
- 'o': 1,
112
- 'p': 1,
113
- 'q': 1,
114
- 'r': 1,
115
- 's': 1,
116
- 't': 1,
117
- 'u': 1,
118
- 'v': 1,
119
- 'w': 1,
120
- 'x': 1,
121
- 'y': 1,
122
- 'z': 1,
123
- "\f": 2,
124
- '^': 2,
125
- '{': 2,
126
- '}': 2,
127
- '\\': 2,
128
- '[': 2,
129
- '~': 2,
130
- ']': 2,
131
- '|': 2,
132
- 'è': 1,
133
- 'é': 1,
134
- 'ù': 1,
135
- 'ì': 1,
136
- 'ò': 1,
137
- 'Ç': 1,
138
- 'Ø': 1,
139
- 'ø': 1,
140
- 'Å': 1,
141
- 'å': 1,
142
- 'Δ': 1,
143
- 'Φ': 1,
144
- 'Γ': 1,
145
- 'Λ': 1,
146
- 'Ω': 1,
147
- 'Π': 1,
148
- 'Ψ': 1,
149
- 'Σ': 1,
150
- 'Θ': 1,
151
- 'Ξ': 1,
152
- 'Æ': 1,
153
- 'æ': 1,
154
- 'ß': 1,
155
- 'É': 1,
156
- 'Ä': 1,
157
- 'Ö': 1,
158
- 'Ñ': 1,
159
- 'Ü': 1,
160
- 'ä': 1,
161
- 'ö': 1,
162
- 'ñ': 1,
163
- 'ü': 1,
164
- 'à': 1,
165
- '£': 1,
166
- '¥': 1,
167
- '¤': 1,
168
- '§': 1,
169
- '¿': 1,
170
- '€': 2,
171
- };
172
-
173
- msgContent = msgContent.replace(/\u00a0/g, " ").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/\\n\\n/g, "\\n").replace(/\\n/g, " ");
174
- msgContent = msgContent.replace(/\r/g, " ").replace(/\f/g, " ");
175
-
176
- const matches = msgContent.split("");
177
- console.log('Test 1', msgContent, matches);
178
- let use7bit = true;
179
- let length7bit = 0;
180
- let length16bit = 0;
181
- let parts = {
182
- sms_count: 1,
183
- chars_left: 160,
184
- };
185
-
186
- matches.forEach( (char) => {
187
- if (use7bit && charset7bit[char] === undefined) {
188
- use7bit = false;
189
- }
190
-
191
- if (use7bit) {
192
- length7bit += charset7bit[char];
193
- }
194
-
195
- length16bit += 1;
196
- });
197
-
198
- if (use7bit) {
199
- parts = smsCount(length7bit, false);
200
- } else {
201
- parts = smsCount(length16bit, true);
202
- }
203
-
204
- if (typeof settings.getCount === 'function') {
205
- settings.getCount.call(this, parts);
206
- }
207
- };
208
-
209
- let smsCount = (chars, enc16) => {
210
- let charactersLeft = 0;
211
- let smsCharCounter = 0;
212
-
213
- if (enc16 === false && chars <= 160) {
214
- charactersLeft = 160 - chars;
215
- return {
216
- sms_count: 1,
217
- chars_left: charactersLeft,
218
- chars,
219
- charset: false,
220
- };
221
- }
222
-
223
- if (enc16 === true && chars <= 70) {
224
- charactersLeft = 70 - chars;
225
- return {
226
- sms_count: 1,
227
- chars_left: charactersLeft,
228
- chars,
229
- charset: "Unicode charset",
230
- };
231
- }
232
-
233
- if (enc16 === false) {
234
- smsCharCounter = Math.ceil(chars / 153);
235
- charactersLeft = (smsCount * 153) - chars;
236
- return {
237
- sms_count: smsCharCounter,
238
- chars_left: charactersLeft,
239
- chars,
240
- charset: false,
241
- };
242
- }
243
-
244
- smsCharCounter = Math.ceil(chars / 67);
245
- charactersLeft = (smsCharCounter * 67) - chars;
246
- return {
247
- sms_count: smsCharCounter,
248
- chars_left: charactersLeft,
249
- chars,
250
- charset: "Unicode charset",
251
- };
252
- };
253
-
254
- function _camp1(s) {
255
- try {
256
- return i18n.dgettext("camp1", s) !== '' ? this.i18n.dgettext("camp1", s) : s;
257
- } catch (err) {
258
- console.log('i18n Error', err.message);
259
- return s;
260
- }
261
- }
262
-
263
- /**
264
- * returns no of char an SMS contains in
265
- * messaging of campaign based on ascii and
266
- * non-ascii characters.
267
- * @param message
268
- * @returns
269
- */
270
- function smsCharCount(message) {
271
- // const that = this;
272
- let msgcount = 1;
273
- let countLbl = 0;
274
- const props = {
275
- chars_left: 160,
276
- };
277
-
278
- smsCounter({
279
- getCount: (parts) => {
280
- props.chars_left = parts.chars_left;
281
- props.total_chars = parts.chars;
282
- props.charset = parts.charset;
283
- msgcount = parts.sms_count;
284
- countLbl = parts.chars;
285
- if (parts.charset !== false) {
286
- countLbl = `${parts.chars} ${_camp1("Unicode")}`;
287
- }
288
- },
289
- }, message);
290
- return [countLbl, msgcount, props];
291
- }
292
-
293
- // function escapeRegex(text) {
294
- // return text.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&").replace(/\s/g, "\\s+").replace(/'|"/g, "(?:'|\")");
295
- // }
296
-
297
- export function checkUnicode(str, msg) {
298
- const non_unicode = {'@': 1, '$': 1, "\n":1, "\r":1, '_': 1, ' ': 1, '!': 1, '"': 1, '#': 1, '%': 1, '&': 1, "'":1, '(': 1, ')': 1, '*': 1, '+': 1, ',': 1, '-': 1, '.': 1, '/': 1, '0': 1, '1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, '7': 1, '8': 1, '9': 1, ':': 1, ';': 1, '<': 1, '=': 1, '>': 1, '?': 1, '¡': 1, 'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1, 'F': 1, 'G': 1, 'H': 1, 'I': 1, 'J': 1, 'K': 1, 'L': 1, 'M': 1, 'N': 1, 'O': 1, 'P': 1, 'Q': 1, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 1, 'W': 1, 'X': 1, 'Y': 1, 'Z': 1, 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1, 'h': 1, 'i': 1, 'j': 1, 'k': 1, 'l': 1, 'm': 1, 'n': 1, 'o': 1, 'p': 1, 'q': 1, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 1, 'w': 1, 'x': 1, 'y': 1, 'z': 1, "\f": 2, '^': 2, '{': 2, '}': 2, '\\': 2, '[': 2, '~': 2,']':2,'|':2,'è':1,'é':1,'ù':1,'ì':1,'ò':1,'Ç':1,'Ø':1,'ø':1,'Å':1,'å':1,'Δ':1,'Φ':1,'Γ':1,'Λ':1,'Ω':1,'Π':1,'Ψ':1,'Σ':1,'Θ':1,'Ξ':1,'Æ':1,'æ':1,'ß':1,'É':1,'Ä':1,'Ö':1,'Ñ':1,'Ü':1,'¿':1,'ä':1,'ö':1,'ñ':1,'ü':1,'à':1,'£': 1,'¥': 1,'¤': 1,'§': 1,'¿': 1,'€':2};
299
- var isUnicode=0;
300
- msg = typeof msg !== 'undefined' ? msg : "This message contains Unicode Characters. Do you want to proceed?";
301
-
302
- str = str.replace(/\u00a0/g, " ").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/\\n\\n/g, "\\n").replace(/\\n/g, " ");
303
- str = str.replace(/\r/g," ").replace(/\f/g," ");
304
- var matches = str.split("");
305
- for (var i in matches) {
306
- const char = matches[i];
307
- if (!non_unicode[char]) {
308
- isUnicode = 1;
309
- }
310
- }
311
- // if (isUnicode === 1) {
312
- // const r = confirm(msg);
313
- // if (r === true) {
314
- // return true;
315
- // }
316
- // return false;
317
- // }
318
- //
319
- return isUnicode === 1;
320
- }
321
-
322
- export function updateCharCount(boxVal) {
323
- // let tagHtml = "<span class='editor_tag' title='%desc%' contenteditable='false'>%name%</span>";
324
- // let tagText = "{{%name%}}";
325
-
326
- // let boxVal = html.replace(new RegExp(escapeRegex(tagHtml).replace("%name%", "(.*?)").replace(/%.*?%/g, "(?:.*?)"), "g"), tagText.replace(/%name%/g, "$1")).replace(/\<(p|div|br).*?\>/g, "\\n").replace(/\<.*?\>/g, "");
327
- // boxVal = "" + boxVal;
328
-
329
- // let unicodeFlag = 0;
330
- // let extraChars = 0;
331
- console.log('Box val', boxVal);
332
- let msgCount = 0;
333
- const lenCount = smsCharCount(boxVal);
334
- const len = lenCount[0];
335
- msgCount = lenCount[1];
336
- const charLeft = lenCount[2].chars_left;
337
- const totalChars = lenCount[2].total_chars;
338
- const charset = lenCount[2].charset;
339
- if (!charset && totalChars > 1000) {
340
- console.log("only 1000 character allowed in normal sms remaining character will be discarded");
341
- } else if (charset && totalChars > 500) {
342
- console.log("only 500 character allowed in unicode sms remaining character will be discarded");
343
- }
344
-
345
- // return `${len} characters = ${msgCount} Messages*, Characters left: ${charLeft}`;
346
- return {
347
- totalLength: len,
348
- msgCount,
349
- charLeft,
350
- };
351
- }