videomail-client 5.2.2 → 5.4.1

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.
@@ -0,0 +1,115 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>videomail-client examples</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+
7
+ <style type="text/css">
8
+ input[type='email'],
9
+ input[type='text'],
10
+ fieldset,
11
+ textarea,
12
+ .buttons,
13
+ #startOver {
14
+ margin: 1em 0;
15
+ display: block;
16
+ }
17
+ </style>
18
+ </head>
19
+ <body>
20
+ <h1>With CC and BCC</h1>
21
+ <p>Another form example with optional CC and BCC input fields for email addresses.</p>
22
+
23
+ <!-- Once you set the method to POST, then two request will be made internally. -->
24
+ <!-- The first one to the videomail server and the second one to the specified action -->
25
+ <form action="/contact" method="post" id="videomailFormWithCcAndBcc">
26
+ <input
27
+ name="from"
28
+ size="64"
29
+ type="email"
30
+ placeholder="Enter your email address"
31
+ required
32
+ />
33
+ <input
34
+ multiple
35
+ name="to"
36
+ size="64"
37
+ type="email"
38
+ placeholder="Enter recipient TO email addresss(es)"
39
+ />
40
+ <input
41
+ multiple
42
+ name="cc"
43
+ size="64"
44
+ type="email"
45
+ placeholder="Enter recipient CC email address(es)"
46
+ />
47
+ <input
48
+ multiple
49
+ name="bcc"
50
+ size="64"
51
+ type="email"
52
+ placeholder="Enter recipient BCC email address(es)"
53
+ />
54
+ <input
55
+ name="subject"
56
+ size="64"
57
+ type="text"
58
+ placeholder="Enter a subject"
59
+ required
60
+ />
61
+ <div id="videomail"></div>
62
+ <textarea
63
+ id="body"
64
+ name="body"
65
+ placeholder="Enter your message"
66
+ cols="40"
67
+ rows="4"
68
+ required
69
+ ></textarea>
70
+ </form>
71
+
72
+ <!-- Placed outside the form by intention to ensure code works with that scenario as well -->
73
+ <input type="button" value="Submit" disabled />
74
+
75
+ <div id="viewVideo" style="display: none">
76
+ <h2 class="subject"></h2>
77
+ <h3 class="status"></h3>
78
+ <p class="body"></p>
79
+ <video class="replay"></video>
80
+ <button id="startOver">Start over</button>
81
+ </div>
82
+
83
+ <script src="/js/videomail-client.js"></script>
84
+ <script>
85
+ var videomailClient = new VideomailClient({
86
+ verbose: true,
87
+ video: { limitSeconds: 120, width: 320, countdown: false },
88
+ selectors: {
89
+ submitButtonSelector: 'body input[value="Submit"]',
90
+ formId: 'videomailFormWithCcAndBcc'
91
+ }
92
+ })
93
+
94
+ var startOverButton = document.getElementById('startOver')
95
+
96
+ var onSubmitted = function (videomail, response) {
97
+ var statusHeader = document.querySelector('h3.status')
98
+
99
+ // status has been generated on server side, see gulp task 'connect'
100
+ statusHeader.innerHTML = response.status
101
+
102
+ this.replay(videomail, 'viewVideo')
103
+
104
+ startOverButton.onclick = this.startOver
105
+ }
106
+
107
+ videomailClient.on(
108
+ videomailClient.events.SUBMITTED,
109
+ onSubmitted.bind(videomailClient)
110
+ )
111
+
112
+ videomailClient.show()
113
+ </script>
114
+ </body>
115
+ </html>
package/src/js/options.js CHANGED
@@ -135,6 +135,8 @@ export default {
135
135
  defaults: {
136
136
  from: null, // define default FROM email address
137
137
  to: null, // define default TO email address
138
+ cc: null, // define default CC email address
139
+ bcc: null, // define default BCC email address
138
140
  subject: null, // define default subject line
139
141
  body: null // define default body content
140
142
  },
@@ -222,49 +222,8 @@ const Container = function (options) {
222
222
  hidden(containerElement, true)
223
223
  }
224
224
 
225
- // fixes https://github.com/binarykitchen/videomail-client/issues/71
226
- function trimEmail(email) {
227
- return email.replace(/(^[,\s]+)|([,\s]+$)/g, '')
228
- }
229
-
230
225
  function submitVideomail(formData, method, cb) {
231
- const FORM_FIELDS = {
232
- subject: options.selectors.subjectInputName,
233
- from: options.selectors.fromInputName,
234
- to: options.selectors.toInputName,
235
- cc: options.selectors.ccInputName,
236
- bcc: options.selectors.bccInputName,
237
- body: options.selectors.bodyInputName,
238
- key: options.selectors.keyInputName,
239
- parentKey: options.selectors.parentKeyInputName,
240
- sendCopy: options.selectors.sendCopyInputName
241
- }
242
-
243
- const videomailFormData = {}
244
-
245
- Object.keys(FORM_FIELDS).forEach(function (key) {
246
- const formFieldValue = FORM_FIELDS[key]
247
-
248
- if (formFieldValue in formData) {
249
- videomailFormData[key] = formData[formFieldValue]
250
- }
251
- })
252
-
253
- if (videomailFormData.from) {
254
- videomailFormData.from = trimEmail(videomailFormData.from)
255
- }
256
-
257
- if (videomailFormData.to) {
258
- videomailFormData.to = trimEmail(videomailFormData.to)
259
- }
260
-
261
- if (videomailFormData.cc) {
262
- videomailFormData.cc = trimEmail(videomailFormData.cc)
263
- }
264
-
265
- if (videomailFormData.bcc) {
266
- videomailFormData.bcc = trimEmail(videomailFormData.bcc)
267
- }
226
+ const videomailFormData = form.transformFormData(formData)
268
227
 
269
228
  // when method is undefined, treat it as a post
270
229
  if (isPost(method) || !method) {
@@ -610,7 +569,53 @@ const Container = function (options) {
610
569
  invalidInput.value +
611
570
  '"'
612
571
  } else {
613
- whyInvalid = 'Form input(s() are invalid'
572
+ whyInvalid = 'Form input(s) are invalid'
573
+ }
574
+ }
575
+
576
+ if (valid) {
577
+ // If CC and/or BCC exist, validate one more time to ensure at least
578
+ // one recipient is given
579
+ const recipients = form.getRecipients()
580
+
581
+ const toIsConfigured = 'to' in recipients
582
+ const ccIsConfigured = 'cc' in recipients
583
+ const bccIsConfigured = 'bcc' in recipients
584
+
585
+ const hasTo = recipients.to?.length > 0
586
+ const hasCc = recipients.cc?.length > 0
587
+ const hasBcc = recipients.bcc?.length > 0
588
+
589
+ if (toIsConfigured) {
590
+ if (!hasTo) {
591
+ if (ccIsConfigured && bccIsConfigured) {
592
+ if (!hasCc && !hasBcc) {
593
+ valid = false
594
+ }
595
+ } else if (ccIsConfigured) {
596
+ if (!hasCc) {
597
+ valid = false
598
+ }
599
+ } else if (bccIsConfigured) {
600
+ if (!hasBcc) {
601
+ valid = false
602
+ }
603
+ } else {
604
+ whyInvalid = 'Please configure the form to have at least one recipient.'
605
+ }
606
+ }
607
+ } else if (ccIsConfigured) {
608
+ if (!hasCc) {
609
+ if (bccIsConfigured) {
610
+ if (!hasBcc) {
611
+ valid = false
612
+ }
613
+ }
614
+ }
615
+ }
616
+
617
+ if (!valid) {
618
+ whyInvalid = 'Please enter at least one recipient.'
614
619
  }
615
620
  }
616
621
  } else {
@@ -7,6 +7,11 @@ import Events from '../events'
7
7
  import EventEmitter from '../util/eventEmitter'
8
8
  import VideomailError from '../util/videomailError'
9
9
 
10
+ // fixes https://github.com/binarykitchen/videomail-client/issues/71
11
+ function trimEmail(email) {
12
+ return email.replace(/(^[,\s]+)|([,\s]+$)/g, '')
13
+ }
14
+
10
15
  const Form = function (container, formElement, options) {
11
16
  EventEmitter.call(this, options, 'Form')
12
17
 
@@ -18,6 +23,68 @@ const Form = function (container, formElement, options) {
18
23
  return getFormData(formElement, { includeDisabled: true })
19
24
  }
20
25
 
26
+ this.transformFormData = function (formData) {
27
+ const FORM_FIELDS = {
28
+ subject: options.selectors.subjectInputName,
29
+ from: options.selectors.fromInputName,
30
+ to: options.selectors.toInputName,
31
+ cc: options.selectors.ccInputName,
32
+ bcc: options.selectors.bccInputName,
33
+ body: options.selectors.bodyInputName,
34
+ key: options.selectors.keyInputName,
35
+ parentKey: options.selectors.parentKeyInputName,
36
+ sendCopy: options.selectors.sendCopyInputName
37
+ }
38
+
39
+ const transformedFormData = {}
40
+
41
+ Object.keys(FORM_FIELDS).forEach(function (key) {
42
+ const formFieldValue = FORM_FIELDS[key]
43
+
44
+ if (formFieldValue in formData) {
45
+ transformedFormData[key] = formData[formFieldValue]
46
+ }
47
+ })
48
+
49
+ if (transformedFormData.from) {
50
+ transformedFormData.from = trimEmail(transformedFormData.from)
51
+ }
52
+
53
+ if (transformedFormData.to) {
54
+ transformedFormData.to = trimEmail(transformedFormData.to)
55
+ }
56
+
57
+ if (transformedFormData.cc) {
58
+ transformedFormData.cc = trimEmail(transformedFormData.cc)
59
+ }
60
+
61
+ if (transformedFormData.bcc) {
62
+ transformedFormData.bcc = trimEmail(transformedFormData.bcc)
63
+ }
64
+
65
+ return transformedFormData
66
+ }
67
+
68
+ this.getRecipients = function () {
69
+ const videomailFormData = this.transformFormData(getData())
70
+
71
+ const recipients = {}
72
+
73
+ if ('to' in videomailFormData) {
74
+ recipients.to = videomailFormData.to
75
+ }
76
+
77
+ if ('cc' in videomailFormData) {
78
+ recipients.cc = videomailFormData.cc
79
+ }
80
+
81
+ if ('bcc' in videomailFormData) {
82
+ recipients.bcc = videomailFormData.bcc
83
+ }
84
+
85
+ return recipients
86
+ }
87
+
21
88
  this.loadVideomail = function (videomail) {
22
89
  const limit = formElement.elements.length
23
90
 
@@ -1,39 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>videomail-client examples</title>
5
- <meta name="viewport" content="width=device-width,initial-scale=1" />
6
- </head>
7
- <body>
8
- <h1>BETA! Include time control to ensure video frames are in perfect order</h1>
9
- <div id="videomail"></div>
10
- <script src="/js/videomail-client.js"></script>
11
- <script>
12
- var videomailClient = new VideomailClient({
13
- verbose: true,
14
- enableAutoPause: false,
15
- disableSubmit: true,
16
- audio: {
17
- enabled: true,
18
- switch: true
19
- },
20
- image: {
21
- quality: 0.5
22
- },
23
- video: {
24
- limitSeconds: 120,
25
- countdown: false,
26
- width: 640,
27
- timeControl: true
28
- },
29
- text: {
30
- buttons: {
31
- preview: 'Stop'
32
- }
33
- }
34
- })
35
-
36
- videomailClient.show()
37
- </script>
38
- </body>
39
- </html>