• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / c5f3d7b4-ee0c-44dd-8229-fb0a50cc276f

pending completion
c5f3d7b4-ee0c-44dd-8229-fb0a50cc276f

Pull #2987

circleci

Amri Toufali
add ESLint plugin for camelCase lint
Pull Request #2987: MNTOR-1171: Code Splitting

282 of 1663 branches covered (16.96%)

Branch coverage included in aggregate %.

12 of 12 new or added lines in 9 files covered. (100.0%)

959 of 4511 relevant lines covered (21.26%)

3.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/client/js/partials/settings.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
const settingsPartial = document.querySelector("[data-partial='settings']")
×
6

7
function init () {
8
  document.body.addEventListener('email-added', handleEvent)
×
9
}
10

11
function handleEvent (e) {
12
  switch (true) {
×
13
    case e.type === 'email-added':
14
      document.querySelector('dialog[data-partial="addEmail"]')
×
15
        .addEventListener('close', () => {
16
          window.location.reload()
×
17
        }, { once: true })
18
      break
×
19
  }
20
}
21

22
const settingsAlertOptionsInputs = document.getElementsByClassName('js-settings-alert-options-input')
×
23
if (settingsAlertOptionsInputs?.length) {
×
24
  for (const inputElement of settingsAlertOptionsInputs) {
×
25
    inputElement.addEventListener('change', async event => {
×
26
      try {
×
27
        const communicationOption = event.target.getAttribute('data-alert-option')
×
28
        const csrfToken = document
×
29
          .querySelector('.js-settings[data-csrf-token]')
30
          .getAttribute('data-csrf-token')
31

32
        const response = await fetch('/api/v1/user/update-comm-option', {
×
33
          headers: {
34
            'Content-Type': 'application/json',
35
            'x-csrf-token': csrfToken
36
          },
37
          mode: 'same-origin',
38
          method: 'POST',
39
          body: JSON.stringify({ communicationOption })
40
        })
41

42
        if (response && response.redirected === true) {
×
43
          throw response.error
×
44
        } else {
45
          window.gtag('event', 'changed_email_preference', { action: 'click', page_location: location.href, result: 'success' })
×
46
        }
47
      } catch (err) {
48
        window.gtag('event', 'changed_email_preference', { action: 'click', page_location: location.href, result: 'fail' })
×
49
        throw new Error(`Updating communication option failed: ${err}`)
×
50
      }
51
      event.preventDefault()
×
52
      return false
×
53
    })
54
  }
55
}
56

57
const settingsRemoveEmailButtons = document.getElementsByClassName('js-remove-email-button')
×
58
if (settingsRemoveEmailButtons?.length) {
×
59
  for (const removeEmailButton of settingsRemoveEmailButtons) {
×
60
    removeEmailButton.addEventListener('click', async event => {
×
61
      try {
×
62
        const subscriberId = event.target.getAttribute('data-subscriber-id')
×
63
        const emailId = event.target.getAttribute('data-email-id')
×
64
        const csrfToken = document
×
65
          .querySelector('.js-settings[data-csrf-token]')
66
          .getAttribute('data-csrf-token')
67

68
        const response = await fetch('/api/v1/user/remove-email', {
×
69
          headers: {
70
            'Content-Type': 'application/json',
71
            'x-csrf-token': csrfToken
72
          },
73
          mode: 'same-origin',
74
          method: 'POST',
75
          body: JSON.stringify({ emailId, subscriberId })
76
        })
77

78
        if (response && response.redirected === true) {
×
79
          return window.location.reload(true)
×
80
        }
81

82
        window.gtag('event', 'removed_email', { action: 'click', page_location: location.href })
×
83
      } catch (err) {
84
        console.error(`Error: ${err}`)
×
85
      }
86
    })
87
  }
88
}
89

90
const settingsResendEmailLinks = document.getElementsByClassName('js-settings-resend-email')
×
91
if (settingsResendEmailLinks?.length) {
×
92
  for (const resendEmailLink of settingsResendEmailLinks) {
×
93
    resendEmailLink.addEventListener('click', async event => {
×
94
      try {
×
95
        const emailId = event.target.getAttribute('data-email-id')
×
96
        const csrfToken = document
×
97
          .querySelector('.js-settings[data-csrf-token]')
98
          .getAttribute('data-csrf-token')
99

100
        const response = await fetch('/api/v1/user/resend-email', {
×
101
          headers: {
102
            'Content-Type': 'application/json',
103
            'x-csrf-token': csrfToken,
104
            Accept: 'text/html' // set to request localized response
105
          },
106
          mode: 'same-origin',
107
          method: 'POST',
108
          body: JSON.stringify({ emailId })
109
        })
110

111
        if (!response.ok) {
×
112
          // TODO: localize error messages
113
          const toast = document.createElement('toast-alert')
×
114
          toast.textContent = `Re-sending verification email failed. ${response.statusText}`
×
115
          document.body.append(toast)
×
116
          window.gtag('event', 'resend_email', { action: 'click', page_location: location.href, result: 'success' })
×
117
        }
118

119
        if (response?.redirected) {
×
120
          throw response.error
×
121
        }
122
      } catch (err) {
123
        window.gtag('event', 'resend_email', { action: 'click', page_location: location.href, result: 'fail' })
×
124
        throw new Error(`Re-sending verification email failed. ${err}`)
×
125
      }
126
      event.preventDefault()
×
127
      return false
×
128
    })
129
  }
130
}
131

132
if (settingsPartial) init()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc